calendlyr 0.3.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +1 -1
  3. data/CHANGELOG.md +3 -27
  4. data/Gemfile +1 -5
  5. data/README.md +47 -20
  6. data/bin/console +3 -3
  7. data/{calendly.gemspec → calendlyr.gemspec} +3 -3
  8. data/lib/{calendly → calendlyr}/client.rb +9 -9
  9. data/lib/{calendly → calendlyr}/collection.rb +4 -1
  10. data/lib/{calendly → calendlyr}/error.rb +1 -1
  11. data/lib/{calendly → calendlyr}/object.rb +1 -1
  12. data/lib/{calendly → calendlyr}/objects/event_invitees.rb +1 -1
  13. data/lib/{calendly → calendlyr}/objects/event_types.rb +1 -1
  14. data/lib/{calendly → calendlyr}/objects/events.rb +1 -1
  15. data/lib/{calendly → calendlyr}/objects/invitations.rb +1 -1
  16. data/lib/{calendly → calendlyr}/objects/memberships.rb +1 -1
  17. data/lib/{calendly → calendlyr}/objects/organizations.rb +9 -1
  18. data/lib/{calendly → calendlyr}/objects/scheduling_links.rb +1 -1
  19. data/lib/{calendly → calendlyr}/objects/users.rb +1 -1
  20. data/lib/{calendly → calendlyr}/objects/webhooks.rb +1 -1
  21. data/lib/{calendly → calendlyr}/resource.rb +13 -25
  22. data/lib/{calendly → calendlyr}/resources/data_compliance.rb +1 -1
  23. data/lib/{calendly → calendlyr}/resources/event_invitees.rb +1 -1
  24. data/lib/{calendly → calendlyr}/resources/event_types.rb +1 -1
  25. data/lib/{calendly → calendlyr}/resources/events.rb +1 -1
  26. data/lib/{calendly → calendlyr}/resources/organizations.rb +2 -2
  27. data/lib/{calendly → calendlyr}/resources/scheduling_links.rb +1 -1
  28. data/lib/{calendly → calendlyr}/resources/users.rb +1 -1
  29. data/lib/{calendly → calendlyr}/resources/webhooks.rb +1 -1
  30. data/lib/calendlyr/version.rb +3 -0
  31. data/lib/calendlyr.rb +30 -0
  32. data/test/calendlyr/client_test.rb +11 -0
  33. data/test/calendlyr/object_test.rb +21 -0
  34. data/test/calendlyr/resource_test.rb +14 -0
  35. data/test/{calendly/resources/data_compliance.rb → calendlyr/resources/data_compliance_test.rb} +0 -0
  36. data/test/{calendly → calendlyr}/resources/event_invitees_test.rb +3 -3
  37. data/test/{calendly → calendlyr}/resources/event_types_test.rb +3 -3
  38. data/test/{calendly → calendlyr}/resources/events_test.rb +3 -3
  39. data/test/{calendly → calendlyr}/resources/organizations_test.rb +41 -26
  40. data/test/calendlyr/resources/scheduling_links_test.rb +15 -0
  41. data/test/{calendly → calendlyr}/resources/users_test.rb +24 -12
  42. data/test/{calendly → calendlyr}/resources/webhooks_test.rb +8 -5
  43. data/test/{calendly_test.rb → calendlyr_test.rb} +2 -2
  44. data/test/fixtures/organizations/invite.json +9 -7
  45. data/test/fixtures/organizations/list_invitations.json +1 -1
  46. data/test/fixtures/organizations/retrieve_invitation.json +1 -1
  47. data/test/fixtures/resources/400.json +10 -0
  48. data/test/fixtures/resources/401.json +10 -0
  49. data/test/fixtures/resources/403.json +10 -0
  50. data/test/fixtures/resources/404.json +10 -0
  51. data/test/fixtures/resources/409.json +4 -0
  52. data/test/fixtures/resources/500.json +10 -0
  53. data/test/fixtures/users/reload.json +14 -0
  54. data/test/test_helper.rb +9 -3
  55. metadata +67 -51
  56. data/lib/calendly/version.rb +0 -3
  57. data/lib/calendly.rb +0 -35
  58. data/test/calendly/client_test.rb +0 -8
  59. data/test/calendly/object_test.rb +0 -21
  60. data/test/calendly/resources/scheduling_links.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1154b32aa1af6668b71d74fb9af0e8bd695b53c21fc49d6ed45fbee180bd5a74
