calendly 0.4.1 → 0.6.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: 7eb04cc45dc6c81f18994d5d821e3afc4013467c58fbebc22e39810b6fccee91
4
- data.tar.gz: 5135a1f761cd6e85d24359e80a3e658e640f0834ac5bd3a1169cb96b15e8c256
3
+ metadata.gz: 5890f2e5488593ef1b1edcc4284abb1d50442fe66a782322aff7990d3a1d9424
4
+ data.tar.gz: de8d74e6d9b4b588cca90dc075b74d497ddb92f1cc4ca22db71e15f0da01d8ac
5
5
  SHA512:
6
- metadata.gz: abdc8ba4475063741397bafd3b7bcbba08935817b0c0532d38d3f2b59f87673afd66bf0da99980cacf37f7e1383ac633bb835d710856f16841b656d706ed27d8
7
- data.tar.gz: 65d4cc6e0e23e239bd5e3c2cdc65f6cd10bbdc0410d4be146ae3d228e0fb21ed22cd0172c67f18a6e50a42df19da31a88d0e795a580a2e07db2abad23121a68a
6
+ metadata.gz: 91ed1a2beab52e4e92bc6b1c068323ad882cdef5bf7f74f538ef3919d1cae64139da374471e68200c644571b235a12e8c69ccb74086a1834113add6ebe93dd56
7
+ data.tar.gz: a3a596cfb67f401756b2f913598845003d3b17c861d292da9706f630ff0028c07e97b52e9b7b989b0853be16f09de9c33c4570c71c8c8bc28fd96fc26d4040d8
data/CHANGELOG.md CHANGED
@@ -1,21 +1,83 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.6.0
4
+
5
+ - supported to new features until April 2021. (#29)
6
+ - Client
7
+ - (Change) support organization options in `event_types` api.
8
+ - (Rename) `event_types` to `event_types_by_user`
9
+ - User model
10
+ - (Add field) current_organization
11
+ - (Add method) webhooks
12
+ - (Add method) webhooks!
13
+ - (Add method) create_webhook
14
+ - Event model
15
+ - (Remove field) invitees_counter_total
16
+ - (Remove field) invitees_counter_active
17
+ - (Remove field) invitees_counter_limit
18
+ - (Add field) invitees_counter
19
+ - (Add field) event_memberships
20
+ - (Add field) event_guests
21
+ - EventType model
22
+ - (Remove field) owner_uuid
23
+ - (Remove field) owner_uri
24
+ - (Remove field) owner_name
25
+ - (Add field) profile
26
+ - (Add field) secret
27
+ - (Add field) custom_questions
28
+ - (Add method) owner_user
29
+ - (Add method) owner_team
30
+ - Invitee model
31
+ - (Add field) first_name
32
+ - (Add field) last_name
33
+ - (Add field) cancellation
34
+ - (Add field) payment
35
+ - fixed debug log encoding error. (#30)
36
+ - improved inspect method to be more readable in CLI.
37
+
38
+ ## 0.5.2
39
+
40
+ - started to support a API
41
+ - `POST /scheduling_links`
42
+
43
+ ## 0.5.1
44
+
45
+ - added method EventType#fetch
46
+
47
+ ## 0.5.0
48
+
49
+ - changed Calendly::Client#scheduled_events behavior (refs #21)
50
+ - previous version:
51
+ - getting events belonging to a specific USER
52
+ - current version:
53
+ - getting all events belonging to a specific ORGANIZATION
54
+ - added Calendly::Client#scheduled_events_by_user method instead_of the before behavior
55
+
56
+ ## 0.4.2
57
+
58
+ - added new following fields to Invitee model (refs #21)
59
+ - :rescheduled
60
+ - :old_invitee
61
+ - :new_invitee
62
+ - :cancel_url
63
+ - :reschedule_url
64
+
3
65
  ## 0.4.1
4
66
 
5
- - support API
67
+ - started to support a API
6
68
  - `GET /event_types/{uuid}`
7
69
 
8
70
  ## 0.4.0
9
71
 
10
- - fix changed Location fields such as `kind` to `type`. (refs #18)
72
+ - fixed a changes for Location fields such as `kind` to `type`. (refs #18)
11
73
 
12
74
  ## 0.3.0
13
75
 
14
- - remove zeitwerk dependency. (refs #16)
76
+ - removed zeitwerk dependency. (refs #16)
15
77
 
16
78
  ## 0.2.0
17
79
 
18
- - save fetched data in cache. (refs #14)
80
+ - added caching features in object when fetching data. (refs #14)
19
81
 
20
82
  ## 0.1.3
21
83
 
@@ -27,59 +89,59 @@
27
89
 
28
90
  ## 0.1.2
29
91
 
30
- - fix rubocop warnings.
92
+ - fixed rubocop warnings.
31
93
 
32
94
  ## 0.1.1
33
95
 
34
- - add tests to make coverage 100%.
96
+ - added tests to make coverage 100%.
35
97
 
36
98
  ## 0.1.0
37
99
 
38
- - define methods to access associated resources with each model.
39
- - rename methods:
100
+ - defined methods to access associated resources with each model.
101
+ - renamed methods:
40
102
  - `Calendly::Client#events` to `Calendly::Client#scheduled_events`
41
103
 
42
104
  ## 0.0.7.alpha
43
105
 
44
- - support APIs
106
+ - started to support APIs
45
107
  - `POST /organizations/{uuid}/invitations`
46
108
  - `DELETE /organizations/{org_uuid}/invitations/{invitation_uuid}`
47
109
  - `DELETE /organization_memberships/{uuid}`
48
110
 
49
111
  ## 0.0.6.alpha
50
112
 
51
- - support APIs
113
+ - started to support APIs
52
114
  - `GET /organizations/{uuid}/invitations`
53
115
  - `GET /organizations/{organization_uuid}/invitations/{invitation_uuid}`
54
116
 
55
117
  ## 0.0.5.alpha
56
118
 
57
- - support APIs
119
+ - started to support APIs
58
120
  - `GET /organization_memberships`
59
121
  - `GET /organization_memberships/{uuid}`
60
- - rename fields
122
+ - renamed fields
61
123
  - Invitee#event to Invitee#event_uri
62
124
  - Event#event_type to Event#event_type_uri
63
125
 
64
126
  ## 0.0.4.alpha
65
127
 
66
- - support APIs
128
+ - started to support APIs
67
129
  - `GET /scheduled_events/{event_uuid}/invitees`
68
130
  - `GET /scheduled_events/{event_uuid}/invitees/{invitee_uuid}`
69
131
 
70
132
  ## 0.0.3.alpha
71
133
 
72
- - support APIs
134
+ - started to support APIs
73
135
  - `GET /scheduled_events`
74
136
  - `GET /scheduled_events/{uuid}`
75
137
 
76
138
  ## 0.0.2.alpha
77
139
 
78
- - support APIs
140
+ - started to support APIs
79
141
  - `GET /event_types`
80
142
 
81
143
  ## 0.0.1.alpha
82
144
 
83
145
  - Initial release
84
- - support APIs
146
+ - started to support a API
85
147
  - `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.
@@ -480,7 +539,7 @@ module Calendly
480
539
  else
481
540
  params[:scope] = 'organization'
482
541
  end
483
- body = request(:post, 'webhook_subscriptions', body: params)
542
+ body = request :post, 'webhook_subscriptions', body: params
484
543
  WebhookSubscription.new body[:resource], self
485
544
  end
486
545
 
@@ -498,12 +557,43 @@ module Calendly
498
557
  true
499
558
  end
500
559
 
560
+ #
561
+ # Create a scheduling link.
562
+ #
563
+ # @param [String] uri A link to the resource that owns this scheduling Link.
564
+ # @param [String] max_event_count The max number of events that can be scheduled using this scheduling link.
565
+ # @param [String] resource_type Resource type.
566
+ # @return [Hash]
567
+ # e.g.
568
+ # {
569
+ # booking_url: "https://calendly.com/s/FOO-BAR-SLUG",
570
+ # owner: "https://api.calendly.com/event_types/GBGBDCAADAEDCRZ2",
571
+ # owner_type: "EventType"
572
+ # }
573
+ # @raise [Calendly::Error] if the uri arg is empty.
574
+ # @raise [Calendly::Error] if the max_event_count arg is empty.
575
+ # @raise [Calendly::Error] if the resource_type arg is empty.
576
+ # @raise [Calendly::ApiError] if the api returns error code.
577
+ # @since 0.5.2
578
+ def create_schedule_link(uri, max_event_count = 1, resource_type: 'EventType')
579
+ check_not_empty uri, 'uri'
580
+ check_not_empty max_event_count, 'max_event_count'
581
+ check_not_empty resource_type, 'resource_type'
582
+ params = {
583
+ max_event_count: max_event_count,
584
+ owner: uri,
585
+ owner_type: resource_type
586
+ }
587
+ body = request :post, 'scheduling_links', body: params
588
+ body[:resource]
589
+ end
590
+
501
591
  private
502
592
 
503
593
  def request(method, path, params: nil, body: nil)
504
594
  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}"
595
+ res = access_token.request method, path, params: params, body: body
596
+ debug_log "Response status:#{res.status}, body:#{res.body.dup&.force_encoding(Encoding::UTF_8)}"
507
597
  parse_as_json res
508
598
  rescue OAuth2::Error => e
509
599
  res = e.response.response