calendly 0.1.2 → 0.1.3

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: f21bb676098bf2f9d6f6e3ea600f7c4017d48207834646b185dbd459a6a8a531
4
- data.tar.gz: e5e2accd3cc7145d99b3457f7ed87d79223b3b9fc18e0d49abdeb3a6b75b094f
3
+ metadata.gz: 73fe04308ea6b80fec0d5141f3a848476d0b4dd0e818cc32019ab54f9ad02243
4
+ data.tar.gz: 2adaee2381b6631af1d19eb07d0fa122b1cd8d347c877c07808bac5cb3670d6e
5
5
  SHA512:
6
- metadata.gz: ad14b69a614f2f3d39ff993f58b2b5c6f2e5c3a3d74a41b24ac5b17a9a6e915a84f0b99a7282695827d73009019d7ab9c6209a60c1ce8063609f5ab4a1cf5ba1
7
- data.tar.gz: 5c5418b39536db9b1d88247e963e9277ae0964eaa64fdd7aabaef9edc29024aa6afed84e4df9b542fd93bf65fd0f311bdc467365bb7ac3097cc2a1a371dd5774
6
+ metadata.gz: 3a3b7a7dc8926ea80d87e9a3cc5b96a4c6816b78baebeac4d28773eba80ad6078c44ea379e01d0be87ecd47bc8f12eef4d64516a67b7e11adc2a5e843aacc9a7
7
+ data.tar.gz: bf1eb06ab1432c27b7d557cd4c703a6d157ce26f526942a89f3102b34c9d8ba6b3e123d78b5e7ca53348e49125be7e2e3423da7f68540c799745b7b2c35d8c3b
@@ -1,5 +1,14 @@
1
+
1
2
  # CHANGELOG
2
3
 
4
+ ## 0.1.3
5
+
6
+ - support webhook APIs
7
+ - `GET /webhook_subscriptions`
8
+ - `GET /webhook_subscriptions/{webhook_uuid}`
9
+ - `POST /webhook_subscriptions`
10
+ - `DELETE /webhook_subscriptions/{webhook_uuid}`
11
+
3
12
  ## 0.1.2
4
13
 
5
14
  - fix rubocop warnings.
data/README.md CHANGED
@@ -35,7 +35,10 @@ As of now the supported statuses each Calendly API are as below.
35
35
  - [x] Get List of Event Invitees
36
36
  - [x] Get List of User Events
37
37
  - Webhook V2
38
- - These endpoints havn't been released yet.
38
+ - [x] Create Webhook Subscription
39
+ - [x] Delete Webhook Subscription
40
+ - [x] Get Webhook Subscription
41
+ - [x] List Webhook Subscriptions
39
42
 
40
43
  ## Installation
41
44
 
@@ -55,6 +58,8 @@ Or install it yourself as:
55
58
 
56
59
  ## Usage
57
60
 
61
+ ### Basic
62
+
58
63
  The APIs client needs access token.
59
64
  This client setup step is below.
60
65
 
@@ -116,7 +121,50 @@ invitation.status
116
121
 
117
122
  # cancel the invitation
118
123
  invitation.delete
124
+ ```
125
+
126
+ ### Webhook
127
+
128
+ The webhook usage is below.
129
+
130
+ ```ruby
131
+ events = ['invitee.created', 'invitee.canceled']
132
+ own_member = client.me.organization_membership
133
+ org = own_member.organization
134
+
135
+ # create user scope webhook
136
+ url = 'https://example.com/received_event'
137
+ user_webhook = own_member.create_user_scope_webhook(url, events)
138
+ # => #<Calendly::WebhookSubscription uuid:USER_WEBHOOK_001>
139
+
140
+ # list of user scope webhooks
141
+ own_member.user_scope_webhooks
142
+ # => [#<Calendly::WebhookSubscription uuid:USER_WEBHOOK_001>]
143
+
144
+ # delete the webhook
145
+ user_webhook.delete
146
+ # => true
119
147
 
