Class: Emites::Resources::Webhook

Inherits:
Base
  • Object
show all
Defined in:
lib/emites/resources/webhook.rb

Overview

A wrapper to Emites webhooks API

API

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/webhooks.html

Examples:

Listing all webhooks:

client = Emites.client("MY_SECRET_TOKEN")
client.webhooks.list

Creating an webhook:

client = Emites.client("MY_SECRET_TOKEN")
client.webhooks.create({name: "My Fake Web Hook", url: "http://web.hook")

See Also:

Instance Attribute Summary

Attributes inherited from Base

#http

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Hooks

#notify

Constructor Details

This class inherits a constructor from Emites::Resources::Base

Instance Method Details

#create(params) ⇒ Emites::Entities::Webhook

Creates an Webhook

API

Method: POST /api/v1/webhooks

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/webhooks.html#criacao

Parameters:

  • params (Hash)

    a hash with Webhook attributes

Returns:



75
76
77
78
79
# File 'lib/emites/resources/webhook.rb', line 75

def create(params)
  http.post("/webhooks", { body: params }) do |response|
    respond_with_entity(response)
  end
end

#destroy(id) ⇒ Boolean

Deletes an Webhook by it’s id. Returns true</true> if deletion performed well, otherwise, returns <tt>false.

API

Method: DELETE /api/v1/webhooks/:id

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/webhooks.html#remocao

Parameters:

  • id (Integer)

    the Wehook id

Returns:

  • (Boolean)

    whether deletion was performed or not



60
61
62
63
64
# File 'lib/emites/resources/webhook.rb', line 60

def destroy(id)
  http.delete("/webhooks/#{id}") do |response|
    response.code == 204
  end
end

#listArray

Lists all Webhooks related to the account

API

Method: GET /api/v1/webhooks

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/webhooks.html#listagem

Returns:

  • (Array)

    an array of Webhook



28
29
30
31
32
# File 'lib/emites/resources/webhook.rb', line 28

def list
  http.get("/webhooks") do |response|
    respond_with_collection(response)
  end
end

#update(id, params) ⇒ Array

Updates an Webhook identified by id

API

Method: PUT /api/v1/webhooks/:id

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/webhooks.html#atualizacao

Parameters:

  • id (Integer)

    the webhook id

  • params (Hash)

    a hash with new data

Returns:

  • (Array)

    an array of Webhook



44
45
46
47
48
# File 'lib/emites/resources/webhook.rb', line 44

def update(id, params)
  http.put("/webhooks/#{id}", { body: params }) do |response|
    respond_with_entity(response)
  end
end