Class: Lago::Api::Resources::Nested
- Inherits:
-
Base
- Object
- Base
- Lago::Api::Resources::Nested
show all
- Defined in:
- lib/lago/api/resources/nested.rb
Instance Attribute Summary
Attributes inherited from Base
#client
Instance Method Summary
collapse
Methods inherited from Base
#api_resource, #root_name, #whitelist_params
Constructor Details
#initialize(client) ⇒ Nested
Returns a new instance of Nested.
9
10
11
12
13
14
15
16
17
|
# File 'lib/lago/api/resources/nested.rb', line 9
def initialize(client)
super(client)
@connection = Lago::Api::Connection.new(
client.api_key,
client.base_api_url,
max_retries: client.max_retries,
retry_on_rate_limit: client.retry_on_rate_limit,
)
end
|
Instance Method Details
#create(*parent_ids, params) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/lago/api/resources/nested.rb', line 19
def create(*parent_ids, params)
path = api_resource(*parent_ids)
payload = whitelist_create_params(params)
response = connection.post(payload, path)[root_name]
JSON.parse(response.to_json, object_class: OpenStruct)
end
|
#destroy(*parent_ids, resource_id) ⇒ Object
42
43
44
45
46
47
|
# File 'lib/lago/api/resources/nested.rb', line 42
def destroy(*parent_ids, resource_id)
path = api_resource(*parent_ids)
response = connection.destroy(path, identifier: resource_id)[root_name]
JSON.parse(response.to_json, object_class: OpenStruct)
end
|
#get(*parent_ids, resource_id) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/lago/api/resources/nested.rb', line 27
def get(*parent_ids, resource_id)
path = api_resource(*parent_ids)
response = connection.get(path, identifier: resource_id)[root_name]
JSON.parse(response.to_json, object_class: OpenStruct)
end
|
#get_all(*parent_ids, **options) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/lago/api/resources/nested.rb', line 49
def get_all(*parent_ids, **options)
path = api_resource(*parent_ids)
response = connection.get_all(options, path)
JSON.parse(response.to_json, object_class: OpenStruct)
end
|
#update(*parent_ids, resource_id, params) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/lago/api/resources/nested.rb', line 34
def update(*parent_ids, resource_id, params)
path = api_resource(*parent_ids)
payload = whitelist_update_params(params)
response = connection.put(path, identifier: resource_id, body: payload)[root_name]
JSON.parse(response.to_json, object_class: OpenStruct)
end
|