-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(analytics): Add analytics resources (#144)
- Loading branch information
1 parent
9df5ad6
commit 789297a
Showing
4 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package lago | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
) | ||
|
||
type GrossRevenueRequest struct { | ||
client *Client | ||
} | ||
|
||
type GrossRevenueListInput struct { | ||
AmountCurrency string `json:"currency,omitempty,string"` | ||
ExternalCustomerId string `json:"external_customer_id,omitempty,string"` | ||
Months int `json:"months,omitempty,string"` | ||
} | ||
|
||
type GrossRevenueResult struct { | ||
GrossRevenue *GrossRevenue `json:"gross_revenue,omitempty"` | ||
GrossRevenues []GrossRevenue `json:"gross_revenues,omitempty"` | ||
} | ||
|
||
type GrossRevenue struct { | ||
Month string `json:"month,omitempty"` | ||
AmountCents int `json:"amount_cents,omitempty"` | ||
AmountCurrency Currency `json:"currency,omitempty"` | ||
} | ||
|
||
func (c *Client) GrossRevenue() *GrossRevenueRequest { | ||
return &GrossRevenueRequest{ | ||
client: c, | ||
} | ||
} | ||
|
||
func (adr *GrossRevenueRequest) GetList(ctx context.Context, GrossRevenueListInput *GrossRevenueListInput) (*GrossRevenueResult, *Error) { | ||
jsonQueryparams, err := json.Marshal(GrossRevenueListInput) | ||
if err != nil { | ||
return nil, &Error{Err: err} | ||
} | ||
|
||
queryParams := make(map[string]string) | ||
if err = json.Unmarshal(jsonQueryparams, &queryParams); err != nil { | ||
return nil, &Error{Err: err} | ||
} | ||
|
||
clientRequest := &ClientRequest{ | ||
Path: "analytics/gross_revenue", | ||
QueryParams: queryParams, | ||
Result: &GrossRevenueResult{}, | ||
} | ||
|
||
result, clientErr := adr.client.Get(ctx, clientRequest) | ||
if clientErr != nil { | ||
return nil, clientErr | ||
} | ||
|
||
GrossRevenueResult, ok := result.(*GrossRevenueResult) | ||
if !ok { | ||
return nil, &ErrorTypeAssert | ||
} | ||
|
||
return GrossRevenueResult, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package lago | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
) | ||
|
||
type InvoicedUsageRequest struct { | ||
client *Client | ||
} | ||
|
||
type InvoicedUsageListInput struct { | ||
AmountCurrency string `json:"currency,omitempty,string"` | ||
Months int `json:"months,omitempty,string"` | ||
} | ||
|
||
type InvoicedUsageResult struct { | ||
InvoicedUsage *InvoicedUsage `json:"invoiced_usage,omitempty"` | ||
InvoicedUsages []InvoicedUsage `json:"invoiced_usages,omitempty"` | ||
} | ||
|
||
type InvoicedUsage struct { | ||
Month string `json:"month,omitempty"` | ||
Code string `json:"code,omitempty"` | ||
AmountCents int `json:"amount_cents,omitempty"` | ||
AmountCurrency Currency `json:"currency,omitempty"` | ||
} | ||
|
||
func (c *Client) InvoicedUsage() *InvoicedUsageRequest { | ||
return &InvoicedUsageRequest{ | ||
client: c, | ||
} | ||
} | ||
|
||
func (adr *InvoicedUsageRequest) GetList(ctx context.Context, InvoicedUsageListInput *InvoicedUsageListInput) (*InvoicedUsageResult, *Error) { | ||
jsonQueryparams, err := json.Marshal(InvoicedUsageListInput) | ||
if err != nil { | ||
return nil, &Error{Err: err} | ||
} | ||
|
||
queryParams := make(map[string]string) | ||
if err = json.Unmarshal(jsonQueryparams, &queryParams); err != nil { | ||
return nil, &Error{Err: err} | ||
} | ||
|
||
clientRequest := &ClientRequest{ | ||
Path: "analytics/invoiced_usage", | ||
QueryParams: queryParams, | ||
Result: &InvoicedUsageResult{}, | ||
} | ||
|
||
result, clientErr := adr.client.Get(ctx, clientRequest) | ||
if clientErr != nil { | ||
return nil, clientErr | ||
} | ||
|
||
InvoicedUsageResult, ok := result.(*InvoicedUsageResult) | ||
if !ok { | ||
return nil, &ErrorTypeAssert | ||
} | ||
|
||
return InvoicedUsageResult, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package lago | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
) | ||
|
||
type MrrRequest struct { | ||
client *Client | ||
} | ||
|
||
type MrrListInput struct { | ||
AmountCurrency string `json:"currency,omitempty,string"` | ||
Months int `json:"months,omitempty,string"` | ||
} | ||
|
||
type MrrResult struct { | ||
Mrr *Mrr `json:"mrr,omitempty"` | ||
Mrrs []Mrr `json:"mrrs,omitempty"` | ||
} | ||
|
||
type Mrr struct { | ||
Month string `json:"month,omitempty"` | ||
AmountCents int `json:"amount_cents,omitempty"` | ||
AmountCurrency Currency `json:"currency,omitempty"` | ||
} | ||
|
||
func (c *Client) Mrr() *MrrRequest { | ||
return &MrrRequest{ | ||
client: c, | ||
} | ||
} | ||
|
||
func (adr *MrrRequest) GetList(ctx context.Context, MrrListInput *MrrListInput) (*MrrResult, *Error) { | ||
jsonQueryparams, err := json.Marshal(MrrListInput) | ||
if err != nil { | ||
return nil, &Error{Err: err} | ||
} | ||
|
||
queryParams := make(map[string]string) | ||
if err = json.Unmarshal(jsonQueryparams, &queryParams); err != nil { | ||
return nil, &Error{Err: err} | ||
} | ||
|
||
clientRequest := &ClientRequest{ | ||
Path: "analytics/mrr", | ||
QueryParams: queryParams, | ||
Result: &MrrResult{}, | ||
} | ||
|
||
result, clientErr := adr.client.Get(ctx, clientRequest) | ||
if clientErr != nil { | ||
return nil, clientErr | ||
} | ||
|
||
MrrResult, ok := result.(*MrrResult) | ||
if !ok { | ||
return nil, &ErrorTypeAssert | ||
} | ||
|
||
return MrrResult, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package lago | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
) | ||
|
||
type PaymentStatus string | ||
|
||
type OutstandingInvoiceRequest struct { | ||
client *Client | ||
} | ||
|
||
type OutstandingInvoiceListInput struct { | ||
AmountCurrency string `json:"currency,omitempty,string"` | ||
Months int `json:"months,omitempty,string"` | ||
} | ||
|
||
type OutstandingInvoiceResult struct { | ||
OutstandingInvoice *OutstandingInvoice `json:"outstanding_invoice,omitempty"` | ||
OutstandingInvoices []OutstandingInvoice `json:"outstanding_invoices,omitempty"` | ||
} | ||
|
||
type OutstandingInvoice struct { | ||
Month string `json:"month,omitempty"` | ||
PaymentStatus InvoicePaymentStatus `json:"payment_status,omitempty"` | ||
InvoicesCount int `json:"invoices_count,omitempty"` | ||
AmountCents int `json:"amount_cents,omitempty"` | ||
AmountCurrency Currency `json:"currency,omitempty"` | ||
} | ||
|
||
func (c *Client) OutstandingInvoice() *OutstandingInvoiceRequest { | ||
return &OutstandingInvoiceRequest{ | ||
client: c, | ||
} | ||
} | ||
|
||
func (adr *OutstandingInvoiceRequest) GetList(ctx context.Context, OutstandingInvoiceListInput *OutstandingInvoiceListInput) (*OutstandingInvoiceResult, *Error) { | ||
jsonQueryparams, err := json.Marshal(OutstandingInvoiceListInput) | ||
if err != nil { | ||
return nil, &Error{Err: err} | ||
} | ||
|
||
queryParams := make(map[string]string) | ||
if err = json.Unmarshal(jsonQueryparams, &queryParams); err != nil { | ||
return nil, &Error{Err: err} | ||
} | ||
|
||
clientRequest := &ClientRequest{ | ||
Path: "analytics/outstanding_invoices", | ||
QueryParams: queryParams, | ||
Result: &OutstandingInvoiceResult{}, | ||
} | ||
|
||
result, clientErr := adr.client.Get(ctx, clientRequest) | ||
if clientErr != nil { | ||
return nil, clientErr | ||
} | ||
|
||
OutstandingInvoiceResult, ok := result.(*OutstandingInvoiceResult) | ||
if !ok { | ||
return nil, &ErrorTypeAssert | ||
} | ||
|
||
return OutstandingInvoiceResult, nil | ||
} |