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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06ba574d911ff7447d87b9dafe93105da126e1b78cc054d1e2d220e1403961e0
4
- data.tar.gz: 7cd7c74bd6ad8679c0f83d8832fc3da0ef81013d677186a207890194116f69eb
3
+ metadata.gz: 7ba1370ffbfb35b34a37f514d94f48879a20a2ee5b33ebb1791969883a7303a7
4
+ data.tar.gz: 5deec005ae70cdbf6f864c7ed7eec03d8186ef3127452f4221e9c9e3863f7c8d
5
5
  SHA512:
6
- metadata.gz: 0d95d23f7acfea8d1f5884930125f9f6489fb7ab7515090a39571712d994893b6de66a880bba72425cd090dae26a3cd07bb4a12266e8de48d347a8e334ce6604
7
- data.tar.gz: b7b7902adf506e3498d32161794f7dc871e3797e6ed307aa72d35378cd8f1837feb8ea732e79d9f21d80adb45886c1e8611fcc33d8d244987a338bfca6dd5eae
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
- - add new following fields to Invitee model (refs #21)
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
- - fix changed Location fields such as `kind` to `type`. (refs #18)
80
+ - fixed a changes for Location fields such as `kind` to `type`. (refs #18)
20
81
 
21
82
  ## 0.3.0
22
83
 
23
- - remove zeitwerk dependency. (refs #16)
84
+ - removed zeitwerk dependency. (refs #16)
24
85
 
25
86
  ## 0.2.0
26
87
 
27
- - save fetched data in cache. (refs #14)
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
- - fix rubocop warnings.
100
+ - fixed rubocop warnings.
40
101
 
41
102
  ## 0.1.1
42
103
 
43
- - add tests to make coverage 100%.
104
+ - added tests to make coverage 100%.
44
105
 
45
106
  ## 0.1.0
46
107
 
47
- - define methods to access associated resources with each model.
48
- - rename methods:
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
- - rename fields
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 APIs
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
- # => <Calendly::User uuid:U001>
57
+ # => #<Calendly::User uuid="U001", name="Foo Bar", slug="foobar", email="foobar@example.com", ..>
58
+
56
59
  me.scheduling_url
57
- # => "https://calendly.com/your_name"
60
+ # => "https://calendly.com/foobar"
58
61
 
59
- # get all Event Types
62
+ #
63
+ # get all event types
64
+ #
60
65
  event_types = me.event_types
61
- # => [#<Calendly::EventType uuid:ET001>, #<Calendly::EventType uuid:ET002>, #<Calendly::EventType uuid:ET003>]
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/your_name/30min"
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:EV001>, #<Calendly::Event uuid:EV002>, #<Calendly::Event uuid:EV003>]
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
- # get organization information
77
- own_member = me.organization_membership
78
- # => #<Calendly::OrganizationMembership uuid:MEM001>
79
- my_org = own_member.organization
80
- all_members = my_org.memberships
81
- # => [#<Calendly::OrganizationMembership uuid:MEM001>, #<Calendly::OrganizationMembership uuid:MEM002>]
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
- invitation = my_org.create_invitation('foobar@example.com')
85
- # => #<Calendly::OrganizationInvitation uuid:INV001>
86
- invitation.status
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
- user_webhook = own_member.create_user_scope_webhook(url, events)
105
- # => #<Calendly::WebhookSubscription uuid:USER_WEBHOOK_001>
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
- own_member.user_scope_webhooks
109
- # => [#<Calendly::WebhookSubscription uuid:USER_WEBHOOK_001>]
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
- url = 'https://example.com/received_event'
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:ORG_WEBHOOK_001>
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:ORG_WEBHOOK_001>]
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
@@ -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
 
@@ -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 User.
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 event_types(user_uri, opts = {})
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 User Events.
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 scheduled_events(user_uri, opts = {})
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 memberships of all users belonging to an organization.
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 memberships of all users belonging to an organization by user.
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 = nil)
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(:post, 'webhook_subscriptions', body: params)
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(method, path, params: params, body: body)
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