calendly 0.1.2 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f21bb676098bf2f9d6f6e3ea600f7c4017d48207834646b185dbd459a6a8a531
4
- data.tar.gz: e5e2accd3cc7145d99b3457f7ed87d79223b3b9fc18e0d49abdeb3a6b75b094f
3
+ metadata.gz: 7eb04cc45dc6c81f18994d5d821e3afc4013467c58fbebc22e39810b6fccee91
4
+ data.tar.gz: 5135a1f761cd6e85d24359e80a3e658e640f0834ac5bd3a1169cb96b15e8c256
5
5
  SHA512:
6
- metadata.gz: ad14b69a614f2f3d39ff993f58b2b5c6f2e5c3a3d74a41b24ac5b17a9a6e915a84f0b99a7282695827d73009019d7ab9c6209a60c1ce8063609f5ab4a1cf5ba1
7
- data.tar.gz: 5c5418b39536db9b1d88247e963e9277ae0964eaa64fdd7aabaef9edc29024aa6afed84e4df9b542fd93bf65fd0f311bdc467365bb7ac3097cc2a1a371dd5774
6
+ metadata.gz: abdc8ba4475063741397bafd3b7bcbba08935817b0c0532d38d3f2b59f87673afd66bf0da99980cacf37f7e1383ac633bb835d710856f16841b656d706ed27d8
7
+ data.tar.gz: 65d4cc6e0e23e239bd5e3c2cdc65f6cd10bbdc0410d4be146ae3d228e0fb21ed22cd0172c67f18a6e50a42df19da31a88d0e795a580a2e07db2abad23121a68a
@@ -1,5 +1,30 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.4.1
4
+
5
+ - support API
6
+ - `GET /event_types/{uuid}`
7
+
8
+ ## 0.4.0
9
+
10
+ - fix changed Location fields such as `kind` to `type`. (refs #18)
11
+
12
+ ## 0.3.0
13
+
14
+ - remove zeitwerk dependency. (refs #16)
15
+
16
+ ## 0.2.0
17
+
18
+ - save fetched data in cache. (refs #14)
19
+
20
+ ## 0.1.3
21
+
22
+ - support webhook APIs (refs #9)
23
+ - `GET /webhook_subscriptions`
24
+ - `GET /webhook_subscriptions/{webhook_uuid}`
25
+ - `POST /webhook_subscriptions`
26
+ - `DELETE /webhook_subscriptions/{webhook_uuid}`
27
+
3
28
  ## 0.1.2
4
29
 
5
30
  - fix rubocop warnings.
data/README.md CHANGED
@@ -5,37 +5,7 @@
5
5
  [![Gem Version](https://badge.fury.io/rb/calendly.svg)](http://badge.fury.io/rb/calendly)
6
6
  [![license](https://img.shields.io/github/license/koshilife/calendly-api-ruby-client)](https://github.com/koshilife/calendly-api-ruby-client/blob/master/LICENSE.txt)
7
7
 
8
- ## About
9
-
10
- These client libraries are created for [Calendly v2 APIs](https://calendly.stoplight.io/docs/gh/calendly/api-docs).
11
-
12
- As of August 2020, Calendly v2 API is currently undergoing an upgrade.
13
- This library is trying to follow and support for the upgrade.
14
-
15
- As of now the supported statuses each Calendly API are as below.
16
-
17
- ## Supported statuses each Calendly API
18
-
19
- - User
20
- - [x] Get basic information about a user
21
- - EventType
22
- - [ ] Get Event Type (This endpoint hasn't been released yet.)
23
- - [x] User Event Types
24
- - Organization
25
- - [x] Get Organization Invitation
26
- - [x] Get Organization Invitations
27
- - [x] Get Organization Membership
28
- - [x] Get a list of Organization Memberships
29
- - [x] Invite a person to Organization
30
- - [x] Remove a User from an Organization
31
- - [x] Revoke Organization Invitation
32
- - ScheduledEvent
33
- - [x] Get Event
34
- - [x] Get Invitee of an Event
35
- - [x] Get List of Event Invitees
36
- - [x] Get List of User Events
37
- - Webhook V2
38
- - These endpoints havn't been released yet.
8
+ These client libraries are created for [Calendly v2 APIs](https://calendly.stoplight.io/).
39
9
 
40
10
  ## Installation
41
11
 
@@ -55,6 +25,8 @@ Or install it yourself as:
55
25
 
56
26
  ## Usage
57
27
 
28
+ ### Basic
29
+
58
30
  The APIs client needs access token.
59
31
  This client setup step is below.
60
32
 
@@ -116,7 +88,50 @@ invitation.status
116
88
 
117
89
  # cancel the invitation
118
90
  invitation.delete
91
+ ```
92
+
93
+ ### Webhook
94
+
95
+ The webhook usage is below.
96
+
97
+ ```ruby
98
+ events = ['invitee.created', 'invitee.canceled']
99
+ own_member = client.me.organization_membership
100
+ org = own_member.organization
101
+
102
+ # create user scope webhook
103
+ url = 'https://example.com/received_event'
104
+ user_webhook = own_member.create_user_scope_webhook(url, events)
105
+ # => #<Calendly::WebhookSubscription uuid:USER_WEBHOOK_001>
106
+
107
+ # list of user scope webhooks
108
+ own_member.user_scope_webhooks
109
+ # => [#<Calendly::WebhookSubscription uuid:USER_WEBHOOK_001>]
110
+
111
+ # delete the webhook
112
+ user_webhook.delete
113
+ # => true
119
114
 
115
+
116
+ # create organization scope webhook
117
+ url = 'https://example.com/received_event'
118
+ org_webhook = org.create_webhook(url, events)
119
+ # => #<Calendly::WebhookSubscription uuid:ORG_WEBHOOK_001>
120
+
121
+ # list of organization scope webhooks
122
+ org.webhooks
123
+ # => [#<Calendly::WebhookSubscription uuid:ORG_WEBHOOK_001>]
124
+
125
+ # delete the webhook
126
+ org_webhook.delete
127
+ # => true
128
+ ```
129
+
130
+ ### Logging
131
+
132
+ This library supports a configurable logger.
133
+
134
+ ```ruby
120
135
  # if the log level set :debug, you can get the request/response information.
121
136
  Calendly.configuration.logger.level = :debug
122
137
  invitation = my_org.create_invitation('foobar@example.com')
@@ -124,6 +139,8 @@ invitation = my_org.create_invitation('foobar@example.com')
124
139
  # D, [2020-08-10T10:48:16] DEBUG -- : Response status:201, body:{"resource":{"created_at":"2020-08-10T10:48:16.051159Z","email":"foobar@example.com","last_sent_at":"2020-08-10T10:48:16.096518Z","organization":"https://api.calendly.com/organizations/ORG001","status":"pending","updated_at":"2020-08-10T10:48:16.051159Z","uri":"https://api.calendly.com/organizations/ORG001/invitations/INV001"}}
125
140
  ```
126
141
 
142
+ More in-depth method documentation can be found at [RubyDoc.info](https://www.rubydoc.info/gems/calendly/).
143
+
127
144
  ## Contributing
128
145
 
129
146
  Bug reports and pull requests are welcome on [GitHub](https://github.com/koshilife/calendly-api-ruby-client). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -29,7 +29,6 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ['lib']
30
30
 
31
31
  spec.add_runtime_dependency 'oauth2', '>= 1.4.4'
32
- spec.add_runtime_dependency 'zeitwerk', '>= 2.3.0'
33
32
 
34
33
  spec.add_development_dependency 'bundler'
35
34
  spec.add_development_dependency 'codecov'
@@ -1,9 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'zeitwerk'
4
- loader = Zeitwerk::Loader.for_gem
5
- loader.collapse('**/models')
6
- loader.setup
3
+ Dir[
4
+ File.join(
5
+ File.dirname(__FILE__),
6
+ 'calendly',
7
+ '**',
8
+ '*'
9
+ )
10
+ ].sort.each do |f|
11
+ next if File.directory? f
12
+
13
+ require f
14
+ end
7
15
 
8
16
  # module for Calendly apis client
9
17
  module Calendly
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/error'
4
+
3
5
  module Calendly
4
6
  # Calendly apis client error object.
5
- class ApiError < Calendly::Error
7
+ class ApiError < Error
6
8
  # @return [Faraday::Response]
7
9
  attr_reader :response
8
10
  # @return [Integer]
@@ -59,11 +59,21 @@ 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
- user
62
+ return @cached_current_user if @cached_current_user
63
+
64
+ @cached_current_user = user
63
65
  end
64
66
 
65
67
  alias me current_user
66
68
 
69
+ # @since 0.2.0
70
+ def current_user!
71
+ @cached_current_user = nil
72
+ current_user
73
+ end
74
+
75
+ alias me! current_user!
76
+
67
77
  #
68
78
  # Get basic information about a user
69
79
  #
@@ -78,6 +88,20 @@ module Calendly
78
88
  User.new body[:resource], self
79
89
  end
80
90
 
91
+ #
92
+ # Returns a single Event Type by its UUID.
93
+ #
94
+ # @param [String] uuid the specified event type (event type's uuid).
95
+ # @return [Calendly::EventType]
96
+ # @raise [Calendly::Error] if the uuid arg is empty.
97
+ # @raise [Calendly::ApiError] if the api returns error code.
98
+ # @since 0.4.1
99
+ def event_type(uuid)
100
+ check_not_empty uuid, 'uuid'
101
+ body = request :get, "event_types/#{uuid}"
102
+ EventType.new body[:resource], self
103
+ end
104
+
81
105
  #
82
106
  # Returns all Event Types associated with a specified User.
83
107
  #
@@ -125,12 +149,12 @@ module Calendly
125
149
  # @param [String] user_uri the specified user (user's uri).
126
150
  # @param [Hash] opts the optional request parameters.
127
151
  # @option opts [Integer] :count Number of rows to return.
128
- # @option opts [String] :invitee_email Return events scheduled with the specified invitee email
152
+ # @option opts [String] :invitee_email Return events scheduled with the specified invitee email.
129
153
  # @option opts [String] :max_start_time Upper bound (inclusive) for an event's start time to filter by.
130
154
  # @option opts [String] :min_start_time Lower bound (inclusive) for an event's start time to filter by.
131
155
  # @option opts [String] :page_token Pass this to get the next portion of collection.
132
156
  # @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
157
+ # @option opts [String] :status Whether the scheduled event is active or canceled.
134
158
  # @return [Array<Array<Calendly::Event>, Hash>]
135
159
  # - [Array<Calendly::Event>] events
136
160
  # - [Hash] next_params the parameters to get next data. if thre is no next it returns nil.
@@ -362,6 +386,118 @@ module Calendly
362
386
  true
363
387
  end
364
388
 
389
+ #
390
+ # Get a webhook subscription for an organization or user with a specified UUID.
391
+ #
392
+ # @param [String] uuid the specified webhook (webhook's uuid).
393
+ # @return [Calendly::WebhookSubscription]
394
+ # @raise [Calendly::Error] if the uuid arg is empty.
395
+ # @raise [Calendly::ApiError] if the api returns error code.
396
+ # @since 0.1.3
397
+ def webhook(uuid)
398
+ check_not_empty uuid, 'uuid'
399
+ body = request :get, "webhook_subscriptions/#{uuid}"
400
+ WebhookSubscription.new body[:resource], self
401
+ end
402
+
403
+ #
404
+ # Get List of organization scope Webhooks.
405
+ #
406
+ # @param [String] org_uri the specified organization (organization's uri).
407
+ # @param [Hash] opts the optional request parameters.
408
+ # @option opts [Integer] :count Number of rows to return.
409
+ # @option opts [String] :page_token Pass this to get the next portion of collection.
410
+ # @option opts [String] :sort Order results by the specified field and directin. Accepts comma-separated list of {field}:{direction} values.
411
+ # @return [Array<Array<Calendly::WebhookSubscription>, Hash>]
412
+ # - [Array<Calendly::WebhookSubscription>] webhooks
413
+ # - [Hash] next_params the parameters to get next data. if thre is no next it returns nil.
414
+ # @raise [Calendly::Error] if the org_uri arg is empty.
415
+ # @raise [Calendly::ApiError] if the api returns error code.
416
+ # @since 0.1.3
417
+ def webhooks(org_uri, opts = {})
418
+ check_not_empty org_uri, 'org_uri'
419
+
420
+ opts_keys = %i[count page_token sort]
421
+ params = {organization: org_uri, scope: 'organization'}
422
+ params = merge_options opts, opts_keys, params
423
+ body = request :get, 'webhook_subscriptions', params: params
424
+ items = body[:collection] || []
425
+ evs = items.map { |item| WebhookSubscription.new item, self }
426
+ [evs, next_page_params(body)]
427
+ end
428
+
429
+ #
430
+ # Get List of user scope Webhooks.
431
+ #
432
+ # @param [String] org_uri the specified organization (organization's uri).
433
+ # @param [String] user_uri the specified user (user's uri).
434
+ # @param [Hash] opts the optional request parameters.
435
+ # @option opts [Integer] :count Number of rows to return.
436
+ # @option opts [String] :page_token Pass this to get the next portion of collection.
437
+ # @option opts [String] :sort Order results by the specified field and directin. Accepts comma-separated list of {field}:{direction} values.
438
+ # @return [Array<Array<Calendly::WebhookSubscription>, Hash>]
439
+ # - [Array<Calendly::WebhookSubscription>] webhooks
440
+ # - [Hash] next_params the parameters to get next data. if thre is no next it returns nil.
441
+ # @raise [Calendly::Error] if the org_uri arg is empty.
442
+ # @raise [Calendly::Error] if the user_uri arg is empty.
443
+ # @raise [Calendly::ApiError] if the api returns error code.
444
+ # @since 0.1.3
445
+ def user_scope_webhooks(org_uri, user_uri, opts = {})
446
+ check_not_empty org_uri, 'org_uri'
447
+ check_not_empty user_uri, 'user_uri'
448
+
449
+ opts_keys = %i[count page_token sort]
450
+ params = {organization: org_uri, user: user_uri, scope: 'user'}
451
+ params = merge_options opts, opts_keys, params
452
+ body = request :get, 'webhook_subscriptions', params: params
453
+ items = body[:collection] || []
454
+ evs = items.map { |item| WebhookSubscription.new item, self }
455
+ [evs, next_page_params(body)]
456
+ end
457
+
458
+ #
459
+ # Create a webhook subscription for an organization or user.
460
+ #
461
+ # @param [String] url Canonical reference (unique identifier) for the resource.
462
+ # @param [Array<String>] events List of user events to subscribe to. options: invitee.created or invitee.canceled
463
+ # @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.
465
+ # @return [Calendly::WebhookSubscription]
466
+ # @raise [Calendly::Error] if the url arg is empty.
467
+ # @raise [Calendly::Error] if the events arg is empty.
468
+ # @raise [Calendly::Error] if the org_uri arg is empty.
469
+ # @raise [Calendly::ApiError] if the api returns error code.
470
+ # @since 0.1.3
471
+ def create_webhook(url, events, org_uri, user_uri = nil)
472
+ check_not_empty url, 'url'
473
+ check_not_empty events, 'events'
474
+ check_not_empty org_uri, 'org_uri'
475
+
476
+ params = {url: url, events: events, organization: org_uri}
477
+ if user_uri
478
+ params[:scope] = 'user'
479
+ params[:user] = user_uri
480
+ else
481
+ params[:scope] = 'organization'
482
+ end
483
+ body = request(:post, 'webhook_subscriptions', body: params)
484
+ WebhookSubscription.new body[:resource], self
485
+ end
486
+
487
+ #
488
+ # Delete a webhook subscription for an organization or user with a specified UUID.
489
+ #
490
+ # @param [String] uuid the specified webhook (webhook's uuid).
491
+ # @return [true]
492
+ # @raise [Calendly::Error] if the uuid arg is empty.
493
+ # @raise [Calendly::ApiError] if the api returns error code.
494
+ # @since 0.1.3
495
+ def delete_webhook(uuid)
496
+ check_not_empty uuid, 'uuid'
497
+ request :delete, "webhook_subscriptions/#{uuid}"
498
+ true
499
+ end
500
+
365
501
  private
366
502
 
367
503
  def request(method, path, params: nil, body: nil)
@@ -383,12 +519,13 @@ module Calendly
383
519
  end
384
520
 
385
521
  def check_not_empty(value, name)
386
- raise Calendly::Error.new("#{name} is required.") if blank? value
522
+ raise Error.new("#{name} is required.") if blank? value
387
523
  end
388
524
 
389
525
  def blank?(value)
390
526
  return true if value.nil?
391
527
  return true if value.to_s.empty?
528
+ return true if value.is_a?(Array) && value.empty?
392
529
 
393
530
  false
394
531
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/loggable'
4
+
3
5
  module Calendly
4
6
  # calendly module's base error object
5
7
  class Error < StandardError
@@ -19,7 +19,7 @@ module Calendly
19
19
  log msg, :debug
20
20
  end
21
21
 
22
- private
22
+ private
23
23
 
24
24
  def log(msg, level = :info)
25
25
  logger = Calendly.configuration.logger
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/client'
4
+ require 'calendly/models/model_utils'
5
+ require 'calendly/models/event_type'
6
+
3
7
  module Calendly
4
8
  # Calendly's event model.
5
9
  # A meeting that has been scheduled
@@ -79,8 +83,16 @@ module Calendly
79
83
  # @raise [Calendly::ApiError] if the api returns error code.
80
84
  # @since 0.1.0
81
85
  def invitees(opts = {})
86
+ return @cached_invitees if @cached_invitees
87
+
82
88
  request_proc = proc { |options| client.event_invitees uuid, options }
83
- auto_pagination request_proc, opts
89
+ @cached_invitees = auto_pagination request_proc, opts
90
+ end
91
+
92
+ # @since 0.2.0
93
+ def invitees!(opts = {})
94
+ @cached_invitees = nil
95
+ invitees opts
84
96
  end
85
97
 
86
98
  private
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/client'
4
+ require 'calendly/models/model_utils'
5
+
3
6
  module Calendly
4
7
  # Calendly's event type model.
5
8
  # A configuration for a schedulable event
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/client'
4
+ require 'calendly/models/model_utils'
5
+ require 'calendly/models/event'
6
+
3
7
  module Calendly
4
8
  # Calendly's Invitee model.
5
9
  # An individual who has been invited to meet with a Calendly member.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/models/model_utils'
4
+
3
5
  module Calendly
4
6
  # Calendly's InviteeQuestionAndAnswer model.
5
7
  # An individual form question and response.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/models/model_utils'
4
+
3
5
  module Calendly
4
6
  # Calendly's InviteeTracking model.
5
7
  # Object that represents UTM and Salesforce tracking parameters associated with the invitee.
@@ -1,52 +1,70 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/models/model_utils'
4
+
3
5
  module Calendly
4
6
  # Calendly's location model.
5
- # Polymorphic base type for the various supported meeting locations.
7
+ # The polymorphic base type for an event location that Calendly supports
6
8
  class Location
7
9
  include ModelUtils
8
10
 
11
+ #
9
12
  # data patterns is below:
10
- # - 1. A meeting at a pre-specified physical location
11
- # - [String] :kind
12
- # - [String] :location A physical location specified by the meeting publisher.
13
- # - 2. Meeting publisher will call the invitee
14
- # - [String] :kind
15
- # - 3. Invitee will call meeting publisher at the specified phone number.
16
- # - [String] :kind
17
- # - [String] :phone_number Phone number invitee should use to reach meeting publisher.
18
- # - 4. Meeting will take place in a Google Meet / Hangout conference.
19
- # - [String] :kind
20
- # - 5. Meeting will take place in a Zoom conference.
21
- # - [String] :kind
22
- # - 6. Meeting will take place in a GotoMeeting conference.
23
- # - [String] :kind
24
- # - [String] :external_id Zoom-supplied conference id.
25
- # - [String] :state Current state of the conference in Zoom.
26
- # - [Hash] :data Arbitrary conference metadata supplied by Zoom.
27
- # - 7. Arbitrary conference metadata supplied by GotoMeeting.
28
- # - [String] :kind
29
- # - [String] :external_id GotoMeeting-supplied conference id.
30
- # - [String] :state Current state of the conference in GotoMeeting.
31
- # - [String] :data Arbitrary conference metadata supplied by GotoMeeting.
32
- # - 8. Meeting location does not fall in a standard category, and is as described by the meeting publisher.
33
- # - [String] :kind
34
- # - [String] :location Location description provided by meeting publisher.
35
- # - 9. Meeting location was specified by invitee.
36
- # - [String] :kind
37
- # - [String] :location Meeting location was specified by invitee.
13
+ #
14
+ # 1. In-Person Meeting: Information about the physical (in-person) event location.
15
+ # @param [String] type Indicates that the event host (publisher) will call the invitee.
16
+ # @param [String] location The physical location specified by the event host (publisher).
17
+ #
18
+ # 2. Outbound Call: Meeting publisher will call the Invitee
19
+ # @param [String] type Indicates that the event host (publisher) will call the invitee.
20
+ # @param [String] location The phone number the event host (publisher) will use to call the invitee.
21
+ #
22
+ # 3. Inbound Call: Invitee will call meeting publisher at the specified phone number.
23
+ # @param [String] type Indicates that the invitee will call the event host.
24
+ # @param [String] location The phone number the invitee will use to call the event host (publisher).
25
+ #
26
+ # 4. Google Conference: Details about an Event that will take place using a Google Meet / Hangout conference.
27
+ # @param [String] type The event location is a Google Meet or Hangouts conference.
28
+ # @param [String] status Indicates the current status of the Google conference.
29
+ # @param [String] join_url Google conference meeting url.
30
+ #
31
+ # 5. Zoom Conference: Meeting will take place in a Zoom conference.
32
+ # @param [String] type The event location is a Zoom conference
33
+ # @param [String] status Indicates the current status of the Zoom conference.
34
+ # @param [String] join_url Zoom meeting url.
35
+ # @param [Hash] data The conference metadata supplied by Zoom.
36
+ #
37
+ # 6. GoToMeeting Conference: Details about an Event that will take place using a GotoMeeting conference
38
+ # @param [String] type The event location is a GoToMeeting conference.
39
+ # @param [String] status Indicates the current status of the GoToMeeting conference.
40
+ # @param [String] join_url GoToMeeting conference meeting url.
41
+ # @param [Hash] data The conference metadata supplied by GoToMeeting.
42
+ #
43
+ # 7. Microsoft Teams Conference:
44
+ # @param [String] type The event location is a Zoom conference.
45
+ # @param [String] status Indicates the current status of the Microsoft Teams conference.
46
+ # @param [String] join_url Microsoft Teams meeting url.
47
+ # @param [Hash] data The conference metadata supplied by Microsoft Teams.
48
+ #
49
+ # 8. Custom Location:
50
+ # Use this to describe an existing Calendly-supported event location.
51
+ # @param [String] type The event location doesn't fall into a standard category defined by the event host (publisher).
52
+ # @param [String] location The event location description provided by the invitee.
53
+ #
54
+ # 9. Invitee Specified Location:
55
+ # Information about an event location that’s specified by the invitee.
56
+ # @param [String] type The event location selected by the invitee.
57
+ # @param [String] location The event location description provided by the invitee.
38
58
  #
39
59
 
40
60
  # @return [String]
41
- attr_accessor :kind
61
+ attr_accessor :type
42
62
  # @return [String]
43
63
  attr_accessor :location
44
64
  # @return [String]
45
- attr_accessor :phone_number
46
- # @return [String]
47
- attr_accessor :external_id
65
+ attr_accessor :status
48
66
  # @return [String]
49
- attr_accessor :state
67
+ attr_accessor :join_url
50
68
  # @return [Hash]
51
69
  attr_accessor :data
52
70
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'time'
4
+ require 'calendly/error'
4
5
 
5
6
  module Calendly
6
7
  # Calendly model utility.
@@ -68,10 +69,10 @@ module Calendly
68
69
  attrs.each do |key, value|
69
70
  next unless respond_to? "#{key}=".to_sym
70
71
 
71
- if defined?(self.class::ASSOCIATION) && self.class::ASSOCIATION.key?(key)
72
+ if value && defined?(self.class::ASSOCIATION) && self.class::ASSOCIATION.key?(key)
72
73
  associated_attrs = value.is_a?(Hash) ? value : {uri: value}
73
74
  value = self.class::ASSOCIATION[key].new associated_attrs, @client
74
- elsif defined?(self.class::TIME_FIELDS) && self.class::TIME_FIELDS.include?(key)
75
+ elsif value && defined?(self.class::TIME_FIELDS) && self.class::TIME_FIELDS.include?(key)
75
76
  value = Time.parse value
76
77
  end
77
78
  instance_variable_set "@#{key}", value
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/client'
4
+ require 'calendly/models/model_utils'
5
+
3
6
  module Calendly
4
7
  # Calendly's organization model.
5
8
  class Organization
@@ -25,8 +28,16 @@ module Calendly
25
28
  # @raise [Calendly::ApiError] if the api returns error code.
26
29
  # @since 0.1.0
27
30
  def memberships(opts = {})
31
+ return @cached_memberships if @cached_memberships
32
+
28
33
  request_proc = proc { |options| client.memberships uri, options }
29
- auto_pagination request_proc, opts
34
+ @cached_memberships = auto_pagination request_proc, opts
35
+ end
36
+
37
+ # @since 0.2.0
38
+ def memberships!(opts = {})
39
+ @cached_memberships = nil
40
+ memberships opts
30
41
  end
31
42
 
32
43
  #
@@ -44,8 +55,16 @@ module Calendly
44
55
  # @raise [Calendly::ApiError] if the api returns error code.
45
56
  # @since 0.1.0
46
57
  def invitations(opts = {})
58
+ return @cached_invitations if @cached_invitations
59
+
47
60
  request_proc = proc { |options| client.invitations uuid, options }
48
- auto_pagination request_proc, opts
61
+ @cached_invitations = auto_pagination request_proc, opts
62
+ end
63
+
64
+ # @since 0.2.0
65
+ def invitations!(opts = {})
66
+ @cached_invitations = nil
67
+ invitations opts
49
68
  end
50
69
 
51
70
  #
@@ -60,5 +79,45 @@ module Calendly
60
79
  def create_invitation(email)
61
80
  client.create_invitation uuid, email
62
81
  end
82
+
83
+ #
84
+ # Get List of organization scope Webhooks associated with self.
85
+ #
86
+ # @param [Hash] opts the optional request parameters.
87
+ # @option opts [Integer] :count Number of rows to return.
88
+ # @option opts [String] :page_token Pass this to get the next portion of collection.
89
+ # @option opts [String] :sort Order results by the specified field and directin. Accepts comma-separated list of {field}:{direction} values.
90
+ # Accepts comma-separated list of {field}:{direction} values.
91
+ # @return [Array<Calendly::WebhookSubscription>]
92
+ # @raise [Calendly::Error] if the uri is empty.
93
+ # @raise [Calendly::ApiError] if the api returns error code.
94
+ # @since 0.1.3
95
+ def webhooks(opts = {})
96
+ return @cached_webhooks if @cached_webhooks
97
+
98
+ request_proc = proc { |options| client.webhooks uri, options }
99
+ @cached_webhooks = auto_pagination request_proc, opts
100
+ end
101
+
102
+ # @since 0.2.0
103
+ def webhooks!(opts = {})
104
+ @cached_webhooks = nil
105
+ webhooks opts
106
+ end
107
+
108
+ #
109
+ # Create a user scope webhook associated with self.
110
+ #
111
+ # @param [String] url Canonical reference (unique identifier) for the resource.
112
+ # @param [Array<String>] events List of user events to subscribe to. options: invitee.created or invitee.canceled
113
+ # @return [Calendly::WebhookSubscription]
114
+ # @raise [Calendly::Error] if the url arg is empty.
115
+ # @raise [Calendly::Error] if the events arg is empty.
116
+ # @raise [Calendly::Error] if the uri is empty.
117
+ # @raise [Calendly::ApiError] if the api returns error code.
118
+ # @since 0.1.3
119
+ def create_webhook(url, events)
120
+ client.create_webhook url, events, uri
121
+ end
63
122
  end
64
123
  end
@@ -1,5 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/client'
4
+ require 'calendly/models/model_utils'
5
+ require 'calendly/models/organization'
6
+ require 'calendly/models/user'
7
+
3
8
  module Calendly
4
9
  # Calendly's organization invitation model.
5
10
  class OrganizationInvitation
@@ -1,5 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/client'
4
+ require 'calendly/models/model_utils'
5
+ require 'calendly/models/organization'
6
+ require 'calendly/models/user'
7
+
3
8
  module Calendly
4
9
  # Calendly's organization membership model.
5
10
  class OrganizationMembership
@@ -52,5 +57,50 @@ module Calendly
52
57
  def delete
53
58
  client.delete_membership uuid
54
59
  end
60
+
61
+ #
62
+ # Get List of user scope Webhooks associated with self.
63
+ #
64
+ # @param [Hash] opts the optional request parameters.
65
+ # @option opts [Integer] :count Number of rows to return.
66
+ # @option opts [String] :page_token Pass this to get the next portion of collection.
67
+ # @option opts [String] :sort Order results by the specified field and directin. Accepts comma-separated list of {field}:{direction} values.
68
+ # Accepts comma-separated list of {field}:{direction} values.
69
+ # @return [Array<Calendly::WebhookSubscription>]
70
+ # @raise [Calendly::Error] if the organization.uri is empty.
71
+ # @raise [Calendly::Error] if the user.uri is empty.
72
+ # @raise [Calendly::ApiError] if the api returns error code.
73
+ # @since 0.1.3
74
+ def user_scope_webhooks(opts = {})
75
+ return @cached_user_scope_webhooks if @cached_user_scope_webhooks
76
+
77
+ org_uri = organization.uri if organization
78
+ user_uri = user.uri if user
79
+ request_proc = proc { |options| client.user_scope_webhooks org_uri, user_uri, options }
80
+ @cached_user_scope_webhooks = auto_pagination request_proc, opts
81
+ end
82
+
83
+ # @since 0.2.0
84
+ def user_scope_webhooks!(opts = {})
85
+ @cached_user_scope_webhooks = nil
86
+ user_scope_webhooks opts
87
+ end
88
+
89
+ #
90
+ # Create a user scope webhook associated with self.
91
+ #
92
+ # @param [String] url Canonical reference (unique identifier) for the resource.
93
+ # @param [Array<String>] events List of user events to subscribe to. options: invitee.created or invitee.canceled
94
+ # @return [Calendly::WebhookSubscription]
95
+ # @raise [Calendly::Error] if the url arg is empty.
96
+ # @raise [Calendly::Error] if the events arg is empty.
97
+ # @raise [Calendly::Error] if the organization.uri is empty.
98
+ # @raise [Calendly::ApiError] if the api returns error code.
99
+ # @since 0.1.3
100
+ def create_user_scope_webhook(url, events)
101
+ org_uri = organization.uri if organization
102
+ user_uri = user.uri if user
103
+ client.create_webhook url, events, org_uri, user_uri
104
+ end
55
105
  end
56
106
  end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/client'
4
+ require 'calendly/models/model_utils'
5
+
3
6
  module Calendly
4
7
  # Calendly's user model.
5
8
  # Primary account details of a specific user.
@@ -57,8 +60,16 @@ module Calendly
57
60
  # @raise [Calendly::Error] if the uri is empty.
58
61
  # @since 0.1.0
59
62
  def organization_membership
63
+ return @cached_organization_membership if @cached_organization_membership
64
+
60
65
  mems, = client.memberships_by_user uri
61
- mems.first
66
+ @cached_organization_membership = mems.first
67
+ end
68
+
69
+ # @since 0.2.0
70
+ def organization_membership!
71
+ @cached_organization_membership = nil
72
+ organization_membership
62
73
  end
63
74
 
64
75
  #
@@ -74,8 +85,16 @@ module Calendly
74
85
  # @raise [Calendly::ApiError] if the api returns error code.
75
86
  # @since 0.1.0
76
87
  def event_types(opts = {})
88
+ return @cached_event_types if @cached_event_types
89
+
77
90
  request_proc = proc { |options| client.event_types uri, options }
78
- auto_pagination request_proc, opts
91
+ @cached_event_types = auto_pagination request_proc, opts
92
+ end
93
+
94
+ # @since 0.2.0
95
+ def event_types!(opts = {})
96
+ @cached_event_types = nil
97
+ event_types opts
79
98
  end
80
99
 
81
100
  #
@@ -95,8 +114,16 @@ module Calendly
95
114
  # @raise [Calendly::ApiError] if the api returns error code.
96
115
  # @since 0.1.0
97
116
  def scheduled_events(opts = {})
117
+ return @cached_scheduled_events if @cached_scheduled_events
118
+
98
119
  request_proc = proc { |options| client.scheduled_events uri, options }
99
- auto_pagination request_proc, opts
120
+ @cached_scheduled_events = auto_pagination request_proc, opts
121
+ end
122
+
123
+ # @since 0.2.0
124
+ def scheduled_events!(opts = {})
125
+ @cached_scheduled_events = nil
126
+ scheduled_events opts
100
127
  end
101
128
  end
102
129
  end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'calendly/client'
4
+ require 'calendly/models/model_utils'
5
+ require 'calendly/models/organization'
6
+ require 'calendly/models/user'
7
+
8
+ module Calendly
9
+ # Calendly's webhook model.
10
+ class WebhookSubscription
11
+ include ModelUtils
12
+ UUID_RE = %r{\A#{Client::API_HOST}/webhook_subscriptions/(\w+)\z}.freeze
13
+ TIME_FIELDS = %i[created_at updated_at retry_started_at].freeze
14
+ ASSOCIATION = {organization: Organization, user: User, creator: User}.freeze
15
+
16
+ # @return [String]
17
+ # unique id of the WebhookSubscription object.
18
+ attr_accessor :uuid
19
+ # @return [String]
20
+ # Canonical reference (unique identifier) for the webhook.
21
+ attr_accessor :uri
22
+ # @return [String]
23
+ # The callback URL to use when the event is triggered.
24
+ attr_accessor :callback_url
25
+ # @return [Time]
26
+ # The moment when the webhook subscription was created.
27
+ attr_accessor :created_at
28
+ # @return [Time]
29
+ # The moment when the webhook subscription was last updated.
30
+ attr_accessor :updated_at
31
+ # @return [Time]
32
+ # The date and time the webhook subscription is retried.
33
+ attr_accessor :retry_started_at
34
+ # @return [String]
35
+ # Indicates if the webhook subscription is "active" or "disabled".
36
+ attr_accessor :state
37
+ # @return [Array<String>]
38
+ # A list of events to which the webhook is subscribed.
39
+ attr_accessor :events
40
+ # @return [String]
41
+ # The scope of the webhook subscription.
42
+ attr_accessor :scope
43
+ # @return [Calendly::Organization]
44
+ # The organization that's associated with the webhook subscription.
45
+ attr_accessor :organization
46
+ # @return [Calendly::User]
47
+ # The user that's associated with the webhook subscription.
48
+ attr_accessor :user
49
+ # @return [Calendly::User]
50
+ # The user who created the webhook subscription.
51
+ attr_accessor :creator
52
+
53
+ #
54
+ # Get a webhook subscription associated with self.
55
+ #
56
+ # @return [Calendly::WebhookSubscription]
57
+ # @raise [Calendly::Error] if the uuid is empty.
58
+ # @raise [Calendly::ApiError] if the api returns error code.
59
+ # @since 0.1.3
60
+ def fetch
61
+ client.webhook uuid
62
+ end
63
+
64
+ #
65
+ # Delete a webhook subscription associated with self.
66
+ #
67
+ # @return [true]
68
+ # @raise [Calendly::Error] if the uuid is empty.
69
+ # @raise [Calendly::ApiError] if the api returns error code.
70
+ # @since 0.1.0
71
+ def delete
72
+ client.delete_webhook uuid
73
+ end
74
+ end
75
+ 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.4.1'
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.4.1
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-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.4.4
27
- - !ruby/object:Gem::Dependency
28
- name: zeitwerk
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 2.3.0
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 2.3.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -159,6 +145,7 @@ files:
159
145
  - lib/calendly/models/organization_invitation.rb
160
146
  - lib/calendly/models/organization_membership.rb
161
147
  - lib/calendly/models/user.rb
148
+ - lib/calendly/models/webhook_subscription.rb
162
149
  - lib/calendly/version.rb
163
150
  homepage: https://github.com/koshilife/calendly-api-ruby-client
164
151
  licenses:
@@ -167,7 +154,7 @@ metadata:
167
154
  homepage_uri: https://github.com/koshilife/calendly-api-ruby-client
168
155
  source_code_uri: https://github.com/koshilife/calendly-api-ruby-client
169
156
  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
157
+ documentation_uri: https://www.rubydoc.info/gems/calendly/0.4.1
171
158
  post_install_message:
172
159
  rdoc_options: []
173
160
  require_paths: