diff --git a/Gemfile.lock b/Gemfile.lock index 4b2ce34..b13d32f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/lib/lago-ruby-client.rb b/lib/lago-ruby-client.rb index d2ba5de..33b4904 100644 --- a/lib/lago-ruby-client.rb +++ b/lib/lago-ruby-client.rb @@ -20,9 +20,13 @@ require 'lago/api/resources/customer' require 'lago/api/resources/event' require 'lago/api/resources/fee' +require 'lago/api/resources/gross_revenue' require 'lago/api/resources/group' require 'lago/api/resources/invoice' +require 'lago/api/resources/invoiced_usage' +require 'lago/api/resources/mrr' require 'lago/api/resources/organization' +require 'lago/api/resources/outstanding_invoice' require 'lago/api/resources/plan' require 'lago/api/resources/subscription' require 'lago/api/resources/tax' diff --git a/lib/lago/api/resources/gross_revenue.rb b/lib/lago/api/resources/gross_revenue.rb new file mode 100644 index 0000000..c02403d --- /dev/null +++ b/lib/lago/api/resources/gross_revenue.rb @@ -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 diff --git a/lib/lago/api/resources/invoiced_usage.rb b/lib/lago/api/resources/invoiced_usage.rb new file mode 100644 index 0000000..87c31ed --- /dev/null +++ b/lib/lago/api/resources/invoiced_usage.rb @@ -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 diff --git a/lib/lago/api/resources/mrr.rb b/lib/lago/api/resources/mrr.rb new file mode 100644 index 0000000..fb60888 --- /dev/null +++ b/lib/lago/api/resources/mrr.rb @@ -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 diff --git a/lib/lago/api/resources/outstanding_invoice.rb b/lib/lago/api/resources/outstanding_invoice.rb new file mode 100644 index 0000000..9d4ce6b --- /dev/null +++ b/lib/lago/api/resources/outstanding_invoice.rb @@ -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 diff --git a/spec/fixtures/api/gross_revenue_index.json b/spec/fixtures/api/gross_revenue_index.json new file mode 100644 index 0000000..2ff7696 --- /dev/null +++ b/spec/fixtures/api/gross_revenue_index.json @@ -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" + } + ] +} diff --git a/spec/fixtures/api/invoiced_usage_index.json b/spec/fixtures/api/invoiced_usage_index.json new file mode 100644 index 0000000..c878bcd --- /dev/null +++ b/spec/fixtures/api/invoiced_usage_index.json @@ -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" + } + ] +} diff --git a/spec/fixtures/api/mrr_index.json b/spec/fixtures/api/mrr_index.json new file mode 100644 index 0000000..a71f369 --- /dev/null +++ b/spec/fixtures/api/mrr_index.json @@ -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" + } + ] +} diff --git a/spec/fixtures/api/outstanding_invoice_index.json b/spec/fixtures/api/outstanding_invoice_index.json new file mode 100644 index 0000000..fd809fd --- /dev/null +++ b/spec/fixtures/api/outstanding_invoice_index.json @@ -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" + } + ] +} diff --git a/spec/lago/api/resources/gross_revenue_spec.rb b/spec/lago/api/resources/gross_revenue_spec.rb new file mode 100644 index 0000000..81f9fab --- /dev/null +++ b/spec/lago/api/resources/gross_revenue_spec.rb @@ -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 diff --git a/spec/lago/api/resources/invoiced_usage_spec.rb b/spec/lago/api/resources/invoiced_usage_spec.rb new file mode 100644 index 0000000..101eb95 --- /dev/null +++ b/spec/lago/api/resources/invoiced_usage_spec.rb @@ -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 diff --git a/spec/lago/api/resources/mrr_spec.rb b/spec/lago/api/resources/mrr_spec.rb new file mode 100644 index 0000000..19909c1 --- /dev/null +++ b/spec/lago/api/resources/mrr_spec.rb @@ -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 diff --git a/spec/lago/api/resources/outstanding_invoice_spec.rb b/spec/lago/api/resources/outstanding_invoice_spec.rb new file mode 100644 index 0000000..50ad702 --- /dev/null +++ b/spec/lago/api/resources/outstanding_invoice_spec.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Lago::Api::Resources::OutstandingInvoice 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(:outstanding_invoices_response) { load_fixture('outstanding_invoice_index') } + + context 'when there is no options' do + before do + stub_request(:get, 'https://api.getlago.com/api/v1/analytics/outstanding_invoices') + .to_return(body: outstanding_invoices_response, status: 200) + end + + it 'returns gross revenue' do + response = resource.get_all + + expect(response['outstanding_invoices'].first['currency']).to eq('EUR') + expect(response['outstanding_invoices'].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/outstanding_invoices?currency=EUR') + .to_return(body: outstanding_invoices_response, status: 200) + end + + it 'returns gross revenue' do + response = resource.get_all({ currency: 'EUR' }) + + expect(response['outstanding_invoices'].first['currency']).to eq('EUR') + expect(response['outstanding_invoices'].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/outstanding_invoices') + .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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 98d5952..17f128b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,9 +16,13 @@ require 'lago/api/resources/customer' require 'lago/api/resources/event' require 'lago/api/resources/fee' +require 'lago/api/resources/gross_revenue' require 'lago/api/resources/group' require 'lago/api/resources/invoice' +require 'lago/api/resources/invoiced_usage' +require 'lago/api/resources/mrr' require 'lago/api/resources/organization' +require 'lago/api/resources/outstanding_invoice' require 'lago/api/resources/plan' require 'lago/api/resources/subscription' require 'lago/api/resources/tax'