calendlyr 0.3.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +1 -1
  3. data/CHANGELOG.md +3 -31
  4. data/README.md +27 -4
  5. data/lib/calendlyr/client.rb +3 -2
  6. data/lib/calendlyr/collection.rb +3 -0
  7. data/lib/calendlyr/objects/organizations.rb +8 -0
  8. data/lib/calendlyr/resource.rb +11 -23
  9. data/lib/calendlyr/resources/event_invitees.rb +1 -1
  10. data/lib/calendlyr/resources/organizations.rb +1 -1
  11. data/lib/calendlyr/version.rb +1 -1
  12. data/lib/calendlyr.rb +0 -5
  13. data/test/calendlyr/client_test.rb +5 -2
  14. data/test/calendlyr/resource_test.rb +14 -0
  15. data/test/calendlyr/resources/{data_compliance.rb → data_compliance_test.rb} +0 -0
  16. data/test/calendlyr/resources/organizations_test.rb +26 -11
  17. data/test/calendlyr/resources/scheduling_links_test.rb +15 -0
  18. data/test/calendlyr/resources/users_test.rb +15 -3
  19. data/test/calendlyr/resources/webhooks_test.rb +5 -2
  20. data/test/fixtures/event_invitees/retrieve.json +36 -34
  21. data/test/fixtures/organizations/invite.json +9 -7
  22. data/test/fixtures/organizations/list_invitations.json +1 -1
  23. data/test/fixtures/organizations/retrieve_invitation.json +1 -1
  24. data/test/fixtures/resources/400.json +10 -0
  25. data/test/fixtures/resources/401.json +10 -0
  26. data/test/fixtures/resources/403.json +10 -0
  27. data/test/fixtures/resources/404.json +10 -0
  28. data/test/fixtures/resources/409.json +4 -0
  29. data/test/fixtures/resources/500.json +10 -0
  30. data/test/fixtures/users/reload.json +14 -0
  31. data/test/test_helper.rb +7 -1
  32. metadata +22 -6
  33. data/test/calendlyr/resources/scheduling_links.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 716fb90f54ab5c73f5441ccb7d8d6f8e636bceb3b3f55a6a9053fc06adabb2b0
4
- data.tar.gz: 6bebccb4df4028bfdbad116fdef8b49768e640f4858dbb1fc7a930d98cf558f0
3
+ metadata.gz: 4dba013e04be70a3fdefdae9d2457b5f14b22d8cfd253b6b9247237b1a33aec6
4
+ data.tar.gz: 9900aa135496d99c7e6e1a13071e2b7366153f9d47db00d5265ac96b61a029dc
5
5
  SHA512:
6
- metadata.gz: 79f76039110d8ff409c573229851e4cc130772f210a769d41bb2dac8ac05679b5a9db07a1d543604dc0e2858cc8c604dac16459fcdbbbeac9e059ce91f0b7267
7
- data.tar.gz: 5de26c0f7b9da6389918ba123935902814ce125dbd193ed50596d06c329044bb161cacb7d9ce5d0b11a032157a01f3e06d6551b2b27d0e542b964f0a5dae11c2
6
+ metadata.gz: 165450520bdd93a7e6f30566035db95ff2bd99b764bd86c1ea44e52e90cdf398636791e49f7829dbbd238ef966cf6e09562f4b2fed0149985152cc11cc81b13b
7
+ data.tar.gz: 3885225e6feaea75a074f868ae3ad321c33a4c6413455ee9c10a16ba186e7144972391a20a125804f623ba9de92d69164560701fed6815e9fea9d9b1ce8f7f7c
@@ -12,7 +12,7 @@ jobs:
12
12
  runs-on: ubuntu-latest
13
13
  strategy:
14
14
  matrix:
15
- ruby: ["2.4", "2.5", "2.6", "2.7", "3.0"]
15
+ ruby: ["2.5", "2.6", "2.7", "3.0"]
16
16
 
17
17
  steps:
18
18
  - uses: actions/checkout@master
data/CHANGELOG.md CHANGED
@@ -2,35 +2,7 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [0.3.4]
6
- * Renaming variables and directories Calendly to Calendlyr
5
+ ## [0.6.0]
6
+ * First real usable release :tada:
7
7
 
