Class: Nylas::SchedulerCollection

Inherits:
Collection show all
Defined in:
lib/nylas/scheduler_collection.rb

Overview

Additional methods for some of Scheduler’s other functionality

Instance Attribute Summary

Attributes inherited from Collection

#api, #constraints, #model

Instance Method Summary collapse

Methods inherited from Collection

#count, #create, #each, #execute, #expanded, #find, #find_each, #find_model, #find_raw, #ids, #initialize, #limit, #more_pages?, #new, #next_page, #offset, #raw, #resources_path, #search, #to_be_executed, #where

Constructor Details

This class inherits a constructor from Nylas::Collection

Instance Method Details

#book_time_slot(slug, timeslot) ⇒ SchedulerBookingConfirmation

Book a time slot

Parameters:

Returns:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/nylas/scheduler_collection.rb', line 51

def book_time_slot(slug, timeslot)
  payload = timeslot.to_h
  # The booking endpoint requires additional_values and additional_emails
  # to exist regardless if they are empty or not
  payload[:additional_values] = {} unless payload[:additional_values]
  payload[:additional_emails] = [] unless payload[:additional_emails]
  booking_response = api.execute(
    method: :post,
    path: "/schedule/#{slug}/timeslots",
    payload: JSON.dump(payload)
  )

  SchedulerBookingConfirmation.new(**booking_response.merge(api: api))
end

#cancel_booking(slug, edit_hash, reason) ⇒ Hash

Cancel a booking

Parameters:

  • slug (String)

    The Scheduler page slug

  • edit_hash (String)

    The token used for editing the booked time slot

  • reason (String)

    The reason for cancelling the booking

Returns:

  • (Hash)

    Returns a hash of a boolean representing success of cancellation



71
72
73
74
75
76
77
# File 'lib/nylas/scheduler_collection.rb', line 71

def cancel_booking(slug, edit_hash, reason)
  api.execute(
    method: :post,
    path: "/schedule/#{slug}/#{edit_hash}/cancel",
    payload: JSON.dump(reason: reason)
  )
end

#confirm_booking(slug, edit_hash) ⇒ SchedulerBookingConfirmation

Confirm a booking

Parameters:

  • slug (String)

    The Scheduler page slug

  • edit_hash (String)

    The token used for editing the booked time slot

Returns:



83
84
85
86
87
88
89
90
91
# File 'lib/nylas/scheduler_collection.rb', line 83

def confirm_booking(slug, edit_hash)
  booking_response = api.execute(
    method: :post,
    path: "/schedule/#{slug}/#{edit_hash}/confirm",
    payload: {}
  )

  SchedulerBookingConfirmation.new(**booking_response.merge(api: api))
end

#get_available_time_slots(slug) ⇒ Array<SchedulerTimeSlot>

Retrieve available time slots

Parameters:

  • slug (String)

    The Scheduler page slug

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/nylas/scheduler_collection.rb', line 34

def get_available_time_slots(slug)
  response = api.execute(
    method: :get,
    path: "/schedule/#{slug}/timeslots"
  )

  timeslots = []
  response.each do |available_slot|
    timeslots.push(SchedulerTimeSlot.new(**available_slot.merge(api: api)))
  end
  timeslots
end

#get_google_availabilityHash

Retrieve Google availability

Returns:

  • (Hash)

    Returns the availability



9
10
11
# File 'lib/nylas/scheduler_collection.rb', line 9

def get_google_availability
  execute_provider_availability("google")
end

#get_office_365_availabilityHash

Retrieve Office 365 availability

Returns:

  • (Hash)

    Returns the availability



15
16
17
# File 'lib/nylas/scheduler_collection.rb', line 15

def get_office_365_availability
  execute_provider_availability("o365")
end

#get_page_slug(slug) ⇒ Scheduler

Retrieve public config for a scheduling page

Parameters:

  • slug (String)

    The Scheduler page slug

Returns:

  • (Scheduler)

    Returns the Scheduler object representing the page configuration



22
23
24
25
26
27
28
29
# File 'lib/nylas/scheduler_collection.rb', line 22

def get_page_slug(slug)
  page_response = api.execute(
    method: :get,
    path: "/schedule/#{slug}/info"
  )

  Scheduler.new(**page_response.merge(api: api))
end