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.
-
#cancel_event(uuid, options: nil) ⇒ Calendly::InviteeCancellation
Cancels specified event.
-
#create_invitation(uuid, email) ⇒ Calendly::OrganizationInvitation
Invite a person to an Organization.
-
#create_invitee_no_show(invitee_uri) ⇒ Calendly::InviteeNoShow
Create Invitee No Show Marks an Invitee as a No Show.
-
#create_schedule_link(uri, max_event_count: 1, owner_type: 'EventType') ⇒ Hash
Create a scheduling link.
-
#create_webhook(url, events, org_uri, user_uri: nil, signing_key: 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_invitee_data(emails) ⇒ true
Delete Invitee Data To submit a request to remove invitee data from all previously booked events in your organization.
-
#delete_invitee_no_show(uuid) ⇒ true
Delete Invitee No Show Undoes marking an Invitee as a No Show.
-
#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, options: nil) ⇒ Array<Array<Calendly::Invitee>, Hash>
Get List of Event Invitees.
-
#event_type(uuid) ⇒ Calendly::EventType
Returns a single Event Type by its UUID.
-
#event_types(org_uri, options: nil) ⇒ Array<Array<Calendly::EventType>, Hash>
Returns all Event Types associated with a specified organization.
-
#event_types_by_user(user_uri, options: nil) ⇒ 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, options: nil) ⇒ <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.
-
#invitee_no_show(uuid) ⇒ Calendly::InviteeNoShow
Get Invitee No Show Returns information about a specified Invitee No Show.
-
#membership(uuid) ⇒ Calendly::OrganizationMembership
Returns information about a user’s organization membership.
-
#memberships(org_uri, options: nil) ⇒ Array<Array<Calendly::OrganizationMembership>, Hash>
Get List of memberships belonging to specific an organization.
-
#memberships_by_user(user_uri, options: nil) ⇒ Array<Array<Calendly::OrganizationMembership>, Hash>
Get List of memberships belonging to specific a user.
-
#refresh! ⇒ Object
Refresh access token.
-
#routing_form(uuid) ⇒ Calendly::RoutingForm
Get a specified Routing Form.
-
#routing_form_submission(uuid) ⇒ Calendly::RoutingFormSubmission
Get a specified Routing Form Submission.
-
#routing_form_submissions(form_uri, options: nil) ⇒ Array<Array<Calendly::RoutingFormSubmission>, Hash>
Get a list of Routing Form Submissions for a specified Routing Form.
-
#routing_forms(org_uri, options: nil) ⇒ Array<Array<Calendly::RoutingForm>, Hash>
Get a list of Routing Forms for a specified Organization.
-
#scheduled_event(uuid) ⇒ Calendly::Event
Returns a single Event by its URI.
-
#scheduled_events(org_uri, options: nil) ⇒ Array<Array<Calendly::Event>, Hash>
Get List of scheduled events belonging to a specific organization.
-
#scheduled_events_by_user(user_uri, options: nil) ⇒ Array<Array<Calendly::Event>, Hash>
Get List of scheduled events belonging to a specific user.
-
#user(uuid = 'me') ⇒ Calendly::User
Get basic information about a user.
-
#user_scope_webhooks(org_uri, user_uri, options: nil) ⇒ 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, options: nil) ⇒ 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.
15 16 17 18 19 20 21 |
# File 'lib/calendly/client.rb', line 15 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.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/calendly/client.rb', line 28 def access_token return @access_token if defined?(@access_token) && @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 |
#cancel_event(uuid, options: nil) ⇒ Calendly::InviteeCancellation
Cancels specified event.
217 218 219 220 221 222 223 224 225 |
# File 'lib/calendly/client.rb', line 217 def cancel_event(uuid, options: nil) check_not_empty uuid, 'uuid' opts_keys = %i[reason] params = , opts_keys body = request :post, "scheduled_events/#{uuid}/cancellation", body: params InviteeCancellation.new body[:resource], self end |
#create_invitation(uuid, email) ⇒ Calendly::OrganizationInvitation
Invite a person to an Organization.
511 512 513 514 515 516 517 518 519 520 |
# File 'lib/calendly/client.rb', line 511 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_invitee_no_show(invitee_uri) ⇒ Calendly::InviteeNoShow
Create Invitee No Show Marks an Invitee as a No Show.
329 330 331 332 333 334 335 336 337 |
# File 'lib/calendly/client.rb', line 329 def create_invitee_no_show(invitee_uri) check_not_empty invitee_uri, 'invitee_uri' body = request( :post, 'invitee_no_shows', body: {invitee: invitee_uri} ) InviteeNoShow.new body[:resource], self end |
#create_schedule_link(uri, max_event_count: 1, owner_type: 'EventType') ⇒ Hash
Create a scheduling link.
e.g.
booking_url: "https://calendly.com/s/FOO-BAR-SLUG",
owner: "https://api.calendly.com/event_types/GBGBDCAADAEDCRZ2",
owner_type: "EventType"
754 755 756 757 758 759 760 761 762 763 764 765 |
# File 'lib/calendly/client.rb', line 754 def create_schedule_link(uri, max_event_count: 1, owner_type: 'EventType') check_not_empty uri, 'uri' check_not_empty max_event_count, 'max_event_count' check_not_empty owner_type, 'owner_type' params = { max_event_count: max_event_count, owner: uri, owner_type: owner_type } body = request :post, 'scheduling_links', body: params body[:resource] end |
#create_webhook(url, events, org_uri, user_uri: nil, signing_key: nil) ⇒ Calendly::WebhookSubscription
Create a webhook subscription for an organization or user.
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 |
# File 'lib/calendly/client.rb', line 622 def create_webhook(url, events, org_uri, user_uri: nil, signing_key: nil) # rubocop:disable Metrics/ParameterLists 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} params[:signing_key] = signing_key if signing_key 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.
62 63 64 65 66 |
# File 'lib/calendly/client.rb', line 62 def current_user return @cached_current_user if defined?(@cached_current_user) && @cached_current_user @cached_current_user = user end |
#current_user! ⇒ Object Also known as: me!
71 72 73 74 |
# File 'lib/calendly/client.rb', line 71 def current_user! @cached_current_user = nil current_user end |
#delete_invitation(org_uuid, inv_uuid) ⇒ true
Revoke Organization Invitation.
532 533 534 535 536 537 |
# File 'lib/calendly/client.rb', line 532 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_invitee_data(emails) ⇒ true
Delete Invitee Data To submit a request to remove invitee data from all previously booked events in your organization.
363 364 365 366 367 368 369 370 371 |
# File 'lib/calendly/client.rb', line 363 def delete_invitee_data(emails) check_not_empty emails, 'emails' request( :post, 'data_compliance/deletion/invitees', body: {emails: emails} ) true end |
#delete_invitee_no_show(uuid) ⇒ true
Delete Invitee No Show Undoes marking an Invitee as a No Show.
348 349 350 351 352 |
# File 'lib/calendly/client.rb', line 348 def delete_invitee_no_show(uuid) check_not_empty uuid, 'uuid' request :delete, "invitee_no_shows/#{uuid}" true end |
#delete_membership(uuid) ⇒ true
Remove a User from an Organization.
449 450 451 452 453 |
# File 'lib/calendly/client.rb', line 449 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.
648 649 650 651 652 |
# File 'lib/calendly/client.rb', line 648 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.
270 271 272 273 274 275 |
# File 'lib/calendly/client.rb', line 270 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, options: nil) ⇒ Array<Array<Calendly::Invitee>, Hash>
Get List of Event Invitees.
293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/calendly/client.rb', line 293 def event_invitees(uuid, options: nil) check_not_empty uuid, 'uuid' opts_keys = %i[count email page_token sort status] params = , 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_type(uuid) ⇒ Calendly::EventType
Returns a single Event Type by its UUID.
100 101 102 103 104 |
# File 'lib/calendly/client.rb', line 100 def event_type(uuid) check_not_empty uuid, 'uuid' body = request :get, "event_types/#{uuid}" EventType.new body[:resource], self end |
#event_types(org_uri, options: nil) ⇒ Array<Array<Calendly::EventType>, Hash>
Returns all Event Types associated with a specified organization.
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/calendly/client.rb', line 121 def event_types(org_uri, options: nil) check_not_empty org_uri, 'org_uri' opts_keys = %i[active count page_token sort] params = {organization: org_uri} params = , 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 |
#event_types_by_user(user_uri, options: nil) ⇒ Array<Array<Calendly::EventType>, Hash>
Returns all Event Types associated with a specified user.
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/calendly/client.rb', line 149 def event_types_by_user(user_uri, options: nil) check_not_empty user_uri, 'user_uri' opts_keys = %i[active count page_token sort] params = {user: user_uri} params = , 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.
465 466 467 468 469 470 471 |
# File 'lib/calendly/client.rb', line 465 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, options: nil) ⇒ <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.
489 490 491 492 493 494 495 496 497 498 499 |
# File 'lib/calendly/client.rb', line 489 def invitations(uuid, options: nil) check_not_empty uuid, 'uuid' opts_keys = %i[count email page_token sort status] params = , 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 |
#invitee_no_show(uuid) ⇒ Calendly::InviteeNoShow
Get Invitee No Show Returns information about a specified Invitee No Show.
314 315 316 317 318 |
# File 'lib/calendly/client.rb', line 314 def invitee_no_show(uuid) check_not_empty uuid, 'uuid' body = request :get, "invitee_no_shows/#{uuid}" InviteeNoShow.new body[:resource], self end |
#membership(uuid) ⇒ Calendly::OrganizationMembership
Returns information about a user’s organization membership
381 382 383 384 385 |
# File 'lib/calendly/client.rb', line 381 def membership(uuid) check_not_empty uuid, 'uuid' body = request :get, "organization_memberships/#{uuid}" OrganizationMembership.new body[:resource], self end |
#memberships(org_uri, options: nil) ⇒ Array<Array<Calendly::OrganizationMembership>, Hash>
Get List of memberships belonging to specific an organization.
401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/calendly/client.rb', line 401 def memberships(org_uri, options: nil) check_not_empty org_uri, 'org_uri' opts_keys = %i[count email page_token] params = {organization: org_uri} params = , 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, options: nil) ⇒ Array<Array<Calendly::OrganizationMembership>, Hash>
Get List of memberships belonging to specific a user.
428 429 430 431 432 433 434 435 436 437 438 439 |
# File 'lib/calendly/client.rb', line 428 def memberships_by_user(user_uri, options: nil) check_not_empty user_uri, 'user_uri' opts_keys = %i[count email page_token] params = {user: user_uri} params = , 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.
47 48 49 50 51 52 53 54 |
# File 'lib/calendly/client.rb', line 47 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 |
#routing_form(uuid) ⇒ Calendly::RoutingForm
Get a specified Routing Form.
662 663 664 665 666 |
# File 'lib/calendly/client.rb', line 662 def routing_form(uuid) check_not_empty uuid, 'uuid' body = request :get, "routing_forms/#{uuid}" RoutingForm.new body[:resource], self end |
#routing_form_submission(uuid) ⇒ Calendly::RoutingFormSubmission
Get a specified Routing Form Submission.
703 704 705 706 707 |
# File 'lib/calendly/client.rb', line 703 def routing_form_submission(uuid) check_not_empty uuid, 'uuid' body = request :get, "routing_form_submissions/#{uuid}" RoutingFormSubmission.new body[:resource], self end |
#routing_form_submissions(form_uri, options: nil) ⇒ Array<Array<Calendly::RoutingFormSubmission>, Hash>
Get a list of Routing Form Submissions for a specified Routing Form.
723 724 725 726 727 728 729 730 731 732 733 734 |
# File 'lib/calendly/client.rb', line 723 def routing_form_submissions(form_uri, options: nil) check_not_empty form_uri, 'form_uri' opts_keys = %i[count page_token sort] params = {form: form_uri} params = , opts_keys, params body = request :get, 'routing_form_submissions', params: params items = body[:collection] || [] submissions = items.map { |item| RoutingFormSubmission.new item, self } [submissions, next_page_params(body)] end |
#routing_forms(org_uri, options: nil) ⇒ Array<Array<Calendly::RoutingForm>, Hash>
Get a list of Routing Forms for a specified Organization.
682 683 684 685 686 687 688 689 690 691 692 693 |
# File 'lib/calendly/client.rb', line 682 def routing_forms(org_uri, options: nil) check_not_empty org_uri, 'org_uri' opts_keys = %i[count page_token sort] params = {organization: org_uri} params = , opts_keys, params body = request :get, 'routing_forms', params: params items = body[:collection] || [] forms = items.map { |item| RoutingForm.new item, self } [forms, next_page_params(body)] end |
#scheduled_event(uuid) ⇒ Calendly::Event
Returns a single Event by its URI.
170 171 172 173 174 |
# File 'lib/calendly/client.rb', line 170 def scheduled_event(uuid) check_not_empty uuid, 'uuid' body = request :get, "scheduled_events/#{uuid}" Event.new body[:resource], self end |
#scheduled_events(org_uri, options: nil) ⇒ Array<Array<Calendly::Event>, Hash>
Get List of scheduled events belonging to a specific organization.
194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/calendly/client.rb', line 194 def scheduled_events(org_uri, options: nil) check_not_empty org_uri, 'org_uri' opts_keys = %i[count invitee_email max_start_time min_start_time page_token sort status] params = {organization: org_uri} params = , 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 |
#scheduled_events_by_user(user_uri, options: nil) ⇒ Array<Array<Calendly::Event>, Hash>
Get List of scheduled events belonging to a specific user.
246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/calendly/client.rb', line 246 def scheduled_events_by_user(user_uri, options: nil) check_not_empty user_uri, 'user_uri' opts_keys = %i[organization count invitee_email max_start_time min_start_time page_token sort status] params = {user: user_uri} params = , 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
86 87 88 89 90 |
# File 'lib/calendly/client.rb', line 86 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, options: nil) ⇒ Array<Array<Calendly::WebhookSubscription>, Hash>
Get List of user scope Webhooks.
595 596 597 598 599 600 601 602 603 604 605 606 |
# File 'lib/calendly/client.rb', line 595 def user_scope_webhooks(org_uri, user_uri, options: nil) 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_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.
547 548 549 550 551 |
# File 'lib/calendly/client.rb', line 547 def webhook(uuid) check_not_empty uuid, 'uuid' body = request :get, "webhook_subscriptions/#{uuid}" WebhookSubscription.new body[:resource], self end |
#webhooks(org_uri, options: nil) ⇒ Array<Array<Calendly::WebhookSubscription>, Hash>
Get List of organization scope Webhooks.
567 568 569 570 571 572 573 574 575 576 577 |
# File 'lib/calendly/client.rb', line 567 def webhooks(org_uri, options: nil) check_not_empty org_uri, 'org_uri' opts_keys = %i[count page_token sort] params = {organization: org_uri, scope: 'organization'} params = , 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 |