Class: Lago::Api::Resources::Event

Inherits:
Base
  • Object
show all
Defined in:
lib/lago/api/resources/event.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



7
8
9
# File 'lib/lago/api/resources/event.rb', line 7

def api_resource
  'events'
end

#batch_create(params) ⇒ Object



15
16
17
18
19
20
# File 'lib/lago/api/resources/event.rb', line 15

def batch_create(params)
  uri = URI("#{client.base_api_url}#{api_resource}/batch")

  payload = whitelist_batch_params(params)
  connection.post(payload, uri)
end

#estimate_fees(params) ⇒ Object



22
23
24
25
26
27
# File 'lib/lago/api/resources/event.rb', line 22

def estimate_fees(params)
  uri = URI("#{client.base_api_url}#{api_resource}/estimate_fees")

  payload = whitelist_estimate_params(params)
  connection.post(payload, uri)
end

#root_nameObject



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

def root_name
  'event'
end

#whitelist_batch_params(params) ⇒ Object



42
43
44
45
46
# File 'lib/lago/api/resources/event.rb', line 42

def whitelist_batch_params(params)
  {
    events: params[:events],
  }
end

#whitelist_estimate_params(params) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/lago/api/resources/event.rb', line 48

def whitelist_estimate_params(params)
  {
    root_name => {
      code: params[:code],
      external_customer_id: params[:external_customer_id],
      external_subscription_id: params[:external_subscription_id],
      properties: params[:properties],
    }.compact,
  }
end

#whitelist_params(params) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lago/api/resources/event.rb', line 29

def whitelist_params(params)
  {
    root_name => {
      transaction_id: params[:transaction_id],
      external_customer_id: params[:external_customer_id],
      code: params[:code],
      timestamp: params[:timestamp],
      external_subscription_id: params[:external_subscription_id],
      properties: params[:properties],
    }.compact,
  }
end