calendlyr 0.3.3

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.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yml +34 -0
  3. data/.gitignore +25 -0
  4. data/CHANGELOG.md +32 -0
  5. data/Gemfile +8 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +159 -0
  8. data/Rakefile +10 -0
  9. data/bin/console +13 -0
  10. data/bin/setup +8 -0
  11. data/bin/test +6 -0
  12. data/calendly.gemspec +27 -0
  13. data/lib/calendly/client.rb +57 -0
  14. data/lib/calendly/collection.rb +31 -0
  15. data/lib/calendly/error.rb +4 -0
  16. data/lib/calendly/object.rb +27 -0
  17. data/lib/calendly/objects/event_invitees.rb +4 -0
  18. data/lib/calendly/objects/event_types.rb +4 -0
  19. data/lib/calendly/objects/events.rb +4 -0
  20. data/lib/calendly/objects/invitations.rb +11 -0
  21. data/lib/calendly/objects/memberships.rb +7 -0
  22. data/lib/calendly/objects/organizations.rb +27 -0
  23. data/lib/calendly/objects/scheduling_links.rb +4 -0
  24. data/lib/calendly/objects/users.rb +19 -0
  25. data/lib/calendly/objects/webhooks.rb +11 -0
  26. data/lib/calendly/resource.rb +73 -0
  27. data/lib/calendly/resources/data_compliance.rb +7 -0
  28. data/lib/calendly/resources/event_invitees.rb +12 -0
  29. data/lib/calendly/resources/event_types.rb +12 -0
  30. data/lib/calendly/resources/events.rb +12 -0
  31. data/lib/calendly/resources/organizations.rb +33 -0
  32. data/lib/calendly/resources/scheduling_links.rb +8 -0
  33. data/lib/calendly/resources/users.rb +11 -0
  34. data/lib/calendly/resources/webhooks.rb +21 -0
  35. data/lib/calendly/version.rb +3 -0
  36. data/lib/calendly.rb +35 -0
  37. data/test/calendly/client_test.rb +8 -0
  38. data/test/calendly/object_test.rb +21 -0
  39. data/test/calendly/resources/data_compliance.rb +13 -0
  40. data/test/calendly/resources/event_invitees_test.rb +29 -0
  41. data/test/calendly/resources/event_types_test.rb +31 -0
  42. data/test/calendly/resources/events_test.rb +29 -0
  43. data/test/calendly/resources/organizations_test.rb +140 -0
  44. data/test/calendly/resources/scheduling_links.rb +12 -0
  45. data/test/calendly/resources/users_test.rb +79 -0
  46. data/test/calendly/resources/webhooks_test.rb +42 -0
  47. data/test/calendly_test.rb +7 -0
  48. data/test/fixtures/data_compliance/delete_invitee_data.json +1 -0
  49. data/test/fixtures/event_invitees/list.json +58 -0
  50. data/test/fixtures/event_invitees/retrieve.json +38 -0
  51. data/test/fixtures/event_types/list.json +88 -0
  52. data/test/fixtures/event_types/retrieve.json +82 -0
  53. data/test/fixtures/events/list.json +39 -0
  54. data/test/fixtures/events/retrieve.json +33 -0
  55. data/test/fixtures/organizations/invite.json +9 -0
  56. data/test/fixtures/organizations/list_invitations.json +18 -0
  57. data/test/fixtures/organizations/list_memberships.json +26 -0
  58. data/test/fixtures/organizations/remove_user.json +1 -0
  59. data/test/fixtures/organizations/retrieve_invitation.json +12 -0
  60. data/test/fixtures/organizations/retrieve_membership.json +20 -0
  61. data/test/fixtures/organizations/revoke_invitation.json +1 -0
  62. data/test/fixtures/scheduling_links/create.json +7 -0
  63. data/test/fixtures/users/retrieve.json +14 -0
  64. data/test/fixtures/webhooks/create.json +17 -0
  65. data/test/fixtures/webhooks/delete.json +1 -0
  66. data/test/fixtures/webhooks/list.json +23 -0
  67. data/test/fixtures/webhooks/retrieve.json +17 -0
  68. data/test/test_helper.rb +27 -0
  69. metadata +230 -0
