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

#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



25
26
27
28
29
30
# File 'lib/lago/api/resources/event.rb', line 25

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

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

#create(params) ⇒ Object



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

def create(params)
  uri = URI("#{client.base_ingest_api_url}#{api_resource}")
  connection = Lago::Api::Connection.new(client.api_key, uri)

  payload = whitelist_params(params)
  response = connection.post(payload, uri)[root_name]

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

#estimate_fees(params) ⇒ Object



32
33
34
35
36
37
# File 'lib/lago/api/resources/event.rb', line 32

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



51
52
53
54
55
# File 'lib/lago/api/resources/event.rb', line 51

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

#whitelist_estimate_params(params) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/lago/api/resources/event.rb', line 57

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

#whitelist_params(params) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/lago/api/resources/event.rb', line 39

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