148
+
149
+ # create organization scope webhook
150
+ url = 'https://example.com/received_event'
151
+ org_webhook = org.create_webhook(url, events)
152
+ # => #<Calendly::WebhookSubscription uuid:ORG_WEBHOOK_001>
153
+
154
+ # list of organization scope webhooks
155
+ org.webhooks
156
+ # => [#<Calendly::WebhookSubscription uuid:ORG_WEBHOOK_001>]
157
+
158
+ # delete the webhook
159
+ org_webhook.delete
160
+ # => true
161
+ ```
162
+
163
+ ### Logging
164
+
165
+ This library supports a configurable logger.
166
+
167
+ ```ruby
120
168
  # if the log level set :debug, you can get the request/response information.
121
169
  Calendly.configuration.logger.level = :debug
122
170
  invitation = my_org.create_invitation('foobar@example.com')
@@ -125,12 +125,12 @@ module Calendly
125
125
  # @param [String] user_uri the specified user (user's uri).
126
126
  # @param [Hash] opts the optional request parameters.
127
127
  # @option opts [Integer] :count Number of rows to return.
128
- # @option opts [String] :invitee_email Return events scheduled with the specified invitee email
128
+ # @option opts [String] :invitee_email Return events scheduled with the specified invitee email.
129
129
  # @option opts [String] :max_start_time Upper bound (inclusive) for an event's start time to filter by.
130
130
  # @option opts [String] :min_start_time Lower bound (inclusive) for an event's start time to filter by.
131
131
  # @option opts [String] :page_token Pass this to get the next portion of collection.
132
132
  # @option opts [String] :sort Order results by the specified field and directin. Accepts comma-separated list of {field}:{direction} values.
133
- # @option opts [String] :status Whether the scheduled event is active or canceled
133
+ # @option opts [String] :status Whether the scheduled event is active or canceled.
134
134
  # @return [Array<Array<Calendly::Event>, Hash>]
135
135
  # - [Array<Calendly::Event>] events
136
136
  # - [Hash] next_params the parameters to get next data. if thre is no next it returns nil.
@@ -362,6 +362,118 @@ module Calendly
362
362
  true
363
363
  end
364
364
 