@@ -0,0 +1,12 @@
1
+ module Calendly
2
+ class EventInviteeResource < Resource
3
+ def list(event_uuid:, **params)
4
+ response = get_request("scheduled_events/#{event_uuid}/invitees", params: params.compact)
5
+ Collection.from_response(response, key: "collection", type: EventInvitee, client: client)
6
+ end
7
+
8
+ def retrieve(event_uuid:, invitee_uuid:)
9
+ EventInvitee.new get_request("scheduled_events/#{event_uuid}/invitees/#{invitee_uuid}").merge(client: client)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Calendly
2
+ class EventTypeResource < Resource
3
+ def list(user_uri:, organization_uri:, **params)
4
+ response = get_request("event_types", params: {user: user_uri, organization: organization_uri}.merge(params))
5
+ Collection.from_response(response, key: "collection", type: EventType, client: client)
6
+ end
7
+
8
+ def retrieve(event_type_uuid:)
9
+ EventType.new get_request("event_types/#{event_type_uuid}").dig("resource").merge(client: client)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Calendly
2
+ class EventResource < Resource
3
+ def list(user_uri:, organization_uri:, **params)
4
+ response = get_request("scheduled_events", params: {user: user_uri, organization: organization_uri}.merge(params).compact)
5
+ Collection.from_response(response, key: "collection", type: Event, client: client)
6
+ end
7
+
8
+ def retrieve(event_uuid:)
9
+ Event.new get_request("scheduled_events/#{event_uuid}").dig("resource").merge(client: client)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,33 @@
1
+ module Calendly
2
+ class OrganizationResource < Resource
3
+ def invite(organization_uuid:, email:)
4
+ Invitation.new post_request("organizations/#{organization_uuid}/invitations", body: {email: email}).merge(client: client)
5
+ end
6
+
7
+ def list_invitations(organization_uuid:, **params)
8
+ response = get_request("organizations/#{organization_uuid}/invitations", params: params)
9
+ Collection.from_response(response, key: "collection", type: Invitation, client: client)
10
+ end
11
+
12
+ def list_memberships(user_uri: nil, organization_uri: nil, **params)
13
+ response = get_request("organization_memberships", params: {user: user_uri, organization: organization_uri}.merge(params).compact)
14
+ Collection.from_response(response, key: "collection", type: Membership, client: client)
15
+ end
16
+
17
+ def retrieve_invitation(organization_uuid:, invitation_uuid:)
18
+ Invitation.new get_request("organizations/#{organization_uuid}/invitations/#{invitation_uuid}").dig("resource").merge(client: client)
19
+ end
20
+
21
+ def retrieve_membership(membership_uuid:)
22
+ Membership.new get_request("organization_memberships/#{membership_uuid}").dig("resource").merge(client: client)
23
+ end
24
+
25
+ def revoke_invitation(organization_uuid:, invitation_uuid:)
26
+ delete_request("organizations/#{organization_uuid}/invitations/#{invitation_uuid}")
27
+ end
28
+
29
+ def remove_user(membership_uuid:)
30
+ delete_request("organization_memberships/#{membership_uuid}")
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,8 @@
1
+ module Calendly
2
+ class SchedulingLinkResource < Resource
3
+ def create(owner_uri:, max_event_count:, owner_type: "EventType")
4
+ body = {owner: owner_uri, max_event_count: max_event_count, owner_type: owner_type}
5
+ SchedulingLink.new post_request("scheduling_links", body: body).dig("resource").merge(client: client)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ module Calendly
2
+ class UserResource < Resource
3
+ def me
4
+ retrieve(user_uuid: "me")
5
+ end
6
+
7
+ def retrieve(user_uuid:)
8
+ User.new get_request("users/#{user_uuid}").dig("resource").merge(client: client)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ module Calendly
2
+ class WebhookResource < Resource
3
+ def list(organization_uri:, scope:, **params)
4
+ response = get_request("webhook_subscriptions", params: {organization: organization_uri, scope: scope}.merge(params).compact)
5
+ Collection.from_response(response, key: "collection", type: Webhook, client: client)
6
+ end
7
+
8
+ def create(url:, events:, organization_uri:, scope:, signing_key: nil, user_uri: nil)
9
+ body = {url: url, events: events, organization: organization_uri, user: user_uri, scope: scope, signing_key: signing_key}.compact
10
+ Webhook.new post_request("webhook_subscriptions", body: body).dig("resource").merge(client: client)
11
+ end
12
+
13
+ def retrieve(webhook_uuid:)
14
+ Webhook.new get_request("webhook_subscriptions/#{webhook_uuid}").dig("resource").merge(client: client)
15
+ end
16
+
17
+ def delete(webhook_uuid:)
18
+ delete_request("webhook_subscriptions/#{webhook_uuid}")
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Calendly
2
+ VERSION = "0.3.3"
3
+ end
data/lib/calendly.rb ADDED
@@ -0,0 +1,35 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require "json"
4
+ require "openssl"
5
+ require "cgi"
6
+ require "calendly/version"
7
+
8
+ module Calendly
9
+ autoload :Client, "calendly/client"
10
+ autoload :Collection, "calendly/collection"
11
+ autoload :Error, "calendly/error"
12
+ autoload :Resource, "calendly/resource"
13
+ autoload :Object, "calendly/object"
14
+
15
+ # High-level categories of Calendly API calls
16
+ autoload :UserResource, "calendly/resources/users"
17
+ autoload :EventTypeResource, "calendly/resources/event_types"
18
+ autoload :OrganizationResource, "calendly/resources/organizations"
19
+ autoload :EventResource, "calendly/resources/events"
20
+ autoload :EventInviteeResource, "calendly/resources/event_invitees"
21
+ autoload :SchedulingLinkResource, "calendly/resources/scheduling_links"
22
+ autoload :WebhookResource, "calendly/resources/webhooks"
23
+ autoload :DataComplianceResource, "calendly/resources/data_compliance"
24
+
25
+ # Classes used to return a nicer object wrapping the response data
26
+ autoload :User, "calendly/objects/users"
27
+ autoload :EventType, "calendly/objects/event_types"
28
+ autoload :Event, "calendly/objects/events"
29
+ autoload :Organization, "calendly/objects/organizations"
30
+ autoload :Invitation, "calendly/objects/invitations"
31
+ autoload :EventInvitee, "calendly/objects/event_invitees"
32
+ autoload :SchedulingLink, "calendly/objects/scheduling_links"
33
+ autoload :Membership, "calendly/objects/memberships"
34
+ autoload :Webhook, "calendly/objects/webhooks"
35
+ end
@@ -0,0 +1,8 @@
1
+ require "test_helper"
2
+
3
+ class ClientTest < Minitest::Test
4
+ def test_api_key
5
+ client = Calendly::Client.new api_key: "test"
6
+ assert_equal "test", client.api_key
7
+ end
8
+ end
@@ -0,0 +1,21 @@
1
+ require "test_helper"
2
+
3
+ class ObjectTest < Minitest::Test
4
+ def test_creating_object_from_hash
5
+ assert_equal "bar", Calendly::Object.new(foo: "bar").foo
6
+ end
7
+
8
+ def test_nested_hash
9
+ assert_equal "foobar", Calendly::Object.new(foo: {bar: {baz: "foobar"}}, client: nil).foo.bar.baz
10
+ end
11
+
12
+ def test_nested_number
13
+ assert_equal 1, Calendly::Object.new(foo: {bar: 1}, client: nil).foo.bar
14
+ end
15
+
16
+ def test_array
17
+ object = Calendly::Object.new(foo: [{bar: :baz}], client: nil)
18
+ assert_equal OpenStruct, object.foo.first.class
19
+ assert_equal :baz, object.foo.first.bar
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class DataComplianceResourceTest < Minitest::Test
6
+ def test_delete_invitee_data
7
+ body = {emails: %w[test@test.com test2@test.com]}
8
+ response = {body: fixture_file("data_compliance/delete_invitee_data"), status: 202}
9
+ stub(method: :post, path: "data_compliance/deletion/invitees", body: body, response: response)
10
+
11
+ assert client.data_compliance.delete_invitee_data(**body)
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class EventInviteesResourceTest < Minitest::Test
6
+ def test_list
7
+ event_uuid = "ABCDABCDABCDABCD"
8
+ response = {body: fixture_file("event_invitees/list"), status: 200}
9
+ stub(path: "scheduled_events/#{event_uuid}/invitees", response: response)
10
+ event_invitees = client.event_invitees.list(event_uuid: event_uuid)
11
+
12
+ assert_equal Calendly::Collection, event_invitees.class
13
+ assert_equal Calendly::EventInvitee, event_invitees.data.first.class
14
+ assert_equal 1, event_invitees.count
15
+ assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", event_invitees.next_page_token
16
+ end
17
+
18
+ def test_retrieve
19
+ event_uuid = "AAAAAAAAAAAAAAAA"
20
+ invitee_uuid = "AAAAAAAAAAAAAAAA"
21
+ response = {body: fixture_file("event_invitees/retrieve"), status: 200}
22
+ stub(path: "scheduled_events/#{event_uuid}/invitees/#{invitee_uuid}", response: response)
23
+ event_invitee = client.event_invitees.retrieve(event_uuid: event_uuid, invitee_uuid: invitee_uuid)
24
+
25
+ assert_equal Calendly::EventInvitee, event_invitee.class
26
+ assert_equal "https://api.calendly.com/api/v2/scheduled_events/ABCDABCDABCDABCD/invitees/ABCDABCDABCDABCD", event_invitee.uri
27
+ assert_equal "John Doe", event_invitee.name
28
+ end
29
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class EventTypesResourceTest < Minitest::Test
6
+ def test_list
7
+ user_uri = "https://api.calendly.com/users/AAAAAAAAAAAAAAAA"
8
+ organization_uri = "https://api.calendly.com/organizations/AAAAAAAAAAAAAAAA"
9
+ response = {body: fixture_file("event_types/list"), status: 200}
10
+ stub(path: "event_types?user=#{user_uri}&organization=#{organization_uri}", response: response)
11
+ event_types = client.event_types.list(user_uri: user_uri, organization_uri: organization_uri)
12
+
13
+ assert_equal Calendly::Collection, event_types.class
14
+ assert_equal Calendly::EventType, event_types.data.first.class
15
+ assert_equal 1, event_types.count
16
+ assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", event_types.next_page_token
17
+ end
18
+
19
+ def test_retrieve
20
+ event_type_uuid = "AAAAAAAAAAAAAAAA"
21
+ response = {body: fixture_file("event_types/retrieve"), status: 200}
22
+ stub(path: "event_types/#{event_type_uuid}", response: response)
23
+ event_type = client.event_types.retrieve(event_type_uuid: event_type_uuid)
24
+
25
+ assert_equal Calendly::EventType, event_type.class
26
+ assert_equal "https://api.calendly.com/event_types/AAAAAAAAAAAAAAAA", event_type.uri
27
+ assert_equal "15 Minute Meeting", event_type.name
28
+ assert_equal "acmesales", event_type.slug
29
+ assert_equal 30, event_type.duration
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class EventsResourceTest < Minitest::Test
6
+ def test_list
7
+ user_uri = "https://api.calendly.com/users/AAAAAAAAAAAAAAAA"
8
+ organization_uri = "https://api.calendly.com/organizations/AAAAAAAAAAAAAAAA"
9
+ response = {body: fixture_file("events/list"), status: 200}
10
+ stub(path: "scheduled_events?user=#{user_uri}&organization=#{organization_uri}", response: response)
11
+ events = client.events.list(user_uri: user_uri, organization_uri: organization_uri)
12
+
13
+ assert_equal Calendly::Collection, events.class
14
+ assert_equal Calendly::Event, events.data.first.class
15
+ assert_equal 1, events.count
16
+ assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", events.next_page_token
17
+ end
18
+
19
+ def test_retrieve
20
+ event_uuid = "AAAAAAAAAAAAAAAA"
21
+ response = {body: fixture_file("events/retrieve"), status: 200}
22
+ stub(path: "scheduled_events/#{event_uuid}", response: response)
23
+ event = client.events.retrieve(event_uuid: event_uuid)
24
+
25
+ assert_equal Calendly::Event, event.class
26
+ assert_equal "https://api.calendly.com/scheduled_events/GBGBDCAADAEDCRZ2", event.uri
27
+ assert_equal "15 Minute Meeting", event.name
28
+ end
29
+ end
@@ -0,0 +1,140 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class OrganizationsResourceTest < Minitest::Test
6
+ def test_invite
7
+ organization_uuid = "ABCDABCDABCDABCD"
8
+ email = "email@example.com"
9
+ response = {body: fixture_file("organizations/invite"), status: 201}
10
+ stub(method: :post, path: "organizations/#{organization_uuid}/invitations", body: {email: email}, response: response)
11
+
12
+ invitation = client.organizations.invite(organization_uuid: organization_uuid, email: email)
13
+
14
+ assert_equal Calendly::Invitation, invitation.class
15
+ assert_equal email, invitation.email
16
+ end
17
+
18
+ def test_list_invitations
19
+ organization_uuid = "AAAAAAAAAAAAAAAA"
20
+ response = {body: fixture_file("organizations/list_invitations"), status: 200}
21
+ stub(path: "organizations/#{organization_uuid}/invitations", response: response)
22
+ invitations = client.organizations.list_invitations(organization_uuid: organization_uuid)
23
+
24
+ assert_equal Calendly::Collection, invitations.class
25
+ assert_equal Calendly::Invitation, invitations.data.first.class
26
+ assert_equal 1, invitations.count
27
+ assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", invitations.next_page_token
28
+ end
29
+
30
+ def test_list_memberships
31
+ user_uri = "AAAAAAAAAAAAAAAA"
32
+ organization_uri = "AAAAAAAAAAAAAAAA"
33
+ response = {body: fixture_file("organizations/list_memberships"), status: 200}
34
+ stub(path: "organization_memberships?user=#{user_uri}&organization=#{organization_uri}", response: response)
35
+ memberships = client.organizations.list_memberships(user_uri: user_uri, organization_uri: organization_uri)
36
+
37
+ assert_equal Calendly::Collection, memberships.class
38
+ assert_equal Calendly::Membership, memberships.data.first.class
39
+ assert_equal 1, memberships.count
40
+ assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", memberships.next_page_token
41
+ end
42
+
43
+ def test_retrieve_invitation
44
+ organization_uuid = "AAAAAAAAAAAAAAAA"
45
+ 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)
49
+
50
+ assert_equal Calendly::Invitation, invitation.class
51
+ assert_equal "test@example.com", invitation.email
52
+ end
53
+
54
+ def test_retrieve_membership
55
+ membership_uuid = "AAAAAAAAAAAAAAAA"
56
+ response = {body: fixture_file("organizations/retrieve_membership"), status: 200}
57
+ stub(path: "organization_memberships/#{membership_uuid}", response: response)
58
+ membership = client.organizations.retrieve_membership(membership_uuid: membership_uuid)
59
+
60
+ assert_equal Calendly::Membership, membership.class
61
+ assert_equal "test@example.com", membership.user.email
62
+ end
63
+
64
+ def test_revoke_invitation
65
+ organization_uuid = "AAAAAAAAAAAAAAAA"
66
+ invitation_uuid = "AAAAAAAAAAAAAAAA"
67
+ response = {body: fixture_file("organizations/revoke_invitation")}
68
+ stub(method: :delete, path: "organizations/#{organization_uuid}/invitations/#{invitation_uuid}", response: response)
69
+ assert client.organizations.revoke_invitation(organization_uuid: organization_uuid, invitation_uuid: invitation_uuid)
70
+ end
71
+
72
+ def test_remove_user
73
+ membership_uuid = "AAAAAAAAAAAAAAAA"
74
+ response = {body: fixture_file("organizations/remove_user")}
75
+ stub(method: :delete, path: "organization_memberships/#{membership_uuid}", response: response)
76
+ assert client.organizations.remove_user(membership_uuid: membership_uuid)
77
+ end
78
+
79
+ def test_organization_invite_user
80
+ stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
81
+
82
+ email = "email@example.com"
83
+ response = {body: fixture_file("organizations/invite"), status: 201}
84
+ stub(method: :post, path: "organizations/#{client.organization.uuid}/invitations", body: {email: email}, response: response)
85
+
86
+ invitation = client.organization.invite_user(email: email)
87
+
88
+ assert_equal Calendly::Invitation, invitation.class
89
+ assert_equal email, invitation.email
90
+ end
91
+
92
+ def test_organization_list_invitations
93
+ stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
94
+ stub(path: "organizations/#{client.organization.uuid}/invitations", response: {body: fixture_file("organizations/list_invitations"), status: 200})
95
+ invitations = client.organization.list_invitations
96
+
97
+ assert_equal Calendly::Collection, invitations.class
98
+ assert_equal Calendly::Invitation, invitations.data.first.class
99
+ assert_equal 1, invitations.count
100
+ assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", invitations.next_page_token
101
+ end
102
+
103
+ def test_organization_revoke_invitation
104
+ stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
105
+ stub(method: :delete, path: "organizations/#{client.organization.uuid}/invitations/AAAAAAAAAAAAAAAA", response: {body: fixture_file("organizations/revoke_invitation")})
106
+ assert client.organization.revoke_invitation(invitation_uuid: "AAAAAAAAAAAAAAAA")
107
+ end
108
+
109
+ def test_organization_invitation
110
+ stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
111
+ response = {body: fixture_file("organizations/retrieve_invitation"), status: 200}
112
+ stub(path: "organizations/#{client.organization.uuid}/invitations/AAAAAAAAAAAAAAAA", response: response)
113
+ invitation = client.organization.invitation(invitation_uuid: "AAAAAAAAAAAAAAAA")
114
+
115
+ assert_equal Calendly::Invitation, invitation.class
116
+ assert_equal "test@example.com", invitation.email
117
+ end
118
+
119
+ def test_organization_events
120
+ stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
121
+ stub(path: "scheduled_events?organization=#{client.organization.uri}", response: {body: fixture_file("events/list"), status: 200})
122
+ events = client.organization.events
123
+
124
+ assert_equal Calendly::Collection, events.class
125
+ assert_equal Calendly::Event, events.data.first.class
126
+ assert_equal 1, events.count
127
+ assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", events.next_page_token
128
+ end
129
+
130
+ def test_organization_memberships
131
+ stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
132
+ stub(path: "organization_memberships?organization=#{client.organization.uri}", response: {body: fixture_file("organizations/list_memberships"), status: 200})
133
+ memberships = client.organization.memberships
134
+
135
+ assert_equal Calendly::Collection, memberships.class
136
+ assert_equal Calendly::Membership, memberships.data.first.class
137
+ assert_equal 1, memberships.count
138
+ assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", memberships.next_page_token
139
+ end
140
+ end
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class UsersResourceTest < Minitest::Test
6
+ def test_retrieve
7
+ user_uuid = "AAAAAAAAAAAAAAAA"
8
+ response = {body: fixture_file("users/retrieve"), status: 200}
9
+ stub(path: "users/#{user_uuid}", response: response)
10
+ user = client.users.retrieve(user_uuid: user_uuid)
11
+
12
+ assert_equal Calendly::User, user.class
13
+ assert_equal "https://api.calendly.com/users/AAAAAAAAAAAAAAAA", user.uri
14
+ assert_equal "John Doe", user.name
15
+ assert_equal "acmesales", user.slug
16
+ assert_equal "test@example.com", user.email
17
+ end
18
+
19
+ def test_me
20
+ response = {body: fixture_file("users/retrieve"), status: 200}
21
+ stub(path: "users/me", response: response)
22
+ me = client.me
23
+
24
+ assert_equal Calendly::User, me.class
25
+ assert_equal "https://api.calendly.com/users/AAAAAAAAAAAAAAAA", me.uri
26
+ assert_equal "John Doe", me.name
27
+ assert_equal "acmesales", me.slug
28
+ assert_equal "test@example.com", me.email
29
+ end
30
+
31
+ def test_organization
32
+ response = {body: fixture_file("users/retrieve"), status: 200}
33
+ stub(path: "users/me", response: response)
34
+ organization = client.organization
35
+
36
+ assert_equal Calendly::Organization, organization.class
37
+ assert_equal "https://api.calendly.com/organizations/AAAAAAAAAAAAAAAA", organization.uri
38
+ assert_equal "AAAAAAAAAAAAAAAA", organization.uuid
39
+ end
40
+
41
+ def test_event_types
42
+ stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
43
+ me = client.me
44
+
45
+ stub(path: "event_types?user=#{me.uri}&organization=#{me.organization.uri}", response: {body: fixture_file("event_types/list"), status: 200})
46
+ event_types = client.me.event_types
47
+
48
+ assert_equal Calendly::Collection, event_types.class
49
+ assert_equal Calendly::EventType, event_types.data.first.class
50
+ assert_equal 1, event_types.count
51
+ assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", event_types.next_page_token
52
+ end
53
+
54
+ def test_events
55
+ stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
56
+ me = client.me
57
+
58
+ stub(path: "scheduled_events?user=#{me.uri}&organization=#{me.organization.uri}", response: {body: fixture_file("events/list"), status: 200})
59
+ events = client.me.events
60
+
61
+ assert_equal Calendly::Collection, events.class
62
+ assert_equal Calendly::Event, events.data.first.class
63
+ assert_equal 1, events.count
64
+ assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", events.next_page_token
65
+ end
66
+
67
+ def test_memberships
68
+ stub(path: "users/me", response: {body: fixture_file("users/retrieve"), status: 200})
69
+ me = client.me
70
+
71
+ stub(path: "organization_memberships?user=#{me.uri}&organization=#{me.organization.uri}", response: {body: fixture_file("organizations/list_memberships"), status: 200})
72
+ memberships = client.me.memberships(organization_uri: me.organization.uri)
73
+
74
+ assert_equal Calendly::Collection, memberships.class
75
+ assert_equal Calendly::Membership, memberships.data.first.class
76
+ assert_equal 1, memberships.count
77
+ assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", memberships.next_page_token
78
+ end
79
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class WebhooksResourceTest < Minitest::Test
6
+ def test_list
7
+ organization_uri = "https://api.calendly.com/organizations/AAAAAAAAAAAAAAAA"
8
+ scope = "user"
9
+ response = {body: fixture_file("webhooks/list"), status: 200}
10
+ stub(path: "webhook_subscriptions?organization=#{organization_uri}&scope=#{scope}", response: response)
11
+ webhooks = client.webhooks.list(organization_uri: organization_uri, scope: scope)
12
+
13
+ assert_equal Calendly::Collection, webhooks.class
14
+ assert_equal Calendly::Webhook, webhooks.data.first.class
15
+ assert_equal 1, webhooks.count
16
+ assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", webhooks.next_page_token
17
+ end
18
+
19
+ def test_create
20
+ body = {url: "https://blah.foo/bar", events: ["invitee.created"], organization: "https://api.calendly.com/organizations/AAAAAAAAAAAAAAAA", scope: "user", user: "https://api.calendly.com/users/AAAAAAAAAAAAAAAA"}
21
+ stub(method: :post, path: "webhook_subscriptions", body: body, response: {body: fixture_file("webhooks/create"), status: 201})
22
+
23
+ assert client.webhooks.create(url: body[:url], events: body[:events], organization_uri: body[:organization], scope: body[:scope], user_uri: body[:user])
24
+ end
25
+
26
+ def test_retrieve
27
+ webhook_uuid = "AAAAAAAAAAAAAAAA"
28
+ response = {body: fixture_file("webhooks/retrieve"), status: 200}
29
+ stub(path: "webhook_subscriptions/#{webhook_uuid}", response: response)
30
+ webhook = client.webhooks.retrieve(webhook_uuid: webhook_uuid)
31
+
32
+ assert_equal Calendly::Webhook, webhook.class
33
+ assert_equal "user", webhook.scope
34
+ end
35
+
36
+ def test_delete
37
+ webhook_uuid = "AAAAAAAAAAAAAAAA"
38
+ response = {body: fixture_file("webhooks/delete")}
39
+ stub(method: :delete, path: "webhook_subscriptions/#{webhook_uuid}", response: response)
40
+ assert client.webhooks.delete(webhook_uuid: webhook_uuid)
41
+ end
42
+ end
@@ -0,0 +1,7 @@
1
+ require "test_helper"
2
+
3
+ class CalendlyTest < Minitest::Test
4
+ def test_that_it_has_a_version_number
5
+ refute_nil ::Calendly::VERSION
6
+ end
7
+ end
@@ -0,0 +1,58 @@
1
+ {
2
+ "collection": [
3
+ {
4
+ "cancel_url": "https://calendly.com/cancellations/AAAAAAAAAAAAAAAA",
5
+ "created_at": "2020-11-23T17:51:18.327602Z",
6
+ "email": "test@example.com",
7
+ "event": "https://api.calendly.com/scheduled_events/AAAAAAAAAAAAAAAA",
8
+ "name": "John Doe",
9
+ "new_invitee": null,
10
+ "old_invitee": null,
11
+ "questions_and_answers": [
12
+ {
13
+ "answer": "radio button answer",
14
+ "position": 0,
15
+ "question": "Question with Radio Buttons answer type"
16
+ },
17
+ {
18
+ "answer": "Multiple line\nAnswer",
19
+ "position": 1,
20
+ "question": "Question with Multiple Lines answer type"
21
+ },
22
+ {
23
+ "answer": "Answer 1\nAnswer 2\nAnswer 3",
24
+ "position": 2,
25
+ "question": "Question with Checkboxes answer type"
26
+ }
27
+ ],
28
+ "reschedule_url": "https://calendly.com/reschedulings/AAAAAAAAAAAAAAAA",
29
+ "rescheduled": false,
30
+ "status": "active",
31
+ "text_reminder_number": null,
32
+ "timezone": "America/New_York",
33
+ "tracking": {
34
+ "utm_campaign": null,
35
+ "utm_source": null,
36
+ "utm_medium": null,
37
+ "utm_content": null,
38
+ "utm_term": null,
39
+ "salesforce_uuid": null
40
+ },
41
+ "updated_at": "2020-11-23T17:51:18.341657Z",
42
+ "uri": "https://api.calendly.com/scheduled_events/AAAAAAAAAAAAAAAA/invitees/AAAAAAAAAAAAAAAA",
43
+ "canceled": false,
44
+ "payment": {
45
+ "external_id": "ch_AAAAAAAAAAAAAAAAAAAAAAAA",
46
+ "provider": "stripe",
47
+ "amount": 1234.56,
48
+ "currency": "USD",
49
+ "terms": "sample terms of payment (up to 1,024 characters)",
50
+ "successful": true
51
+ }
52
+ }
53
+ ],
54
+ "pagination": {
55
+ "count": 1,
56
+ "next_page": "https://calendly.com/scheduled_events/AAAAAAAAAAAAAAAA/invitees?count=1&page_token=sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi"
57
+ }
58
+ }