class Trello::Webhook

A webhook is a URL called each time a specified model is updated

@!attribute [r] id

@return [String]

@!attribute [r] description

@return [String]

@!attribute [r] id_model

@return [String] A 24-character hex string

@!attribute [r] callback_url

@return [String]

@!attribute [r] active

@return [Boolean]

Public Class Methods

create(options) click to toggle source

Create a new webhook and save it to Trello.

@param [Hash] options

@option options [String] :description (optional) A string with a length from 0 to 16384 @option options [String] :callback_url (required) A valid URL that is

reachable with a HEAD request

@option options [String] :id_model (required) id of the model that should be hooked

@raise [Trello::Error] if the Webhook could not be created.

@return [Trello::Webhook]

# File lib/trello/webhook.rb, line 41
def create(options)
  client.create(:webhook,
      'description' => options[:description],
      'idModel'     => options[:id_model],
      'callbackURL' => options[:callback_url])
end
find(id, params = {}) click to toggle source

Find a specific webhook by its ID.

@raise [Trello::Error] if a Webhook with the given ID can't be found. @return [Trello::Webhook] the Webhook with the given ID.

# File lib/trello/webhook.rb, line 25
def find(id, params = {})
  client.find(:webhook, id, params)
end

Public Instance Methods

activated?() click to toggle source

Check if the webhook is activated

@return [Boolean]

# File lib/trello/webhook.rb, line 99
def activated?
  active
end
delete() click to toggle source

Delete this webhook

@return [String] the JSON response from the Trello API

# File lib/trello/webhook.rb, line 92
def delete
  client.delete("/webhooks/#{id}")
end
save() click to toggle source

Save the webhook.

@raise [Trello::Error] if the Webhook could not be saved.

@return [String] the JSON representation of the saved webhook.

# File lib/trello/webhook.rb, line 64
def save
  # If we have an id, just update our fields.
  return update! if id

  from_response client.post("/webhooks", {
    description: description,
    idModel: id_model,
    callbackURL: callback_url
  })
end
update!() click to toggle source

Update the webhook.

@raise [Trello::Error] if the Webhook could not be saved.

@return [String] the JSON representation of the updated webhook.

# File lib/trello/webhook.rb, line 80
def update!
  client.put("/webhooks/#{id}", {
    description: description,
    idModel: id_model,
    callbackURL: callback_url,
    active: active
  })
end
update_fields(fields) click to toggle source

@return [Trello::Webhook] self

# File lib/trello/webhook.rb, line 50
def update_fields(fields)
  attributes[:id]              = fields['id'] || attributes[:id]
  attributes[:description]     = fields['description'] || fields[:description] || attributes[:description]
  attributes[:id_model]        = fields['idModel'] || fields[:id_model] || attributes[:id_model]
  attributes[:callback_url]    = fields['callbackURL'] || fields[:callback_url] || attributes[:callback_url]
  attributes[:active]          = fields['active'] if fields.has_key?('active')
  self
end