Class: SupportOps::Calendly::Webhooks

Inherits:
Base
  • Object
show all
Defined in:
lib/support_ops_calendly/calendly/webhooks.rb

Overview

Defines the module Webhooks within the module SupportOps::Calendly.

Author:

  • Jason Colyer

Since:

  • 1.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

attributes, client, #client=, configure, define_attributes, #find, #find!, #initialize, #members, readonly_attributes, #store_original_attributes

Constructor Details

This class inherits a constructor from SupportOps::Calendly::Base

Instance Attribute Details

#callback_urlString

The callback URL to use when the event is triggered

Returns:

  • (String)

    the current value of callback_url



27
28
29
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 27

def callback_url
  @callback_url
end

#created_atString

The moment when the webhook subscription was created (e.g. “2020-01-02T03:04:05.678123Z”)

Returns:

  • (String)

    the current value of created_at



27
28
29
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 27

def created_at
  @created_at
end

#creatorString

The URI of the user who created the webhook subscription

Returns:

  • (String)

    the current value of creator



27
28
29
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 27

def creator
  @creator
end

#eventsArray

A list of events to which the webhook is subscribed

Returns:

  • (Array)

    the current value of events



27
28
29
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 27

def events
  @events
end

#groupString

The URI of the group that’s associated with the webhook subscription

Returns:

  • (String)

    the current value of group



27
28
29
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 27

def group
  @group
end

#organizationString

The URI of the organization that’s associated with the webhook subscription

Returns:

  • (String)

    the current value of organization



27
28
29
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 27

def organization
  @organization
end

#retry_started_atString

The date and time the webhook subscription is retried

Returns:

  • (String)

    the current value of retry_started_at



27
28
29
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 27

def retry_started_at
  @retry_started_at
end

#scopeString

The scope of the webhook subscription

Returns:

  • (String)

    the current value of scope



27
28
29
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 27

def scope
  @scope
end

#signing_keyString

Optional secret key shared between your application and Calendly (creates only)

Returns:

  • (String)

    the current value of signing_key



27
28
29
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 27

def signing_key
  @signing_key
end

#stateString

Indicates if the webhook subscription is “active” or “disabled”

Returns:

  • (String)

    the current value of state



27
28
29
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 27

def state
  @state
end

#updated_atString

The moment when the webhook subscription was last updated (e.g. “2020-01-02T03:04:05.678123Z”)

Returns:

  • (String)

    the current value of updated_at



27
28
29
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 27

def updated_at
  @updated_at
end

#uriString

Canonical reference (unique identifier) for the webhook

Returns:

  • (String)

    the current value of uri



27
28
29
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 27

def uri
  @uri
end

#urlString

The URL where you want to receive POST requests for events you are subscribed to (creates only)

Returns:

  • (String)

    the current value of url



27
28
29
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 27

def url
  @url
end

#userString

The URI of the user that’s associated with the webhook subscription

Returns:

  • (String)

    the current value of user



27
28
29
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 27

def user
  @user
end

Class Method Details

.get(object) ⇒ Object

Get a specified Webhook Subscription

Examples:

require 'support_ops_calendly'

SupportOps::Calendly::Configuration.configure do |config|
  config.token = 'abc123'
end

webhook = SupportOps::Calendly::Webhooks.get('DDDDDDDDDDDDDDDD')
pp webhook.uri
#=> "https://api.calendly.com/webhook_subscriptions/DDDDDDDDDDDDDDDD"

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



184
185
186
187
188
189
190
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 184

def self.get(object)
  if object.is_a? Webhooks
    Webhooks.new(uri: uri).find
  else
    Webhooks.new(uri: object).find
  end
end

.get!(object) ⇒ Object

Get a specified Webhook Subscription

Examples:

require 'support_ops_calendly'

SupportOps::Calendly::Configuration.configure do |config|
  config.token = 'abc123'
end

webhook = SupportOps::Calendly::Webhooks.get!('DDDDDDDDDDDDDDDD')
pp webhook.uri
#=> "https://api.calendly.com/webhook_subscriptions/DDDDDDDDDDDDDDDD"

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



210
211
212
213
214
215
216
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 210

def self.get!(object)
  if object.is_a? Webhooks
    Webhooks.new(uri: uri).find!
  else
    Webhooks.new(uri: object).find!
  end
end

