gitlab-customer-support-operations_calendly 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/support_ops_calendly/calendly/base.rb +169 -0
- data/lib/support_ops_calendly/calendly/client.rb +46 -0
- data/lib/support_ops_calendly/calendly/configuration.rb +79 -0
- data/lib/support_ops_calendly/calendly/groups.rb +157 -0
- data/lib/support_ops_calendly/calendly/organization_memberships.rb +216 -0
- data/lib/support_ops_calendly/calendly/organizations.rb +160 -0
- data/lib/support_ops_calendly/calendly/users.rb +146 -0
- data/lib/support_ops_calendly/calendly/webhooks.rb +265 -0
- data/lib/support_ops_calendly/calendly.rb +22 -0
- data/lib/support_ops_calendly.rb +28 -0
- metadata +172 -0
@@ -0,0 +1,160 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module SupportOps.
|
4
|
+
module SupportOps
|
5
|
+
# Defines the module Calendly
|
6
|
+
module Calendly
|
7
|
+
##
|
8
|
+
# Defines the module Organizations within the module {SupportOps::Calendly}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @attr [String] created_at Timestamp of when the organization was created
|
13
|
+
# @attr [String] kind Indicates whether the organization is a single-user or multiple-user organization
|
14
|
+
# @attr [String] name The Organization name (in human-readable format)
|
15
|
+
# @attr [String] plan Active subscription plan or trial plan
|
16
|
+
# @attr [String] stage Current stage of organization
|
17
|
+
# @attr [String] updated_at Timestamp of when the organization was created or updated
|
18
|
+
# @attr [String] uri Canonical resource reference
|
19
|
+
class Organizations < SupportOps::Calendly::Base
|
20
|
+
# @!parse
|
21
|
+
# # Returns the UUID of an organization
|
22
|
+
# #
|
23
|
+
# # @author Jason Colyer
|
24
|
+
# # @since 1.0.0
|
25
|
+
# # @return [String] The UUID
|
26
|
+
# # @note This is inherited from {SupportOps::Calendly::Base#uuid}
|
27
|
+
# # @example
|
28
|
+
# # require 'support_ops_calendly'
|
29
|
+
# #
|
30
|
+
# # SupportOps::Calendly::Configuration.configure do |config|
|
31
|
+
# # config.token = 'abc123'
|
32
|
+
# # end
|
33
|
+
# #
|
34
|
+
# # org = SupportOps::Calendly::Organizations.current
|
35
|
+
# # pp org.uuid
|
36
|
+
# # #=> "BBBBBBBBBBBBBBBB"
|
37
|
+
# def uuid; end
|
38
|
+
# @!parse
|
39
|
+
# # Returns the organization memberships of an organization
|
40
|
+
# #
|
41
|
+
# # @author Jason Colyer
|
42
|
+
# # @since 1.0.0
|
43
|
+
# # @return [Array]
|
44
|
+
# # @note This is inherited from {SupportOps::Calendly::Base#members}
|
45
|
+
# # @example
|
46
|
+
# # require 'support_ops_calendly'
|
47
|
+
# #
|
48
|
+
# # SupportOps::Calendly::Configuration.configure do |config|
|
49
|
+
# # config.token = 'abc123'
|
50
|
+
# # end
|
51
|
+
# #
|
52
|
+
# # org = SupportOps::Calendly::Organizations.current
|
53
|
+
# # members = org.members
|
54
|
+
# # pp members.count
|
55
|
+
# # #=> 13
|
56
|
+
# # pp members.first.user.uuid
|
57
|
+
# # #=> "AAAAAAAAAAAAAAAA"
|
58
|
+
# def members; end
|
59
|
+
define_attributes :created_at, :kind, :name, :plan, :stage, :updated_at,
|
60
|
+
:uri
|
61
|
+
readonly_attributes :created_at, :kind, :name, :plan, :stage, :updated_at,
|
62
|
+
:uri
|
63
|
+
|
64
|
+
##
|
65
|
+
# Returns basic information about your user's current organization
|
66
|
+
#
|
67
|
+
# @author Jason Colyer
|
68
|
+
# @since 1.0.0
|
69
|
+
# @example
|
70
|
+
# require 'support_ops_calendly'
|
71
|
+
#
|
72
|
+
# SupportOps::Calendly::Configuration.configure do |config|
|
73
|
+
# config.token = 'abc123'
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# org = SupportOps::Calendly::Organizations.current
|
77
|
+
# pp org.name
|
78
|
+
# # => "Sales Team"
|
79
|
+
def self.current
|
80
|
+
user = Users.current
|
81
|
+
Organizations.get!(user.current_organization.split('/').last)
|
82
|
+
end
|
83
|
+
|
84
|
+
##
|
85
|
+
# Returns information about a specified Organization
|
86
|
+
#
|
87
|
+
# @author Jason Colyer
|
88
|
+
# @since 1.0.0
|
89
|
+
# @see
|
90
|
+
# https://developer.calendly.com/api-docs/9738aea27ba80-get-organization
|
91
|
+
# Calendly API > Organizations > Get Organization
|
92
|
+
# @example
|
93
|
+
# require 'support_ops_calendly'
|
94
|
+
#
|
95
|
+
# SupportOps::Calendly::Configuration.configure do |config|
|
96
|
+
# config.token = 'abc123'
|
97
|
+
# end
|
98
|
+
#
|
99
|
+
# org = SupportOps::Calendly::Organizations.get('BBBBBBBBBBBBBBBB')
|
100
|
+
# pp org.name
|
101
|
+
# # => "Sales Team"
|
102
|
+
def self.get(object)
|
103
|
+
if object.is_a? Organizations
|
104
|
+
Organizations.new(uri: uri).find
|
105
|
+
else
|
106
|
+
Organizations.new(uri: object).find
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# Returns information about a specified Organization
|
112
|
+
#
|
113
|
+
# @author Jason Colyer
|
114
|
+
# @since 1.0.0
|
115
|
+
# @see
|
116
|
+
# https://developer.calendly.com/api-docs/9738aea27ba80-get-organization
|
117
|
+
# Calendly API > Organizations > Get Organization
|
118
|
+
# @example
|
119
|
+
# require 'support_ops_calendly'
|
120
|
+
#
|
121
|
+
# SupportOps::Calendly::Configuration.configure do |config|
|
122
|
+
# config.token = 'abc123'
|
123
|
+
# end
|
124
|
+
#
|
125
|
+
# org = SupportOps::Calendly::Organizations.get!('BBBBBBBBBBBBBBBB')
|
126
|
+
# pp org.name
|
127
|
+
# # => "Sales Team"
|
128
|
+
def self.get!(object)
|
129
|
+
if object.is_a? Organizations
|
130
|
+
Organizations.new(uri: uri).find!
|
131
|
+
else
|
132
|
+
Organizations.new(uri: object).find!
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
##
|
139
|
+
# @private
|
140
|
+
def uuid_record
|
141
|
+
(uri =~ /^https/ ? uri.split('/').last : uri)
|
142
|
+
end
|
143
|
+
|
144
|
+
##
|
145
|
+
# @private
|
146
|
+
def get_record
|
147
|
+
response = self.client.connection.get("organizations/#{uuid}")
|
148
|
+
return nil if response.status != 200
|
149
|
+
|
150
|
+
Oj.load(response.body)['resource']
|
151
|
+
end
|
152
|
+
|
153
|
+
##
|
154
|
+
# @private
|
155
|
+
def members_record
|
156
|
+
OrganizationMemberships.list(self.uri)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module SupportOps.
|
4
|
+
module SupportOps
|
5
|
+
# Defines the module Calendly
|
6
|
+
module Calendly
|
7
|
+
##
|
8
|
+
# Defines the module Users within the module {SupportOps::Calendly}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @attr [String] avatar_url The URL of the user's avatar (image)
|
13
|
+
# @attr [String] created_at The moment when the user's record was created (e.g. "2020-01-02T03:04:05.678123Z")
|
14
|
+
# @attr [String] current_organization A unique reference to the user's current organization
|
15
|
+
# @attr [String] email The user's email address
|
16
|
+
# @attr [String] locale The user's language preference
|
17
|
+
# @attr [String] name The user's name (human-readable format)
|
18
|
+
# @attr [String] resource_type Resource type to support polymorphic associations.
|
19
|
+
# @attr [String] scheduling_url The URL of the user's Calendly landing page (that lists all the user's event types)
|
20
|
+
# @attr [String] slug The portion of URL for the user's scheduling page (where invitees book sessions), rendered in a human-readable format
|
21
|
+
# @attr [String] time_notation Time notation used by the user; accepts "12h" or "24h" as a value.
|
22
|
+
# @attr [String] timezone The time zone to use when presenting time to the user
|
23
|
+
# @attr [String] updated_at The moment when the user's record was last updated (e.g. "2020-01-02T03:04:05.678123Z")
|
24
|
+
# @attr [String] uri Canonical reference (unique identifier) for the user
|
25
|
+
class Users < SupportOps::Calendly::Base
|
26
|
+
# @!parse
|
27
|
+
# # Returns the UUID of a user
|
28
|
+
# #
|
29
|
+
# # @author Jason Colyer
|
30
|
+
# # @since 1.0.0
|
31
|
+
# # @return [String] The UUID
|
32
|
+
# # @note This is inherited from {SupportOps::Calendly::Base#uuid}
|
33
|
+
# # @example
|
34
|
+
# # require 'support_ops_calendly'
|
35
|
+
# #
|
36
|
+
# # SupportOps::Calendly::Configuration.configure do |config|
|
37
|
+
# # config.token = 'abc123'
|
38
|
+
# # end
|
39
|
+
# #
|
40
|
+
# # user = SupportOps::Calendly::Users.current
|
41
|
+
# # pp user.uuid
|
42
|
+
# # #=> "AAAAAAAAAAAAAAAA"
|
43
|
+
# def uuid; end
|
44
|
+
define_attributes :avatar_url, :created_at, :current_organization, :email,
|
45
|
+
:locale, :name, :resource_type, :scheduling_url, :slug,
|
46
|
+
:time_notation, :timezone, :updated_at, :uri
|
47
|
+
readonly_attributes :avatar_url, :created_at, :current_organization,
|
48
|
+
:email, :locale, :name, :resource_type,
|
49
|
+
:scheduling_url, :slug, :time_notation, :timezone,
|
50
|
+
:updated_at, :uri
|
51
|
+
|
52
|
+
##
|
53
|
+
# Returns basic information about your user account.
|
54
|
+
#
|
55
|
+
# @author Jason Colyer
|
56
|
+
# @since 1.0.0
|
57
|
+
# @see
|
58
|
+
# https://developer.calendly.com/api-docs/005832c83aeae-get-current-user
|
59
|
+
# Calendly API > Users > Get current user
|
60
|
+
# @example
|
61
|
+
# require 'support_ops_calendly'
|
62
|
+
#
|
63
|
+
# SupportOps::Calendly::Configuration.configure do |config|
|
64
|
+
# config.token = 'abc123'
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
# user = SupportOps::Calendly::Users.current
|
68
|
+
# pp user.email
|
69
|
+
# # => "admin@example.com"
|
70
|
+
def self.current
|
71
|
+
response = client.connection.get('users/me')
|
72
|
+
body = Oj.load(response.body)
|
73
|
+
Users.new(body['resource'])
|
74
|
+
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# Returns information about a specified User
|
78
|
+
#
|
79
|
+
# @author Jason Colyer
|
80
|
+
# @since 1.0.0
|
81
|
+
# @see
|
82
|
+
# https://developer.calendly.com/api-docs/ff9832c5a6640-get-user
|
83
|
+
# Calendly API > Users > Get user
|
84
|
+
# @example
|
85
|
+
# require 'support_ops_calendly'
|
86
|
+
#
|
87
|
+
# SupportOps::Calendly::Configuration.configure do |config|
|
88
|
+
# config.token = 'abc123'
|
89
|
+
# end
|
90
|
+
#
|
91
|
+
# user = SupportOps::Calendly::Users.get('AAAAAAAAAAAAAAAA')
|
92
|
+
# pp user.email
|
93
|
+
# # => "admin@example.com"
|
94
|
+
def self.get(object)
|
95
|
+
if object.is_a? Users
|
96
|
+
Users.new(uri: uri).find
|
97
|
+
else
|
98
|
+
Users.new(uri: object).find
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
##
|
103
|
+
# Returns information about a specified User
|
104
|
+
#
|
105
|
+
# @author Jason Colyer
|
106
|
+
# @since 1.0.0
|
107
|
+
# @see
|
108
|
+
# https://developer.calendly.com/api-docs/ff9832c5a6640-get-user
|
109
|
+
# Calendly API > Users > Get user
|
110
|
+
# @example
|
111
|
+
# require 'support_ops_calendly'
|
112
|
+
#
|
113
|
+
# SupportOps::Calendly::Configuration.configure do |config|
|
114
|
+
# config.token = 'abc123'
|
115
|
+
# end
|
116
|
+
#
|
117
|
+
# user = SupportOps::Calendly::Users.get!('AAAAAAAAAAAAAAAA')
|
118
|
+
# pp user.email
|
119
|
+
# # => "admin@example.com"
|
120
|
+
def self.get!(object)
|
121
|
+
if object.is_a? Users
|
122
|
+
Users.new(uri: uri).find!
|
123
|
+
else
|
124
|
+
Users.new(uri: object).find!
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
##
|
131
|
+
# @private
|
132
|
+
def uuid_record
|
133
|
+
(uri =~ /^https/ ? uri.split('/').last : uri)
|
134
|
+
end
|
135
|
+
|
136
|
+
##
|
137
|
+
# @private
|
138
|
+
def get_record
|
139
|
+
response = self.client.connection.get("users/#{uuid}")
|
140
|
+
return nil if response.status != 200
|
141
|
+
|
142
|
+
Oj.load(response.body)['resource']
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,265 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module SupportOps.
|
4
|
+
module SupportOps
|
5
|
+
# Defines the module Calendly
|
6
|
+
module Calendly
|
7
|
+
##
|
8
|
+
# Defines the module Webhooks within the module {SupportOps::Calendly}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @attr [String] callback_url The callback URL to use when the event is triggered
|
13
|
+
# @attr [String] created_at The moment when the webhook subscription was created (e.g. "2020-01-02T03:04:05.678123Z")
|
14
|
+
# @attr [String] creator The URI of the user who created the webhook subscription
|
15
|
+
# @attr [Array] events A list of events to which the webhook is subscribed
|
16
|
+
# @attr [String] group The URI of the group that's associated with the webhook subscription
|
17
|
+
# @attr [String] organization The URI of the organization that's associated with the webhook subscription
|
18
|
+
# @attr [String] retry_started_at The date and time the webhook subscription is retried
|
19
|
+
# @attr [String] scope The scope of the webhook subscription
|
20
|
+
# @attr [String] signing_key Optional secret key shared between your application and Calendly (creates only)
|
21
|
+
# @attr [String] state Indicates if the webhook subscription is "active" or "disabled"
|
22
|
+
# @attr [String] updated_at The moment when the webhook subscription was last updated (e.g. "2020-01-02T03:04:05.678123Z")
|
23
|
+
# @attr [String] uri Canonical reference (unique identifier) for the webhook
|
24
|
+
# @attr [String] url The URL where you want to receive POST requests for events you are subscribed to (creates only)
|
25
|
+
# @attr [String] user The URI of the user that's associated with the webhook subscription
|
26
|
+
# @todo Get sample webhook data => https://developer.calendly.com/api-docs/1da466e7fbc1b-get-sample-webhook-data
|
27
|
+
class Webhooks < SupportOps::Calendly::Base
|
28
|
+
# @!parse
|
29
|
+
# # Create a Webhook Subscription for an Organization or User
|
30
|
+
# #
|
31
|
+
# # @author Jason Colyer
|
32
|
+
# # @since 1.0.0
|
33
|
+
# # @see
|
34
|
+
# # https://developer.calendly.com/api-docs/c1ddc06ce1f1b-create-webhook-subscription
|
35
|
+
# # Calendly API > Webhooks > Create Webhook Subscription
|
36
|
+
# # @note This is inherited from {SupportOps::Calendly::Base#save!}
|
37
|
+
# # @example
|
38
|
+
# # require 'support_ops_calendly'
|
39
|
+
# #
|
40
|
+
# # SupportOps::Calendly::Configuration.configure do |config|
|
41
|
+
# # config.token = 'abc123'
|
42
|
+
# # end
|
43
|
+
# #
|
44
|
+
# # new_webhook = SupportOps::Calendly::Webhooks.new
|
45
|
+
# # new_webhook.events = ['invitee.created', 'invitee.canceled']
|
46
|
+
# # new_webhook.organization = https://api.calendly.com/organizations/BBBBBBBBBBBBBBBB'
|
47
|
+
# # new_webhook.scope = 'user'
|
48
|
+
# # new_webhook.url = 'https://blah.foo/bar'
|
49
|
+
# # new_webhook.user = 'https://api.calendly.com/users/AAAAAAAAAAAAAAAA'
|
50
|
+
# # new_webhook.save!
|
51
|
+
# # pp new_webhook.uuid
|
52
|
+
# # #=> "DDDDDDDDDDDDDDDD"
|
53
|
+
# def save!; end
|
54
|
+
# @!parse
|
55
|
+
# # Delete a Webhook Subscription
|
56
|
+
# #
|
57
|
+
# # @author Jason Colyer
|
58
|
+
# # @since 1.0.0
|
59
|
+
# # @see
|
60
|
+
# # https://developer.calendly.com/api-docs/565b97f62dafe-delete-webhook-subscription
|
61
|
+
# # Calendly API > Webhooks > Delete Webhook Subscription
|
62
|
+
# # @note This is inherited from {SupportOps::Calendly::Base#delete!}
|
63
|
+
# # @example
|
64
|
+
# # require 'support_ops_calendly'
|
65
|
+
# #
|
66
|
+
# # SupportOps::Calendly::Configuration.configure do |config|
|
67
|
+
# # config.token = 'abc123'
|
68
|
+
# # end
|
69
|
+
# #
|
70
|
+
# # webhook = SupportOps::Calendly::Webhooks.get!('DDDDDDDDDDDDDDDD')
|
71
|
+
# # webhook.delete!
|
72
|
+
# def delete!; end
|
73
|
+
# @!parse
|
74
|
+
# # Returns the UUID of a webhook
|
75
|
+
# #
|
76
|
+
# # @author Jason Colyer
|
77
|
+
# # @since 1.0.0
|
78
|
+
# # @return [String] The UUID
|
79
|
+
# # @note This is inherited from {SupportOps::Calendly::Base#uuid}
|
80
|
+
# # @example
|
81
|
+
# # require 'support_ops_calendly'
|
82
|
+
# #
|
83
|
+
# # SupportOps::Calendly::Configuration.configure do |config|
|
84
|
+
# # config.token = 'abc123'
|
85
|
+
# # end
|
86
|
+
# #
|
87
|
+
# # webhooks = SupportOps::Calendly::Webhooks.list(
|
88
|
+
# # organization: 'BBBBBBBBBBBBBBBB',
|
89
|
+
# # scope: 'organization'
|
90
|
+
# # )
|
91
|
+
# # pp webhooks.first.uuid
|
92
|
+
# # #=> "DDDDDDDDDDDDDDDD"
|
93
|
+
# def uuid; end
|
94
|
+
define_attributes :callback_url, :created_at, :creator, :events, :group,
|
95
|
+
:organization, :retry_started_at, :scope, :signing_key,
|
96
|
+
:state, :updated_at, :uri, :url, :user
|
97
|
+
readonly_attributes :callback_url, :created_at, :creator,
|
98
|
+
:retry_started_at, :state, :updated_at, :uri
|
99
|
+
|
100
|
+
##
|
101
|
+
# Get a list of Webhook Subscriptions for a specified Organization or User
|
102
|
+
#
|
103
|
+
# @author Jason Colyer
|
104
|
+
# @since 1.0.0
|
105
|
+
# @overload list(key: value)
|
106
|
+
# @param group [String optional] Indicates if the results should be
|
107
|
+
# filtered by group URI
|
108
|
+
# @param organization [String required] The given organization URI that
|
109
|
+
# owns the subscriptions being returned
|
110
|
+
# @param scope [String required] Filter the list by organization, user,
|
111
|
+
# or group
|
112
|
+
# @param sort [String optional] Order results by the specified field and
|
113
|
+
# direction; accepts comma-separated list of {field}:{direction}
|
114
|
+
# values; supported fields are: created_at; sort direction is
|
115
|
+
# specified as: asc, desc
|
116
|
+
# @param user [String optional] Indicates if the results should be
|
117
|
+
# filtered by user URI
|
118
|
+
# @see
|
119
|
+
# https://developer.calendly.com/api-docs/faac832d7c57d-list-webhook-subscriptions
|
120
|
+
# Calendly API > Webhooks > List Webhook Subscriptions
|
121
|
+
# @example
|
122
|
+
# require 'support_ops_calendly'
|
123
|
+
#
|
124
|
+
# SupportOps::Calendly::Configuration.configure do |config|
|
125
|
+
# config.token = 'abc123'
|
126
|
+
# end
|
127
|
+
#
|
128
|
+
# webhooks = SupportOps::Calendly::Webhooks.list(
|
129
|
+
# organization: 'https://api.calendly.com/organizations/BBBBBBBBBBBBBBBB',
|
130
|
+
# scope: 'organization'
|
131
|
+
# )
|
132
|
+
# pp webhooks.first.uri
|
133
|
+
# #=> "https://api.calendly.com/webhook_subscriptions/DDDDDDDDDDDDDDDD"
|
134
|
+
# pp webhooks.count
|
135
|
+
# #=> 3
|
136
|
+
def self.list(**args)
|
137
|
+
args[:organization] = nil unless args[:organization]
|
138
|
+
args[:scope] = nil unless args[:scope]
|
139
|
+
raise 'You must provide an organization URI' if args[:organization].nil?
|
140
|
+
raise 'You must provide a scope' if args[:scope].nil?
|
141
|
+
raise 'You must provide a valid scope (group, organization, user)' unless %w[organization user group].include? args[:scope]
|
142
|
+
|
143
|
+
args[:group] = nil unless args[:group]
|
144
|
+
args[:sort] = nil unless args[:sort]
|
145
|
+
args[:user] = nil unless args[:user]
|
146
|
+
raise 'You must provide a user URI when using the scope of user' if args[:scope] == 'user' && args[:user].nil?
|
147
|
+
raise 'You must provide a group URI when using the scope of group' if args[:scope] == 'group' && args[:group].nil?
|
148
|
+
array = []
|
149
|
+
data = { count: 100 }
|
150
|
+
data['group'] = args[:group] unless args[:group].nil?
|
151
|
+
data['organization'] = args[:organization] unless args[:organization].nil?
|
152
|
+
data['scope'] = args[:scope] unless args[:scope].nil?
|
153
|
+
data['sort'] = args[:sort] unless args[:sort].nil?
|
154
|
+
data['user'] = args[:user] unless args[:user].nil?
|
155
|
+
loop do
|
156
|
+
response = client.connection.get('webhook_subscriptions', data)
|
157
|
+
body = Oj.load(response.body)
|
158
|
+
array += body['collection'].map { |w| Webhooks.new(w) }
|
159
|
+
break if body['pagination']['next_page_token'].nil?
|
160
|
+
|
161
|
+
data['page_token'] = body['pagination']['next_page_token']
|
162
|
+
end
|
163
|
+
array
|
164
|
+
end
|
165
|
+
|
166
|
+
##
|
167
|
+
# Get a specified Webhook Subscription
|
168
|
+
#
|
169
|
+
# @author Jason Colyer
|
170
|
+
# @since 1.0.0
|
171
|
+
# @see
|
172
|
+
# https://developer.calendly.com/api-docs/4d800dc2cb119-get-webhook-subscription
|
173
|
+
# Calendly API > Webhooks > Get Webhook Subscription
|
174
|
+
# @example
|
175
|
+
# require 'support_ops_calendly'
|
176
|
+
#
|
177
|
+
# SupportOps::Calendly::Configuration.configure do |config|
|
178
|
+
# config.token = 'abc123'
|
179
|
+
# end
|
180
|
+
#
|
181
|
+
# webhook = SupportOps::Calendly::Webhooks.get('DDDDDDDDDDDDDDDD')
|
182
|
+
# pp webhook.uri
|
183
|
+
# #=> "https://api.calendly.com/webhook_subscriptions/DDDDDDDDDDDDDDDD"
|
184
|
+
def self.get(object)
|
185
|
+
if object.is_a? Webhooks
|
186
|
+
Webhooks.new(uri: uri).find
|
187
|
+
else
|
188
|
+
Webhooks.new(uri: object).find
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
##
|
193
|
+
# Get a specified Webhook Subscription
|
194
|
+
#
|
195
|
+
# @author Jason Colyer
|
196
|
+
# @since 1.0.0
|
197
|
+
# @see
|
198
|
+
# https://developer.calendly.com/api-docs/4d800dc2cb119-get-webhook-subscription
|
199
|
+
# Calendly API > Webhooks > Get Webhook Subscription
|
200
|
+
# @example
|
201
|
+
# require 'support_ops_calendly'
|
202
|
+
#
|
203
|
+
# SupportOps::Calendly::Configuration.configure do |config|
|
204
|
+
# config.token = 'abc123'
|
205
|
+
# end
|
206
|
+
#
|
207
|
+
# webhook = SupportOps::Calendly::Webhooks.get!('DDDDDDDDDDDDDDDD')
|
208
|
+
# pp webhook.uri
|
209
|
+
# #=> "https://api.calendly.com/webhook_subscriptions/DDDDDDDDDDDDDDDD"
|
210
|
+
def self.get!(object)
|
211
|
+
if object.is_a? Webhooks
|
212
|
+
Webhooks.new(uri: uri).find!
|
213
|
+
else
|
214
|
+
Webhooks.new(uri: object).find!
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
private
|
219
|
+
|
220
|
+
##
|
221
|
+
# @private
|
222
|
+
def get_record
|
223
|
+
response = self.client.connection.get("webhook_subscriptions/#{self.uuid}")
|
224
|
+
return nil if response.status != 200
|
225
|
+
|
226
|
+
Oj.load(response.body)['resource']
|
227
|
+
end
|
228
|
+
|
229
|
+
##
|
230
|
+
# @private
|
231
|
+
def create_record
|
232
|
+
data = {
|
233
|
+
events: self.events,
|
234
|
+
organization: self.organization,
|
235
|
+
scope: self.scope,
|
236
|
+
url: self.url
|
237
|
+
}
|
238
|
+
data[:group] = self.group unless self.group.nil?
|
239
|
+
data[:signing_key] = self.signing_key unless self.signing_key.nil?
|
240
|
+
data[:user] = self.user unless self.user.nil?
|
241
|
+
response = self.client.connection.post('webhook_subscriptions', data.to_json)
|
242
|
+
body = Oj.load(response.body)
|
243
|
+
raise "Unable to creation webhook => #{body}" unless response.status == 201
|
244
|
+
|
245
|
+
body
|
246
|
+
end
|
247
|
+
|
248
|
+
##
|
249
|
+
# @private
|
250
|
+
def delete_record
|
251
|
+
response = self.client.connection.delete("webhook_subscriptions/#{self.uuid}")
|
252
|
+
body = Oj.load(response.body)
|
253
|
+
raise "Failed to remove webhook subscription #{self.uuid} => #{body}" unless response.status == 204
|
254
|
+
|
255
|
+
true
|
256
|
+
end
|
257
|
+
|
258
|
+
##
|
259
|
+
# @private
|
260
|
+
def uuid_record
|
261
|
+
(uri =~ /^https/ ? uri.split('/').last : uri)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module SupportOps.
|
4
|
+
module SupportOps
|
5
|
+
##
|
6
|
+
# Defines the module Calendly within the module {SupportOps}.
|
7
|
+
#
|
8
|
+
# @author Jason Colyer
|
9
|
+
# @since 1.0.0
|
10
|
+
module Calendly
|
11
|
+
# This one should always be first
|
12
|
+
require "#{__dir__}/calendly/base"
|
13
|
+
# Order does not matter here
|
14
|
+
require "#{__dir__}/calendly/client"
|
15
|
+
require "#{__dir__}/calendly/configuration"
|
16
|
+
require "#{__dir__}/calendly/groups"
|
17
|
+
require "#{__dir__}/calendly/organization_memberships"
|
18
|
+
require "#{__dir__}/calendly/organizations"
|
19
|
+
require "#{__dir__}/calendly/users"
|
20
|
+
require "#{__dir__}/calendly/webhooks"
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$VERBOSE = nil
|
4
|
+
|
5
|
+
##
|
6
|
+
# Defines the module SupportOps
|
7
|
+
# @author Jason Colyer
|
8
|
+
# @since 1.0.0
|
9
|
+
module SupportOps; end
|
10
|
+
|
11
|
+
require 'active_support'
|
12
|
+
require 'active_support/time'
|
13
|
+
require 'base64'
|
14
|
+
require 'cgi'
|
15
|
+
require 'digest'
|
16
|
+
require 'erb'
|
17
|
+
require 'faraday'
|
18
|
+
require 'faraday/multipart'
|
19
|
+
require 'faraday/retry'
|
20
|
+
require 'json'
|
21
|
+
require 'oj'
|
22
|
+
require 'restforce'
|
23
|
+
require 'yaml'
|
24
|
+
|
25
|
+
# This one should always be first
|
26
|
+
|
27
|
+
# Order does not matter here
|
28
|
+
require "#{__dir__}/support_ops_calendly/calendly"
|