Class: Lago::Api::Resources::Order

Inherits:
Base
  • Object
show all
Defined in:
lib/lago/api/resources/order.rb

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#create, #destroy, #get, #get_all, #initialize, #update

Constructor Details

This class inherits a constructor from Lago::Api::Resources::Base

Instance Method Details

#api_resourceObject



11
12
13
# File 'lib/lago/api/resources/order.rb', line 11

def api_resource
  'orders'
end

#execute(order_id, params = {}) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/lago/api/resources/order.rb', line 19

def execute(order_id, params = {})
  path = "/api/v1/orders/#{order_id}/execute"
  payload = whitelist_params(params)
  response = connection.post(payload, path)[root_name]

  JSON.parse(response.to_json, object_class: OpenStruct)
end

#root_nameObject



15
16
17
# File 'lib/lago/api/resources/order.rb', line 15

def root_name
  'order'
end

#whitelist_params(params) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/lago/api/resources/order.rb', line 27

def whitelist_params(params)
  result = {
    execution_mode: params[:execution_mode],
  }.compact

  return {} if result.empty?

  { root_name => result }
end