class Monzo::Webhook
Public: Webhooks allow your application to receive real-time,
push notification of events in an account.
Attributes
account_id[R]
id[R]
url[R]
Public Class Methods
all(account_id)
click to toggle source
Public: Find all webhooks for a given account id.
account_id
- The account id to list registered webhooks for.
Returns an Array of Monzo::Webhook
instances.
# File lib/monzo/webhook.rb, line 42 def self.all(account_id) client = Monzo.client response = client.get("/webhooks", :account_id => account_id) parsed_response = JSON.parse(response.body, :symbolize_names => true) parsed_response[:webhooks].map do |item| Monzo::Webhook.new(item) end end
create(account_id, url)
click to toggle source
Public: Create a webhook for the given account id.
account_id
- The account to receive event notifications for. url - The URL Monzo
will send notifications to.
Returns an instance of Monzo::Webhook
.
# File lib/monzo/webhook.rb, line 24 def self.create(account_id, url) client = Monzo.client data = { "account_id" => account_id, "url" => url } response = client.post("/webhooks", data, {}) parsed_response = JSON.parse(response.body, :symbolize_names => true) Monzo::Webhook.new(parsed_response[:webhook]) end
delete(webhook_id)
click to toggle source
Public: Delete a webhook.
webhook_id - The webhook id to be deleted.
Returns an empty Hash.
# File lib/monzo/webhook.rb, line 59 def self.delete(webhook_id) client = Monzo.client response = client.delete("/webhooks/#{webhook_id}") JSON.parse(response.body, :symbolize_names => true) end
new(params)
click to toggle source
Public: Initialize a Webhook
.
params - A Hash of webhook parameters.
# File lib/monzo/webhook.rb, line 12 def initialize(params) @id = params[:id] @account_id = params[:account_id] @url = params[:url] end