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.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +34 -0
- data/.gitignore +25 -0
- data/CHANGELOG.md +32 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +159 -0
- data/Rakefile +10 -0
- data/bin/console +13 -0
- data/bin/setup +8 -0
- data/bin/test +6 -0
- data/calendly.gemspec +27 -0
- data/lib/calendly/client.rb +57 -0
- data/lib/calendly/collection.rb +31 -0
- data/lib/calendly/error.rb +4 -0
- data/lib/calendly/object.rb +27 -0
- data/lib/calendly/objects/event_invitees.rb +4 -0
- data/lib/calendly/objects/event_types.rb +4 -0
- data/lib/calendly/objects/events.rb +4 -0
- data/lib/calendly/objects/invitations.rb +11 -0
- data/lib/calendly/objects/memberships.rb +7 -0
- data/lib/calendly/objects/organizations.rb +27 -0
- data/lib/calendly/objects/scheduling_links.rb +4 -0
- data/lib/calendly/objects/users.rb +19 -0
- data/lib/calendly/objects/webhooks.rb +11 -0
- data/lib/calendly/resource.rb +73 -0
- data/lib/calendly/resources/data_compliance.rb +7 -0
- data/lib/calendly/resources/event_invitees.rb +12 -0
- data/lib/calendly/resources/event_types.rb +12 -0
- data/lib/calendly/resources/events.rb +12 -0
- data/lib/calendly/resources/organizations.rb +33 -0
- data/lib/calendly/resources/scheduling_links.rb +8 -0
- data/lib/calendly/resources/users.rb +11 -0
- data/lib/calendly/resources/webhooks.rb +21 -0
- data/lib/calendly/version.rb +3 -0
- data/lib/calendly.rb +35 -0
- data/test/calendly/client_test.rb +8 -0
- data/test/calendly/object_test.rb +21 -0
- data/test/calendly/resources/data_compliance.rb +13 -0
- data/test/calendly/resources/event_invitees_test.rb +29 -0
- data/test/calendly/resources/event_types_test.rb +31 -0
- data/test/calendly/resources/events_test.rb +29 -0
- data/test/calendly/resources/organizations_test.rb +140 -0
- data/test/calendly/resources/scheduling_links.rb +12 -0
- data/test/calendly/resources/users_test.rb +79 -0
- data/test/calendly/resources/webhooks_test.rb +42 -0
- data/test/calendly_test.rb +7 -0
- data/test/fixtures/data_compliance/delete_invitee_data.json +1 -0
- data/test/fixtures/event_invitees/list.json +58 -0
- data/test/fixtures/event_invitees/retrieve.json +38 -0
- data/test/fixtures/event_types/list.json +88 -0
- data/test/fixtures/event_types/retrieve.json +82 -0
- data/test/fixtures/events/list.json +39 -0
- data/test/fixtures/events/retrieve.json +33 -0
- data/test/fixtures/organizations/invite.json +9 -0
- data/test/fixtures/organizations/list_invitations.json +18 -0
- data/test/fixtures/organizations/list_memberships.json +26 -0
- data/test/fixtures/organizations/remove_user.json +1 -0
- data/test/fixtures/organizations/retrieve_invitation.json +12 -0
- data/test/fixtures/organizations/retrieve_membership.json +20 -0
- data/test/fixtures/organizations/revoke_invitation.json +1 -0
- data/test/fixtures/scheduling_links/create.json +7 -0
- data/test/fixtures/users/retrieve.json +14 -0
- data/test/fixtures/webhooks/create.json +17 -0
- data/test/fixtures/webhooks/delete.json +1 -0
- data/test/fixtures/webhooks/list.json +23 -0
- data/test/fixtures/webhooks/retrieve.json +17 -0
- data/test/test_helper.rb +27 -0
- metadata +230 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 1154b32aa1af6668b71d74fb9af0e8bd695b53c21fc49d6ed45fbee180bd5a74
|
|
4
|
+
data.tar.gz: bb85f5220261459ebf3fd4304fa207be57ac6b5a8226202d9ac2816064b3229e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a4f4ccb083646d19c45599294ba2684b302960cbff32d6eac1ab8c6f02f1ce76f570b96057638b11623e4d4dcde3baa8e11dbfb905ce2fb93d3c71ac0fa353c8
|
|
7
|
+
data.tar.gz: 86566019597243e8e84a1a48f1540e8e8cbbc14b8641ba9a816c62ce8267e446ab7ddb596ddeb1a94464d2536059f0ee975a2d1c4b39b9eb6a269b17ded2182e
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches:
|
|
6
|
+
- "*"
|
|
7
|
+
push:
|
|
8
|
+
branches:
|
|
9
|
+
- master
|
|
10
|
+
jobs:
|
|
11
|
+
tests:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
strategy:
|
|
14
|
+
matrix:
|
|
15
|
+
ruby: ["2.4", "2.5", "2.6", "2.7", "3.0"]
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@master
|
|
19
|
+
|
|
20
|
+
- name: Set up Ruby
|
|
21
|
+
uses: ruby/setup-ruby@v1
|
|
22
|
+
with:
|
|
23
|
+
ruby-version: ${{ matrix.ruby }}
|
|
24
|
+
bundler: default
|
|
25
|
+
bundler-cache: true
|
|
26
|
+
|
|
27
|
+
- name: StandardRb check
|
|
28
|
+
run: bundle exec standardrb
|
|
29
|
+
|
|
30
|
+
- name: Run tests
|
|
31
|
+
run: |
|
|
32
|
+
bundle exec rake test
|
|
33
|
+
env:
|
|
34
|
+
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
|
data/.gitignore
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
.bundle
|
|
4
|
+
.config
|
|
5
|
+
.yardoc
|
|
6
|
+
Gemfile.lock
|
|
7
|
+
InstalledFiles
|
|
8
|
+
_yardoc
|
|
9
|
+
coverage
|
|
10
|
+
doc/
|
|
11
|
+
lib/bundler/man
|
|
12
|
+
pkg
|
|
13
|
+
rdoc
|
|
14
|
+
spec/reports
|
|
15
|
+
test/tmp
|
|
16
|
+
test/version_tmp
|
|
17
|
+
tmp
|
|
18
|
+
*.bundle
|
|
19
|
+
*.so
|
|
20
|
+
*.o
|
|
21
|
+
*.a
|
|
22
|
+
mkmf.log
|
|
23
|
+
vendor
|
|
24
|
+
.idea/
|
|
25
|
+
bin/my_console
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.3.3]
|
|
6
|
+
* Fix - Error when trying to send an invitation through the organization
|
|
7
|
+
* More testing = More coverage
|
|
8
|
+
|
|
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
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 araluce
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
[](https://github.com/araluce/calendly.rb/blob/master/LICENSE.txt)
|
|
2
|
+

|
|
3
|
+
[](https://codecov.io/gh/araluce/calendly.rb)
|
|
4
|
+
[](https://badge.fury.io/gh/araluce%2Fcalendly.rb)
|
|
5
|
+
|
|
6
|
+
# Calendly API Rubygem
|
|
7
|
+
|
|
8
|
+
Easy and complete rubygem for [Calendly](https://calendly.com/). Currently supports [API v2](https://calendly.stoplight.io/docs/api-docs).
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Add this line to your application's Gemfile:
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
gem 'calendlyr', github: "araluce/calendly.rb"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
And then execute:
|
|
19
|
+
|
|
20
|
+
$ bundle
|
|
21
|
+
|
|
22
|
+
Or install it yourself as:
|
|
23
|
+
|
|
24
|
+
$ gem install calendlyr
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
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)
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
client = Calendly::Client.new(api_key: ENV["CALENDLY_API_KEY"])
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The client then gives you access to each of the resources.
|
|
35
|
+
|
|
36
|
+
## Resources
|
|
37
|
+
|
|
38
|
+
The gem maps as closely as we can to the Calendly API so you can easily convert API examples to gem code.
|
|
39
|
+
|
|
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.
|
|
41
|
+
|
|
42
|
+
##### Pagination
|
|
43
|
+
|
|
44
|
+
`collection` endpoints return pages of results. The result object will have a `data` key to access the results, as well as pagination like `next_page` for retrieving the next pages. You may also specify the
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
results = client.me.events(count: 5)
|
|
48
|
+
#=> Calendly::Collection
|
|
49
|
+
|
|
50
|
+
results.count
|
|
51
|
+
#=> 5
|
|
52
|
+
|
|
53
|
+
results.data
|
|
54
|
+
#=> [#<Calendly::Event>, #<Calendly::Event>]
|
|
55
|
+
|
|
56
|
+
results.next_page_token
|
|
57
|
+
#=> "KfKBetd7bS0wsFINjYky9mp8ZJXv76aL"
|
|
58
|
+
|
|
59
|
+
# Retrieve the next page
|
|
60
|
+
client.me.events(count: 5, next_page_token: results.next_page_token)
|
|
61
|
+
#=> Calendly::Collection
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Users
|
|
65
|
+
```ruby
|
|
66
|
+
client.me
|
|
67
|
+
client.users.me
|
|
68
|
+
client.retrieve(user_uuid: "uuid")
|
|
69
|
+
|
|
70
|
+
client.organization
|
|
71
|
+
#=> #<Calendly::Organization>
|
|
72
|
+
|
|
73
|
+
client.me.event_types
|
|
74
|
+
#=> Calendly::Collection @data=[#<Calendly::EventType>, #<Calendly::EventType>]
|
|
75
|
+
|
|
76
|
+
client.me.events
|
|
77
|
+
#=> Calendly::Collection @data=[#<Calendly::Event>, #<Calendly::Event>]
|
|
78
|
+
|
|
79
|
+
client.me.memberships
|
|
80
|
+
#=> Calendly::Collection @data=[#<Calendly::MemberShip>, #<Calendly::MemberShip>]
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Event Types
|
|
84
|
+
````ruby
|
|
85
|
+
client.event_types.list user_uri: "user_uri", organization_uri: "organization_uri"
|
|
86
|
+
client.event_types.retrieve event_type_uuid: "id"
|
|
87
|
+
````
|
|
88
|
+
|
|
89
|
+
### Events
|
|
90
|
+
````ruby
|
|
91
|
+
client.events.list user_uri: "user_uri", organization_uri: "organization_uri"
|
|
92
|
+
client.events.retrieve event_uuid: "event_uuid"
|
|
93
|
+
````
|
|
94
|
+
|
|
95
|
+
### Event Invitees
|
|
96
|
+
````ruby
|
|
97
|
+
client.event_invitees.list event_uuid: "event_uuid"
|
|
98
|
+
client.event_invitees.retrieve event_uuid: "event_uuid", invitee_uuid: "invitee_uuid"
|
|
99
|
+
````
|
|
100
|
+
|
|
101
|
+
### Scheduling Links
|
|
102
|
+
````ruby
|
|
103
|
+
client.scheduling_links.create owner_uri: "owner_uri", max_event_count: 1, owner_type: "EventType"
|
|
104
|
+
````
|
|
105
|
+
|
|
106
|
+
### Organizations
|
|
107
|
+
````ruby
|
|
108
|
+
# Create invitation
|
|
109
|
+
client.organizations.invite(organization_uuid: "organization_uuid", email: "test@test.com")
|
|
110
|
+
client.organization.invite(email: "test@test.com")
|
|
111
|
+
# List invitations
|
|
112
|
+
client.organizations.list_invitations(organization_uuid: "organization_uuid")
|
|
113
|
+
client.organization.list_invitations
|
|
114
|
+
# Get invitation
|
|
115
|
+
client.organizations.retrieve_invitation(organization_uuid: "organization_uuid", invitation_uuid: "invitation_uuid")
|
|
116
|
+
client.organization.invitation(invitation_uuid: "invitation_uuid")
|
|
117
|
+
#Revoke invitation
|
|
118
|
+
client.organizations.revoke_invitation(organization_uuid: "organization_uuid", invitation_uuid: "organization_uuid")
|
|
119
|
+
client.organization.revoke_invitation(invitation_uuid: "organization_uuid")
|
|
120
|
+
invitation = client.organization.invitation(invitation_uuid: "invitation_uuid")
|
|
121
|
+
invitation.revoke
|
|
122
|
+
|
|
123
|
+
# List memberships
|
|
124
|
+
client.organizations.list_memberships
|
|
125
|
+
client.organization.memberships
|
|
126
|
+
# Get membership
|
|
127
|
+
client.organizations.retrieve_membership(membership_uuid: "membership_uuid")
|
|
128
|
+
# Remove membership
|
|
129
|
+
client.organizations.remove_user(membership_uuid: "membership_uuid")
|
|
130
|
+
|
|
131
|
+
client.organization.events
|
|
132
|
+
````
|
|
133
|
+
|
|
134
|
+
### Webhooks
|
|
135
|
+
```ruby
|
|
136
|
+
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")
|
|
138
|
+
client.webhooks.retrieve(webhook_uuid: "webhook_uuid")
|
|
139
|
+
client.webhooks.delete(webhook_uuid: "webhook_uuid")
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Data Compliance
|
|
143
|
+
```ruby
|
|
144
|
+
client.data_compliance.delete_invitee_data
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Contributing
|
|
148
|
+
|
|
149
|
+
1. Fork it ( https://github.com/araluce/calendly.rb/fork )
|
|
150
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
151
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
152
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
153
|
+
5. Create a new Pull Request
|
|
154
|
+
|
|
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.
|
|
156
|
+
|
|
157
|
+
## Thanks
|
|
158
|
+
|
|
159
|
+
Thanks [@excid3](https://github.com/excid3) and his [Vultr.rb](https://github.com/excid3/vultr.rb) rubygem project.
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "calendly"
|
|
5
|
+
|
|
6
|
+
client = Calendly::Client.new(api_key: ENV["CALENDLY_API_KEY"])
|
|
7
|
+
|
|
8
|
+
puts
|
|
9
|
+
puts "We've created a 'client' variable as a Calendly::Client using ENV['CALENDLY_API_KEY'] as the API key."
|
|
10
|
+
puts
|
|
11
|
+
|
|
12
|
+
require "irb"
|
|
13
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/bin/test
ADDED
data/calendly.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require "./lib/calendly/version"
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = "calendlyr"
|
|
5
|
+
spec.version = Calendly::VERSION
|
|
6
|
+
spec.authors = ["araluce"]
|
|
7
|
+
spec.email = ["araluce11@gmail.com"]
|
|
8
|
+
|
|
9
|
+
spec.summary = "Ruby bindings for Calendly API."
|
|
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"
|
|
12
|
+
spec.license = "MIT"
|
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
|
22
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
|
23
|
+
spec.add_development_dependency "standard"
|
|
24
|
+
spec.add_development_dependency "webmock", "~> 3.14.0"
|
|
25
|
+
spec.add_development_dependency "codecov"
|
|
26
|
+
spec.add_development_dependency "simplecov"
|
|
27
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
module Calendly
|
|
2
|
+
class Client
|
|
3
|
+
BASE_URL = "https://api.calendly.com"
|
|
4
|
+
|
|
5
|
+
attr_reader :api_key
|
|
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
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def me
|
|
13
|
+
users.me
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def organization
|
|
17
|
+
me.organization
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def users
|
|
21
|
+
UserResource.new(self)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def organizations
|
|
25
|
+
OrganizationResource.new(self)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def event_types
|
|
29
|
+
EventTypeResource.new(self)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def events
|
|
33
|
+
EventResource.new(self)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def event_invitees
|
|
37
|
+
EventInviteeResource.new(self)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def scheduling_links
|
|
41
|
+
SchedulingLinkResource.new(self)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def webhooks
|
|
45
|
+
WebhookResource.new(self)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def data_compliance
|
|
49
|
+
DataComplianceResource.new(self)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Avoid returning #<Calendly::Client @api_key="api_key" ...>
|
|
53
|
+
def inspect
|
|
54
|
+
"#<Calendly::Client>"
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Calendly
|
|
2
|
+
class Collection
|
|
3
|
+
attr_reader :data, :count, :next_page, :next_page_token, :client
|
|
4
|
+
|
|
5
|
+
def self.from_response(response, key:, type:, client:)
|
|
6
|
+
new(
|
|
7
|
+
data: response[key].map { |attrs| type.new(attrs.merge(client: client)) },
|
|
8
|
+
count: response.dig("pagination", "count"),
|
|
9
|
+
next_page: response.dig("pagination", "next_page"),
|
|
10
|
+
client: client
|
|
11
|
+
)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def initialize(data:, count:, next_page:, client:)
|
|
15
|
+
@data = data
|
|
16
|
+
@count = count
|
|
17
|
+
@next_page = next_page
|
|
18
|
+
@next_page_token = get_params(next_page)["page_token"]&.first
|
|
19
|
+
@client = client
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def get_params(url)
|
|
25
|
+
return {} unless url
|
|
26
|
+
|
|
27
|
+
uri = URI.parse(url)
|
|
28
|
+
CGI.parse(uri.query)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require "ostruct"
|
|
2
|
+
|
|
3
|
+
module Calendly
|
|
4
|
+
class Object < OpenStruct
|
|
5
|
+
def initialize(attributes)
|
|
6
|
+
super to_ostruct(attributes.merge(uuid: extract_uuid(attributes)))
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def to_ostruct(obj)
|
|
10
|
+
if obj.is_a?(Hash)
|
|
11
|
+
OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h)
|
|
12
|
+
elsif obj.is_a?(Array)
|
|
13
|
+
obj.map { |o| to_ostruct(o) }
|
|
14
|
+
else # Assumed to be a primitive value
|
|
15
|
+
obj
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def extract_uuid(attrs)
|
|
20
|
+
attrs["uri"] ? get_slug(attrs["uri"]) : nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def get_slug(path)
|
|
24
|
+
path.split("/").last
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Calendly
|
|
2
|
+
class Invitation < Object
|
|
3
|
+
def associated_organization
|
|
4
|
+
@associated_organization ||= Organization.new({"uri" => organization}.merge(client: client))
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def revoke
|
|
8
|
+
associated_organization.revoke_invitation invitation_uuid: uuid
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Calendly
|
|
2
|
+
class Organization < Object
|
|
3
|
+
def invite_user(email:)
|
|
4
|
+
client.organizations.invite organization_uuid: uuid, email: email
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def list_invitations(**params)
|
|
8
|
+
client.organizations.list_invitations organization_uuid: uuid, **params
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def revoke_invitation(invitation_uuid:)
|
|
12
|
+
client.organizations.revoke_invitation(organization_uuid: uuid, invitation_uuid: invitation_uuid)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def invitation(invitation_uuid:)
|
|
16
|
+
client.organizations.retrieve_invitation(organization_uuid: uuid, invitation_uuid: invitation_uuid)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def events(user_uri: nil, **params)
|
|
20
|
+
client.events.list user_uri: user_uri, organization_uri: uri, **params
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def memberships(user_uri: nil, **params)
|
|
24
|
+
client.organizations.list_memberships user_uri: user_uri, organization_uri: uri, **params
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Calendly
|
|
2
|
+
class User < Object
|
|
3
|
+
def organization
|
|
4
|
+
@organization ||= Organization.new({"uri" => current_organization}.merge(client: client))
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def event_types(**params)
|
|
8
|
+
client.event_types.list user_uri: uri, organization_uri: current_organization, **params
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def events(**params)
|
|
12
|
+
client.events.list user_uri: uri, organization_uri: current_organization, **params
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def memberships(organization_uri: nil, **params)
|
|
16
|
+
client.organizations.list_memberships user_uri: uri, organization_uri: organization_uri, **params
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Calendly
|
|
2
|
+
class Webhook < Object
|
|
3
|
+
def associated_user
|
|
4
|
+
client.users.retrieve(user_uuid: get_slug(user))
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def associated_organization
|
|
8
|
+
@associated_organization ||= Organization.new({"uri" => organization}.merge(client: client))
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module Calendly
|
|
2
|
+
class Resource
|
|
3
|
+
attr_reader :client
|
|
4
|
+
|
|
5
|
+
def initialize(client)
|
|
6
|
+
@client = client
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def get_request(url, params: {})
|
|
12
|
+
handle_response request(url, Net::HTTP::Get, params: params)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def post_request(url, body:)
|
|
16
|
+
handle_response request(url, Net::HTTP::Post, body: body)
|
|
17
|
+
end
|
|
18
|
+
|
|
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
|
+
def delete_request(url, params: {})
|
|
28
|
+
handle_response request(url, Net::HTTP::Delete, params: params)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def request(url, req_type, body: {}, params: {}, base_url: Client::BASE_URL)
|
|
32
|
+
uri = URI("#{base_url}/#{url}")
|
|
33
|
+
|
|
34
|
+
if params.any?
|
|
35
|
+
params = URI.decode_www_form(uri.query || "") + params.to_a
|
|
36
|
+
uri.query = URI.encode_www_form params
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
40
|
+
http.use_ssl = true
|
|
41
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
42
|
+
|
|
43
|
+
request = req_type.new(uri)
|
|
44
|
+
request["Content-Type"] = "application/json"
|
|
45
|
+
request["Authorization"] = "Bearer #{client.api_key}"
|
|
46
|
+
request.body = body.to_json if body.any?
|
|
47
|
+
|
|
48
|
+
http.request(request)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def handle_response(response)
|
|
52
|
+
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"]}"
|
|
68
|
+
else
|
|
69
|
+
body
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|