4
- data.tar.gz: bb85f5220261459ebf3fd4304fa207be57ac6b5a8226202d9ac2816064b3229e
3
+ metadata.gz: 8333c9dbe0f1d7e633eaff538790c0cd4f57ee3d9cf8c1b0f5e4638373578a60
4
+ data.tar.gz: 9eb3dfaab07649e6b15d1fca3286c6fab0592a74f689f6809c7b2506e13e6b2b
5
5
  SHA512:
6
- metadata.gz: a4f4ccb083646d19c45599294ba2684b302960cbff32d6eac1ab8c6f02f1ce76f570b96057638b11623e4d4dcde3baa8e11dbfb905ce2fb93d3c71ac0fa353c8
7
- data.tar.gz: 86566019597243e8e84a1a48f1540e8e8cbbc14b8641ba9a816c62ce8267e446ab7ddb596ddeb1a94464d2536059f0ee975a2d1c4b39b9eb6a269b17ded2182e
6
+ metadata.gz: 81f0d93eb9049accadaf68e8af5174800bfb6630570008a69d50e3f0ede02c60d9577a59e9a2aa161d92c68222957cefae618fee7471b5474d2569317b8e86ab
7
+ data.tar.gz: 6073bce53858d69dc7c40b814e54bd3d3dce0be7abf720873f55441b2b1e62eae360ecf30b4f201703c12cd337b94b8ff7a1e78370e1848bc1844e262c2f393a
@@ -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,31 +2,7 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [0.3.3]
6
- * Fix - Error when trying to send an invitation through the organization
7
- * More testing = More coverage
5
+ ## [0.5.0]
6
+ * First real usable release :tada:
8
7
 
9
- ## [0.3.2]
10
- * Minor fixes
11
-
12
- ## [0.3.0]
13
- * No runtime dependencies
14
- * Minor fixes
15
-
16
- ## [0.2.0]
17
- * Support for ruby 3.0
18
- * Minor fixes
19
-
20
- ## [0.1.1]
21
- * Changed required ruby version from `>= 2.3.0` to `>= 2.4.0`
22
- * Minitest
23
- * Minor fixes
24
-
25
- ## 0.1.0
26
- * Birthday!
27
-
28
- [0.3.3]: https://github.com/araluce/calendly.rb/compare/v0.3.2...v0.3.3
29
- [0.3.2]: https://github.com/araluce/calendly.rb/compare/v0.3.0...v0.3.2
30
- [0.3.0]: https://github.com/araluce/calendly.rb/compare/v0.2.0...v0.3.0
31
- [0.2.0]: https://github.com/araluce/calendly.rb/compare/v0.1.1...v0.2.0
32
- [0.1.1]: https://github.com/araluce/calendly.rb/compare/v0.1.0...v0.1.1
8
+ [0.5.0]: https://github.com/araluce/calendlyr/compare/v0.1.0...v0.5.0
data/Gemfile CHANGED
@@ -1,8 +1,4 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in calendly.gemspec
3
+ # Specify your gem's dependencies in calendlyr.gemspec
4
4
  gemspec