8
- ## [0.3.3]
9
- * Fix - Error when trying to send an invitation through the organization
10
- * More testing = More coverage
11
-
12
- ## [0.3.2]
13
- * Minor fixes
14
-
15
- ## [0.3.0]
16
- * No runtime dependencies
17
- * Minor fixes
18
-
19
- ## [0.2.0]
20
- * Support for ruby 3.0
21
- * Minor fixes
22
-
23
- ## [0.1.1]
24
- * Changed required ruby version from `>= 2.3.0` to `>= 2.4.0`
25
- * Minitest
26
- * Minor fixes
27
-
28
- ## 0.1.0
29
- * Birthday!
30
-
31
- [0.3.4]: https://github.com/araluce/calendlyr/compare/v0.3.3...v0.3.4
32
- [0.3.3]: https://github.com/araluce/calendlyr/compare/v0.3.2...v0.3.3
33
- [0.3.2]: https://github.com/araluce/calendlyr/compare/v0.3.0...v0.3.2
34
- [0.3.0]: https://github.com/araluce/calendlyr/compare/v0.2.0...v0.3.0
35
- [0.2.0]: https://github.com/araluce/calendlyr/compare/v0.1.1...v0.2.0
36
- [0.1.1]: https://github.com/araluce/calendlyr/compare/v0.1.0...v0.1.1
8
+ [0.6.0]: https://github.com/araluce/calendlyr/compare/v0.1.0...v0.6.0
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [![](https://img.shields.io/github/license/araluce/calendlyr)](https://github.com/araluce/calendlyr/blob/master/LICENSE.txt)
2
- ![](https://github.com/araluce/calendlyr/actions/workflows/ci.yml/badge.svg)
2
+ [![](https://github.com/araluce/calendlyr/actions/workflows/ci.yml/badge.svg)](https://github.com/araluce/calendlyr/actions)
3
3
  [![codecov](https://codecov.io/gh/araluce/calendlyr/branch/master/graph/badge.svg?token=YSUU4PHM6Y)](https://codecov.io/gh/araluce/calendlyr)
4
4
  [![Gem Version](https://badge.fury.io/rb/calendlyr.svg)](https://badge.fury.io/rb/calendlyr)
5
5
 
@@ -7,10 +7,16 @@
7
7
 
8
8
  Easy and complete rubygem for [Calendly](https://calendly.com/). Currently supports [API v2](https://calendly.stoplight.io/docs/api-docs).
9
9
 
10
- No dependencies, just needed a Personal Access Token.
10
+ Just needed a Personal Access Token.
11
11
 
12
12
  > If you need a Oauth authentication maybe you need [calendly-api-ruby-client](https://github.com/koshilife/calendly-api-ruby-client)
13
13
 
14
+ ## Dependencies
15
+
16
+ No dependencies :tada:
17
+
18
+ We know about the importance of not add dependencies that you don't want.
19
+
14
20
  ## Installation
15
21
 
16
22
  Add this line to your application's Gemfile:
@@ -84,6 +90,17 @@ client.me.memberships
84
90
  #=> Calendlyr::Collection @data=[#<Calendlyr::MemberShip>, #<Calendlyr::MemberShip>]
85
91
  ```
86
92
 
93
+ #### Me (Cached)
94
+
95
+ Probably you need to make many calls through `client.me`, so we decided to not make calls for every `client.me` reference by caching it the first time. However, if you need to reload the content of `me` you can `force_relaod` to force a new call.
96
+
97
+ ```ruby
98
+ client.me # makes a call and caches the response
99
+ client.me # no call, value cached
100
+ client.me(force_reload: true) # makes a new call and update cache value
101
+ ```
102
+
103
+
87
104
  ### Event Types
88
105
  ````ruby
89
106
  client.event_types.list user_uri: "user_uri", organization_uri: "organization_uri"
@@ -118,7 +135,7 @@ client.organization.list_invitations
118
135
  # Get invitation
119
136
  client.organizations.retrieve_invitation(organization_uuid: "organization_uuid", invitation_uuid: "invitation_uuid")
120
137
  client.organization.invitation(invitation_uuid: "invitation_uuid")
121
- #Revoke invitation
138
+ # Revoke invitation
122
139
  client.organizations.revoke_invitation(organization_uuid: "organization_uuid", invitation_uuid: "organization_uuid")
123
140
  client.organization.revoke_invitation(invitation_uuid: "organization_uuid")
124
141
  invitation = client.organization.invitation(invitation_uuid: "invitation_uuid")
@@ -133,12 +150,16 @@ client.organizations.retrieve_membership(membership_uuid: "membership_uuid")
133
150
  client.organizations.remove_user(membership_uuid: "membership_uuid")
134
151
 
135
152
  client.organization.events
153
+
154
+ # List/Creaete webhooks
155
+ client.organization.list_webhooks(scope: "scope")
156
+ client.organization.create_webhook(url: "post_callback_url", events: ["invitee.canceled", "invitee.created"], scope: "scope")
136
157
  ````
137
158
 
138
159
  ### Webhooks
139
160
  ```ruby
140
161
  client.webhooks.list(organization_uri: "organization_uri", scope: "scope")
141
- client.webhooks.create(resource_uri: "resource_uri", events: ["invitee.canceled", "invitee.created"], organization_uri: "organization_uri", scope: "scope")
162
+ client.webhooks.create(url: "post_callback_url", events: ["invitee.canceled", "invitee.created"], organization_uri: "organization_uri", scope: "scope")
142
163
  client.webhooks.retrieve(webhook_uuid: "webhook_uuid")
143
164
  client.webhooks.delete(webhook_uuid: "webhook_uuid")
144
165
  ```
@@ -160,4 +181,6 @@ When adding resources, add to the list of resources in lib/calendlyr. Additional
160
181
 
161
182
  ## Thanks
162
183
 
184
+ Many thanks [@markets](https://github.com/markets) (our contributor in the shadows) for all comments, details and tips for this rubygem project and for made me grow professionally in my day by day :raised_hands:
185
+
163
186
  Thanks [@excid3](https://github.com/excid3) and his [Vultr.rb](https://github.com/excid3/vultr.rb) rubygem project.
@@ -8,8 +8,9 @@ module Calendlyr
8
8
  @token = token
9
9
  end
10
10
 
11
- def me
12
- users.me
11
+ def me(force_reload: false)
12
+ @me = nil if force_reload
13
+ @me ||= users.me
13
14
  end
14
15
 
15
16
  def organization
@@ -1,3 +1,6 @@
1
+ require "uri"
2
+ require "cgi"
3
+
1
4
  module Calendlyr
2
5
  class Collection
3
6
  attr_reader :data, :count, :next_page, :next_page_token, :client
@@ -8,6 +8,14 @@ module Calendlyr
8
8
  client.organizations.list_invitations organization_uuid: uuid, **params
9
9
  end
10
10
 
11
+ def list_webhooks(**params)
12
+ client.webhooks.list(organization_uri: uri, **params)
13
+ end
14
+
15
+ def create_webhook(**params)
16
+ client.webhooks.create(organization_uri: uri, **params)
17
+ end
18
+
11
19
  def revoke_invitation(invitation_uuid:)
12
20
  client.organizations.revoke_invitation(organization_uuid: uuid, invitation_uuid: invitation_uuid)
13
21
  end
@@ -1,7 +1,14 @@
1
+ require "net/http"
2
+ require "json"
3
+ require "openssl"
4
+ require "uri"
5
+
1
6
  module Calendlyr
2
7
  class Resource
3
8
  attr_reader :client
4
9
 
10
+ ERROR_CODES = %w[400 401 403 404 409 500]
11
+
5
12
  def initialize(client)
6
13
  @client = client
7
14
  end
@@ -16,14 +23,6 @@ module Calendlyr
16
23
  handle_response request(url, Net::HTTP::Post, body: body)
17
24
  end
18
25
 
19
- def patch_request(url, body:)
20
- handle_response request(url, Net::HTTP::Patch, body: body)
21
- end
22
-
23
- def put_request(url, body)
24
- handle_response request(url, Net::HTTP::Put, body: body)
25
- end
26
-
27
26
  def delete_request(url, params: {})
28
27
  handle_response request(url, Net::HTTP::Delete, params: params)
29
28
  end
@@ -49,22 +48,11 @@ module Calendlyr
49
48
  end
50
49
 
51
50
  def handle_response(response)
51
+ return true unless response.read_body
52
+
52
53
  body = JSON.parse(response.read_body)
53
- case response.code
54
- when 400
55
- raise Error, "#{body["title"]}. #{body["message"]}"
56
- when 401
57
- raise Error, "#{body["title"]}. #{body["message"]}"
58
- when 403
59
- raise Error, "#{body["title"]}. #{body["message"]}"
60
- when 404
61
- raise Error, "#{body["title"]}. #{body["message"]}"
62
- when 429
63
- raise Error, "#{body["title"]}. #{body["message"]}"
64
- when 500
65
- raise Error, "#{body["title"]}. #{body["message"]}"
66
- when 503
67
- raise Error, "#{body["title"]}. #{body["message"]}"
54
+ if ERROR_CODES.include? response.code
55
+ raise Error, "[Error #{response.code}] #{body["title"]}. #{body["message"]}"
68
56
  else
69
57
  body
70
58
  end
@@ -6,7 +6,7 @@ module Calendlyr
6
6
  end
7
7
 
8
8
  def retrieve(event_uuid:, invitee_uuid:)
9
- EventInvitee.new get_request("scheduled_events/#{event_uuid}/invitees/#{invitee_uuid}").merge(client: client)
9
+ EventInvitee.new get_request("scheduled_events/#{event_uuid}/invitees/#{invitee_uuid}").dig("resource").merge(client: client)
10
10
  end
11
11
  end
12
12
  end
@@ -1,7 +1,7 @@
1
1
  module Calendlyr
2
2
  class OrganizationResource < Resource
3
3
  def invite(organization_uuid:, email:)
4
- Invitation.new post_request("organizations/#{organization_uuid}/invitations", body: {email: email}).merge(client: client)
4
+ Invitation.new post_request("organizations/#{organization_uuid}/invitations", body: {email: email}).dig("resource").merge(client: client)
5
5
  end
6
6
 
7
7
  def list_invitations(organization_uuid:, **params)
@@ -1,3 +1,3 @@
1
1
  module Calendlyr
2
- VERSION = "0.3.5"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/calendlyr.rb CHANGED
@@ -1,8 +1,3 @@
1
- require "net/http"
2
- require "uri"
3
- require "json"
4
- require "openssl"
5
- require "cgi"
6
1
  require "calendlyr/version"
7
2
 
8
3
  module Calendlyr
@@ -2,7 +2,10 @@ require "test_helper"
2
2
 
3
3
  class ClientTest < Minitest::Test
4
4
  def test_token
5
- client = Calendlyr::Client.new token: "test"
6
- assert_equal "test", client.token
5
+ assert_equal "fake", client.token
6
+ end
7
+
8
+ def test_inspect
9
+ assert_equal "#<Calendlyr::Client>", client.inspect
7
10
  end
8
11
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class ResourceTest < Minitest::Test
6
+ def test_handle_response_error
7
+ error_code = Calendlyr::Resource::ERROR_CODES.sample
8
+ stub(path: "users/me", response: {body: fixture_file("resources/#{error_code}"), status: error_code.to_i})
9
+
10
+ assert_raises Calendlyr::Error do
11
+ client.me
12
+ end
13
+ end
14
+ end
@@ -40,25 +40,47 @@ class OrganizationsResourceTest < Minitest::Test
40
40
  assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", memberships.next_page_token
41
41
  end
42
42
 
43
+ def test_list_webhooks
44
+ stub(path: "webhook_subscriptions?organization=#{client.organization.uri}&scope=user", response: {body: fixture_file("webhooks/list"), status: 200})
45
+ webhooks = client.organization.list_webhooks(scope: "user")
46
+
47
+ assert_equal Calendlyr::Collection, webhooks.class
48
+ assert_equal Calendlyr::Webhook, webhooks.data.first.class
49
+ assert_equal 1, webhooks.count
50
+ assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", webhooks.next_page_token
51
+ end
52
+
53
+ def test_create_webhook
54
+ body = {url: "https://blah.foo/bar", events: ["invitee.created"], organization: client.organization.uri, scope: "user", user: client.me.uri}
55
+ stub(method: :post, path: "webhook_subscriptions", body: body, response: {body: fixture_file("webhooks/create"), status: 201})
56
+
57
+ assert client.webhooks.create(url: body[:url], events: body[:events], organization_uri: body[:organization], scope: body[:scope], user_uri: body[:user])
58
+ end
59
+
43
60
  def test_retrieve_invitation
44
- organization_uuid = "AAAAAAAAAAAAAAAA"
45
61
  invitation_uuid = "AAAAAAAAAAAAAAAA"
46
- response = {body: fixture_file("organizations/retrieve_invitation"), status: 200}
47
- stub(path: "organizations/#{organization_uuid}/invitations/#{invitation_uuid}", response: response)
48
- invitation = client.organizations.retrieve_invitation(organization_uuid: organization_uuid, invitation_uuid: invitation_uuid)
62
+
63
+ stub(path: "organizations/#{client.organization.uuid}/invitations/#{invitation_uuid}", response: {body: fixture_file("organizations/retrieve_invitation"), status: 200})
64
+ stub(method: :delete, path: "organizations/#{client.organization.uuid}/invitations/#{invitation_uuid}", response: {body: fixture_file("organizations/revoke_invitation")})
65
+ invitation = client.organizations.retrieve_invitation(organization_uuid: client.organization.uuid, invitation_uuid: invitation_uuid)
49
66
 
50
67
  assert_equal Calendlyr::Invitation, invitation.class
51
68
  assert_equal "test@example.com", invitation.email
69
+
70
+ assert invitation.associated_organization
71
+ assert invitation.revoke
52
72
  end
53
73
 
54
74
  def test_retrieve_membership
55
75
  membership_uuid = "AAAAAAAAAAAAAAAA"
56
76
  response = {body: fixture_file("organizations/retrieve_membership"), status: 200}
57
77
  stub(path: "organization_memberships/#{membership_uuid}", response: response)
78
+ stub(path: "users/#{membership_uuid}", response: {body: fixture_file("users/retrieve"), status: 200})
58
79
  membership = client.organizations.retrieve_membership(membership_uuid: membership_uuid)
59
80
 
60
81
  assert_equal Calendlyr::Membership, membership.class
61
82
  assert_equal "test@example.com", membership.user.email
83
+ assert_equal membership.associated_user, client.users.retrieve(user_uuid: membership_uuid)
62
84
  end
63
85
 
64
86
  def test_revoke_invitation
@@ -77,8 +99,6 @@ class OrganizationsResourceTest < Minitest::Test
77
99
  end
78
100
 
79
101
  def test_organization_invite_user
80
- stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
81
-
82
102
  email = "email@example.com"
83
103
  response = {body: fixture_file("organizations/invite"), status: 201}
84
104
  stub(method: :post, path: "organizations/#{client.organization.uuid}/invitations", body: {email: email}, response: response)
@@ -90,7 +110,6 @@ class OrganizationsResourceTest < Minitest::Test
90
110
  end
91
111
 
92
112
  def test_organization_list_invitations
93
- stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
94
113
  stub(path: "organizations/#{client.organization.uuid}/invitations", response: {body: fixture_file("organizations/list_invitations"), status: 200})
95
114
  invitations = client.organization.list_invitations
96
115
 
@@ -101,13 +120,11 @@ class OrganizationsResourceTest < Minitest::Test
101
120
  end
102
121
 
103
122
  def test_organization_revoke_invitation
104
- stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
105
123
  stub(method: :delete, path: "organizations/#{client.organization.uuid}/invitations/AAAAAAAAAAAAAAAA", response: {body: fixture_file("organizations/revoke_invitation")})
106
124
  assert client.organization.revoke_invitation(invitation_uuid: "AAAAAAAAAAAAAAAA")
107
125
  end
108
126
 
109
127
  def test_organization_invitation
110
- stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
111
128
  response = {body: fixture_file("organizations/retrieve_invitation"), status: 200}
112
129
  stub(path: "organizations/#{client.organization.uuid}/invitations/AAAAAAAAAAAAAAAA", response: response)
113
130
  invitation = client.organization.invitation(invitation_uuid: "AAAAAAAAAAAAAAAA")
@@ -117,7 +134,6 @@ class OrganizationsResourceTest < Minitest::Test
117
134
  end
118
135
 
119
136
  def test_organization_events
120
- stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
121
137
  stub(path: "scheduled_events?organization=#{client.organization.uri}", response: {body: fixture_file("events/list"), status: 200})
122
138
  events = client.organization.events
123
139
 
@@ -128,7 +144,6 @@ class OrganizationsResourceTest < Minitest::Test
128
144
  end
129
145
 
130
146
  def test_organization_memberships
131
- stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
132
147
  stub(path: "organization_memberships?organization=#{client.organization.uri}", response: {body: fixture_file("organizations/list_memberships"), status: 200})
133
148
  memberships = client.organization.memberships
134
149
 
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class SchedulingLinksResourceTest < Minitest::Test
6
+ def test_create
7
+ owner_uri = "https://api.calendly.com/event_types/GBGBDCAADAEDCRZ2"
8
+ max_event_count = 20
9
+ owner_type = "EventType"
10
+ response = {body: fixture_file("scheduling_links/create"), status: 201}
11
+ stub(method: :post, path: "scheduling_links", body: {owner: owner_uri, max_event_count: max_event_count, owner_type: owner_type}, response: response)
12
+
13
+ assert client.scheduling_links.create(owner_uri: owner_uri, max_event_count: max_event_count, owner_type: owner_type)
14
+ end
15
+ end
@@ -28,6 +28,21 @@ class UsersResourceTest < Minitest::Test
28
28
  assert_equal "test@example.com", me.email
29
29
  end
30
30
 
31
+ def test_me_caching
32
+ response = {body: fixture_file("users/retrieve"), status: 200}
33
+ stub = stub(path: "users/me", response: response)
34
+ me = client.me
35
+ remove_request_stub(stub)
36
+ assert_equal client.me, me
37
+ end
38
+
39
+ def test_me_caching_reload
40
+ me = client.me
41
+ stub(path: "users/me", response: {body: fixture_file("users/reload"), status: 200})
42
+ reloaded_me = client.me(force_reload: true)
43
+ assert me.name != reloaded_me.name
44
+ end
45
+
31
46
  def test_organization
32
47
  response = {body: fixture_file("users/retrieve"), status: 200}
33
48
  stub(path: "users/me", response: response)
@@ -39,7 +54,6 @@ class UsersResourceTest < Minitest::Test
39
54
  end
40
55
 
41
56
  def test_event_types
42
- stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
43
57
  me = client.me
44
58
 
45
59
  stub(path: "event_types?user=#{me.uri}&organization=#{me.organization.uri}", response: {body: fixture_file("event_types/list"), status: 200})
@@ -52,7 +66,6 @@ class UsersResourceTest < Minitest::Test
52
66
  end
53
67
 
54
68
  def test_events
55
- stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
56
69
  me = client.me
57
70
 
58
71
  stub(path: "scheduled_events?user=#{me.uri}&organization=#{me.organization.uri}", response: {body: fixture_file("events/list"), status: 200})
@@ -65,7 +78,6 @@ class UsersResourceTest < Minitest::Test
65
78
  end
66
79
 
67
80
  def test_memberships
68
- stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
69
81
  me = client.me
70
82
 
71
83
  stub(path: "organization_memberships?user=#{me.uri}&organization=#{me.organization.uri}", response: {body: fixture_file("organizations/list_memberships"), status: 200})
@@ -21,16 +21,19 @@ class WebhooksResourceTest < Minitest::Test
21
21
  stub(method: :post, path: "webhook_subscriptions", body: body, response: {body: fixture_file("webhooks/create"), status: 201})
22
22
 
23
23
  assert client.webhooks.create(url: body[:url], events: body[:events], organization_uri: body[:organization], scope: body[:scope], user_uri: body[:user])
24
+ assert client.organization.create_webhook(url: body[:url], events: body[:events], scope: body[:scope], user_uri: body[:user])
24
25
  end
25
26
 
26
27
  def test_retrieve
27
28
  webhook_uuid = "AAAAAAAAAAAAAAAA"
28
- response = {body: fixture_file("webhooks/retrieve"), status: 200}
29
- stub(path: "webhook_subscriptions/#{webhook_uuid}", response: response)
29
+ stub(path: "webhook_subscriptions/#{webhook_uuid}", response: {body: fixture_file("webhooks/retrieve"), status: 200})
30
+ stub(path: "users/AAAAAAAAAAAAAAAA", response: {body: fixture_file("users/retrieve"), status: 200})
30
31
  webhook = client.webhooks.retrieve(webhook_uuid: webhook_uuid)
31
32
 
32
33
  assert_equal Calendlyr::Webhook, webhook.class
33
34
  assert_equal "user", webhook.scope
35
+ assert_equal webhook.associated_user, client.users.retrieve(user_uuid: "AAAAAAAAAAAAAAAA")
36
+ assert_equal webhook.associated_organization, client.users.retrieve(user_uuid: "AAAAAAAAAAAAAAAA").organization
34
37
  end
35
38
 
36
39
  def test_delete
@@ -1,38 +1,40 @@
1
1
  {
2
- "cancel_url": "https://calendly.com/cancellations/AAAAAAAAAAAAAAAA",
3
- "created_at": "2020-01-01T20:30:00Z",
4
- "email": "email@example.com",
5
- "reschedule_url": "https://calendly.com/reschedulings/AAAAAAAAAAAAAAAA",
6
- "event": "https://api.calendly.com/scheduled_events/ABCDABCDABCDABCD",
7
- "name": "John Doe",
8
- "status": "active",
9
- "timezone": "America/New_York",
10
- "updated_at": "2020-01-01T20:30:00Z",
11
- "uri": "https://api.calendly.com/api/v2/scheduled_events/ABCDABCDABCDABCD/invitees/ABCDABCDABCDABCD",
12
- "questions_and_answers": [
13
- {
14
- "answer": "radio button answer",
15
- "position": 0,
16
- "question": "Question with Radio Buttons answer type"
17
- },
18
- {
19
- "answer": "Multiple line\nAnswer",
20
- "position": 1,
21
- "question": "Question with Multiple Lines answer type"
22
- },
23
- {
24
- "answer": "Answer 1\nAnswer 2\nAnswer 3",
25
- "position": 2,
26
- "question": "Question with Checkboxes answer type"
2
+ "resource": {
3
+ "cancel_url": "https://calendly.com/cancellations/AAAAAAAAAAAAAAAA",
4
+ "created_at": "2020-01-01T20:30:00Z",
5
+ "email": "email@example.com",
6
+ "reschedule_url": "https://calendly.com/reschedulings/AAAAAAAAAAAAAAAA",
7
+ "event": "https://api.calendly.com/scheduled_events/ABCDABCDABCDABCD",
8
+ "name": "John Doe",
9
+ "status": "active",
10
+ "timezone": "America/New_York",
11
+ "updated_at": "2020-01-01T20:30:00Z",
12
+ "uri": "https://api.calendly.com/api/v2/scheduled_events/ABCDABCDABCDABCD/invitees/ABCDABCDABCDABCD",
13
+ "questions_and_answers": [
14
+ {
15
+ "answer": "radio button answer",
16
+ "position": 0,
17
+ "question": "Question with Radio Buttons answer type"
18
+ },
19
+ {
20
+ "answer": "Multiple line\nAnswer",
21
+ "position": 1,
22
+ "question": "Question with Multiple Lines answer type"
23
+ },
24
+ {
25
+ "answer": "Answer 1\nAnswer 2\nAnswer 3",
26
+ "position": 2,
27
+ "question": "Question with Checkboxes answer type"
28
+ }
29
+ ],
30
+ "canceled": false,
31
+ "payment": {
32
+ "external_id": "ch_AAAAAAAAAAAAAAAAAAAAAAAA",
33
+ "provider": "stripe",
34
+ "amount": 1234.56,
35
+ "currency": "USD",
36
+ "terms": "sample terms of payment (up to 1,024 characters)",
37
+ "successful": true
27
38
  }
28
- ],
29
- "canceled": false,
30
- "payment": {
31
- "external_id": "ch_AAAAAAAAAAAAAAAAAAAAAAAA",
32
- "provider": "stripe",
33
- "amount": 1234.56,
34
- "currency": "USD",
35
- "terms": "sample terms of payment (up to 1,024 characters)",
36
- "successful": true
37
39
  }
38
40
  }
@@ -1,9 +1,11 @@
1
1
  {
2
- "created_at": "2020-01-01T20:30:00Z",
3
- "email": "email@example.com",
4
- "last_sent_at": "2020-01-01T20:30:00Z",
5
- "organization": "https://api.calendly.com/organizations/ABCDABCDABCDABCD",
6
- "status": "pending",
7
- "updated_at": "2020-01-01T20:30:00Z",
8
- "uri": "https://api.calendly.com/organizations/ABCDABCDABCDABCD/invitations/DCBADCBADCBADCBA"
2
+ "resource": {
3
+ "created_at": "2020-01-01T20:30:00Z",
4
+ "email": "email@example.com",
5
+ "last_sent_at": "2020-01-01T20:30:00Z",
6
+ "organization": "https://api.calendly.com/organizations/ABCDABCDABCDABCD",
7
+ "status": "pending",
8
+ "updated_at": "2020-01-01T20:30:00Z",
9
+ "uri": "https://api.calendly.com/organizations/ABCDABCDABCDABCD/invitations/DCBADCBADCBADCBA"
10
+ }
9
11
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "collection": [
3
3
  {
4
- "uri": "https://api.calendly.com/organizations/AAAAAAAAAAAAAAAA/invitations",
4
+ "uri": "https://api.calendly.com/organizations/AAAAAAAAAAAAAAAA/invitations/AAAAAAAAAAAAAAAA",
5
5
  "organization": "https://api.calendly.com/organizations/AAAAAAAAAAAAAAAA",
6
6
  "email": "test@example.com",
7
7
  "status": "accepted",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "resource": {
3
- "uri": "https://api.calendly.com/organizations/AAAAAAAAAAAAAAAA/invitations",
3
+ "uri": "https://api.calendly.com/organizations/AAAAAAAAAAAAAAAA/invitations/AAAAAAAAAAAAAAAA",
4
4
  "organization": "https://api.calendly.com/organizations/AAAAAAAAAAAAAAAA",
5
5
  "email": "test@example.com",
6
6
  "status": "accepted",
@@ -0,0 +1,10 @@
1
+ {
2
+ "title": "Unauthenticated",
3
+ "message": "The access token is invalid",
4
+ "details": [
5
+ {
6
+ "parameter": "string",
7
+ "message": "string"
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "title": "Invalid Argument",
3
+ "message": "The supplied parameters are invalid.",
4
+ "details": [
5
+ {
6
+ "parameter": "string",
7
+ "message": "string"
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "title": "Permission Denied",
3
+ "message": "This user is not in your organization",
4
+ "details": [
5
+ {
6
+ "parameter": "string",
7
+ "message": "string"
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "title": "Resource Not Found",
3
+ "message": "The server could not find the requested resource.",
4
+ "details": [
5
+ {
6
+ "parameter": "string",
7
+ "message": "string"
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "title": "Already Exists",
3
+ "message": "Hook with this url already exists"
4
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "title": "Internal Server Error",
3
+ "message": "The server encountered an unexpected condition that prevented it from fulfilling the request.",
4
+ "details": [
5
+ {
6
+ "parameter": "string",
7
+ "message": "string"
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "resource": {
3
+ "uri": "https://api.calendly.com/users/AAAAAAAAAAAAAAAA",
4
+ "name": "John Doe Reloaded",
5
+ "slug": "acmesales",
6
+ "email": "test@example.com",
7
+ "scheduling_url": "https://calendly.com/acmesales",
8
+ "timezone": "America/New York",
9
+ "avatar_url": "https://01234567890.cloudfront.net/uploads/user/avatar/0123456/a1b2c3d4.png",
10
+ "created_at": "2019-01-02T03:04:05.678Z",
11
+ "updated_at": "2019-08-07T06:05:04.321Z",
12
+ "current_organization": "https://api.calendly.com/organizations/AAAAAAAAAAAAAAAA"
13
+ }
14
+ }
data/test/test_helper.rb CHANGED
@@ -11,8 +11,13 @@ require "minitest/autorun"
11
11
  require "webmock/minitest"
12
12
 
13
13
  class Minitest::Test
14
+ def initialize(name)
15
+ stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
16
+ super
17
+ end
18
+
14
19
  def client
15
- Calendlyr::Client.new(token: "fake")
20
+ @client ||= Calendlyr::Client.new(token: "fake")
16
21
  end
17
22
 
18
23
  def fixture_file(fixture)
@@ -23,5 +28,6 @@ class Minitest::Test
23
28
  stub_req = stub_request(method, "#{Calendlyr::Client::BASE_URL}/#{path}")
24
29
  stub_req.with(body: body) if [:post, :put, :patch].include?(method)
25
30
  stub_req.to_return(**response)
31
+ stub_req
26
32
  end
27
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calendlyr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - araluce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-23 00:00:00.000000000 Z
11
+ date: 2021-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -141,12 +141,13 @@ files:
141
141
  - lib/calendlyr/version.rb
142
142
  - test/calendlyr/client_test.rb
143
143
  - test/calendlyr/object_test.rb
144
- - test/calendlyr/resources/data_compliance.rb
144
+ - test/calendlyr/resource_test.rb
145
+ - test/calendlyr/resources/data_compliance_test.rb
145
146
  - test/calendlyr/resources/event_invitees_test.rb
146
147
  - test/calendlyr/resources/event_types_test.rb
147
148
  - test/calendlyr/resources/events_test.rb
148
149
  - test/calendlyr/resources/organizations_test.rb
149
- - test/calendlyr/resources/scheduling_links.rb
150
+ - test/calendlyr/resources/scheduling_links_test.rb
150
151
  - test/calendlyr/resources/users_test.rb
151
152
  - test/calendlyr/resources/webhooks_test.rb
152
153
  - test/calendlyr_test.rb
@@ -164,7 +165,14 @@ files:
164
165
  - test/fixtures/organizations/retrieve_invitation.json
165
166
  - test/fixtures/organizations/retrieve_membership.json
166
167
  - test/fixtures/organizations/revoke_invitation.json
168
+ - test/fixtures/resources/400.json
169
+ - test/fixtures/resources/401.json
170
+ - test/fixtures/resources/403.json
171
+ - test/fixtures/resources/404.json
172
+ - test/fixtures/resources/409.json
173
+ - test/fixtures/resources/500.json
167
174
  - test/fixtures/scheduling_links/create.json
175
+ - test/fixtures/users/reload.json
168
176
  - test/fixtures/users/retrieve.json
169
177
  - test/fixtures/webhooks/create.json
170
178
  - test/fixtures/webhooks/delete.json
@@ -198,12 +206,13 @@ summary: Ruby bindings for Calendly API.
198
206
  test_files:
199
207
  - test/calendlyr/client_test.rb
200
208
  - test/calendlyr/object_test.rb
201
- - test/calendlyr/resources/data_compliance.rb
209
+ - test/calendlyr/resource_test.rb
210
+ - test/calendlyr/resources/data_compliance_test.rb
202
211
  - test/calendlyr/resources/event_invitees_test.rb
203
212
  - test/calendlyr/resources/event_types_test.rb
204
213
  - test/calendlyr/resources/events_test.rb
205
214
  - test/calendlyr/resources/organizations_test.rb
206
- - test/calendlyr/resources/scheduling_links.rb
215
+ - test/calendlyr/resources/scheduling_links_test.rb
207
216
  - test/calendlyr/resources/users_test.rb
208
217
  - test/calendlyr/resources/webhooks_test.rb
209
218
  - test/calendlyr_test.rb
@@ -221,7 +230,14 @@ test_files:
221
230
  - test/fixtures/organizations/retrieve_invitation.json
222
231
  - test/fixtures/organizations/retrieve_membership.json
223
232
  - test/fixtures/organizations/revoke_invitation.json
233
+ - test/fixtures/resources/400.json
234
+ - test/fixtures/resources/401.json
235
+ - test/fixtures/resources/403.json
236
+ - test/fixtures/resources/404.json
237
+ - test/fixtures/resources/409.json
238
+ - test/fixtures/resources/500.json
224
239
  - test/fixtures/scheduling_links/create.json
240
+ - test/fixtures/users/reload.json
225
241
  - test/fixtures/users/retrieve.json
226
242
  - test/fixtures/webhooks/create.json
227
243
  - test/fixtures/webhooks/delete.json
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class SchedulingLinksResourceTest < Minitest::Test
6
- def test_create
7
- body = {owner_uri: "https://api.calendly.com/event_types/GBGBDCAADAEDCRZ2", max_event_count: 20, owner_type: "EventType"}
8
- stub(method: :post, path: "scheduling_links", body: body, response: {body: fixture_file("scheduling_links/create"), status: 201})
9
-
10
- assert client.data_compliance.delete_invitee_data(**body)
11
- end
12
- end