doshii 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21c3d8430f4026ad2ccea4495e07ce6fb1163f7f
4
- data.tar.gz: 5071726124ea7f93c3b91973aa3db9f111c29b8b
3
+ metadata.gz: fc12f5286fcf9522bdeee07839b37fa910c8039a
4
+ data.tar.gz: d5f313d0ae5599d608c9d8ed455042e700aea176
5
5
  SHA512:
6
- metadata.gz: 1909698d9330f046cc2c39306a0973c7dab9d3beb8ced8dd5a9e931379c6e4536e790e2c8c55804a41e41196cfb5e4afee5360199cc98b1677525fd90f4f331c
7
- data.tar.gz: 5451a22cd9299aa64819679ab2fbe6082b499fb8371c2094c574cc970b6b15ac98b42b572672ab9615d5d9fc1ff54de105d64253c73679d59a5b2414edbe80f0
6
+ metadata.gz: 0e08e6e96990623286bdd8447aac8a73ca2935f4b11c9262722ff86645773a1dcc4080e00c5bd1ffb05806b6a5131303d068b6df4ac1a0d2934eda01bc85bb1b
7
+ data.tar.gz: 227fb626f9d06096dc616b674068a2ecd2ab31966717ba9f8d7396ca1128fc26a403aadf53231a48fc70376e2824487f84ef7fd65fdf70f496549e24c909c66b
data/README.md CHANGED
@@ -24,6 +24,18 @@ Or install it yourself as:
24
24
 
25
25
  $ gem install doshii
26
26
 
27
+
28
+ rock'n'roll
29
+
30
+ ## Usage
31
+
32
+ There are two ways to use Doshii:
33
+
34
+ 1. System wide shared configuration
35
+ 2. Per instance configuration
36
+
37
+ ### 1. System wide shared configuration
38
+
27
39
  Run this to create configuration file ```config/initializers/doshii.rb```:
28
40
 
29
41
  $ rails g doshii:install
@@ -34,16 +46,12 @@ Doshii.configure do |config|
34
46
  # you might want to set these values in environment files
35
47
  config.client_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
36
48
  config.client_secret = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
37
- config.endpoint = 'https://alphasandbox.doshii.co/partner/api'
49
+ config.subdomain = 'alphasandbox'
38
50
  config.verify_ssl = false
39
51
  config.version = 'v1'
40
52
  end
41
53
  ```
42
54
 
43
- rock'n'roll
44
-
45
- ## Usage
46
-
47
55
  **CHECKINS**
48
56
 
49
57
  DELETE /checkins/:checkinId
@@ -59,7 +67,7 @@ POST /checkins/:locationId
59
67
  Doshii.checkin.create :location_id do |params|
60
68
  params[:name] = 'John Smith'
61
69
  params[:externalId] = 'ias2kk2'
62
- params[:photoURL] = 'http://example.com/profile.png'
70
+ params[:photoURL] = 'http://example.com/profile.png'
63
71
  end
64
72
  ```
65
73
  or
@@ -150,6 +158,125 @@ GET /tables/:tableId
150
158
  Doshii.table.find :table_id
