Class: Trello::Webhook

Inherits:
BasicData show all
Defined in:
lib/trello/webhook.rb

Overview

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

Instance Attribute Summary collapse

Attributes inherited from BasicData

#client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BasicData

#==, client, #initialize, many, one, parse, parse_many, path_name, #refresh!, register_attributes, save

Methods included from JsonUtils

included

Constructor Details

This class inherits a constructor from Trello::BasicData

Instance Attribute Details

#activeBoolean (readonly)

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/trello/webhook.rb', line 14

class Webhook < BasicData
  register_attributes :id, :description, :id_model, :callback_url, :active,
    readonly: [ :id ]
  validates_presence_of :id, :id_model, :callback_url
  validates_length_of   :description,  in: 1..16384

  class << self
    # 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.
    def find(id, params = {})
      client.find(:webhook, id, params)
    end

    # 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]
    def create(options)
      client.create(:webhook,
          'description' => options[:description],
          'idModel'     => options[:id_model],
          'callbackURL' => options[:callback_url])
    end
  end

  # @return [Trello::Webhook] self
  def update_fields(fields)
    attributes[:id]              = fields['id']
    attributes[:description]     = fields['description'] || fields[:description]
    attributes[:id_model]        = fields['idModel'] || fields[:id_model]
    attributes[:callback_url]    = fields['callbackURL'] || fields[:callback_url]
    attributes[:active]          = fields['active']
    self
  end

  # Save the webhook.
  #
  # @raise  [Trello::Error] if the Webhook could not be saved.
  #
  # @return [String] the JSON representation of the saved webhook.
  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 the webhook.
  #
  # @raise  [Trello::Error] if the Webhook could not be saved.
  #
  # @return [String] the JSON representation of the updated webhook.
  def update!
    client.put("/webhooks/#{id}", {
      description: description,
      idModel: id_model,
      callbackURL: callback_url,
      active: active
    })
  end

  # Delete this webhook
  #
  # @return [String] the JSON response from the Trello API
  def delete
    client.delete("/webhooks/#{id}")
  end

  # Check if the webhook is activated
  #
  # @return [Boolean]
  def activated?
    active
  end
end

#callback_urlString (readonly)

Returns:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/trello/webhook.rb', line 14

class Webhook < BasicData
  register_attributes :id, :description, :id_model, :callback_url, :active,
    readonly: [ :id ]
  validates_presence_of :id, :id_model, :callback_url
  validates_length_of   :description,  in: 1..16384

  class << self
    # 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.
    def find(id, params = {})
      client.find(:webhook, id, params)
    end

    # 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]
    def create(options)
      client.create(:webhook,
          'description' => options[:description],
          'idModel'     => options[:id_model],
          'callbackURL' => options[:callback_url])
    end
  end

  # @return [Trello::Webhook] self
  def update_fields(fields)
    attributes[:id]              = fields['id']
    attributes[:description]     = fields['description'] || fields[:description]
    attributes[:id_model]        = fields['idModel'] || fields[:id_model]
    attributes[:callback_url]    = fields['callbackURL'] || fields[:callback_url]
    attributes[:active]          = fields['active']
    self
  end

  # Save the webhook.
  #
  # @raise  [Trello::Error] if the Webhook could not be saved.
  #
  # @return [String] the JSON representation of the saved webhook.
  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 the webhook.
  #
  # @raise  [Trello::Error] if the Webhook could not be saved.
  #
  # @return [String] the JSON representation of the updated webhook.
  def update!
    client.put("/webhooks/#{id}", {
      description: description,
      idModel: id_model,
      callbackURL: callback_url,
      active: active
    })
  end

  # Delete this webhook
  #
  # @return [String] the JSON response from the Trello API
  def delete
    client.delete("/webhooks/#{id}")
  end

  # Check if the webhook is activated
  #
  # @return [Boolean]
  def activated?
    active
  end
end

#descriptionString (readonly)

Returns:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/trello/webhook.rb', line 14

class Webhook < BasicData
  register_attributes :id, :description, :id_model, :callback_url, :active,
    readonly: [ :id ]
  validates_presence_of :id, :id_model, :callback_url
  validates_length_of   :description,  in: 1..16384

  class << self
    # 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.
    def find(id, params = {})
      client.find(:webhook, id, params)
    end

    # 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]
    def create(options)
      client.create(:webhook,
          'description' => options[:description],
          'idModel'     => options[:id_model],
          'callbackURL' => options[:callback_url])
    end
  end

  # @return [Trello::Webhook] self
  def update_fields(fields)
    attributes[:id]              = fields['id']
    attributes[:description]     = fields['description'] || fields[:description]
    attributes[:id_model]        = fields['idModel'] || fields[:id_model]
    attributes[:callback_url]    = fields['callbackURL'] || fields[:callback_url]
    attributes[:active]          = fields['active']
    self
  end

  # Save the webhook.
  #
  # @raise  [Trello::Error] if the Webhook could not be saved.
  #
  # @return [String] the JSON representation of the saved webhook.
  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 the webhook.
  #
  # @raise  [Trello::Error] if the Webhook could not be saved.
  #
  # @return [String] the JSON representation of the updated webhook.
  def update!
    client.put("/webhooks/#{id}", {
      description: description,
      idModel: id_model,
      callbackURL: callback_url,
      active: active
    })
  end

  # Delete this webhook
  #
  # @return [String] the JSON response from the Trello API
  def delete
    client.delete("/webhooks/#{id}")
  end

  # Check if the webhook is activated
  #
  # @return [Boolean]
  def activated?
    active
  end
