Class: Monzo::Webhook

Inherits:
Object
  • Object
show all
Defined in:
lib/monzo/webhook.rb

Overview

Public: Webhooks allow your application to receive real-time,

push notification of events in an account.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Webhook

Public: Initialize a Webhook.

params - A Hash of webhook parameters.



12
13
14
15
16
# File 'lib/monzo/webhook.rb', line 12

def initialize(params)
  @id = params[:id]
  @account_id = params[:account_id]
  @url = params[:url]
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



7
8
9
# File 'lib/monzo/webhook.rb', line 7

def 
  @account_id
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/monzo/webhook.rb', line 7

def id
  @id
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/monzo/webhook.rb', line 7

def url
  @url
end

Class Method Details

.all(account_id) ⇒ Object

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.



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/monzo/webhook.rb', line 42

def self.all()
  client = Monzo.client

  response = client.get("/webhooks", :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) ⇒ Object

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.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/monzo/webhook.rb', line 24

def self.create(, url)
  client = Monzo.client

  data = {
    "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) ⇒ Object

Public: Delete a webhook.

webhook_id - The webhook id to be deleted.

Returns an empty Hash.



59
60
61
62
63
64
# 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