Class: Moip2::WebhooksApi

Inherits:
Object
  • Object
show all
Defined in:
lib/moip2/webhooks_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ WebhooksApi



5
6
7
# File 'lib/moip2/webhooks_api.rb', line 5

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/moip2/webhooks_api.rb', line 3

def client
  @client
end

Instance Method Details

#find_all(limit: nil, offset: nil, resource_id: nil, event: nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/moip2/webhooks_api.rb', line 9

def find_all(limit: nil, offset: nil, resource_id: nil, event: nil)
  # `URI.encode...` will accept nil params, but they will pollute the URI
  params = {
    limit: limit,
    offset: offset,
    resourceId: resource_id,
    event: event,
  }.reject { |_, value| value.nil? }

  query_string = URI.encode_www_form(params)
  path = "#{base_path}?#{query_string}"
  response = client.get(path)

  # We need to transform raw JSON in Webhooks objects
  response.webhooks.map! { |webhooks| Resource::Webhooks.new client, webhooks }
  Resource::Webhooks.new client, response
end