365
+ #
366
+ # Get a webhook subscription for an organization or user with a specified UUID.
367
+ #
368
+ # @param [String] uuid the specified webhook (webhook's uuid).
369
+ # @return [Calendly::WebhookSubscription]
370
+ # @raise [Calendly::Error] if the uuid arg is empty.
371
+ # @raise [Calendly::ApiError] if the api returns error code.
372
+ # @since 0.1.3
373
+ def webhook(uuid)
374
+ check_not_empty uuid, 'uuid'
375
+ body = request :get, "webhook_subscriptions/#{uuid}"
376
+ WebhookSubscription.new body[:resource], self
377
+ end
378
+
379
+ #
380
+ # Get List of organization scope Webhooks.
381
+ #
382
+ # @param [String] org_uri the specified organization (organization's uri).
383
+ # @param [Hash] opts the optional request parameters.
384
+ # @option opts [Integer] :count Number of rows to return.
385
+ # @option opts [String] :page_token Pass this to get the next portion of collection.
386
+ # @option opts [String] :sort Order results by the specified field and directin. Accepts comma-separated list of {field}:{direction} values.
387
+ # @return [Array<Array<Calendly::WebhookSubscription>, Hash>]
388
+ # - [Array<Calendly::WebhookSubscription>] webhooks
389
+ # - [Hash] next_params the parameters to get next data. if thre is no next it returns nil.
390
+ # @raise [Calendly::Error] if the org_uri arg is empty.
391
+ # @raise [Calendly::ApiError] if the api returns error code.
392
+ # @since 0.1.3
393
+ def webhooks(org_uri, opts = {})
394
+ check_not_empty org_uri, 'org_uri'
395
+
396
+ opts_keys = %i[count page_token sort]
397
+ params = {organization: org_uri, scope: 'organization'}
398
+ params = merge_options opts, opts_keys, params
399
+ body = request :get, 'webhook_subscriptions', params: params
400
+ items = body[:collection] || []
401
+ evs = items.map { |item| WebhookSubscription.new item, self }
402
+ [evs, next_page_params(body)]
403
+ end
404
+
405
+ #
406
+ # Get List of user scope Webhooks.
407
+ #
408
+ # @param [String] org_uri the specified organization (organization's uri).
409
+ # @param [String] user_uri the specified user (user's uri).
410
+ # @param [Hash] opts the optional request parameters.
411
+ # @option opts [Integer] :count Number of rows to return.
412
+ # @option opts [String] :page_token Pass this to get the next portion of collection.
413
+ # @option opts [String] :sort Order results by the specified field and directin. Accepts comma-separated list of {field}:{direction} values.
414
+ # @return [Array<Array<Calendly::WebhookSubscription>, Hash>]
415
+ # - [Array<Calendly::WebhookSubscription>] webhooks
416
+ # - [Hash] next_params the parameters to get next data. if thre is no next it returns nil.
417
+ # @raise [Calendly::Error] if the org_uri arg is empty.
418
+ # @raise [Calendly::Error] if the user_uri arg is empty.
419
+ # @raise [Calendly::ApiError] if the api returns error code.
420
+ # @since 0.1.3
421
+ def user_scope_webhooks(org_uri, user_uri, opts = {})
422
+ check_not_empty org_uri, 'org_uri'
423
+ check_not_empty user_uri, 'user_uri'
424
+
425
+ opts_keys = %i[count page_token sort]
426
+ params = {organization: org_uri, user: user_uri, scope: 'user'}
427
+ params = merge_options opts, opts_keys, params
428
+ body = request :get, 'webhook_subscriptions', params: params
429
+ items = body[:collection] || []
430
+ evs = items.map { |item| WebhookSubscription.new item, self }
431
+ [evs, next_page_params(body)]
432
+ end
433
+
434
+ #
435
+ # Create a webhook subscription for an organization or user.
436
+ #
437
+ # @param [String] url Canonical reference (unique identifier) for the resource.
438
+ # @param [Array<String>] events List of user events to subscribe to. options: invitee.created or invitee.canceled
439
+ # @param [String] org_uri The unique reference to the organization that the webhook will be tied to.
440
+ # @param [String] user_uri The unique reference to the user that the webhook will be tied to.
441
+ # @return [Calendly::WebhookSubscription]
442
+ # @raise [Calendly::Error] if the url arg is empty.
443
+ # @raise [Calendly::Error] if the events arg is empty.
444
+ # @raise [Calendly::Error] if the org_uri arg is empty.
445
+ # @raise [Calendly::ApiError] if the api returns error code.
446
+ # @since 0.1.3
447
+ def create_webhook(url, events, org_uri, user_uri = nil)
448
+ check_not_empty url, 'url'
449
+ check_not_empty events, 'events'
450
+ check_not_empty org_uri, 'org_uri'
451
+
452
+ params = {url: url, events: events, organization: org_uri}
453
+ if user_uri
454
+ params[:scope] = 'user'
455
+ params[:user] = user_uri
456
+ else
457
+ params[:scope] = 'organization'
458
+ end
459
+ body = request(:post, 'webhook_subscriptions', body: params)
460
+ WebhookSubscription.new body[:resource], self
461
+ end
462
+
463
+ #
464
+ # Delete a webhook subscription for an organization or user with a specified UUID.
465
+ #
466
+ # @param [String] uuid the specified webhook (webhook's uuid).
467
+ # @return [true]
468
+ # @raise [Calendly::Error] if the uuid arg is empty.
469
+ # @raise [Calendly::ApiError] if the api returns error code.
470
+ # @since 0.1.3
471
+ def delete_webhook(uuid)
472
+ check_not_empty uuid, 'uuid'
473
+ request :delete, "webhook_subscriptions/#{uuid}"
474
+ true
475
+ end
476
+
365
477
  private
366
478
 
367
479
  def request(method, path, params: nil, body: nil)
@@ -389,6 +501,7 @@ module Calendly
389
501
  def blank?(value)
390
502
  return true if value.nil?
391
503
  return true if value.to_s.empty?
504
+ return true if value.is_a?(Array) && value.empty?
392
505
 
393
506
  false
394
507
  end
@@ -68,10 +68,10 @@ module Calendly
68
68
  attrs.each do |key, value|
69
69
  next unless respond_to? "#{key}=".to_sym
70
70
 
71
- if defined?(self.class::ASSOCIATION) && self.class::ASSOCIATION.key?(key)
71
+ if value && defined?(self.class::ASSOCIATION) && self.class::ASSOCIATION.key?(key)
72
72
  associated_attrs = value.is_a?(Hash) ? value : {uri: value}
