Sha256: 171f5329dd0e3d24021d25f855f1db51bb3bc9066e0915886d7c11c4997bf648

Contents?: true

Size: 822 Bytes

Versions: 4

Compression:

Stored size: 822 Bytes

Contents

module Moip2
  class WebhooksApi
    attr_reader :client

    def initialize(client)
      @client = client
    end

    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

    private

    def base_path
      "/v2/webhooks"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
moip2-1.3.1 lib/moip2/webhooks_api.rb
moip2-1.2.1 lib/moip2/webhooks_api.rb
moip2-1.2.0 lib/moip2/webhooks_api.rb
moip2-1.1.0 lib/moip2/webhooks_api.rb