Class: Booker::Client
- Inherits:
-
Object
- Object
- Booker::Client
- Defined in:
- lib/booker.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#expires_in ⇒ Object
readonly
Returns the value of attribute expires_in.
-
#server_time_offset ⇒ Object
readonly
Returns the value of attribute server_time_offset.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#all(method, result_name, options = {}) ⇒ Object
Useful to pull all of paged results and return them as if you did one request for them all.
- #create_appointment(options = {}) ⇒ Object
- #find_locations(options = {}) ⇒ Object
- #find_locations_partial(options = {}) ⇒ Object
- #find_treatments(options = {}) ⇒ Object
- #get_credit_card_types(location_id) ⇒ Object
- #get_location(location_id) ⇒ Object
- #get_location_online_booking_settings(location_id) ⇒ Object
- #get_server_information ⇒ Object
- #get_treatment(treatment_id) ⇒ Object
- #get_treatment_categories(location_id) ⇒ Object
- #get_treatment_sub_categories(location_id, category_id) ⇒ Object
-
#initialize(key, secret, options = {}) ⇒ Client
constructor
A new instance of Client.
- #run_multi_service_availability(options = {}) ⇒ Object
- #run_multi_spa_availability(options = {}) ⇒ Object
- #run_service_availability(options = {}) ⇒ Object
Constructor Details
permalink #initialize(key, secret, options = {}) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 |
# File 'lib/booker.rb', line 13 def initialize(key, secret, = {}) @production = .fetch(:production) { false } @key = key @secret = secret set_access_token! set_server_time_offset! end |
Instance Attribute Details
permalink #access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
11 12 13 |
# File 'lib/booker.rb', line 11 def access_token @access_token end |
permalink #expires_in ⇒ Object (readonly)
Returns the value of attribute expires_in.
11 12 13 |
# File 'lib/booker.rb', line 11 def expires_in @expires_in end |
permalink #server_time_offset ⇒ Object (readonly)
Returns the value of attribute server_time_offset.
11 12 13 |
# File 'lib/booker.rb', line 11 def server_time_offset @server_time_offset end |
permalink #url ⇒ Object (readonly)
Returns the value of attribute url.
11 12 13 |
# File 'lib/booker.rb', line 11 def url @url end |
Instance Method Details
permalink #all(method, result_name, options = {}) ⇒ Object
Useful to pull all of paged results and return them as if you did one request for them all
ex: client.all(:find_locations, ‘Results’)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/booker.rb', line 25 def all method, result_name, = {} page_number = 1 results = [] # this allows page size to be overidden but NOT page_number as I want to # control that to know when we have all results = {"PageSize" => 500}.merge begin .merge!({ "PageNumber" => page_number, }) last_result = self.send(method, ) results << last_result[result_name] results.flatten! if last_result['TotalResultsCount'] total_results = last_result['TotalResultsCount'] else total_results = 0 end page_number+=1 end while results.length < total_results-1 last_result.merge({ result_name => results }) end |
permalink #create_appointment(options = {}) ⇒ Object
[View source]
196 197 198 199 200 201 202 203 |
# File 'lib/booker.rb', line 196 def create_appointment = {} url = build_url "/appointment/create" defaults = { "access_token" => @access_token, } convert_time_to_booker_format! return_post_response url, defaults, end |
permalink #find_locations(options = {}) ⇒ Object
[View source]
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/booker.rb', line 156 def find_locations = {} url = build_url "/locations" defaults = { "access_token" => @access_token, "BrandID" => nil, "BusinessName" => nil, "FeatureLevel" => nil, "PageNumber" => 1, "PageSize" => 5, "SortBy" => [ { "SortBy" => "Name", "SortDirection" => 0 } ], "UsePaging" => true, # throws a weird exception about null arguments } return_post_response url, defaults, end |
permalink #find_locations_partial(options = {}) ⇒ Object
[View source]
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/booker.rb', line 177 def find_locations_partial = {} url = build_url "/locations/partial" defaults = { "access_token" => @access_token, "BusinessTypeId" => nil, "PageNumber" => 1, "PageSize" => 5, "SortBy" => [ { "SortBy" => "Name", "SortDirection" => 0 } ], #"UsePaging" => true, # throws a weird exception about null arguments "Name" => nil } return_post_response url, defaults, end |
permalink #find_treatments(options = {}) ⇒ Object
[View source]
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/booker.rb', line 129 def find_treatments = {} raise Booker::ArgumentError, 'LocationID is required' unless ['LocationID'] url = build_url "/treatments" defaults = { "access_token" => @access_token, "AllowOnGiftCertificateSale" => nil, "CategoryID" => nil, "EmployeeID" => nil, "LocationID" => nil, "PageNumber" => 1, "PageSize" => 100, "SortBy" => [ { "SortBy" => "Name", "SortDirection" => 0 } ], "SubCategoryID" => nil, "UsePaging" => true, "ExcludeClassesAndWorkshops" => nil, "OnlyClassesAndWorkshops" => nil, "SkipLoadingRoomsAndEmployees" => nil, } return_post_response url, defaults, end |
permalink #get_credit_card_types(location_id) ⇒ Object
[View source]
239 240 241 242 243 |
# File 'lib/booker.rb', line 239 def get_credit_card_types location_id url = build_url "/location/#{location_id}/creditcard_types", "?access_token=#{@access_token}" return_get_response url end |
permalink #get_location(location_id) ⇒ Object
[View source]
226 227 228 229 |
# File 'lib/booker.rb', line 226 def get_location location_id url = build_url "/location/#{location_id}", "?access_token=#{@access_token}" return_get_response url end |
permalink #get_location_online_booking_settings(location_id) ⇒ Object
[View source]
232 233 234 235 236 |
# File 'lib/booker.rb', line 232 def get_location_online_booking_settings location_id url = build_url "/location/#{location_id}/online_booking_settings", "?access_token=#{@access_token}" return_get_response url end |
permalink #get_server_information ⇒ Object
[View source]
246 247 248 249 |
# File 'lib/booker.rb', line 246 def get_server_information url = build_url "/server_information", "?access_token=#{@access_token}" return_get_response url end |
permalink #get_treatment(treatment_id) ⇒ Object
[View source]
206 207 208 209 |
# File 'lib/booker.rb', line 206 def get_treatment treatment_id url = build_url "/treatment/#{treatment_id}", "?access_token=#{@access_token}" return_get_response url end |
permalink #get_treatment_categories(location_id) ⇒ Object
[View source]
212 213 214 215 216 |
# File 'lib/booker.rb', line 212 def get_treatment_categories location_id url = build_url "/treatment_categories", "?access_token=#{@access_token}&culture_name=&location_id=#{location_id}" return_get_response url end |
permalink #get_treatment_sub_categories(location_id, category_id) ⇒ Object
[View source]
219 220 221 222 223 |
# File 'lib/booker.rb', line 219 def get_treatment_sub_categories location_id, category_id url = build_url "/treatment_subcategories", "?access_token=#{@access_token}&culture_name=&location_id=#{location_id}&category_id=#{category_id}" return_get_response url end |
permalink #run_multi_service_availability(options = {}) ⇒ Object
[View source]
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/booker.rb', line 73 def run_multi_service_availability = {} raise Booker::ArgumentError, 'Itineraries is required' unless ['Itineraries'] url = build_url "/availability/multiservice" defaults = { "access_token" => @access_token, "StartDateTime" => Time.now, "Itineraries" => [ #{ #"IsPackage" => false, #"PackageID" => nil, #"Treatments" => [ #{ #"EmployeeID" => nil, #"TreatmentID" => nil #} #] #} ], "LocationID" => nil, "MaxTimesPerDay" => nil, "EndDateTime" => Time.now.to_i + 60 * 60 * 5, } convert_time_to_booker_format! return_post_response url, defaults, end |
permalink #run_multi_spa_availability(options = {}) ⇒ Object
[View source]
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/booker.rb', line 100 def run_multi_spa_availability = {} # TODO: Assert required fields are present url = build_url '/availability/multispa' defaults = { #"AirportCode" => "", #"BrandID" => null, #"CityName" => "New York City", #"CountryCode" => "USA", #"IsApiDistributionPartner" => null, #"Latitude" => null, #"Longitude" => null, "Radius" => 20, #"SpaExistsInSpaFinder" => null, #"StateAbbr" => "NY", "ZipCode" => "77057", "MaxNumberOfLocations" => 5, "EndDateTime" => Time.now.to_i + 60 * 60 * 5, #"LocationID" => 3749, #"MaxTimesPerTreatment" => 2, "StartDateTime" => Time.now.to_i, "TreatmentCategoryID" => 30, "TreatmentSubCategoryID" => 218, "access_token" => @access_token } convert_time_to_booker_format! return_post_response url, defaults, end |
permalink #run_service_availability(options = {}) ⇒ Object
[View source]
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/booker.rb', line 57 def run_service_availability = {} url = build_url '/availability/service' defaults = { "EndDateTime" => Time.now.to_i + 60 * 60 * 5, "LocationID" => 3749, "MaxTimesPerTreatment" => 5, "StartDateTime" => Time.now, "TreatmentCategoryID" => 1, "TreatmentSubCategoryID" => 218, "access_token" => @access_token } convert_time_to_booker_format! return_post_response url, defaults, end |