5
-
6
- gem "rake", "~> 12.0"
7
- gem "minitest", "~> 5.0"
8
- gem "standard"
data/README.md CHANGED
@@ -1,18 +1,28 @@
1
- [![](https://img.shields.io/github/license/araluce/calendly.rb)](https://github.com/araluce/calendly.rb/blob/master/LICENSE.txt)
2
- ![](https://github.com/araluce/calendly.rb/actions/workflows/ci.yml/badge.svg)
3
- [![codecov](https://codecov.io/gh/araluce/calendly.rb/branch/master/graph/badge.svg?token=YSUU4PHM6Y)](https://codecov.io/gh/araluce/calendly.rb)
4
- [![GitHub version](https://badge.fury.io/gh/araluce%2Fcalendly.rb.svg)](https://badge.fury.io/gh/araluce%2Fcalendly.rb)
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)](https://github.com/araluce/calendlyr/actions)
3
+ [![codecov](https://codecov.io/gh/araluce/calendlyr/branch/master/graph/badge.svg?token=YSUU4PHM6Y)](https://codecov.io/gh/araluce/calendlyr)
4
+ [![Gem Version](https://badge.fury.io/rb/calendlyr.svg)](https://badge.fury.io/rb/calendlyr)
5
5
 
6
- # Calendly API Rubygem
6
+ # Calendly API Rubygem LITE version
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
+ Just needed a Personal Access Token.
11
+
12
+ > If you need a Oauth authentication maybe you need [calendly-api-ruby-client](https://github.com/koshilife/calendly-api-ruby-client)
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
+
10
20
  ## Installation
11
21
 
12
22
  Add this line to your application's Gemfile:
13
23
 
14
24
  ```ruby
15
- gem 'calendlyr', github: "araluce/calendly.rb"
25
+ gem 'calendlyr'
16
26
  ```
17
27
 
18
28
  And then execute:
@@ -25,10 +35,10 @@ Or install it yourself as:
25
35
 
26
36
  ## Usage
27
37
 
28
- To access the API, you'll need to create a `Calendly::Client` and pass in your API key. You can generate your Personal Access Token at [https://calendly.com/integrations/api_webhooks](https://calendly.com/integrations/api_webhooks)
38
+ To access the API, you'll need to create a `Calendlyr::Client` and pass in your token. You can generate your Personal Access Token at [https://calendly.com/integrations/api_webhooks](https://calendly.com/integrations/api_webhooks)
29
39
 
30
40
  ```ruby
31
- client = Calendly::Client.new(api_key: ENV["CALENDLY_API_KEY"])
41
+ client = Calendlyr::Client.new(token: ENV["CALENDLY_TOKEN"])
32
42
  ```
33
43
 
34
44
  The client then gives you access to each of the resources.
@@ -37,7 +47,7 @@ The client then gives you access to each of the resources.
37
47
 
38
48
  The gem maps as closely as we can to the Calendly API so you can easily convert API examples to gem code.
39
49
 
40
- Responses are created as objects like `Calendly::Event`. Having types like `Calendly::User` is handy for understanding what type of object you're working with. They're built using OpenStruct so you can easily access data in a Ruby-ish way.
50
+ Responses are created as objects like `Calendlyr::Event`. Having types like `Calendlyr::User` is handy for understanding what type of object you're working with. They're built using OpenStruct so you can easily access data in a Ruby-ish way.
41
51
 
42
52
  ##### Pagination
43
53
 
@@ -45,20 +55,20 @@ Responses are created as objects like `Calendly::Event`. Having types like `Cale
45
55
 
46
56
  ```ruby
47
57
  results = client.me.events(count: 5)
48
- #=> Calendly::Collection
58
+ #=> Calendlyr::Collection
49
59
 
50
60
  results.count
51
61
  #=> 5
52
62
 
53
63
  results.data
54
- #=> [#<Calendly::Event>, #<Calendly::Event>]
64
+ #=> [#<Calendlyr::Event>, #<Calendlyr::Event>]
55
65
 
56
66
  results.next_page_token
57
67
  #=> "KfKBetd7bS0wsFINjYky9mp8ZJXv76aL"
58
68
 
59
69
  # Retrieve the next page
60
70
  client.me.events(count: 5, next_page_token: results.next_page_token)
61
- #=> Calendly::Collection
71
+ #=> Calendlyr::Collection
62
72
  ```
63
73
 
64
74
  ### Users
@@ -68,18 +78,29 @@ client.users.me
68
78
  client.retrieve(user_uuid: "uuid")
69
79
 
70
80
  client.organization
71
- #=> #<Calendly::Organization>
81
+ #=> #<Calendlyr::Organization>
72
82
 
73
83
  client.me.event_types
74
- #=> Calendly::Collection @data=[#<Calendly::EventType>, #<Calendly::EventType>]
84
+ #=> Calendlyr::Collection @data=[#<Calendlyr::EventType>, #<Calendlyr::EventType>]
75
85
 
76
86
  client.me.events
77
- #=> Calendly::Collection @data=[#<Calendly::Event>, #<Calendly::Event>]
87
+ #=> Calendlyr::Collection @data=[#<Calendlyr::Event>, #<Calendlyr::Event>]
78
88
 
79
89
  client.me.memberships
80
- #=> Calendly::Collection @data=[#<Calendly::MemberShip>, #<Calendly::MemberShip>]
90
+ #=> Calendlyr::Collection @data=[#<Calendlyr::MemberShip>, #<Calendlyr::MemberShip>]
81
91
  ```
82
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
+
83
104
  ### Event Types
84
105
  ````ruby
85
106
  client.event_types.list user_uri: "user_uri", organization_uri: "organization_uri"
@@ -114,7 +135,7 @@ client.organization.list_invitations
114
135
  # Get invitation
115
136
  client.organizations.retrieve_invitation(organization_uuid: "organization_uuid", invitation_uuid: "invitation_uuid")
116
137
  client.organization.invitation(invitation_uuid: "invitation_uuid")
117
- #Revoke invitation
138
+ # Revoke invitation
118
139
  client.organizations.revoke_invitation(organization_uuid: "organization_uuid", invitation_uuid: "organization_uuid")
119
140
  client.organization.revoke_invitation(invitation_uuid: "organization_uuid")
120
141
  invitation = client.organization.invitation(invitation_uuid: "invitation_uuid")
@@ -129,12 +150,16 @@ client.organizations.retrieve_membership(membership_uuid: "membership_uuid")
129
150
  client.organizations.remove_user(membership_uuid: "membership_uuid")
130
151
 
131
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")
132
157
  ````
133
158
 
134
159
  ### Webhooks
135
160
  ```ruby
136
161
  client.webhooks.list(organization_uri: "organization_uri", scope: "scope")
137
- 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")
138
163
  client.webhooks.retrieve(webhook_uuid: "webhook_uuid")
139
164
  client.webhooks.delete(webhook_uuid: "webhook_uuid")
140
165
  ```
@@ -146,14 +171,16 @@ client.data_compliance.delete_invitee_data
146
171
 
147
172
  ## Contributing
148
173
 
149
- 1. Fork it ( https://github.com/araluce/calendly.rb/fork )
174
+ 1. Fork it ( https://github.com/araluce/calendlyr/fork )
150
175
  2. Create your feature branch (`git checkout -b my-new-feature`)
151
176
  3. Commit your changes (`git commit -am 'Add some feature'`)
152
177
  4. Push to the branch (`git push origin my-new-feature`)
153
178
  5. Create a new Pull Request
154
179
 
155
- When adding resources, add to the list of resources in lib/calendly.rb. Additionally, write a spec and add it to the list in the README.
180
+ When adding resources, add to the list of resources in lib/calendlyr. Additionally, write a spec and add it to the list in the README.
156
181
 
157
182
  ## Thanks
158
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
+
159
186
  Thanks [@excid3](https://github.com/excid3) and his [Vultr.rb](https://github.com/excid3/vultr.rb) rubygem project.
data/bin/console CHANGED
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "calendly"
4
+ require "calendlyr"
5
5
 
6
- client = Calendly::Client.new(api_key: ENV["CALENDLY_API_KEY"])
6
+ client = Calendlyr::Client.new(token: ENV["CALENDLY_TOKEN"])
7
7
 
8
8
  puts
9
- puts "We've created a 'client' variable as a Calendly::Client using ENV['CALENDLY_API_KEY'] as the API key."
9
+ puts "We've created a 'client' variable as a Calendlyr::Client using ENV['CALENDLY_TOKEN'] as the Personal Access Token."
10
10
  puts
11
11
 
12
12
  require "irb"
@@ -1,14 +1,14 @@
1
- require "./lib/calendly/version"
1
+ require "./lib/calendlyr/version"
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "calendlyr"
5
- spec.version = Calendly::VERSION
5
+ spec.version = Calendlyr::VERSION
6
6
  spec.authors = ["araluce"]
7
7
  spec.email = ["araluce11@gmail.com"]
8
8
 
9
9
  spec.summary = "Ruby bindings for Calendly API."
10
10
  spec.description = "Ruby bindings for Calendly API. Calendly APIs can be found here: https://calendly.stoplight.io/docs/api-docs/"
11
- spec.homepage = "https://github.com/araluce/calendly.rb"
11
+ spec.homepage = "https://github.com/araluce/calendlyr"
12
12
  spec.license = "MIT"
13
13
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
14
14
  spec.metadata["homepage_uri"] = spec.homepage
@@ -1,16 +1,16 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class Client
3
3
  BASE_URL = "https://api.calendly.com"
4
4
 
5
- attr_reader :api_key
5
+ attr_reader :token
6
6
 
7
- def initialize(api_key:)
8
- @api_key = api_key
9
- raise Error, "Add an api_key to use Calendly. Calendly::Client.new(api_key: 'your_api_key')" unless api_key
7
+ def initialize(token:)
8
+ @token = token
10
9
  end
11
10
 
12
- def me
13
- users.me
11
+ def me(force_reload: false)
12
+ @me = nil if force_reload
13
+ @me ||= users.me
14
14
  end
15
15
 
16
16
  def organization
@@ -49,9 +49,9 @@ module Calendly
49
49
  DataComplianceResource.new(self)
50
50
  end
51
51
 
52
- # Avoid returning #<Calendly::Client @api_key="api_key" ...>
52
+ # Avoid returning #<Calendlyr::Client @token="token" ...>
53
53
  def inspect
54
- "#<Calendly::Client>"
54
+ "#<Calendlyr::Client>"
55
55
  end
56
56
  end
57
57
  end
@@ -1,4 +1,7 @@
1
- module Calendly
1
+ require "uri"
2
+ require "cgi"
3
+
4
+ module Calendlyr
2
5
  class Collection
3
6
  attr_reader :data, :count, :next_page, :next_page_token, :client
4
7
 
@@ -1,4 +1,4 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class Error < StandardError
3
3
  end
4
4
  end
@@ -1,6 +1,6 @@
1
1
  require "ostruct"
2
2
 
3
- module Calendly
3
+ module Calendlyr
4
4
  class Object < OpenStruct
5
5
  def initialize(attributes)
6
6
  super to_ostruct(attributes.merge(uuid: extract_uuid(attributes)))
@@ -1,4 +1,4 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class EventInvitee < Object
3
3
  end
4
4
  end
@@ -1,4 +1,4 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class EventType < Object
3
3
  end
4
4
  end
@@ -1,4 +1,4 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class Event < Object
3
3
  end
4
4
  end
@@ -1,4 +1,4 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class Invitation < Object
3
3
  def associated_organization
4
4
  @associated_organization ||= Organization.new({"uri" => organization}.merge(client: client))
@@ -1,4 +1,4 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class Membership < Object
3
3
  def associated_user
4
4
  client.users.retrieve user_uuid: get_slug(user.uri)
@@ -1,4 +1,4 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class Organization < Object
3
3
  def invite_user(email:)
4
4
  client.organizations.invite organization_uuid: uuid, email: email
@@ -8,6 +8,14 @@ module Calendly
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,4 +1,4 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class SchedulingLink < Object
3
3
  end
4
4
  end
@@ -1,4 +1,4 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class User < Object
3
3
  def organization
4
4
  @organization ||= Organization.new({"uri" => current_organization}.merge(client: client))
@@ -1,4 +1,4 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class Webhook < Object
3
3
  def associated_user
4
4
  client.users.retrieve(user_uuid: get_slug(user))
@@ -1,7 +1,14 @@
1
- module Calendly
1
+ require "net/http"
2
+ require "json"
3
+ require "openssl"
4
+ require "uri"
5
+
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 Calendly
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
@@ -42,29 +41,18 @@ module Calendly
42
41
 
43
42
  request = req_type.new(uri)
44
43
  request["Content-Type"] = "application/json"
45
- request["Authorization"] = "Bearer #{client.api_key}"
44
+ request["Authorization"] = "Bearer #{client.token}"
46
45
  request.body = body.to_json if body.any?
47
46
 
48
47
  http.request(request)
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
@@ -1,4 +1,4 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class DataComplianceResource < Resource
3
3
  def delete_invitee_data(emails:)
4
4
  post_request("data_compliance/deletion/invitees", body: {emails: emails})
@@ -1,4 +1,4 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class EventInviteeResource < Resource
3
3
  def list(event_uuid:, **params)
4
4
  response = get_request("scheduled_events/#{event_uuid}/invitees", params: params.compact)
@@ -1,4 +1,4 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class EventTypeResource < Resource
3
3
  def list(user_uri:, organization_uri:, **params)
4
4
  response = get_request("event_types", params: {user: user_uri, organization: organization_uri}.merge(params))
@@ -1,4 +1,4 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class EventResource < Resource
3
3
  def list(user_uri:, organization_uri:, **params)
4
4
  response = get_request("scheduled_events", params: {user: user_uri, organization: organization_uri}.merge(params).compact)
@@ -1,7 +1,7 @@
1
- module Calendly
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,4 +1,4 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class SchedulingLinkResource < Resource
3
3
  def create(owner_uri:, max_event_count:, owner_type: "EventType")
4
4
  body = {owner: owner_uri, max_event_count: max_event_count, owner_type: owner_type}
@@ -1,4 +1,4 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class UserResource < Resource
3
3
  def me
4
4
  retrieve(user_uuid: "me")
@@ -1,4 +1,4 @@
1
- module Calendly
1
+ module Calendlyr
2
2
  class WebhookResource < Resource
3
3
  def list(organization_uri:, scope:, **params)
4
4
  response = get_request("webhook_subscriptions", params: {organization: organization_uri, scope: scope}.merge(params).compact)
@@ -0,0 +1,3 @@
1
+ module Calendlyr
2
+ VERSION = "0.5.0"
3
+ end
data/lib/calendlyr.rb ADDED
@@ -0,0 +1,30 @@
1
+ require "calendlyr/version"
2
+
3
+ module Calendlyr
4
+ autoload :Client, "calendlyr/client"
5
+ autoload :Collection, "calendlyr/collection"
6
+ autoload :Error, "calendlyr/error"
7
+ autoload :Resource, "calendlyr/resource"
8
+ autoload :Object, "calendlyr/object"
9
+
10
+ # High-level categories of Calendly API calls
11
+ autoload :UserResource, "calendlyr/resources/users"
12
+ autoload :EventTypeResource, "calendlyr/resources/event_types"
13
+ autoload :OrganizationResource, "calendlyr/resources/organizations"
14
+ autoload :EventResource, "calendlyr/resources/events"
15
+ autoload :EventInviteeResource, "calendlyr/resources/event_invitees"
16
+ autoload :SchedulingLinkResource, "calendlyr/resources/scheduling_links"
17
+ autoload :WebhookResource, "calendlyr/resources/webhooks"
18
+ autoload :DataComplianceResource, "calendlyr/resources/data_compliance"
19
+
20
+ # Classes used to return a nicer object wrapping the response data
21
+ autoload :User, "calendlyr/objects/users"
22
+ autoload :EventType, "calendlyr/objects/event_types"
23
+ autoload :Event, "calendlyr/objects/events"
24
+ autoload :Organization, "calendlyr/objects/organizations"
25
+ autoload :Invitation, "calendlyr/objects/invitations"
26
+ autoload :EventInvitee, "calendlyr/objects/event_invitees"
27
+ autoload :SchedulingLink, "calendlyr/objects/scheduling_links"
28
+ autoload :Membership, "calendlyr/objects/memberships"
29
+ autoload :Webhook, "calendlyr/objects/webhooks"
30
+ end
@@ -0,0 +1,11 @@
1
+ require "test_helper"
2
+
3
+ class ClientTest < Minitest::Test
4
+ def test_token
5
+ assert_equal "fake", client.token
6
+ end
7
+
8
+ def test_inspect
9
+ assert_equal "#<Calendlyr::Client>", client.inspect
10
+ end
11
+ 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", Calendlyr::Object.new(foo: "bar").foo
6
+ end
7
+
8
+ def test_nested_hash
9
+ assert_equal "foobar", Calendlyr::Object.new(foo: {bar: {baz: "foobar"}}, client: nil).foo.bar.baz
10
+ end
11
+
12
+ def test_nested_number
13
+ assert_equal 1, Calendlyr::Object.new(foo: {bar: 1}, client: nil).foo.bar
14
+ end
15
+
16
+ def test_array
17
+ object = Calendlyr::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,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
@@ -9,8 +9,8 @@ class EventInviteesResourceTest < Minitest::Test
9
9
  stub(path: "scheduled_events/#{event_uuid}/invitees", response: response)
10
10
  event_invitees = client.event_invitees.list(event_uuid: event_uuid)
11
11
 
12
- assert_equal Calendly::Collection, event_invitees.class
13
- assert_equal Calendly::EventInvitee, event_invitees.data.first.class
12
+ assert_equal Calendlyr::Collection, event_invitees.class
13
+ assert_equal Calendlyr::EventInvitee, event_invitees.data.first.class
14
14
  assert_equal 1, event_invitees.count
15
15
  assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", event_invitees.next_page_token
16
16
  end
@@ -22,7 +22,7 @@ class EventInviteesResourceTest < Minitest::Test
22
22
  stub(path: "scheduled_events/#{event_uuid}/invitees/#{invitee_uuid}", response: response)
23
23
  event_invitee = client.event_invitees.retrieve(event_uuid: event_uuid, invitee_uuid: invitee_uuid)
24
24
 
25
- assert_equal Calendly::EventInvitee, event_invitee.class
25
+ assert_equal Calendlyr::EventInvitee, event_invitee.class
26
26
  assert_equal "https://api.calendly.com/api/v2/scheduled_events/ABCDABCDABCDABCD/invitees/ABCDABCDABCDABCD", event_invitee.uri
27
27
  assert_equal "John Doe", event_invitee.name
28
28
  end