Skip to content

Commit

Permalink
feat(analytics): Add analytics resources (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivannovosad authored Nov 21, 2023
1 parent 9df5ad6 commit 789297a
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 0 deletions.
63 changes: 63 additions & 0 deletions gross_revenue.go
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
}
63 changes: 63 additions & 0 deletions invoiced_usage.go
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
}
62 changes: 62 additions & 0 deletions mrr.go
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
}
66 changes: 66 additions & 0 deletions outstanding_invoice.go
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
}

0 comments on commit 789297a

Please sign in to comment.