.list(key: value) ⇒ Object

Get a list of Webhook Subscriptions for a specified Organization or User

Examples:

require 'support_ops_calendly'

SupportOps::Calendly::Configuration.configure do |config|
  config.token = 'abc123'
end

webhooks = SupportOps::Calendly::Webhooks.list(
  organization: 'https://api.calendly.com/organizations/BBBBBBBBBBBBBBBB',
  scope: 'organization'
)
pp webhooks.first.uri
#=> "https://api.calendly.com/webhook_subscriptions/DDDDDDDDDDDDDDDD"
pp webhooks.count
#=> 3

Parameters:

  • group (String optional)

    Indicates if the results should be filtered by group URI

  • organization (String required)

    The given organization URI that owns the subscriptions being returned

  • scope (String required)

    Filter the list by organization, user, or group

  • sort (String optional)

    Order results by the specified field and direction; accepts comma-separated list of field:direction values; supported fields are: created_at; sort direction is specified as: asc, desc

  • user (String optional)

    Indicates if the results should be filtered by user URI

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 136

def self.list(**args)
  args[:organization] = nil unless args[:organization]
  args[:scope] = nil unless args[:scope]
  raise 'You must provide an organization URI' if args[:organization].nil?
  raise 'You must provide a scope' if args[:scope].nil?
  raise 'You must provide a valid scope (group, organization, user)' unless %w[organization user group].include? args[:scope]

  args[:group] = nil unless args[:group]
  args[:sort] = nil unless args[:sort]
  args[:user] = nil unless args[:user]
  raise 'You must provide a user URI when using the scope of user' if args[:scope] == 'user' && args[:user].nil?
  raise 'You must provide a group URI when using the scope of group' if args[:scope] == 'group' && args[:group].nil?
  array = []
  data = { count: 100 }
  data['group'] = args[:group] unless args[:group].nil?
  data['organization'] = args[:organization] unless args[:organization].nil?
  data['scope'] = args[:scope] unless args[:scope].nil?
  data['sort'] = args[:sort] unless args[:sort].nil?
  data['user'] = args[:user] unless args[:user].nil?
  loop do
    response = client.connection.get('webhook_subscriptions', data)
    body = Oj.load(response.body)
    array += body['collection'].map { |w| Webhooks.new(w) }
    break if body['pagination']['next_page_token'].nil?

    data['page_token'] = body['pagination']['next_page_token']
  end
  array
end

Instance Method Details

#delete!Object

Note:

This is inherited from Base#delete!

Delete a Webhook Subscription

Examples:

require 'support_ops_calendly'

SupportOps::Calendly::Configuration.configure do |config|
  config.token = 'abc123'
end

webhook = SupportOps::Calendly::Webhooks.get!('DDDDDDDDDDDDDDDD')
webhook.delete!

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



18
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 18

def delete!; end

#save!Object

Note:

This is inherited from Base#save!

Create a Webhook Subscription for an Organization or User

Examples:

require 'support_ops_calendly'

SupportOps::Calendly::Configuration.configure do |config|
  config.token = 'abc123'
end

new_webhook = SupportOps::Calendly::Webhooks.new
new_webhook.events = ['invitee.created', 'invitee.canceled']
new_webhook.organization = https://api.calendly.com/organizations/BBBBBBBBBBBBBBBB'
new_webhook.scope = 'user'
new_webhook.url = 'https://blah.foo/bar'
new_webhook.user = 'https://api.calendly.com/users/AAAAAAAAAAAAAAAA'
new_webhook.save!
pp new_webhook.uuid
#=> "DDDDDDDDDDDDDDDD"

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



25
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 25

def save!; end

#uuidString

Note:

This is inherited from Base#uuid

Returns the UUID of a webhook

Examples:

require 'support_ops_calendly'

SupportOps::Calendly::Configuration.configure do |config|
  config.token = 'abc123'
end

webhooks = SupportOps::Calendly::Webhooks.list(
  organization: 'BBBBBBBBBBBBBBBB',
  scope: 'organization'
)
pp webhooks.first.uuid
#=> "DDDDDDDDDDDDDDDD"

Returns:

  • (String)

    The UUID

Author:

  • Jason Colyer

Since:

  • 1.0.0



20
# File 'lib/support_ops_calendly/calendly/webhooks.rb', line 20

def uuid; end