lago-ruby-client 0.15.1.pre.alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/lago/api/client.rb +79 -0
- data/lib/lago/api/connection.rb +109 -0
- data/lib/lago/api/http_error.rb +23 -0
- data/lib/lago/api/resources/add_on.rb +29 -0
- data/lib/lago/api/resources/applied_add_on.rb +28 -0
- data/lib/lago/api/resources/applied_coupon.rb +28 -0
- data/lib/lago/api/resources/base.rb +67 -0
- data/lib/lago/api/resources/billable_metric.rb +30 -0
- data/lib/lago/api/resources/coupon.rb +30 -0
- data/lib/lago/api/resources/customer.rb +59 -0
- data/lib/lago/api/resources/event.rb +55 -0
- data/lib/lago/api/resources/group.rb +24 -0
- data/lib/lago/api/resources/invoice.rb +32 -0
- data/lib/lago/api/resources/organization.rb +45 -0
- data/lib/lago/api/resources/plan.rb +49 -0
- data/lib/lago/api/resources/subscription.rb +30 -0
- data/lib/lago/api/resources/wallet.rb +30 -0
- data/lib/lago/api/resources/wallet_transaction.rb +27 -0
- data/lib/lago/version.rb +5 -0
- data/lib/lago-ruby-client.rb +26 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a85aba24c145cd3473895ebd058d026ac59651368ba36be71fc1ae4223224918
|
4
|
+
data.tar.gz: 2fe6bc15aa9a3b7c32ac4b8ba24158de1eeffeaaed68db2b04b87940e005dd2c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa379557b825d4d3dfebfadb56886084abdd9eddb488aa2b7d5108f0baaa32d2cbb706a7e6e7ac9e594ff30326a6c141b2188a4ddec461f7f0e0e65123b4542d
|
7
|
+
data.tar.gz: 7ab4e1b50482619e3cc7e9dbedb65678b2be3a114557100b287e40ac04eb6698b379cac4a678c87af036bf5228749a638933c65439b0c5bb26cc5cdb92d623d2
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
BASE_URL = 'https://api.getlago.com/'.freeze
|
6
|
+
API_PATH = 'api/v1/'.freeze
|
7
|
+
|
8
|
+
class Client
|
9
|
+
attr_reader :api_key, :api_url
|
10
|
+
|
11
|
+
def initialize(api_key: nil, api_url: nil)
|
12
|
+
@api_key = api_key
|
13
|
+
@api_url = api_url
|
14
|
+
end
|
15
|
+
|
16
|
+
def base_api_url
|
17
|
+
base_url = api_url.nil? ? Lago::Api::BASE_URL : api_url
|
18
|
+
|
19
|
+
URI.join(base_url, Lago::Api::API_PATH)
|
20
|
+
end
|
21
|
+
|
22
|
+
def customers
|
23
|
+
Lago::Api::Resources::Customer.new(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
def invoices
|
27
|
+
Lago::Api::Resources::Invoice.new(self)
|
28
|
+
end
|
29
|
+
|
30
|
+
def subscriptions
|
31
|
+
Lago::Api::Resources::Subscription.new(self)
|
32
|
+
end
|
33
|
+
|
34
|
+
def events
|
35
|
+
Lago::Api::Resources::Event.new(self)
|
36
|
+
end
|
37
|
+
|
38
|
+
def groups
|
39
|
+
Lago::Api::Resources::Group.new(self)
|
40
|
+
end
|
41
|
+
|
42
|
+
def applied_coupons
|
43
|
+
Lago::Api::Resources::AppliedCoupon.new(self)
|
44
|
+
end
|
45
|
+
|
46
|
+
def applied_add_ons
|
47
|
+
Lago::Api::Resources::AppliedAddOn.new(self)
|
48
|
+
end
|
49
|
+
|
50
|
+
def billable_metrics
|
51
|
+
Lago::Api::Resources::BillableMetric.new(self)
|
52
|
+
end
|
53
|
+
|
54
|
+
def plans
|
55
|
+
Lago::Api::Resources::Plan.new(self)
|
56
|
+
end
|
57
|
+
|
58
|
+
def coupons
|
59
|
+
Lago::Api::Resources::Coupon.new(self)
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_ons
|
63
|
+
Lago::Api::Resources::AddOn.new(self)
|
64
|
+
end
|
65
|
+
|
66
|
+
def organizations
|
67
|
+
Lago::Api::Resources::Organization.new(self)
|
68
|
+
end
|
69
|
+
|
70
|
+
def wallets
|
71
|
+
Lago::Api::Resources::Wallet.new(self)
|
72
|
+
end
|
73
|
+
|
74
|
+
def wallet_transactions
|
75
|
+
Lago::Api::Resources::WalletTransaction.new(self)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
class Connection
|
6
|
+
RESPONSE_SUCCESS_CODES = [200, 201, 202, 204].freeze
|
7
|
+
|
8
|
+
def initialize(api_key, uri)
|
9
|
+
@api_key = api_key
|
10
|
+
@uri = uri
|
11
|
+
end
|
12
|
+
|
13
|
+
def post(body, path = uri.path)
|
14
|
+
response = http_client.send_request(
|
15
|
+
'POST',
|
16
|
+
path,
|
17
|
+
prepare_payload(body),
|
18
|
+
headers
|
19
|
+
)
|
20
|
+
|
21
|
+
handle_response(response)
|
22
|
+
end
|
23
|
+
|
24
|
+
def put(path = uri.path, identifier:, body:)
|
25
|
+
uri_path = identifier.nil? ? path : "#{path}/#{identifier}"
|
26
|
+
response = http_client.send_request(
|
27
|
+
'PUT',
|
28
|
+
uri_path,
|
29
|
+
prepare_payload(body),
|
30
|
+
headers
|
31
|
+
)
|
32
|
+
|
33
|
+
handle_response(response)
|
34
|
+
end
|
35
|
+
|
36
|
+
def get(path = uri.path, identifier:)
|
37
|
+
uri_path = identifier.nil? ? path : "#{path}/#{identifier}"
|
38
|
+
response = http_client.send_request(
|
39
|
+
'GET',
|
40
|
+
uri_path,
|
41
|
+
prepare_payload(nil),
|
42
|
+
headers
|
43
|
+
)
|
44
|
+
|
45
|
+
handle_response(response)
|
46
|
+
end
|
47
|
+
|
48
|
+
def destroy(path = uri.path, identifier:)
|
49
|
+
uri_path = "#{path}/#{identifier}"
|
50
|
+
response = http_client.send_request(
|
51
|
+
'DELETE',
|
52
|
+
uri_path,
|
53
|
+
prepare_payload(nil),
|
54
|
+
headers
|
55
|
+
)
|
56
|
+
|
57
|
+
handle_response(response)
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_all(options, path = uri.path)
|
61
|
+
uri_path = options.empty? ? path : "#{path}?#{URI.encode_www_form(options)}"
|
62
|
+
|
63
|
+
response = http_client.send_request(
|
64
|
+
'GET',
|
65
|
+
uri_path,
|
66
|
+
prepare_payload(nil),
|
67
|
+
headers
|
68
|
+
)
|
69
|
+
|
70
|
+
handle_response(response)
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
attr_reader :api_key, :uri
|
76
|
+
|
77
|
+
def headers
|
78
|
+
{
|
79
|
+
'Authorization' => "Bearer #{api_key}",
|
80
|
+
'Content-Type' => 'application/json',
|
81
|
+
'User-Agent' => "Lago Ruby v#{Lago::VERSION}"
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
def handle_response(response)
|
86
|
+
raise_error(response) unless RESPONSE_SUCCESS_CODES.include?(response.code.to_i)
|
87
|
+
|
88
|
+
response.body.empty? ? true : JSON.parse(response.body)
|
89
|
+
end
|
90
|
+
|
91
|
+
def http_client
|
92
|
+
http_client = Net::HTTP.new(uri.hostname, uri.port)
|
93
|
+
http_client.use_ssl = true if uri.scheme == 'https'
|
94
|
+
|
95
|
+
http_client
|
96
|
+
end
|
97
|
+
|
98
|
+
def prepare_payload(payload)
|
99
|
+
return '' unless payload.respond_to?(:empty?)
|
100
|
+
|
101
|
+
payload.empty? ? '' : payload.to_json
|
102
|
+
end
|
103
|
+
|
104
|
+
def raise_error(response)
|
105
|
+
raise Lago::Api::HttpError.new(response.code.to_i, response.body, uri)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
class HttpError < StandardError
|
6
|
+
attr_reader :error_code, :error_body, :uri
|
7
|
+
|
8
|
+
def initialize(code, body, uri)
|
9
|
+
@error_code = code
|
10
|
+
@error_body = body
|
11
|
+
@uri = uri
|
12
|
+
end
|
13
|
+
|
14
|
+
def message
|
15
|
+
"HTTP #{error_code} - URI: #{uri}.\nError: #{error_body}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def json_message
|
19
|
+
JSON.parse(error_body)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class AddOn < Base
|
7
|
+
def api_resource
|
8
|
+
'add_ons'
|
9
|
+
end
|
10
|
+
|
11
|
+
def root_name
|
12
|
+
'add_on'
|
13
|
+
end
|
14
|
+
|
15
|
+
def whitelist_params(params)
|
16
|
+
{
|
17
|
+
root_name => {
|
18
|
+
name: params[:name],
|
19
|
+
code: params[:code],
|
20
|
+
description: params[:description],
|
21
|
+
amount_cents: params[:amount_cents],
|
22
|
+
amount_currency: params[:amount_currency]
|
23
|
+
}.compact
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class AppliedAddOn < Base
|
7
|
+
def api_resource
|
8
|
+
'applied_add_ons'
|
9
|
+
end
|
10
|
+
|
11
|
+
def root_name
|
12
|
+
'applied_add_on'
|
13
|
+
end
|
14
|
+
|
15
|
+
def whitelist_params(params)
|
16
|
+
{
|
17
|
+
root_name => {
|
18
|
+
external_customer_id: params[:external_customer_id],
|
19
|
+
add_on_code: params[:add_on_code],
|
20
|
+
amount_cents: params[:amount_cents],
|
21
|
+
amount_currency: params[:amount_currency]
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class AppliedCoupon < Base
|
7
|
+
def api_resource
|
8
|
+
'applied_coupons'
|
9
|
+
end
|
10
|
+
|
11
|
+
def root_name
|
12
|
+
'applied_coupon'
|
13
|
+
end
|
14
|
+
|
15
|
+
def whitelist_params(params)
|
16
|
+
{
|
17
|
+
root_name => {
|
18
|
+
external_customer_id: params[:external_customer_id],
|
19
|
+
coupon_code: params[:coupon_code],
|
20
|
+
amount_cents: params[:amount_cents],
|
21
|
+
amount_currency: params[:amount_currency]
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class Base
|
7
|
+
attr_reader :client
|
8
|
+
|
9
|
+
def initialize(client)
|
10
|
+
@client = client
|
11
|
+
end
|
12
|
+
|
13
|
+
def api_resource
|
14
|
+
raise NotImplementedError
|
15
|
+
end
|
16
|
+
|
17
|
+
def root_name
|
18
|
+
raise NotImplementedError
|
19
|
+
end
|
20
|
+
|
21
|
+
def whitelist_params(_params)
|
22
|
+
raise NotImplementedError
|
23
|
+
end
|
24
|
+
|
25
|
+
def create(params)
|
26
|
+
payload = whitelist_params(params)
|
27
|
+
response = connection.post(payload)[root_name]
|
28
|
+
|
29
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
30
|
+
end
|
31
|
+
|
32
|
+
def update(params, identifier = nil)
|
33
|
+
payload = whitelist_params(params)
|
34
|
+
response = connection.put(identifier: identifier, body: payload)[root_name]
|
35
|
+
|
36
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
37
|
+
end
|
38
|
+
|
39
|
+
def get(identifier)
|
40
|
+
response = connection.get(identifier: identifier)[root_name]
|
41
|
+
|
42
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
43
|
+
end
|
44
|
+
|
45
|
+
def destroy(identifier)
|
46
|
+
response = connection.destroy(identifier: identifier)[root_name]
|
47
|
+
|
48
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_all(options = {})
|
52
|
+
response = connection.get_all(options)
|
53
|
+
|
54
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def connection
|
60
|
+
uri = URI.join(client.base_api_url, api_resource)
|
61
|
+
|
62
|
+
Lago::Api::Connection.new(client.api_key, uri)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class BillableMetric < Base
|
7
|
+
def api_resource
|
8
|
+
'billable_metrics'
|
9
|
+
end
|
10
|
+
|
11
|
+
def root_name
|
12
|
+
'billable_metric'
|
13
|
+
end
|
14
|
+
|
15
|
+
def whitelist_params(params)
|
16
|
+
{
|
17
|
+
root_name => {
|
18
|
+
name: params[:name],
|
19
|
+
code: params[:code],
|
20
|
+
description: params[:description],
|
21
|
+
aggregation_type: params[:aggregation_type],
|
22
|
+
field_name: params[:field_name],
|
23
|
+
group: params[:group],
|
24
|
+
}.compact,
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class Coupon < Base
|
7
|
+
def api_resource
|
8
|
+
'coupons'
|
9
|
+
end
|
10
|
+
|
11
|
+
def root_name
|
12
|
+
'coupon'
|
13
|
+
end
|
14
|
+
|
15
|
+
def whitelist_params(params)
|
16
|
+
{
|
17
|
+
root_name => {
|
18
|
+
name: params[:name],
|
19
|
+
code: params[:code],
|
20
|
+
amount_cents: params[:amount_cents],
|
21
|
+
amount_currency: params[:amount_currency],
|
22
|
+
expiration: params[:expiration],
|
23
|
+
expiration_duration: params[:expiration_duration]
|
24
|
+
}.compact
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class Customer < Base
|
7
|
+
def api_resource
|
8
|
+
'customers'
|
9
|
+
end
|
10
|
+
|
11
|
+
def root_name
|
12
|
+
'customer'
|
13
|
+
end
|
14
|
+
|
15
|
+
def current_usage(external_customer_id, external_subscription_id)
|
16
|
+
uri = URI(
|
17
|
+
"#{client.base_api_url}#{api_resource}/#{external_customer_id}/current_usage?external_subscription_id=#{external_subscription_id}"
|
18
|
+
)
|
19
|
+
connection.get(uri, identifier: nil)
|
20
|
+
end
|
21
|
+
|
22
|
+
def whitelist_params(params)
|
23
|
+
result_hash = {
|
24
|
+
external_customer_id: params[:external_customer_id],
|
25
|
+
address_line1: params[:address_line1],
|
26
|
+
address_line2: params[:address_line2],
|
27
|
+
city: params[:city],
|
28
|
+
country: params[:country],
|
29
|
+
email: params[:email],
|
30
|
+
legal_name: params[:legal_name],
|
31
|
+
legal_number: params[:legal_number],
|
32
|
+
logo_url: params[:logo_url],
|
33
|
+
name: params[:name],
|
34
|
+
phone: params[:phone],
|
35
|
+
state: params[:state],
|
36
|
+
url: params[:url],
|
37
|
+
zipcode: params[:zipcode],
|
38
|
+
currency: params[:currency],
|
39
|
+
}
|
40
|
+
|
41
|
+
whitelist_billing_configuration(params[:billing_configuration]).tap do |config|
|
42
|
+
result_hash[:billing_configuration] = config unless config.empty?
|
43
|
+
end
|
44
|
+
|
45
|
+
{ root_name => result_hash }
|
46
|
+
end
|
47
|
+
|
48
|
+
def whitelist_billing_configuration(billing_params)
|
49
|
+
(billing_params || {}).slice(
|
50
|
+
:payment_provider,
|
51
|
+
:provider_customer_id,
|
52
|
+
:sync,
|
53
|
+
:vat_rate,
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class Event < Base
|
7
|
+
def api_resource
|
8
|
+
'events'
|
9
|
+
end
|
10
|
+
|
11
|
+
def root_name
|
12
|
+
'event'
|
13
|
+
end
|
14
|
+
|
15
|
+
def create(params)
|
16
|
+
payload = whitelist_params(params)
|
17
|
+
connection.post(payload)
|
18
|
+
end
|
19
|
+
|
20
|
+
def batch_create(params)
|
21
|
+
uri = URI("#{client.base_api_url}#{api_resource}/batch")
|
22
|
+
|
23
|
+
payload = whitelist_batch_params(params)
|
24
|
+
connection.post(payload, uri)
|
25
|
+
end
|
26
|
+
|
27
|
+
def whitelist_params(params)
|
28
|
+
{
|
29
|
+
root_name => {
|
30
|
+
transaction_id: params[:transaction_id],
|
31
|
+
external_customer_id: params[:external_customer_id],
|
32
|
+
code: params[:code],
|
33
|
+
timestamp: params[:timestamp],
|
34
|
+
external_subscription_id: params[:external_subscription_id],
|
35
|
+
properties: params[:properties]
|
36
|
+
}.compact
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def whitelist_batch_params(params)
|
41
|
+
{
|
42
|
+
root_name => {
|
43
|
+
transaction_id: params[:transaction_id],
|
44
|
+
external_customer_id: params[:external_customer_id],
|
45
|
+
code: params[:code],
|
46
|
+
timestamp: params[:timestamp],
|
47
|
+
external_subscription_ids: params[:external_subscription_ids],
|
48
|
+
properties: params[:properties]
|
49
|
+
}.compact
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class Group < Base
|
7
|
+
def api_resource
|
8
|
+
'groups'
|
9
|
+
end
|
10
|
+
|
11
|
+
def root_name
|
12
|
+
'group'
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_all(code, options = {})
|
16
|
+
path = "/api/v1/billable_metrics/#{code}/groups"
|
17
|
+
response = connection.get_all(options, path)
|
18
|
+
|
19
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class Invoice < Base
|
7
|
+
def api_resource
|
8
|
+
'invoices'
|
9
|
+
end
|
10
|
+
|
11
|
+
def root_name
|
12
|
+
'invoice'
|
13
|
+
end
|
14
|
+
|
15
|
+
def download(invoice_id)
|
16
|
+
path = "/api/v1/invoices/#{invoice_id}/download"
|
17
|
+
response = connection.post({}, path)
|
18
|
+
|
19
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
20
|
+
end
|
21
|
+
|
22
|
+
def whitelist_params(params)
|
23
|
+
{
|
24
|
+
root_name => {
|
25
|
+
status: params[:status]
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class Organization < Base
|
7
|
+
def api_resource
|
8
|
+
'organizations'
|
9
|
+
end
|
10
|
+
|
11
|
+
def root_name
|
12
|
+
'organization'
|
13
|
+
end
|
14
|
+
|
15
|
+
def whitelist_params(params)
|
16
|
+
result_hash = {
|
17
|
+
webhook_url: params[:webhook_url],
|
18
|
+
country: params[:country],
|
19
|
+
address_line1: params[:address_line1],
|
20
|
+
address_line2: params[:address_line2],
|
21
|
+
state: params[:state],
|
22
|
+
zipcode: params[:zipcode],
|
23
|
+
email: params[:email],
|
24
|
+
city: params[:city],
|
25
|
+
legal_name: params[:legal_name],
|
26
|
+
legal_number: params[:legal_number],
|
27
|
+
}.compact
|
28
|
+
|
29
|
+
whitelist_billing_configuration(params[:billing_configuration]).tap do |config|
|
30
|
+
result_hash[:billing_configuration] = config unless config.empty?
|
31
|
+
end
|
32
|
+
|
33
|
+
{ root_name => result_hash }
|
34
|
+
end
|
35
|
+
|
36
|
+
def whitelist_billing_configuration(billing_params)
|
37
|
+
(billing_params || {}).slice(
|
38
|
+
:invoice_footer,
|
39
|
+
:vat_rate,
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class Plan < Base
|
7
|
+
def api_resource
|
8
|
+
'plans'
|
9
|
+
end
|
10
|
+
|
11
|
+
def root_name
|
12
|
+
'plan'
|
13
|
+
end
|
14
|
+
|
15
|
+
def whitelist_params(params)
|
16
|
+
result_hash = {
|
17
|
+
name: params[:name],
|
18
|
+
code: params[:code],
|
19
|
+
interval: params[:interval],
|
20
|
+
description: params[:description],
|
21
|
+
amount_cents: params[:amount_cents],
|
22
|
+
amount_currency: params[:amount_currency],
|
23
|
+
trial_period: params[:trial_period],
|
24
|
+
pay_in_advance: params[:pay_in_advance],
|
25
|
+
bill_charges_monthly: params[:bill_charges_monthly],
|
26
|
+
}.compact
|
27
|
+
|
28
|
+
whitelist_charges(params[:charges]).tap do |charges|
|
29
|
+
result_hash[:charges] = charges unless charges.empty?
|
30
|
+
end
|
31
|
+
|
32
|
+
{ root_name => result_hash }
|
33
|
+
end
|
34
|
+
|
35
|
+
def whitelist_charges(charges)
|
36
|
+
processed_charges = []
|
37
|
+
|
38
|
+
charges.each do |c|
|
39
|
+
result = (c || {}).slice(:id, :billable_metric_id, :charge_model, :properties, :group_properties)
|
40
|
+
|
41
|
+
processed_charges << result unless result.empty?
|
42
|
+
end
|
43
|
+
|
44
|
+
processed_charges
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class Subscription < Base
|
7
|
+
def api_resource
|
8
|
+
'subscriptions'
|
9
|
+
end
|
10
|
+
|
11
|
+
def root_name
|
12
|
+
'subscription'
|
13
|
+
end
|
14
|
+
|
15
|
+
def whitelist_params(params)
|
16
|
+
{
|
17
|
+
root_name => {
|
18
|
+
external_customer_id: params[:external_customer_id],
|
19
|
+
plan_code: params[:plan_code],
|
20
|
+
name: params[:name],
|
21
|
+
external_id: params[:external_id],
|
22
|
+
billing_time: params[:billing_time],
|
23
|
+
subscription_date: params[:subscription_date],
|
24
|
+
}.compact
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class Wallet < Base
|
7
|
+
def api_resource
|
8
|
+
'wallets'
|
9
|
+
end
|
10
|
+
|
11
|
+
def root_name
|
12
|
+
'wallet'
|
13
|
+
end
|
14
|
+
|
15
|
+
def whitelist_params(params)
|
16
|
+
{
|
17
|
+
root_name => {
|
18
|
+
external_customer_id: params[:external_customer_id],
|
19
|
+
rate_amount: params[:rate_amount],
|
20
|
+
name: params[:name],
|
21
|
+
paid_credits: params[:paid_credits],
|
22
|
+
granted_credits: params[:granted_credits],
|
23
|
+
expiration_date: params[:expiration_date]
|
24
|
+
}.compact
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class WalletTransaction < Base
|
7
|
+
def api_resource
|
8
|
+
'wallet_transactions'
|
9
|
+
end
|
10
|
+
|
11
|
+
def root_name
|
12
|
+
'wallet_transactions'
|
13
|
+
end
|
14
|
+
|
15
|
+
def whitelist_params(params)
|
16
|
+
{
|
17
|
+
'wallet_transaction' => {
|
18
|
+
wallet_id: params[:wallet_id],
|
19
|
+
paid_credits: params[:paid_credits],
|
20
|
+
granted_credits: params[:granted_credits]
|
21
|
+
}.compact
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/lago/version.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
require 'lago/version'
|
8
|
+
require 'lago/api/client'
|
9
|
+
require 'lago/api/connection'
|
10
|
+
require 'lago/api/http_error'
|
11
|
+
|
12
|
+
require 'lago/api/resources/base'
|
13
|
+
require 'lago/api/resources/applied_coupon'
|
14
|
+
require 'lago/api/resources/applied_add_on'
|
15
|
+
require 'lago/api/resources/customer'
|
16
|
+
require 'lago/api/resources/invoice'
|
17
|
+
require 'lago/api/resources/event'
|
18
|
+
require 'lago/api/resources/group'
|
19
|
+
require 'lago/api/resources/subscription'
|
20
|
+
require 'lago/api/resources/billable_metric'
|
21
|
+
require 'lago/api/resources/plan'
|
22
|
+
require 'lago/api/resources/coupon'
|
23
|
+
require 'lago/api/resources/add_on'
|
24
|
+
require 'lago/api/resources/organization'
|
25
|
+
require 'lago/api/resources/wallet'
|
26
|
+
require 'lago/api/resources/wallet_transaction'
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lago-ruby-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.15.1.pre.alpha
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lovro Colic
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-11-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: debug
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: factory_bot
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '13.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '13.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.21'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.21'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- lovro@getlago.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- lib/lago-ruby-client.rb
|
105
|
+
- lib/lago/api/client.rb
|
106
|
+
- lib/lago/api/connection.rb
|
107
|
+
- lib/lago/api/http_error.rb
|
108
|
+
- lib/lago/api/resources/add_on.rb
|
109
|
+
- lib/lago/api/resources/applied_add_on.rb
|
110
|
+
- lib/lago/api/resources/applied_coupon.rb
|
111
|
+
- lib/lago/api/resources/base.rb
|
112
|
+
- lib/lago/api/resources/billable_metric.rb
|
113
|
+
- lib/lago/api/resources/coupon.rb
|
114
|
+
- lib/lago/api/resources/customer.rb
|
115
|
+
- lib/lago/api/resources/event.rb
|
116
|
+
- lib/lago/api/resources/group.rb
|
117
|
+
- lib/lago/api/resources/invoice.rb
|
118
|
+
- lib/lago/api/resources/organization.rb
|
119
|
+
- lib/lago/api/resources/plan.rb
|
120
|
+
- lib/lago/api/resources/subscription.rb
|
121
|
+
- lib/lago/api/resources/wallet.rb
|
122
|
+
- lib/lago/api/resources/wallet_transaction.rb
|
123
|
+
- lib/lago/version.rb
|
124
|
+
homepage: https://github.com/getlago/lago-ruby-client
|
125
|
+
licenses:
|
126
|
+
- AGPL-3.0
|
127
|
+
metadata:
|
128
|
+
homepage_uri: https://www.getlago.com/
|
129
|
+
source_code_uri: https://github.com/getlago/lago-ruby-client
|
130
|
+
documentation_uri: https://doc.getlago.com
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 1.3.1
|
145
|
+
requirements: []
|
146
|
+
rubygems_version: 3.2.15
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: Lago Rest API client
|
150
|
+
test_files: []
|