Class: Calendly::Client
- Inherits:
-
Object
- Object
- Calendly::Client
- Includes:
- Loggable
- Defined in:
- lib/calendly/client.rb
Overview
Calendly apis client.
Constant Summary collapse
- API_HOST =
'https://api.calendly.com'
- AUTH_API_HOST =
'https://auth.calendly.com'
Instance Method Summary collapse
-
#access_token ⇒ OAuth2::AccessToken
Get access token object.
-
#create_invitation(uuid, email) ⇒ Calendly::OrganizationInvitation
Invite a person to an Organization.
-
#create_webhook(url, events, org_uri, user_uri = nil) ⇒ Calendly::WebhookSubscription
Create a webhook subscription for an organization or user.
-
#current_user ⇒ Calendly::User
(also: #me)
Get basic information about current user.
- #current_user! ⇒ Object (also: #me!)
-
#delete_invitation(org_uuid, inv_uuid) ⇒ true
Revoke Organization Invitation.
-
#delete_membership(uuid) ⇒ true
Remove a User from an Organization.
-
#delete_webhook(uuid) ⇒ true
Delete a webhook subscription for an organization or user with a specified UUID.
-
#event_invitee(ev_uuid, inv_uuid) ⇒ Calendly::Invitee
Get Invitee of an Event Returns a single Invitee by their URI.
-
#event_invitees(uuid, opts = {}) ⇒ Array<Array<Calendly::Invitee>, Hash>
Get List of Event Invitees.
-
#event_types(user_uri, opts = {}) ⇒ Array<Array<Calendly::EventType>, Hash>
Returns all Event Types associated with a specified User.
-
#initialize(token = nil) ⇒ Client
constructor
A new instance of Client.
-
#invitation(org_uuid, inv_uuid) ⇒ Calendly::OrganizationInvitation
Returns an Organization Invitation.
-
#invitations(uuid, opts = {}) ⇒ <Array<Array<Calendly::OrganizationInvitation>, Hash>] - [Array<Calendly::OrganizationInvitation>] organizations - [Hash] next_params the parameters to get next data. if thre is no next it returns nil.
Get Organization Invitations.
-
#membership(uuid) ⇒ Calendly::OrganizationMembership
Returns information about a user’s organization membership.
-
#memberships(org_uri, opts = {}) ⇒ Array<Array<Calendly::OrganizationMembership>, Hash>
Get List memberships of all users belonging to an organization.
-
#memberships_by_user(user_uri, opts = {}) ⇒ Array<Array<Calendly::OrganizationMembership>, Hash>
Get List memberships of all users belonging to an organization by user.
-
#refresh! ⇒ Object
Refresh access token.
-
#scheduled_event(uuid) ⇒ Calendly::Event
Returns a single Event by its URI.
-
#scheduled_events(user_uri, opts = {}) ⇒ Array<Array<Calendly::Event>, Hash>
Get List of User Events.
-
#user(uuid = 'me') ⇒ Calendly::User
Get basic information about a user.
-
#user_scope_webhooks(org_uri, user_uri, opts = {}) ⇒ Array<Array<Calendly::WebhookSubscription>, Hash>
Get List of user scope Webhooks.
-
#webhook(uuid) ⇒ Calendly::WebhookSubscription
Get a webhook subscription for an organization or user with a specified UUID.
-
#webhooks(org_uri, opts = {}) ⇒ Array<Array<Calendly::WebhookSubscription>, Hash>
Get List of organization scope Webhooks.
Methods included from Loggable
#debug_log, #error_log, #info_log, #warn_log
Constructor Details
#initialize(token = nil) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 20 |
# File 'lib/calendly/client.rb', line 14 def initialize(token = nil) @config = Calendly.configuration @token = token || Calendly.configuration.token check_not_empty @token, 'token' check_token end |
Instance Method Details
#access_token ⇒ OAuth2::AccessToken
Get access token object.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/calendly/client.rb', line 27 def access_token return @access_token if defined? @access_token client = OAuth2::Client.new(@config.client_id, @config.client_secret, ) @access_token = OAuth2::AccessToken.new( client, @token, refresh_token: @config.refresh_token, expires_at: @config.token_expires_at ) end |
#create_invitation(uuid, email) ⇒ Calendly::OrganizationInvitation
Invite a person to an Organization.
347 348 349 350 351 352 353 354 355 356 |
# File 'lib/calendly/client.rb', line 347 def create_invitation(uuid, email) check_not_empty uuid, 'uuid' check_not_empty email, 'email' body = request( :post, "organizations/#{uuid}/invitations", body: {email: email} ) OrganizationInvitation.new body[:resource], self end |
#create_webhook(url, events, org_uri, user_uri = nil) ⇒ Calendly::WebhookSubscription
Create a webhook subscription for an organization or user.
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
# File 'lib/calendly/client.rb', line 457 def create_webhook(url, events, org_uri, user_uri = nil) check_not_empty url, 'url' check_not_empty events, 'events' check_not_empty org_uri, 'org_uri' params = {url: url, events: events, organization: org_uri} if user_uri params[:scope] = 'user' params[:user] = user_uri else params[:scope] = 'organization' end body = request(:post, 'webhook_subscriptions', body: params) WebhookSubscription.new body[:resource], self end |
#current_user ⇒ Calendly::User Also known as: me
Get basic information about current user.
61 62 63 64 65 |
# File 'lib/calendly/client.rb', line 61 def current_user return @cached_current_user if @cached_current_user @cached_current_user = user end |
#current_user! ⇒ Object Also known as: me!
70 71 72 73 |
# File 'lib/calendly/client.rb', line 70 def current_user! @cached_current_user = nil current_user end |
#delete_invitation(org_uuid, inv_uuid) ⇒ true
Revoke Organization Invitation.
368 369 370 371 372 373 |
# File 'lib/calendly/client.rb', line 368 def delete_invitation(org_uuid, inv_uuid) check_not_empty org_uuid, 'org_uuid' check_not_empty inv_uuid, 'inv_uuid' request :delete, "organizations/#{org_uuid}/invitations/#{inv_uuid}" true end |
#delete_membership(uuid) ⇒ true
Remove a User from an Organization.
285 286 287 288 289 |
# File 'lib/calendly/client.rb', line 285 def delete_membership(uuid) check_not_empty uuid, 'uuid' request :delete, "organization_memberships/#{uuid}" true end |
#delete_webhook(uuid) ⇒ true
Delete a webhook subscription for an organization or user with a specified UUID.
481 482 483 484 485 |
# File 'lib/calendly/client.rb', line 481 def delete_webhook(uuid) check_not_empty uuid, 'uuid' request :delete, "webhook_subscriptions/#{uuid}" true end |
#event_invitee(ev_uuid, inv_uuid) ⇒ Calendly::Invitee
Get Invitee of an Event Returns a single Invitee by their URI.
174 175 176 177 178 179 |
# File 'lib/calendly/client.rb', line 174 def event_invitee(ev_uuid, inv_uuid) check_not_empty ev_uuid, 'ev_uuid' check_not_empty inv_uuid, 'inv_uuid' body = request :get, "scheduled_events/#{ev_uuid}/invitees/#{inv_uuid}" Invitee.new body[:resource], self end |
#event_invitees(uuid, opts = {}) ⇒ Array<Array<Calendly::Invitee>, Hash>
Get List of Event Invitees.
197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/calendly/client.rb', line 197 def event_invitees(uuid, opts = {}) check_not_empty uuid, 'uuid' opts_keys = %i[count email page_token sort status] params = opts, opts_keys body = request :get, "scheduled_events/#{uuid}/invitees", params: params items = body[:collection] || [] evs = items.map { |item| Invitee.new item, self } [evs, next_page_params(body)] end |
#event_types(user_uri, opts = {}) ⇒ Array<Array<Calendly::EventType>, Hash>
Returns all Event Types associated with a specified User.
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/calendly/client.rb', line 105 def event_types(user_uri, opts = {}) check_not_empty user_uri, 'user_uri' opts_keys = %i[count page_token sort] params = {user: user_uri} params = opts, opts_keys, params body = request :get, 'event_types', params: params items = body[:collection] || [] ev_types = items.map { |item| EventType.new item, self } [ev_types, next_page_params(body)] end |
#invitation(org_uuid, inv_uuid) ⇒ Calendly::OrganizationInvitation
Returns an Organization Invitation.
301 302 303 304 305 306 307 |
# File 'lib/calendly/client.rb', line 301 def invitation(org_uuid, inv_uuid) check_not_empty org_uuid, 'org_uuid' check_not_empty inv_uuid, 'inv_uuid' body = request :get, "organizations/#{org_uuid}/invitations/#{inv_uuid}" OrganizationInvitation.new body[:resource], self end |
#invitations(uuid, opts = {}) ⇒ <Array<Array<Calendly::OrganizationInvitation>, Hash>] - [Array<Calendly::OrganizationInvitation>] organizations - [Hash] next_params the parameters to get next data. if thre is no next it returns nil.
Get Organization Invitations.
325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/calendly/client.rb', line 325 def invitations(uuid, opts = {}) check_not_empty uuid, 'uuid' opts_keys = %i[count email page_token sort status] params = opts, opts_keys body = request :get, "organizations/#{uuid}/invitations", params: params items = body[:collection] || [] evs = items.map { |item| OrganizationInvitation.new item, self } [evs, next_page_params(body)] end |
#membership(uuid) ⇒ Calendly::OrganizationMembership
Returns information about a user’s organization membership
217 218 219 220 221 |
# File 'lib/calendly/client.rb', line 217 def membership(uuid) check_not_empty uuid, 'uuid' body = request :get, "organization_memberships/#{uuid}" OrganizationMembership.new body[:resource], self end |
#memberships(org_uri, opts = {}) ⇒ Array<Array<Calendly::OrganizationMembership>, Hash>
Get List memberships of all users belonging to an organization.
237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/calendly/client.rb', line 237 def memberships(org_uri, opts = {}) check_not_empty org_uri, 'org_uri' opts_keys = %i[count email page_token] params = {organization: org_uri} params = opts, opts_keys, params body = request :get, 'organization_memberships', params: params items = body[:collection] || [] memberships = items.map { |item| OrganizationMembership.new item, self } [memberships, next_page_params(body)] end |
#memberships_by_user(user_uri, opts = {}) ⇒ Array<Array<Calendly::OrganizationMembership>, Hash>
Get List memberships of all users belonging to an organization by user.
264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/calendly/client.rb', line 264 def memberships_by_user(user_uri, opts = {}) check_not_empty user_uri, 'user_uri' opts_keys = %i[count email page_token] params = {user: user_uri} params = opts, opts_keys, params body = request :get, 'organization_memberships', params: params items = body[:collection] || [] memberships = items.map { |item| OrganizationMembership.new item, self } [memberships, next_page_params(body)] end |
#refresh! ⇒ Object
Refresh access token.
46 47 48 49 50 51 52 53 |
# File 'lib/calendly/client.rb', line 46 def refresh! check_not_empty @config.client_id, 'client_id' check_not_empty @config.client_secret, 'client_secret' @access_token = access_token.refresh! rescue OAuth2::Error => e res = e.response.response raise ApiError.new res, e end |
#scheduled_event(uuid) ⇒ Calendly::Event
Returns a single Event by its URI.
126 127 128 129 130 |
# File 'lib/calendly/client.rb', line 126 def scheduled_event(uuid) check_not_empty uuid, 'uuid' body = request :get, "scheduled_events/#{uuid}" Event.new body[:resource], self end |
#scheduled_events(user_uri, opts = {}) ⇒ Array<Array<Calendly::Event>, Hash>
Get List of User Events.
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/calendly/client.rb', line 150 def scheduled_events(user_uri, opts = {}) check_not_empty user_uri, 'user_uri' opts_keys = %i[count invitee_email max_start_time min_start_time page_token sort status] params = {user: user_uri} params = opts, opts_keys, params body = request :get, 'scheduled_events', params: params items = body[:collection] || [] evs = items.map { |item| Event.new item, self } [evs, next_page_params(body)] end |
#user(uuid = 'me') ⇒ Calendly::User
Get basic information about a user
85 86 87 88 89 |
# File 'lib/calendly/client.rb', line 85 def user(uuid = 'me') check_not_empty uuid, 'uuid' body = request :get, "users/#{uuid}" User.new body[:resource], self end |
#user_scope_webhooks(org_uri, user_uri, opts = {}) ⇒ Array<Array<Calendly::WebhookSubscription>, Hash>
Get List of user scope Webhooks.
431 432 433 434 435 436 437 438 439 440 441 442 |
# File 'lib/calendly/client.rb', line 431 def user_scope_webhooks(org_uri, user_uri, opts = {}) check_not_empty org_uri, 'org_uri' check_not_empty user_uri, 'user_uri' opts_keys = %i[count page_token sort] params = {organization: org_uri, user: user_uri, scope: 'user'} params = opts, opts_keys, params body = request :get, 'webhook_subscriptions', params: params items = body[:collection] || [] evs = items.map { |item| WebhookSubscription.new item, self } [evs, next_page_params(body)] end |
#webhook(uuid) ⇒ Calendly::WebhookSubscription
Get a webhook subscription for an organization or user with a specified UUID.
383 384 385 386 387 |
# File 'lib/calendly/client.rb', line 383 def webhook(uuid) check_not_empty uuid, 'uuid' body = request :get, "webhook_subscriptions/#{uuid}" WebhookSubscription.new body[:resource], self end |
#webhooks(org_uri, opts = {}) ⇒ Array<Array<Calendly::WebhookSubscription>, Hash>
Get List of organization scope Webhooks.
403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/calendly/client.rb', line 403 def webhooks(org_uri, opts = {}) check_not_empty org_uri, 'org_uri' opts_keys = %i[count page_token sort] params = {organization: org_uri, scope: 'organization'} params = opts, opts_keys, params body = request :get, 'webhook_subscriptions', params: params items = body[:collection] || [] evs = items.map { |item| WebhookSubscription.new item, self } [evs, next_page_params(body)] end |