-
Notifications
You must be signed in to change notification settings - Fork 7
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 (#154)
- Loading branch information
1 parent
d1f8d71
commit fe3e1bd
Showing
15 changed files
with
379 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
lago-ruby-client (0.50.0.pre.beta) | ||
lago-ruby-client (0.51.0.pre.beta) | ||
jwt | ||
openssl | ||
|
||
|
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
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module Lago | ||
module Api | ||
module Resources | ||
class GrossRevenue < Base | ||
def api_resource | ||
'analytics/gross_revenue' | ||
end | ||
|
||
def root_name | ||
'gross_revenue' | ||
end | ||
end | ||
end | ||
end | ||
end |
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module Lago | ||
module Api | ||
module Resources | ||
class InvoicedUsage < Base | ||
def api_resource | ||
'analytics/invoiced_usage' | ||
end | ||
|
||
def root_name | ||
'invoiced_usage' | ||
end | ||
end | ||
end | ||
end | ||
end |
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module Lago | ||
module Api | ||
module Resources | ||
class Mrr < Base | ||
def api_resource | ||
'analytics/mrr' | ||
end | ||
|
||
def root_name | ||
'mrr' | ||
end | ||
end | ||
end | ||
end | ||
end |
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module Lago | ||
module Api | ||
module Resources | ||
class OutstandingInvoice < Base | ||
def api_resource | ||
'analytics/outstanding_invoices' | ||
end | ||
|
||
def root_name | ||
'outstanding_invoice' | ||
end | ||
end | ||
end | ||
end | ||
end |
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,14 @@ | ||
{ | ||
"gross_revenues": [ | ||
{ | ||
"month": "2023-11-01T00:00:00.000Z", | ||
"amount_cents": 100, | ||
"currency": "EUR" | ||
}, | ||
{ | ||
"month": "2023-12-01T00:00:00.000Z", | ||
"amount_cents": 200, | ||
"currency": "USD" | ||
} | ||
] | ||
} |
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,16 @@ | ||
{ | ||
"invoiced_usages": [ | ||
{ | ||
"month": "2023-11-01T00:00:00.000Z", | ||
"amount_cents": 100, | ||
"payment_status": "pending", | ||
"currency": "EUR" | ||
}, | ||
{ | ||
"month": "2023-12-01T00:00:00.000Z", | ||
"amount_cents": 200, | ||
"payment_status": "pending", | ||
"currency": "USD" | ||
} | ||
] | ||
} |
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,14 @@ | ||
{ | ||
"mrrs": [ | ||
{ | ||
"month": "2023-11-01T00:00:00.000Z", | ||
"amount_cents": 100, | ||
"currency": "EUR" | ||
}, | ||
{ | ||
"month": "2023-12-01T00:00:00.000Z", | ||
"amount_cents": 200, | ||
"currency": "USD" | ||
} | ||
] | ||
} |
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,18 @@ | ||
{ | ||
"outstanding_invoices": [ | ||
{ | ||
"month": "2023-11-01T00:00:00.000Z", | ||
"payment_status": "pending", | ||
"invoices_count": 10, | ||
"amount_cents": 100, | ||
"currency": "EUR" | ||
}, | ||
{ | ||
"month": "2023-12-01T00:00:00.000Z", | ||
"payment_status": "pending", | ||
"invoices_count": 7, | ||
"amount_cents": 200, | ||
"currency": "USD" | ||
} | ||
] | ||
} |
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,60 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Lago::Api::Resources::GrossRevenue do | ||
subject(:resource) { described_class.new(client) } | ||
|
||
let(:client) { Lago::Api::Client.new } | ||
|
||
let(:error_response) do | ||
{ | ||
'status' => 422, | ||
'error' => 'Unprocessable Entity', | ||
'message' => 'Validation error on the record', | ||
}.to_json | ||
end | ||
|
||
describe '#get_all' do | ||
let(:gross_revenues_response) { load_fixture('gross_revenue_index') } | ||
|
||
context 'when there is no options' do | ||
before do | ||
stub_request(:get, 'https://api.getlago.com/api/v1/analytics/gross_revenue') | ||
.to_return(body: gross_revenues_response, status: 200) | ||
end | ||
|
||
it 'returns gross revenue' do | ||
response = resource.get_all | ||
|
||
expect(response['gross_revenues'].first['currency']).to eq('EUR') | ||
expect(response['gross_revenues'].first['amount_cents']).to eq(100) | ||
end | ||
end | ||
|
||
context 'when options are present' do | ||
before do | ||
stub_request(:get, 'https://api.getlago.com/api/v1/analytics/gross_revenue?currency=EUR') | ||
.to_return(body: gross_revenues_response, status: 200) | ||
end | ||
|
||
it 'returns gross revenue' do | ||
response = resource.get_all({ currency: 'EUR' }) | ||
|
||
expect(response['gross_revenues'].first['currency']).to eq('EUR') | ||
expect(response['gross_revenues'].first['amount_cents']).to eq(100) | ||
end | ||
end | ||
|
||
context 'when there is an issue' do | ||
before do | ||
stub_request(:get, 'https://api.getlago.com/api/v1/analytics/gross_revenue') | ||
.to_return(body: error_response, status: 422) | ||
end | ||
|
||
it 'raises an error' do | ||
expect { resource.get_all }.to raise_error Lago::Api::HttpError | ||
end | ||
end | ||
end | ||
end |
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,60 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Lago::Api::Resources::InvoicedUsage do | ||
subject(:resource) { described_class.new(client) } | ||
|
||
let(:client) { Lago::Api::Client.new } | ||
|
||
let(:error_response) do | ||
{ | ||
'status' => 422, | ||
'error' => 'Unprocessable Entity', | ||
'message' => 'Validation error on the record', | ||
}.to_json | ||
end | ||
|
||
describe '#get_all' do | ||
let(:invoiced_usages_response) { load_fixture('invoiced_usage_index') } | ||
|
||
context 'when there is no options' do | ||
before do | ||
stub_request(:get, 'https://api.getlago.com/api/v1/analytics/invoiced_usage') | ||
.to_return(body: invoiced_usages_response, status: 200) | ||
end | ||
|
||
it 'returns gross revenue' do | ||
response = resource.get_all | ||
|
||
expect(response['invoiced_usages'].first['currency']).to eq('EUR') | ||
expect(response['invoiced_usages'].first['amount_cents']).to eq(100) | ||
end | ||
end | ||
|
||
context 'when options are present' do | ||
before do | ||
stub_request(:get, 'https://api.getlago.com/api/v1/analytics/invoiced_usage?currency=EUR') | ||
.to_return(body: invoiced_usages_response, status: 200) | ||
end | ||
|
||
it 'returns gross revenue' do | ||
response = resource.get_all({ currency: 'EUR' }) | ||
|
||
expect(response['invoiced_usages'].first['currency']).to eq('EUR') | ||
expect(response['invoiced_usages'].first['amount_cents']).to eq(100) | ||
end | ||
end | ||
|
||
context 'when there is an issue' do | ||
before do | ||
stub_request(:get, 'https://api.getlago.com/api/v1/analytics/invoiced_usage') | ||
.to_return(body: error_response, status: 422) | ||
end | ||
|
||
it 'raises an error' do | ||
expect { resource.get_all }.to raise_error Lago::Api::HttpError | ||
end | ||
end | ||
end | ||
end |
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,60 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Lago::Api::Resources::Mrr do | ||
subject(:resource) { described_class.new(client) } | ||
|
||
let(:client) { Lago::Api::Client.new } | ||
|
||
let(:error_response) do | ||
{ | ||
'status' => 422, | ||
'error' => 'Unprocessable Entity', | ||
'message' => 'Validation error on the record', | ||
}.to_json | ||
end | ||
|
||
describe '#get_all' do | ||
let(:mrrs_response) { load_fixture('mrr_index') } | ||
|
||
context 'when there is no options' do | ||
before do | ||
stub_request(:get, 'https://api.getlago.com/api/v1/analytics/mrr') | ||
.to_return(body: mrrs_response, status: 200) | ||
end | ||
|
||
it 'returns gross revenue' do | ||
response = resource.get_all | ||
|
||
expect(response['mrrs'].first['currency']).to eq('EUR') | ||
expect(response['mrrs'].first['amount_cents']).to eq(100) | ||
end | ||
end | ||
|
||
context 'when options are present' do | ||
before do | ||
stub_request(:get, 'https://api.getlago.com/api/v1/analytics/mrr?currency=EUR') | ||
.to_return(body: mrrs_response, status: 200) | ||
end | ||
|
||
it 'returns gross revenue' do | ||
response = resource.get_all({ currency: 'EUR' }) | ||
|
||
expect(response['mrrs'].first['currency']).to eq('EUR') | ||
expect(response['mrrs'].first['amount_cents']).to eq(100) | ||
end | ||
end | ||
|
||
context 'when there is an issue' do | ||
before do | ||
stub_request(:get, 'https://api.getlago.com/api/v1/analytics/mrr') | ||
.to_return(body: error_response, status: 422) | ||
end | ||
|
||
it 'raises an error' do | ||
expect { resource.get_all }.to raise_error Lago::Api::HttpError | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.