end

#idString (readonly)

Returns:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/trello/webhook.rb', line 14

class Webhook < BasicData
  register_attributes :id, :description, :id_model, :callback_url, :active,
    readonly: [ :id ]
  validates_presence_of :id, :id_model, :callback_url
  validates_length_of   :description,  in: 1..16384

  class << self
    # 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.
    def find(id, params = {})
      client.find(:webhook, id, params)
    end

    # 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]
    def create(options)
      client.create(:webhook,
          'description' => options[:description],
          'idModel'     => options[:id_model],
          'callbackURL' => options[:callback_url])
    end
  end

  # @return [Trello::Webhook] self
  def update_fields(fields)
    attributes[:id]              = fields['id']
    attributes[:description]     = fields['description'] || fields[:description]
    attributes[:id_model]        = fields['idModel'] || fields[:id_model]
    attributes[:callback_url]    = fields['callbackURL'] || fields[:callback_url]
    attributes[:active]          = fields['active']
    self
  end

  # Save the webhook.
  #
  # @raise  [Trello::Error] if the Webhook could not be saved.
  #
  # @return [String] the JSON representation of the saved webhook.
  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 the webhook.
  #
  # @raise  [Trello::Error] if the Webhook could not be saved.
  #
  # @return [String] the JSON representation of the updated webhook.
  def update!
    client.put("/webhooks/#{id}", {
      description: description,
      idModel: id_model,
      callbackURL: callback_url,
      active: active
    })
  end

  # Delete this webhook
  #
  # @return [String] the JSON response from the Trello API
  def delete
    client.delete("/webhooks/#{id}")
  end

  # Check if the webhook is activated
  #
  # @return [Boolean]
  def activated?
    active
  end
end

#id_modelString (readonly)

Returns A 24-character hex string.

Returns:

  • (String)

    A 24-character hex string



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/trello/webhook.rb', line 14

class Webhook < BasicData
  register_attributes :id, :description, :id_model, :callback_url, :active,
    readonly: [ :id ]
  validates_presence_of :id, :id_model, :callback_url
  validates_length_of   :description,  in: 1..16384

  class << self
    # 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.
    def find(id, params = {})
      client.find(:webhook, id, params)
    end

    # 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]
    def create(options)
      client.create(:webhook,
          'description' => options[:description],
          'idModel'     => options[:id_model],
          'callbackURL' => options[:callback_url])
    end
  end

  # @return [Trello::Webhook] self
  def update_fields(fields)
    attributes[:id]              = fields['id']
    attributes[:description]     = fields['description'] || fields[:description]
    attributes[:id_model]        = fields['idModel'] || fields[:id_model]
    attributes[:callback_url]    = fields['callbackURL'] || fields[:callback_url]
    attributes[:active]          = fields['active']
    self
  end

  # Save the webhook.
  #
  # @raise  [Trello::Error] if the Webhook could not be saved.
  #
  # @return [String] the JSON representation of the saved webhook.
  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 the webhook.
  #
  # @raise  [Trello::Error] if the Webhook could not be saved.
  #
  # @return [String] the JSON representation of the updated webhook.
  def update!
    client.put("/webhooks/#{id}", {
      description: description,
      idModel: id_model,
      callbackURL: callback_url,
      active: active
    })
  end

  # Delete this webhook
  #
  # @return [String] the JSON response from the Trello API
  def delete
    client.delete("/webhooks/#{id}")
  end

  # Check if the webhook is activated
  #
  # @return [Boolean]
  def activated?
    active
  end
end

Class Method Details

.create(options) ⇒ Trello::Webhook

Create a new webhook and save it to Trello.

Parameters:

Options Hash (options):

  • :description (String) — default: optional

    A string with a length from 0 to 16384

  • :callback_url (String) — default: required

    A valid URL that is reachable with a HEAD request

  • :id_model (String) — default: required

    id of the model that should be hooked

Returns:

Raises:



41
42
43
44
45
46
# 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 = {}) ⇒ Trello::Webhook

Find a specific webhook by its ID.

Returns:

Raises:

  • (Trello::Error)

    if a Webhook with the given ID can’t be found.



25
26
27
# File 'lib/trello/webhook.rb', line 25

def find(id, params = {})
  client.find(:webhook, id, params)
end

Instance Method Details

#activated?Boolean

Check if the webhook is activated

Returns:

  • (Boolean)


99
100
101
# File 'lib/trello/webhook.rb', line 99

def activated?
  active
end

#deleteString

Delete this webhook

Returns:

  • (String)

    the JSON response from the Trello API



92
93
94
# File 'lib/trello/webhook.rb', line 92

def delete
  client.delete("/webhooks/#{id}")
end

#saveString

Save the webhook.

Returns:

  • (String)

    the JSON representation of the saved webhook.

Raises:



64
65
66
67
68
69
70
71
72
73
# 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!String

Update the webhook.

Returns:

  • (String)

    the JSON representation of the updated webhook.

Raises:



80
81
82
83
84
85
86
87
# 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) ⇒ Trello::Webhook

Returns self.

Returns:



50
51
52
53
54
55
56
57
# File 'lib/trello/webhook.rb', line 50

def update_fields(fields)
  attributes[:id]              = fields['id']
  attributes[:description]     = fields['description'] || fields[:description]
  attributes[:id_model]        = fields['idModel'] || fields[:id_model]
  attributes[:callback_url]    = fields['callbackURL'] || fields[:callback_url]
  attributes[:active]          = fields['active']
  self
end