module MangoApi::Hooks

Provides API method delegates concerning the Hook entity

Public Class Methods

all() click to toggle source

Retrieves all hooks.

Allowed FilterRequest params:

  • page

  • per_page

  • sort_field and sort_direction

@return [Array] Hook entity objects

# File lib/mangopay/api/service/hooks.rb, line 64
def all
  uri = provide_uri(:get_hooks)
  results = HttpClient.get(uri)
  parse_results results
end
create(hook, id_key = nil) click to toggle source

Creates a new hook entity.

Hook properties:

  • Required

    • event_type

    • url

  • Optional

    • tag

@param hook [Hook] model object of the hook to be created @param id_key [String] idempotency key for future response replication @return [Hook] the newly-created Hook entity object

# File lib/mangopay/api/service/hooks.rb, line 23
def create(hook, id_key = nil)
  uri = provide_uri(:create_hook)
  response = HttpClient.post(uri, hook, id_key)
  parse response
end
get(id) click to toggle source

Retrieves a hook entity.

@param id [String] ID of the hook to retrieve @return [Hook] the requested Hook entity object

# File lib/mangopay/api/service/hooks.rb, line 50
def get(id)
  uri = provide_uri(:get_hook, id)
  response = HttpClient.get(uri)
  parse response
end
update(hook) click to toggle source

Updates the hook entity identifiable by the provided Hook object's ID.

Hook optional properties:

  • tag

  • status

  • url

@param hook [Hook] hook object with corresponding ID and updated data @return [Hook] the updated Hook entity object

# File lib/mangopay/api/service/hooks.rb, line 40
def update(hook)
  uri = provide_uri(:update_hook, hook.id)
  response = HttpClient.put(uri, hook)
  parse response
end

Private Class Methods

parse(response) click to toggle source

Parses a JSON-originating hash into the corresponding Hook entity object.

@param response [Hash] JSON-originating data hash @return [Hook] corresponding Hook entity object

# File lib/mangopay/api/service/hooks.rb, line 88
def parse(response)
  MangoModel::Hook.new.dejsonify response
end
parse_results(results) click to toggle source

Parses an array of JSON-originating hashes into the corresponding Hook entity objects.

@param results [Array] JSON-originating data hashes @return [Array] parsed Hook entity objects

# File lib/mangopay/api/service/hooks.rb, line 77
def parse_results(results)
  results.collect do |entity|
    parse entity
  end
end