ruby-booker 0.0.0

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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +20 -0
  3. data/lib/booker.rb +193 -0
  4. data/lib/ruby-booker.rb +1 -0
  5. metadata +74 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 858104afad5e09050a26b6f5ddc81d07714b1043
4
+ data.tar.gz: 1782ac3d23539dc650a508a13547a389378eb5fa
5
+ SHA512:
6
+ metadata.gz: 05b073a629714e3df981d9f8c91da7332ce1b1ad00e6063bdb5013ceac86d223e8ede8b9fe9a2edbf8be9a184b63341fb8da5774809f8ab40707adc1ea913967
7
+ data.tar.gz: d57ccfdaee9583d95f7b069b4e87656dc0491cfb6f6ec7ceed7dec65b77af0f377d7282df2ef3da9d0e5bec22e7f24d884d42c57fb4ac6c5afafa5512a9463b8
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Jake Craige
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,193 @@
1
+ require 'httparty'
2
+
3
+ module Booker
4
+ BASE_HOST = "stable-app.secure-booker.com"
5
+ BASE_PATH = "/WebService4/json/customerService.svc"
6
+
7
+ class Client
8
+ attr_reader :url, :access_token, :expires_in
9
+
10
+ def initialize(key, secret)
11
+ @key = key
12
+ @secret = secret
13
+ set_access_token
14
+ end
15
+
16
+ #http://apidoc.booker.com/Method/Detail/129
17
+ def run_multi_service_availability options = {}
18
+ raise Booker::ArgumentError, 'Itineraries is required' unless options['Itineraries']
19
+ url = build_url "/availability/multiservice"
20
+ defaults =
21
+ {
22
+ "access_token" => @access_token,
23
+ "StartDateTime" => "/Date(#{Time.now.to_i})/",
24
+ "Itineraries" => [
25
+ #{
26
+ #"IsPackage" => false,
27
+ #"PackageID" => nil,
28
+ #"Treatments" => [
29
+ #{
30
+ #"EmployeeID" => nil,
31
+ #"TreatmentID" => nil
32
+ #}
33
+ #]
34
+ #}
35
+ ],
36
+ "LocationID" => nil,
37
+ "MaxTimesPerDay" => nil,
38
+ "EndDateTime" => "/Date(#{Time.now.to_i + 60 * 60 * 24})/",
39
+ }
40
+ return_post_response url, defaults, options
41
+ end
42
+
43
+ # http://apidoc.booker.com/Method/Detail/123
44
+ def find_treatments options = {}
45
+ raise Booker::ArgumentError, 'LocationID is required' unless options['LocationID']
46
+ url = build_url "/treatments"
47
+ defaults = {
48
+ "access_token" => @access_token,
49
+ "AllowOnGiftCertificateSale" => nil,
50
+ "CategoryID" => nil,
51
+ "EmployeeID" => nil,
52
+ "LocationID" => nil,
53
+ "PageNumber" => 1,
54
+ "PageSize" => 10,
55
+ "SortBy" => [
56
+ {
57
+ "SortBy" => "Name",
58
+ "SortDirection" => 0
59
+ }
60
+ ],
61
+ "SubCategoryID" => nil,
62
+ "UsePaging" => true,
63
+ "ExcludeClassesAndWorkshops" => nil,
64
+ "OnlyClassesAndWorkshops" => nil,
65
+ "SkipLoadingRoomsAndEmployees" => nil,
66
+ }
67
+ return_post_response url, defaults, options
68
+ end
69
+
70
+ # http://apidoc.booker.com/Method/Detail/852
71
+ def find_locations options = {}
72
+ url = build_url "/locations"
73
+ defaults = {
74
+ "access_token" => @access_token,
75
+ "BusinessTypeId" => nil,
76
+ "PageNumber" => 1,
77
+ "PageSize" => 5,
78
+ "SortBy" => [
79
+ {
80
+ "SortBy" => "Name",
81
+ "SortDirection" => 0
82
+ }
83
+ ],
84
+ #"UsePaging" => true, # throws a weird exception about null arguments
85
+ "Name" => nil
86
+ }
87
+ return_post_response url, defaults, options
88
+ end
89
+
90
+ # http://apidoc.booker.com/Method/Detail/853
91
+ def find_locations_partial options = {}
92
+ url = build_url "/locations/partial"
93
+ defaults = {
94
+ "access_token" => @access_token,
95
+ "BusinessTypeId" => nil,
96
+ "PageNumber" => 1,
97
+ "PageSize" => 5,
98
+ "SortBy" => [
99
+ {
100
+ "SortBy" => "Name",
101
+ "SortDirection" => 0
102
+ }
103
+ ],
104
+ #"UsePaging" => true, # throws a weird exception about null arguments
105
+ "Name" => nil
106
+ }
107
+ return_post_response url, defaults, options
108
+ end
109
+
110
+ #http://apidoc.booker.com/Method/Detail/125
111
+ def get_treatment_categories location_id
112
+ url = build_url "/treatment_categories",
113
+ "?access_token=#{@access_token}&culture_name=&location_id=#{location_id}"
114
+ return_get_response url
115
+ end
116
+
117
+ #http://apidoc.booker.com/Method/Detail/126
118
+ def get_treatment_sub_categories location_id, category_id
119
+ url = build_url "/treatment_subcategories",
120
+ "?access_token=#{@access_token}&culture_name=&location_id=#{location_id}&category_id=#{category_id}"
121
+ return_get_response url
122
+ end
123
+
124
+ #http://apidoc.booker.com/Method/Detail/153
125
+ def get_location location_id
126
+ url = build_url "/location/#{location_id}", "?access_token=#{@access_token}"
127
+ return_get_response url
128
+ end
129
+
130
+ #http://apidoc.booker.com/Method/Detail/134
131
+ def get_location_online_booking_settings location_id
132
+ url = build_url "/location/#{location_id}/online_booking_settings",
133
+ "?access_token=#{@access_token}"
134
+ return_get_response url
135
+ end
136
+
137
+ private
138
+
139
+ def return_post_response url, defaults, options
140
+ options = defaults.merge(options)
141
+ response = post url, options
142
+ parse_body response.body
143
+ end
144
+
145
+ def return_get_response url
146
+ response = get url
147
+ parse_body response.body
148
+ end
149
+
150
+ def parse_body body
151
+ body = JSON.parse(body)
152
+ raise Booker::ApiSuccessFalseError, body if body['IsSuccess'] == false
153
+ body
154
+ end
155
+
156
+ def post url, post_data
157
+ options = {
158
+ body: post_data.to_json,
159
+ headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
160
+ }
161
+ HTTParty.post url, options
162
+ end
163
+
164
+ def get url
165
+ HTTParty.get url
166
+ end
167
+
168
+
169
+ def set_access_token
170
+ url = build_url '/access_token', "?client_id=#{@key}&client_secret=#{@secret}&grant_type=client_credentials"
171
+ response = HTTParty.get(url)
172
+ body = JSON.parse(response.body)
173
+
174
+ if body['error']
175
+ raise body['error'] + ":" + body['error_description']
176
+ else
177
+ @access_token = body['access_token']
178
+ @expires_in = body['expires_in']
179
+ end
180
+ end
181
+
182
+ def base_url
183
+ "http://" + Booker::BASE_HOST + Booker::BASE_PATH
184
+ end
185
+
186
+ def build_url path, query = ''
187
+ base_url + path + query
188
+ end
189
+ end
190
+
191
+ class ArgumentError < StandardError; end
192
+ class ApiSuccessFalseError < StandardError; end
193
+ end
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'booker')
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-booker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jake Craige
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Interact with booker api in rails
42
+ email: jake@poeticsystems.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/ruby-booker.rb
48
+ - LICENSE
49
+ - lib/booker.rb
50
+ homepage: http://rubygems.org/gems/ruby-booker
51
+ licenses:
52
+ - MIT
53
+ metadata: {}
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 2.0.3
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Interact with booker api
74
+ test_files: []