73
73
  value = self.class::ASSOCIATION[key].new associated_attrs, @client
74
- elsif defined?(self.class::TIME_FIELDS) && self.class::TIME_FIELDS.include?(key)
74
+ elsif value && defined?(self.class::TIME_FIELDS) && self.class::TIME_FIELDS.include?(key)
75
75
  value = Time.parse value
76
76
  end
77
77
  instance_variable_set "@#{key}", value
@@ -60,5 +60,37 @@ module Calendly
60
60
  def create_invitation(email)
61
61
  client.create_invitation uuid, email
62
62
  end
63
+
64
+ #
65
+ # Get List of organization scope Webhooks associated with self.
66
+ #
67
+ # @param [Hash] opts the optional request parameters.
68
+ # @option opts [Integer] :count Number of rows to return.
69
+ # @option opts [String] :page_token Pass this to get the next portion of collection.
70
+ # @option opts [String] :sort Order results by the specified field and directin. Accepts comma-separated list of {field}:{direction} values.
71
+ # Accepts comma-separated list of {field}:{direction} values.
72
+ # @return [Array<Calendly::WebhookSubscription>]
73
+ # @raise [Calendly::Error] if the uri is empty.
74
+ # @raise [Calendly::ApiError] if the api returns error code.
75
+ # @since 0.1.3
76
+ def webhooks(opts = {})
77
+ request_proc = proc { |options| client.webhooks uri, options }
78
+ auto_pagination request_proc, opts
79
+ end
80
+
81
+ #
82
+ # Create a user scope webhook associated with self.
83
+ #
84
+ # @param [String] url Canonical reference (unique identifier) for the resource.
85
+ # @param [Array<String>] events List of user events to subscribe to. options: invitee.created or invitee.canceled
86
+ # @return [Calendly::WebhookSubscription]
87
+ # @raise [Calendly::Error] if the url arg is empty.
88
+ # @raise [Calendly::Error] if the events arg is empty.
89
+ # @raise [Calendly::Error] if the uri is empty.
90
+ # @raise [Calendly::ApiError] if the api returns error code.
91
+ # @since 0.1.3
92
+ def create_webhook(url, events)
93
+ client.create_webhook url, events, uri
94
+ end
63
95
  end
64
96
  end
@@ -52,5 +52,42 @@ module Calendly
52
52
  def delete
53
53
  client.delete_membership uuid
54
54
  end
55
+
56
+ #
57
+ # Get List of user scope Webhooks associated with self.
58
+ #
59
+ # @param [Hash] opts the optional request parameters.
60
+ # @option opts [Integer] :count Number of rows to return.
61
+ # @option opts [String] :page_token Pass this to get the next portion of collection.
62
+ # @option opts [String] :sort Order results by the specified field and directin. Accepts comma-separated list of {field}:{direction} values.
63
+ # Accepts comma-separated list of {field}:{direction} values.
64
+ # @return [Array<Calendly::WebhookSubscription>]
65
+ # @raise [Calendly::Error] if the organization.uri is empty.
66
+ # @raise [Calendly::Error] if the user.uri is empty.
67
+ # @raise [Calendly::ApiError] if the api returns error code.
68
+ # @since 0.1.3
69
+ def user_scope_webhooks(opts = {})
70
+ org_uri = organization.uri if organization
71
+ user_uri = user.uri if user
72
+ request_proc = proc { |options| client.user_scope_webhooks org_uri, user_uri, options }
73
+ auto_pagination request_proc, opts
74
+ end
75
+
76
+ #
77
+ # Create a user scope webhook associated with self.
78
+ #
79
+ # @param [String] url Canonical reference (unique identifier) for the resource.
80
+ # @param [Array<String>] events List of user events to subscribe to. options: invitee.created or invitee.canceled
81
+ # @return [Calendly::WebhookSubscription]
82
+ # @raise [Calendly::Error] if the url arg is empty.
83
+ # @raise [Calendly::Error] if the events arg is empty.
84
+ # @raise [Calendly::Error] if the organization.uri is empty.
85
+ # @raise [Calendly::ApiError] if the api returns error code.
86
+ # @since 0.1.3
87
+ def create_user_scope_webhook(url, events)
88
+ org_uri = organization.uri if organization
89
+ user_uri = user.uri if user
90
+ client.create_webhook url, events, org_uri, user_uri
91
+ end
55
92
  end