151
159
  ```
152
160
 
161
+ ### 2. Per instance configuration
162
+
163
+ Pass configuration when defining new instance
164
+ ```ruby
165
+ client = Doshii::Client.new(
166
+ client_id: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
167
+ client_secret: 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy',
168
+ subdomain: 'alphasandbox', #default
169
+ verify_ssl: false, #default
170
+ version: 'v1' #default
171
+ )
172
+ ```
173
+
174
+ **CHECKINS**
175
+
176
+ DELETE /checkins/:checkinId
177
+ ```ruby
178
+ client.delete_checkin :checkin_id
179
+ ```
180
+ GET /checkins/:checkinId
181
+ ```ruby
182
+ client.get_checkin :checkin_id
183
+ ```
184
+ POST /checkins/:locationId
185
+ ```ruby
186
+ client.create_checkin :location_id do |params|
187
+ params[:name] = 'John Smith'
188
+ params[:externalId] = 'ias2kk2'
189
+ params[:photoURL] = 'http://example.com/profile.png'
190
+ end
191
+ ```
192
+ or
193
+ ```ruby
194
+ checkin_params = {
195
+ name: 'John Smith',
196
+ externalId: 'ias2kk2',
197
+ photoURL: 'http://example.com/profile.png'
198
+ }
199
+ client.create_checkin :location_id do |param|
200
+ params.merge!(checkin_params)
201
+ end
202
+ ```
203
+ POST /checkins/:checkinId/table
204
+ ```ruby
205
+ client.allocate_table "#{:checkin_id}/table" do |params|
206
+ params[:name] = '3'
207
+ end
208
+ ```
209
+
210
+ **LOCATIONS**
211
+
212
+ GET /locations
213
+ ```ruby
214
+ client.list_locations
215
+ ```
216
+ POST /locations
217
+ ```ruby
218
+ client.create_location do |params|
219
+ params[:name] = 'Chickens R Us'
220
+ params[:mobility] = 'fixed'
221
+ params[:availability] = 'closed'
222
+ params[:address_line1] = '608 St Kilda Rd'
223
+ # see the official api page for complete list of available params
224
+ end
225
+ ```
226
+
227
+ **ORDERS**
228
+
229
+ GET /orders/:orderId
230
+ ```ruby
231
+ client.get_order :order_id
232
+ ```
233
+ POST /orders/:checkinId
234
+ ```ruby
235
+ client.create_order :checkin_id do |params|
236
+ params[:status] = 'pending'
237
+ params[:items] = [
238
+ {
239
+ name: 'Toasted Sourdough Bread & Eggs'
240
+ description: 'Just ye old classic'
241
+ # ...
242
+ }
243
+ # ...
244
+ ]
245
+ # see the official api page for complete list of available params
246
+ end
247
+ ```
248
+ PUT /orders/:orderId
249
+ ```ruby
250
+ # sample - consumer wants to pay
251
+ client.update_order :order_id do |params|
252
+ params[:tip] = '0'
253
+ params[:status] = 'ready to pay'
254
+ params[:updatedAt] = '2015-05-20T23:32:58.526Z'
255
+ end
256
+ # sample - payment has been processed and order is updated to paid
257
+ client.update_order :order_id do |params|
258
+ params[:tip] = '0'
259
+ params[:status] = 'ready to pay'
260
+ params[:updatedAt] = '2015-05-20T23:32:58.526Z'
261
+ params[:transactionId] = '123'
262
+ params[:invoiceId] = '123'
263
+ end
264
+ ```
265
+
266
+ **PRODUCTS**
267
+
268
+ GET /products/:locationId
269
+ ```ruby
270
+ client.list_products :location_id
271
+ ```
272
+
273
+ **TABLES**
274
+
275
+ GET /tables/:tableId
276
+ ```ruby
277
+ client.get_table :table_id
278
+ ```
279
+
153
280
 
154
281
  ## Development
155
282
 
@@ -28,12 +28,13 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ["lib"]
29
29
 
30
30
  spec.add_development_dependency "bundler", "~> 1.9"
31
- spec.add_development_dependency "rake", "~> 10.0"
32
31
  spec.add_development_dependency "minitest", "~> 5.7.0"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
33
  spec.add_development_dependency "vcr", "~> 2.9.3"
34
34
  spec.add_development_dependency "webmock", "~> 1.21.0"
35
35
 
36
36
  spec.add_dependency "faraday", "~> 0.9.1"
37
37
  spec.add_dependency "faraday_middleware", "~> 0.10.0"
38
+ spec.add_dependency "hashie", "~> 3.4.0"
38
39
  spec.add_dependency "json", "~> 1.8.3"
39
40
  end
@@ -1,3 +1,9 @@
1
+ require 'doshii/client/checkin'
2
+ require 'doshii/client/location'
3
+ require 'doshii/client/order'
4
+ require 'doshii/client/product'
5
+ require 'doshii/client/table'
6
+ require 'doshii/connection'
1
7
  require 'doshii/resource'
2
8
 
3
9
  module Doshii
@@ -35,4 +41,30 @@ module Doshii
35
41
  Doshii.instance_variable_get(key)
36
42
  end
37
43
  end
44
+
45
+ class Client
46
+ include Connection
47
+ include Checkin
48
+ include Location
49
+ include Order
50
+ include Product
51
+ include Table
52
+
53
+ attr_accessor *Configuration::VALID_CONFIG_KEYS
54
+
55
+ def initialize(options={})
56
+ merged_options = Doshii.options.merge(options)
57
+ Configuration::VALID_CONFIG_KEYS.each do |key|
58
+ send("#{key}=", merged_options[key])
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def process_response(res)
65
+ return res if (res.status != 200 && res.body.blank?) || res.status == 404
66
+ return res.body.collect { |r| Doshii::Response[r] } if res.body.is_a? Array
67
+ body = Doshii::Response[res.body]
68
+ end
69
+ end
38
70
  end
@@ -0,0 +1,27 @@
1
+ module Doshii
2
+ class Client
3
+ module Checkin
4
+ API_URL = 'checkins'
5
+
6
+ def allocate_table(checkin_id, query = {}, &block)
7
+ process_response(request :post, "#{API_URL}/#{checkin_id}", query, &block)
8
+ end
9
+
10
+ def create_checkin(location_id, query = {}, &block)
11
+ process_response(request :post, "#{API_URL}/#{location_id}", query, &block)
12
+ end
13
+
14
+ def delete_checkin(id)
15
+ process_response(request :delete, "#{API_URL}/#{id}")
16
+ end
17
+
18
+ def get_checkin(id)
19
+ process_response(request :get, "#{API_URL}/#{id}")
20
+ end
21
+
22
+ def update_checkin(id, query = {}, &block)
23
+ process_response(request :put, "#{API_URL}/#{id}", query, &block)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ module Doshii
2
+ class Client
3
+ module Location
4
+ API_URL = 'locations'
5
+
6
+ def list_locations
7
+ process_response(request :get, API_URL)
8
+ end
9
+
10
+ def create_location(query = {}, &block)
11
+ process_response(request :post, API_URL, query, &block)
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,19 @@
1
+ module Doshii
2
+ class Client
3
+ module Order
4
+ API_URL = 'orders'
5
+
6
+ def create_order(checkin_id, query = {}, &block)
7
+ process_response(request :post, "#{API_URL}/#{checkin_id}", query, &block)
8
+ end
9
+
10
+ def get_order(id)
11
+ process_response(request :get, "#{API_URL}/#{id}")
12
+ end
13
+
14
+ def update_order(id, query = {}, &block)
15
+ process_response(request :put, "#{API_URL}/#{id}", query, &block)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ module Doshii
2
+ class Client
3
+ module Product
4
+ API_URL = 'products'
5
+
6
+ def list_products(location_id)
7
+ process_response(request :get, "#{API_URL}/#{location_id}")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Doshii
2
+ class Client
3
+ module Table
4
+ API_URL = 'tables'
5
+
6
+ def get_table(id)
7
+ process_response(request :get, "#{API_URL}/#{id}")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,10 +1,10 @@
1
1
  module Doshii
2
2
  module Configuration
3
- VALID_CONNECTION_KEYS = [:endpoint, :verify_ssl, :version].freeze
3
+ VALID_CONNECTION_KEYS = [:subdomain, :verify_ssl, :version].freeze
4
4
  VALID_OPTIONS_KEYS = [:client_id, :client_secret].freeze
5
5
  VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
6
6
 
7
- DEFAULT_ENDPOINT = 'https://alphasandbox.doshii.co/partner/api'
7
+ DEFAULT_SUBDOMAIN = 'alphasandbox'
8
8
  DEFAULT_VERIFY_SSL = false
9
9
  DEFAULT_VERSION = 'v1'
10
10
 
@@ -18,10 +18,10 @@ module Doshii
18
18
  end
19
19
 
20
20
  def reset
21
- @endpoint = DEFAULT_ENDPOINT
22
- @verify_ssl = DEFAULT_VERIFY_SSL
23
21
  @client_id = DEFAULT_CLIENT_ID
24
22
  @client_secret = DEFAULT_CLIENT_SECRET
23
+ @subdomain = DEFAULT_SUBDOMAIN
24
+ @verify_ssl = DEFAULT_VERIFY_SSL
25
25
  @version = DEFAULT_VERSION
26
26
  end
27
27
 
@@ -1,4 +1,5 @@
1
1
  require 'base64'
2
+ require 'doshii/exceptions'
2
3
  require 'faraday'
3
4
  require 'faraday_middleware'
4
5
 
@@ -6,10 +7,12 @@ module Doshii
6
7
  module Connection
7
8
  protected
8
9
 
10
+ URL = "https://%{subdomain}.doshii.co/partner/api"
11
+
9
12
  def http_connection
10
13
  @http_connection ||=
11
- Faraday.new("#{endpoint}/#{version}/") do |faraday|
12
- faraday.response :logger
14
+ Faraday.new("#{URL % { subdomain: subdomain }}/#{version}/") do |faraday|
15
+ # faraday.response :logger
13
16
  faraday.adapter Faraday.default_adapter
14
17
  faraday.use Faraday::Response::ParseJson
15
18
 
@@ -22,10 +25,14 @@ module Doshii
22
25
  def request(method, url, query = {}, &block)
23
26
  body = Hash.new
24
27
  yield body if block_given?
25
- http_connection.send(method) do |req|
28
+ response = http_connection.send(method) do |req|
26
29
  req.url url, query
27
30
  req.body = JSON.generate(body)
28
31
  end
32
+ raise Doshii::AuthenticationError.new(response.body) if response.status == 401
33
+ response
34
+ rescue Faraday::ConnectionFailed => e
35
+ raise Doshii::ConnectionError.new(e)
29
36
  end
30
37
 
31
38
  private
@@ -0,0 +1,4 @@
1
+ module Doshii
2
+ class ConnectionError < StandardError; end
3
+ class AuthenticationError < ConnectionError; end
4
+ end
@@ -1,4 +1,5 @@
1
1
  require 'doshii/connection'
2
+ require 'doshii/response'
2
3
 
3
4
  module Doshii
4
5
  class Resource
@@ -16,24 +17,32 @@ module Doshii
16
17
  end
17
18
 
18
19
  def all
19
- request :get, @url
20
+ process_response(request :get, @url)
20
21
  end
21
22
 
22
23
  def create(id = nil, query = {}, &block)
23
24
  url = id.nil? ? @url : "#{@url}/#{id}"
24
- request :post, url, query, &block
25
+ process_response(request :post, url, query, &block)
25
26
  end
26
27
 
27
28
  def delete(id)
28
- request :delete, "#{@url}/#{id}"
29
+ process_response(request :delete, "#{@url}/#{id}")
29
30
  end
30
31
 
31
32
  def find(id)
32
- request :get, "#{@url}/#{id}"
33
+ process_response(request :get, "#{@url}/#{id}")
33
34
  end
34
35
 
35
36
  def update(id, query = {}, &block)
36
- request :put, "#{@url}/#{id}", query, &block
37
+ process_response(request :put, "#{@url}/#{id}", query, &block)
38
+ end
39
+
40
+ private
41
+
42
+ def process_response(res)
43
+ return res if (res.status != 200 && res.body.blank?) || res.status == 404
44
+ return res.body.collect { |r| Doshii::Response[r] } if res.body.is_a? Array
45
+ body = Doshii::Response[res.body]
37
46
  end
38
47
  end
39
48
  end
@@ -0,0 +1,14 @@
1
+ require 'hashie'
2
+
3
+ module Doshii
4
+ class Response < Hash
5
+ include Hashie::Extensions::MethodAccess
6
+
7
+ def method_missing(name, *args, &block)
8
+ value = super
9
+ return value.collect { |v| Doshii::Response[v] } if value.is_a? Array
10
+ return Response[value] if value.is_a? Hash
11
+ value
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Doshii
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -1,8 +1,8 @@
1
1
  Doshii.configure do |config|
2
2
  # you might want to set these values in environment files
3
- config.client_id = '369c27e8d884e0b54e56035b41eed4b07b0fc59091907418f0368ab643a4ad31'
4
- config.client_secret = 'c0c0441e9bcc671dff9beb8e2a16fb43ed392f8c9a029dc8075cb71b1ac87e5f'
5
- config.endpoint = 'https://alphasandbox.doshii.co/partner/api'
3
+ config.client_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
4
+ config.client_secret = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
5
+ config.subdomain = 'alphasandbox'
6
6
  config.verify_ssl = false
7
7
  config.version = 'v1'
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doshii
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Romel Campos
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-20 00:00:00.000000000 Z
11
+ date: 2015-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -25,33 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.9'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 5.7.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 5.7.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 5.7.0
47
+ version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 5.7.0
54
+ version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: vcr
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.10.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: hashie
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 3.4.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 3.4.0
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: json
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -140,9 +154,16 @@ files:
140
154
  - doshii.gemspec
141
155
  - lib/doshii.rb
142
156
  - lib/doshii/client.rb
157
+ - lib/doshii/client/checkin.rb
158
+ - lib/doshii/client/location.rb
159
+ - lib/doshii/client/order.rb
160
+ - lib/doshii/client/product.rb
161
+ - lib/doshii/client/table.rb
143
162
  - lib/doshii/configuration.rb
144
163
  - lib/doshii/connection.rb
164
+ - lib/doshii/exceptions.rb
145
165
  - lib/doshii/resource.rb
166
+ - lib/doshii/response.rb
146
167
  - lib/doshii/version.rb
147
168
  - lib/generators/doshii/install_generator.rb
148
169
  - lib/generators/doshii/templates/doshii.rb
@@ -166,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
187
  version: '0'
167
188
  requirements: []
168
189
  rubyforge_project:
169
- rubygems_version: 2.4.6
190
+ rubygems_version: 2.4.8
170
191
  signing_key:
171
192
  specification_version: 4
172
193
  summary: Gem to wrap Doshii API