calendly 0.4.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +78 -17
- data/README.md +40 -29
- data/lib/calendly/api_error.rb +3 -0
- data/lib/calendly/client.rb +107 -14
- data/lib/calendly/configuration.rb +6 -1
- data/lib/calendly/models/event.rb +35 -22
- data/lib/calendly/models/event_type.rb +76 -21
- data/lib/calendly/models/event_type_custom_question.rb +48 -0
- data/lib/calendly/models/event_type_profile.rb +54 -0
- data/lib/calendly/models/guest.rb +21 -0
- data/lib/calendly/models/invitee.rb +41 -13
- data/lib/calendly/models/invitee_cancellation.rb +17 -0
- data/lib/calendly/models/invitee_payment.rb +28 -0
- data/lib/calendly/models/invitee_question_and_answer.rb +9 -1
- data/lib/calendly/models/invitee_tracking.rb +12 -1
- data/lib/calendly/models/invitees_counter.rb +19 -0
- data/lib/calendly/models/location.rb +10 -0
- data/lib/calendly/models/model_utils.rb +32 -6
- data/lib/calendly/models/organization.rb +61 -5
- data/lib/calendly/models/organization_invitation.rb +6 -0
- data/lib/calendly/models/organization_membership.rb +22 -12
- data/lib/calendly/models/team.rb +20 -0
- data/lib/calendly/models/user.rb +65 -5
- data/lib/calendly/models/webhook_subscription.rb +17 -0
- data/lib/calendly/version.rb +1 -1
- metadata +11 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ba1370ffbfb35b34a37f514d94f48879a20a2ee5b33ebb1791969883a7303a7
|
4
|
+
data.tar.gz: 5deec005ae70cdbf6f864c7ed7eec03d8186ef3127452f4221e9c9e3863f7c8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9de051c920eb9480c7c337829c75d4a81ce8690fb95c30ba0e8a493677886de52581bbae1d4dc926274f1a6ccb0dfcecf6ea184770b358c3fccf948d64a8d459
|
7
|
+
data.tar.gz: a4f7068f0bbddf86699506133cebbeb1a8871a9f7523eac8e67e443a458367f1f5fc3de10b6d078801f8d502efe31bd20fb6c5d52fcbb0c588024b8ca1625fab
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,69 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.7.0
|
4
|
+
|
5
|
+
- supported a signing key parameter when creating webhooks. (#33)
|
6
|
+
- changed `user_uri` argument to keyword argument on Client#create_webhook.
|
7
|
+
|
8
|
+
## 0.6.0
|
9
|
+
|
10
|
+
- supported new features until April 2021. (#29)
|
11
|
+
- Client
|
12
|
+
- (Change) support organization options in `event_types` api.
|
13
|
+
- (Rename) `event_types` to `event_types_by_user`
|
14
|
+
- User model
|
15
|
+
- (Add field) current_organization
|
16
|
+
- (Add method) webhooks
|
17
|
+
- (Add method) webhooks!
|
18
|
+
- (Add method) create_webhook
|
19
|
+
- Organization model
|
20
|
+
- (Add method) event_types
|
21
|
+
- (Add method) event_types!
|
22
|
+
- Event model
|
23
|
+
- (Remove field) invitees_counter_total
|
24
|
+
- (Remove field) invitees_counter_active
|
25
|
+
- (Remove field) invitees_counter_limit
|
26
|
+
- (Add field) invitees_counter
|
27
|
+
- (Add field) event_memberships
|
28
|
+
- (Add field) event_guests
|
29
|
+
- EventType model
|
30
|
+
- (Remove field) owner_uuid
|
31
|
+
- (Remove field) owner_uri
|
32
|
+
- (Remove field) owner_name
|
33
|
+
- (Add field) profile
|
34
|
+
- (Add field) secret
|
35
|
+
- (Add field) custom_questions
|
36
|
+
- (Add method) owner_user
|
37
|
+
- (Add method) owner_team
|
38
|
+
- Invitee model
|
39
|
+
- (Add field) first_name
|
40
|
+
- (Add field) last_name
|
41
|
+
- (Add field) cancellation
|
42
|
+
- (Add field) payment
|
43
|
+
- fixed debug log encoding error. (#30)
|
44
|
+
- improved inspect method to be more readable in CLI.
|
45
|
+
|
46
|
+
## 0.5.2
|
47
|
+
|
48
|
+
- started to support a API
|
49
|
+
- `POST /scheduling_links`
|
50
|
+
|
51
|
+
## 0.5.1
|
52
|
+
|
53
|
+
- added method EventType#fetch
|
54
|
+
|
55
|
+
## 0.5.0
|
56
|
+
|
57
|
+
- changed Calendly::Client#scheduled_events behavior (refs #21)
|
58
|
+
- previous version:
|
59
|
+
- getting events belonging to a specific USER
|
60
|
+
- current version:
|
61
|
+
- getting all events belonging to a specific ORGANIZATION
|
62
|
+
- added Calendly::Client#scheduled_events_by_user method instead_of the before behavior
|
63
|
+
|
3
64
|
## 0.4.2
|
4
65
|
|
5
|
-
-
|
66
|
+
- added new following fields to Invitee model (refs #21)
|
6
67
|
- :rescheduled
|
7
68
|
- :old_invitee
|
8
69
|
- :new_invitee
|
@@ -11,20 +72,20 @@
|
|
11
72
|
|
12
73
|
## 0.4.1
|
13
74
|
|
14
|
-
- support API
|
75
|
+
- started to support a API
|
15
76
|
- `GET /event_types/{uuid}`
|
16
77
|
|
17
78
|
## 0.4.0
|
18
79
|
|
19
|
-
-
|
80
|
+
- fixed a changes for Location fields such as `kind` to `type`. (refs #18)
|
20
81
|
|
21
82
|
## 0.3.0
|
22
83
|
|
23
|
-
-
|
84
|
+
- removed zeitwerk dependency. (refs #16)
|
24
85
|
|
25
86
|
## 0.2.0
|
26
87
|
|
27
|
-
-
|
88
|
+
- added caching features in object when fetching data. (refs #14)
|
28
89
|
|
29
90
|
## 0.1.3
|
30
91
|
|
@@ -36,59 +97,59 @@
|
|
36
97
|
|
37
98
|
## 0.1.2
|
38
99
|
|
39
|
-
-
|
100
|
+
- fixed rubocop warnings.
|
40
101
|
|
41
102
|
## 0.1.1
|
42
103
|
|
43
|
-
-
|
104
|
+
- added tests to make coverage 100%.
|
44
105
|
|
45
106
|
## 0.1.0
|
46
107
|
|
47
|
-
-
|
48
|
-
-
|
108
|
+
- defined methods to access associated resources with each model.
|
109
|
+
- renamed methods:
|
49
110
|
- `Calendly::Client#events` to `Calendly::Client#scheduled_events`
|
50
111
|
|
51
112
|
## 0.0.7.alpha
|
52
113
|
|
53
|
-
- support APIs
|
114
|
+
- started to support APIs
|
54
115
|
- `POST /organizations/{uuid}/invitations`
|
55
116
|
- `DELETE /organizations/{org_uuid}/invitations/{invitation_uuid}`
|
56
117
|
- `DELETE /organization_memberships/{uuid}`
|
57
118
|
|
58
119
|
## 0.0.6.alpha
|
59
120
|
|
60
|
-
- support APIs
|
121
|
+
- started to support APIs
|
61
122
|
- `GET /organizations/{uuid}/invitations`
|
62
123
|
- `GET /organizations/{organization_uuid}/invitations/{invitation_uuid}`
|
63
124
|
|
64
125
|
## 0.0.5.alpha
|
65
126
|
|
66
|
-
- support APIs
|
127
|
+
- started to support APIs
|
67
128
|
- `GET /organization_memberships`
|
68
129
|
- `GET /organization_memberships/{uuid}`
|
69
|
-
-
|
130
|
+
- renamed fields
|
70
131
|
- Invitee#event to Invitee#event_uri
|
71
132
|
- Event#event_type to Event#event_type_uri
|
72
133
|
|
73
134
|
## 0.0.4.alpha
|
74
135
|
|
75
|
-
- support APIs
|
136
|
+
- started to support APIs
|
76
137
|
- `GET /scheduled_events/{event_uuid}/invitees`
|
77
138
|
- `GET /scheduled_events/{event_uuid}/invitees/{invitee_uuid}`
|
78
139
|
|
79
140
|
## 0.0.3.alpha
|
80
141
|
|
81
|
-
- support APIs
|
142
|
+
- started to support APIs
|
82
143
|
- `GET /scheduled_events`
|
83
144
|
- `GET /scheduled_events/{uuid}`
|
84
145
|
|
85
146
|
## 0.0.2.alpha
|
86
147
|
|
87
|
-
- support APIs
|
148
|
+
- started to support APIs
|
88
149
|
- `GET /event_types`
|
89
150
|
|
90
151
|
## 0.0.1.alpha
|
91
152
|
|
92
153
|
- Initial release
|
93
|
-
- support
|
154
|
+
- started to support a API
|
94
155
|
- `GET /users/{uuid}`
|
data/README.md
CHANGED
@@ -50,21 +50,28 @@ client = Calendly::Client.new '<ACCESS_TOKEN>'
|
|
50
50
|
This client basic usage is below.
|
51
51
|
|
52
52
|
```ruby
|
53
|
+
#
|
53
54
|
# get a current user's information.
|
55
|
+
#
|
54
56
|
me = client.me
|
55
|
-
# =>
|
57
|
+
# => #<Calendly::User uuid="U001", name="Foo Bar", slug="foobar", email="foobar@example.com", ..>
|
58
|
+
|
56
59
|
me.scheduling_url
|
57
|
-
# => "https://calendly.com/
|
60
|
+
# => "https://calendly.com/foobar"
|
58
61
|
|
59
|
-
#
|
62
|
+
#
|
63
|
+
# get all event types
|
64
|
+
#
|
60
65
|
event_types = me.event_types
|
61
|
-
# => [#<Calendly::EventType uuid
|
66
|
+
# => [#<Calendly::EventType uuid="ET001", name="15 Minute Meeting", type="StandardEventType", slug="15min", active=true, kind="solo", scheduling_url="https://calendly.com/foobar/15min", ..>, #<Calendly::EventType uuid="ET002", name="30 Minute Meeting", type="StandardEventType", slug="30min", active=true, kind="solo", scheduling_url="https://calendly.com/foobar/30min", ..>]
|
62
67
|
event_types.first.scheduling_url
|
63
|
-
# => "https://calendly.com/
|
68
|
+
# => "https://calendly.com/foobar/15min"
|
64
69
|
|
70
|
+
#
|
65
71
|
# get scheduled events
|
72
|
+
#
|
66
73
|
events = me.scheduled_events
|
67
|
-
# => => [#<Calendly::Event uuid
|
74
|
+
# => => [#<Calendly::Event uuid="EV001", name="FooBar Meeting", status="active", ..>, #<Calendly::Event uuid="EV002", name="Team Meeting", status="active", ..>]
|
68
75
|
ev = events.first
|
69
76
|
ev.name
|
70
77
|
# => "FooBar Meeting"
|
@@ -73,21 +80,23 @@ ev.start_time
|
|
73
80
|
ev.end_time
|
74
81
|
# => 2020-07-22 02:00:00 UTC
|
75
82
|
|
76
|
-
#
|
77
|
-
|
78
|
-
#
|
79
|
-
|
80
|
-
|
81
|
-
|
83
|
+
#
|
84
|
+
# get a current organization's information
|
85
|
+
#
|
86
|
+
org = me.current_organization
|
87
|
+
# => #<Calendly::Organization uuid="ORG001", ..>
|
88
|
+
all_members = org.memberships
|
89
|
+
# => [#<Calendly::OrganizationMembership uuid="MEM001", role="owner", ..>, #<Calendly::OrganizationMembership uuid="MEM002", role="user", ..>]
|
82
90
|
|
91
|
+
#
|
83
92
|
# create new invitation and send invitation email
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
# => "pending"
|
93
|
+
#
|
94
|
+
invitation = org.create_invitation('foobar@example.com')
|
95
|
+
# => #<Calendly::OrganizationInvitation uuid="INV001", status="pending", email="foobar@example.com", ..>
|
88
96
|
|
89
97
|
# cancel the invitation
|
90
98
|
invitation.delete
|
99
|
+
# => true
|
91
100
|
```
|
92
101
|
|
93
102
|
### Webhook
|
@@ -96,31 +105,33 @@ The webhook usage is below.
|
|
96
105
|
|
97
106
|
```ruby
|
98
107
|
events = ['invitee.created', 'invitee.canceled']
|
99
|
-
own_member = client.me.organization_membership
|
100
|
-
org = own_member.organization
|
101
|
-
|
102
|
-
# create user scope webhook
|
103
108
|
url = 'https://example.com/received_event'
|
104
|
-
|
105
|
-
#
|
109
|
+
|
110
|
+
#
|
111
|
+
# create a user scope webhook
|
112
|
+
#
|
113
|
+
me = client.me
|
114
|
+
user_webhook = me.create_webhook(url, events)
|
115
|
+
# => #<Calendly::WebhookSubscription uuid="USER_WEBHOOK_001", state="active", scope="user", events=["invitee.created", "invitee.canceled"], callback_url="https://example.com/received_event", ..>
|
106
116
|
|
107
117
|
# list of user scope webhooks
|
108
|
-
|
109
|
-
# => [#<Calendly::WebhookSubscription uuid
|
118
|
+
me.webhooks
|
119
|
+
# => [#<Calendly::WebhookSubscription uuid="USER_WEBHOOK_001", state="active", scope="user", events=["invitee.created", "invitee.canceled"], callback_url="https://example.com/received_event", ..>]
|
110
120
|
|
111
121
|
# delete the webhook
|
112
122
|
user_webhook.delete
|
113
123
|
# => true
|
114
124
|
|
115
|
-
|
116
|
-
# create organization scope webhook
|
117
|
-
|
125
|
+
#
|
126
|
+
# create an organization scope webhook
|
127
|
+
#
|
128
|
+
org = client.me.current_organization
|
118
129
|
org_webhook = org.create_webhook(url, events)
|
119
|
-
# => #<Calendly::WebhookSubscription uuid
|
130
|
+
# => #<Calendly::WebhookSubscription uuid="ORG_WEBHOOK_001", state="active", scope="organization", events=["invitee.created", "invitee.canceled"], callback_url="https://example.com/received_event", ..>
|
120
131
|
|
121
132
|
# list of organization scope webhooks
|
122
133
|
org.webhooks
|
123
|
-
# => [#<Calendly::WebhookSubscription uuid
|
134
|
+
# => [#<Calendly::WebhookSubscription uuid="ORG_WEBHOOK_001", state="active", scope="organization", events=["invitee.created", "invitee.canceled"], callback_url="https://example.com/received_event", ..>]
|
124
135
|
|
125
136
|
# delete the webhook
|
126
137
|
org_webhook.delete
|
data/lib/calendly/api_error.rb
CHANGED
@@ -7,10 +7,13 @@ module Calendly
|
|
7
7
|
class ApiError < Error
|
8
8
|
# @return [Faraday::Response]
|
9
9
|
attr_reader :response
|
10
|
+
|
10
11
|
# @return [Integer]
|
11
12
|
attr_reader :status
|
13
|
+
|
12
14
|
# @return [String]
|
13
15
|
attr_reader :title
|
16
|
+
|
14
17
|
# @return [OAuth2::Error, JSON::ParserError]
|
15
18
|
attr_reader :cause_exception
|
16
19
|
|
data/lib/calendly/client.rb
CHANGED
@@ -25,7 +25,7 @@ module Calendly
|
|
25
25
|
# @return [OAuth2::AccessToken]
|
26
26
|
# @since 0.0.1
|
27
27
|
def access_token
|
28
|
-
return @access_token if defined? @access_token
|
28
|
+
return @access_token if defined?(@access_token) && @access_token
|
29
29
|
|
30
30
|
client = OAuth2::Client.new(@config.client_id,
|
31
31
|
@config.client_secret, client_options)
|
@@ -59,7 +59,7 @@ module Calendly
|
|
59
59
|
# @raise [Calendly::ApiError] if the api returns error code.
|
60
60
|
# @since 0.0.1
|
61
61
|
def current_user
|
62
|
-
return @cached_current_user if @cached_current_user
|
62
|
+
return @cached_current_user if defined?(@cached_current_user) && @cached_current_user
|
63
63
|
|
64
64
|
@cached_current_user = user
|
65
65
|
end
|
@@ -103,7 +103,34 @@ module Calendly
|
|
103
103
|
end
|
104
104
|
|
105
105
|
#
|
106
|
-
# Returns all Event Types associated with a specified
|
106
|
+
# Returns all Event Types associated with a specified organization.
|
107
|
+
#
|
108
|
+
# @param [String] org_uri the specified organization (organization's uri).
|
109
|
+
# @param [Hash] opts the optional request parameters.
|
110
|
+
# @option opts [Integer] :count Number of rows to return.
|
111
|
+
# @option opts [String] :page_token Pass this to get the next portion of collection.
|
112
|
+
# @option opts [String] :sort Order results by the specified field and direction. Accepts comma-separated list of {field}:{direction} values.
|
113
|
+
# @return [Array<Array<Calendly::EventType>, Hash>]
|
114
|
+
# - [Array<Calendly::EventType>] event_types
|
115
|
+
# - [Hash] next_params the parameters to get next data. if thre is no next it returns nil.
|
116
|
+
# @raise [Calendly::Error] if the org_uri arg is empty.
|
117
|
+
# @raise [Calendly::ApiError] if the api returns error code.
|
118
|
+
# @since 0.6.0
|
119
|
+
def event_types(org_uri, opts = {})
|
120
|
+
check_not_empty org_uri, 'org_uri'
|
121
|
+
|
122
|
+
opts_keys = %i[count page_token sort]
|
123
|
+
params = {organization: org_uri}
|
124
|
+
params = merge_options opts, opts_keys, params
|
125
|
+
body = request :get, 'event_types', params: params
|
126
|
+
|
127
|
+
items = body[:collection] || []
|
128
|
+
ev_types = items.map { |item| EventType.new item, self }
|
129
|
+
[ev_types, next_page_params(body)]
|
130
|
+
end
|
131
|
+
|
132
|
+
#
|
133
|
+
# Returns all Event Types associated with a specified user.
|
107
134
|
#
|
108
135
|
# @param [String] user_uri the specified user (user's uri).
|
109
136
|
# @param [Hash] opts the optional request parameters.
|
@@ -116,7 +143,7 @@ module Calendly
|
|
116
143
|
# @raise [Calendly::Error] if the user_uri arg is empty.
|
117
144
|
# @raise [Calendly::ApiError] if the api returns error code.
|
118
145
|
# @since 0.0.2
|
119
|
-
def
|
146
|
+
def event_types_by_user(user_uri, opts = {})
|
120
147
|
check_not_empty user_uri, 'user_uri'
|
121
148
|
|
122
149
|
opts_keys = %i[count page_token sort]
|
@@ -144,10 +171,42 @@ module Calendly
|
|
144
171
|
end
|
145
172
|
|
146
173
|
#
|
147
|
-
# Get List of
|
174
|
+
# Get List of scheduled events belonging to a specific organization.
|
175
|
+
#
|
176
|
+
# @param [String] org_uri the specified organization (organization's uri).
|
177
|
+
# @param [Hash] opts the optional request parameters.
|
178
|
+
# @option opts [Integer] :count Number of rows to return.
|
179
|
+
# @option opts [String] :invitee_email Return events scheduled with the specified invitee email.
|
180
|
+
# @option opts [String] :max_start_time Upper bound (inclusive) for an event's start time to filter by.
|
181
|
+
# @option opts [String] :min_start_time Lower bound (inclusive) for an event's start time to filter by.
|
182
|
+
# @option opts [String] :page_token Pass this to get the next portion of collection.
|
183
|
+
# @option opts [String] :sort Order results by the specified field and directin. Accepts comma-separated list of {field}:{direction} values.
|
184
|
+
# @option opts [String] :status Whether the scheduled event is active or canceled.
|
185
|
+
# @return [Array<Array<Calendly::Event>, Hash>]
|
186
|
+
# - [Array<Calendly::Event>] events
|
187
|
+
# - [Hash] next_params the parameters to get next data. if thre is no next it returns nil.
|
188
|
+
# @raise [Calendly::Error] if the org_uri arg is empty.
|
189
|
+
# @raise [Calendly::ApiError] if the api returns error code.
|
190
|
+
# @since 0.5.0
|
191
|
+
def scheduled_events(org_uri, opts = {})
|
192
|
+
check_not_empty org_uri, 'org_uri'
|
193
|
+
|
194
|
+
opts_keys = %i[count invitee_email max_start_time min_start_time page_token sort status]
|
195
|
+
params = {organization: org_uri}
|
196
|
+
params = merge_options opts, opts_keys, params
|
197
|
+
body = request :get, 'scheduled_events', params: params
|
198
|
+
|
199
|
+
items = body[:collection] || []
|
200
|
+
evs = items.map { |item| Event.new item, self }
|
201
|
+
[evs, next_page_params(body)]
|
202
|
+
end
|
203
|
+
|
204
|
+
#
|
205
|
+
# Get List of scheduled events belonging to a specific user.
|
148
206
|
#
|
149
207
|
# @param [String] user_uri the specified user (user's uri).
|
150
208
|
# @param [Hash] opts the optional request parameters.
|
209
|
+
# @option opts [String] :organization the specified organization (organization's uri).
|
151
210
|
# @option opts [Integer] :count Number of rows to return.
|
152
211
|
# @option opts [String] :invitee_email Return events scheduled with the specified invitee email.
|
153
212
|
# @option opts [String] :max_start_time Upper bound (inclusive) for an event's start time to filter by.
|
@@ -161,10 +220,10 @@ module Calendly
|
|
161
220
|
# @raise [Calendly::Error] if the user_uri arg is empty.
|
162
221
|
# @raise [Calendly::ApiError] if the api returns error code.
|
163
222
|
# @since 0.0.3
|
164
|
-
def
|
223
|
+
def scheduled_events_by_user(user_uri, opts = {})
|
165
224
|
check_not_empty user_uri, 'user_uri'
|
166
225
|
|
167
|
-
opts_keys = %i[count invitee_email max_start_time min_start_time page_token sort status]
|
226
|
+
opts_keys = %i[organization count invitee_email max_start_time min_start_time page_token sort status]
|
168
227
|
params = {user: user_uri}
|
169
228
|
params = merge_options opts, opts_keys, params
|
170
229
|
body = request :get, 'scheduled_events', params: params
|
@@ -235,7 +294,7 @@ module Calendly
|
|
235
294
|
end
|
236
295
|
|
237
296
|
#
|
238
|
-
# Get List
|
297
|
+
# Get List of memberships belonging to specific an organization.
|
239
298
|
#
|
240
299
|
# @param [String] org_uri the specified organization (organization's uri).
|
241
300
|
# @param [Hash] opts the optional request parameters.
|
@@ -262,7 +321,7 @@ module Calendly
|
|
262
321
|
end
|
263
322
|
|
264
323
|
#
|
265
|
-
# Get List
|
324
|
+
# Get List of memberships belonging to specific a user.
|
266
325
|
#
|
267
326
|
# @param [String] user_uri the specified user (user's uri).
|
268
327
|
# @param [Hash] opts the optional request parameters.
|
@@ -461,26 +520,29 @@ module Calendly
|
|
461
520
|
# @param [String] url Canonical reference (unique identifier) for the resource.
|
462
521
|
# @param [Array<String>] events List of user events to subscribe to. options: invitee.created or invitee.canceled
|
463
522
|
# @param [String] org_uri The unique reference to the organization that the webhook will be tied to.
|
464
|
-
# @param [String] user_uri The unique reference to the user that the webhook will be tied to.
|
523
|
+
# @param [String] user_uri The unique reference to the user that the webhook will be tied to. Optional.
|
524
|
+
# @param [String] signing_key secret key shared between your application and Calendly. Optional.
|
465
525
|
# @return [Calendly::WebhookSubscription]
|
466
526
|
# @raise [Calendly::Error] if the url arg is empty.
|
467
527
|
# @raise [Calendly::Error] if the events arg is empty.
|
468
528
|
# @raise [Calendly::Error] if the org_uri arg is empty.
|
469
529
|
# @raise [Calendly::ApiError] if the api returns error code.
|
470
530
|
# @since 0.1.3
|
471
|
-
def create_webhook(url, events, org_uri, user_uri
|
531
|
+
def create_webhook(url, events, org_uri, user_uri: nil, signing_key: nil) # rubocop:disable Metrics/ParameterLists
|
472
532
|
check_not_empty url, 'url'
|
473
533
|
check_not_empty events, 'events'
|
474
534
|
check_not_empty org_uri, 'org_uri'
|
475
535
|
|
476
536
|
params = {url: url, events: events, organization: org_uri}
|
537
|
+
params[:signing_key] = signing_key if signing_key
|
538
|
+
|
477
539
|
if user_uri
|
478
540
|
params[:scope] = 'user'
|
479
541
|
params[:user] = user_uri
|
480
542
|
else
|
481
543
|
params[:scope] = 'organization'
|
482
544
|
end
|
483
|
-
body = request
|
545
|
+
body = request :post, 'webhook_subscriptions', body: params
|
484
546
|
WebhookSubscription.new body[:resource], self
|
485
547
|
end
|
486
548
|
|
@@ -498,12 +560,43 @@ module Calendly
|
|
498
560
|
true
|
499
561
|
end
|
500
562
|
|
563
|
+
#
|
564
|
+
# Create a scheduling link.
|
565
|
+
#
|
566
|
+
# @param [String] uri A link to the resource that owns this scheduling Link.
|
567
|
+
# @param [String] max_event_count The max number of events that can be scheduled using this scheduling link.
|
568
|
+
# @param [String] resource_type Resource type.
|
569
|
+
# @return [Hash]
|
570
|
+
# e.g.
|
571
|
+
# {
|
572
|
+
# booking_url: "https://calendly.com/s/FOO-BAR-SLUG",
|
573
|
+
# owner: "https://api.calendly.com/event_types/GBGBDCAADAEDCRZ2",
|
574
|
+
# owner_type: "EventType"
|
575
|
+
# }
|
576
|
+
# @raise [Calendly::Error] if the uri arg is empty.
|
577
|
+
# @raise [Calendly::Error] if the max_event_count arg is empty.
|
578
|
+
# @raise [Calendly::Error] if the resource_type arg is empty.
|
579
|
+
# @raise [Calendly::ApiError] if the api returns error code.
|
580
|
+
# @since 0.5.2
|
581
|
+
def create_schedule_link(uri, max_event_count = 1, resource_type: 'EventType')
|
582
|
+
check_not_empty uri, 'uri'
|
583
|
+
check_not_empty max_event_count, 'max_event_count'
|
584
|
+
check_not_empty resource_type, 'resource_type'
|
585
|
+
params = {
|
586
|
+
max_event_count: max_event_count,
|
587
|
+
owner: uri,
|
588
|
+
owner_type: resource_type
|
589
|
+
}
|
590
|
+
body = request :post, 'scheduling_links', body: params
|
591
|
+
body[:resource]
|
592
|
+
end
|
593
|
+
|
501
594
|
private
|
502
595
|
|
503
596
|
def request(method, path, params: nil, body: nil)
|
504
597
|
debug_log "Request #{method.to_s.upcase} #{API_HOST}/#{path} params:#{params}, body:#{body}"
|
505
|
-
res = access_token.request
|
506
|
-
debug_log "Response status:#{res.status}, body:#{res.body}"
|
598
|
+
res = access_token.request method, path, params: params, body: body
|
599
|
+
debug_log "Response status:#{res.status}, body:#{res.body.dup&.force_encoding(Encoding::UTF_8)}"
|
507
600
|
parse_as_json res
|
508
601
|
rescue OAuth2::Error => e
|
509
602
|
res = e.response.response
|