56
93
  end
@@ -0,0 +1,72 @@
1
+ # Get a webhook subscription matching the provided UUID for the webhook subscription
2
+
3
+ # frozen_string_literal: true
4
+
5
+ module Calendly
6
+ # Calendly's webhook model.
7
+ class WebhookSubscription
8
+ include ModelUtils
9
+ UUID_RE = %r{\A#{Client::API_HOST}/webhook_subscriptions/(\w+)\z}.freeze
10
+ TIME_FIELDS = %i[created_at updated_at retry_started_at].freeze
11
+ ASSOCIATION = {organization: Organization, user: User, creator: User}.freeze
12
+
13
+ # @return [String]
14
+ # unique id of the WebhookSubscription object.
15
+ attr_accessor :uuid
16
+ # @return [String]
17
+ # Canonical reference (unique identifier) for the webhook.
18
+ attr_accessor :uri
19
+ # @return [String]
20
+ # The callback URL to use when the event is triggered.
21
+ attr_accessor :callback_url
22
+ # @return [Time]
23
+ # The moment when the webhook subscription was created.
24
+ attr_accessor :created_at
25
+ # @return [Time]
26
+ # The moment when the webhook subscription was last updated.
27
+ attr_accessor :updated_at
28
+ # @return [Time]
29
+ # The date and time the webhook subscription is retried.
30
+ attr_accessor :retry_started_at
31
+ # @return [String]
32
+ # Indicates if the webhook subscription is "active" or "disabled".
33
+ attr_accessor :state
34
+ # @return [Array<String>]
35
+ # A list of events to which the webhook is subscribed.
36
+ attr_accessor :events
37
+ # @return [String]
38
+ # The scope of the webhook subscription.
39
+ attr_accessor :scope
40
+ # @return [Calendly::Organization]
41
+ # The organization that's associated with the webhook subscription.
42
+ attr_accessor :organization
43
+ # @return [Calendly::User]
44
+ # The user that's associated with the webhook subscription.
45
+ attr_accessor :user
46
+ # @return [Calendly::User]
47
+ # The user who created the webhook subscription.
48
+ attr_accessor :creator
49
+
50
+ #
51
+ # Get a webhook subscription associated with self.
52
+ #
53
+ # @return [Calendly::WebhookSubscription]
54
+ # @raise [Calendly::Error] if the uuid is empty.
55
+ # @raise [Calendly::ApiError] if the api returns error code.
56
+ # @since 0.1.3
57
+ def fetch
58
+ client.webhook uuid
59
+ end
60
+
61
+ #
62
+ # Delete a webhook subscription associated with self.
63
+ #
64
+ # @return [true]
65
+ # @raise [Calendly::Error] if the uuid is empty.
66
+ # @raise [Calendly::ApiError] if the api returns error code.
67
+ # @since 0.1.0
68
+ def delete
69
+ client.delete_webhook uuid
70
+ end
71
+ end
72
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Calendly
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calendly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenji Koshikawa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-03 00:00:00.000000000 Z
11
+ date: 2020-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2
@@ -159,6 +159,7 @@ files:
159
159
  - lib/calendly/models/organization_invitation.rb
160
160
  - lib/calendly/models/organization_membership.rb
161
161
  - lib/calendly/models/user.rb
162
+ - lib/calendly/models/webhook_subscription.rb
162
163
  - lib/calendly/version.rb
163
164
  homepage: https://github.com/koshilife/calendly-api-ruby-client
164
165
  licenses:
@@ -167,7 +168,7 @@ metadata:
167
168
  homepage_uri: https://github.com/koshilife/calendly-api-ruby-client
168
169
  source_code_uri: https://github.com/koshilife/calendly-api-ruby-client
169
170
  changelog_uri: https://github.com/koshilife/calendly-api-ruby-client/blob/master/CHANGELOG.md
170
- documentation_uri: https://www.rubydoc.info/gems/calendly/0.1.2
171
+ documentation_uri: https://www.rubydoc.info/gems/calendly/0.1.3
171
172
  post_install_message:
172
173
  rdoc_options: []
173
174
  require_paths: