tosuto 0.1.0 → 0.4.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 +4 -4
- data/Gemfile.lock +4 -4
- data/README.md +14 -0
- data/lib/tosuto/api.rb +3 -3
- data/lib/tosuto/dining_option.rb +14 -5
- data/lib/tosuto/oauth_token.rb +14 -13
- data/lib/tosuto/order.rb +4 -6
- data/lib/tosuto/resource.rb +2 -0
- data/lib/tosuto/version.rb +1 -1
- data/tosuto.gemspec +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5fb38713a7a05d0cb70b635852e7e1da602a05c6a9d8c5c7ad24580ce2081bf
|
4
|
+
data.tar.gz: b869ffbc6334b3b8e72a544943818650c7b8afc53a0fdb7fa579191a0a6e4868
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef224d74f269376d835a8ada4d75d1b728d6dc8971fd7fcb5a64dc4a30bffc39799c40926a7ce815d8941012cb4154281e035f5736003037797d1039e280602c
|
7
|
+
data.tar.gz: 3154c29c235d1890fdb7c25f6c0b66c5abab9f89a14b32e0839b3bfe0d0bc4f9cc806a5066993417c738bef2b09b24df04066b5e010218ddbe6b0b113cf14498
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tosuto (0.
|
4
|
+
tosuto (0.4.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
diff-lcs (1.3)
|
10
|
-
rake (
|
10
|
+
rake (13.0.1)
|
11
11
|
rspec (3.9.0)
|
12
12
|
rspec-core (~> 3.9.0)
|
13
13
|
rspec-expectations (~> 3.9.0)
|
@@ -27,9 +27,9 @@ PLATFORMS
|
|
27
27
|
|
28
28
|
DEPENDENCIES
|
29
29
|
bundler (~> 2.0)
|
30
|
-
rake (~>
|
30
|
+
rake (~> 13.0)
|
31
31
|
rspec (~> 3.0)
|
32
32
|
tosuto!
|
33
33
|
|
34
34
|
BUNDLED WITH
|
35
|
-
2.
|
35
|
+
2.1.4
|
data/README.md
CHANGED
@@ -58,6 +58,20 @@ if order.dining_option.take_out?
|
|
58
58
|
end
|
59
59
|
```
|
60
60
|
|
61
|
+
## Setting the Toast host URL
|
62
|
+
|
63
|
+
Tosuto defaults to the sandbox Toast host URL: `https://ws-sandbox-api.eng.toasttab.com`
|
64
|
+
|
65
|
+
This can be overridden globally by setting the `TOAST_HOST` environment variable. Or, to set the Toast host URL on a per-request basis just pass in a `Tosuto::API` object with the preferred host:
|
66
|
+
|
67
|
+
```rb
|
68
|
+
token = Tosuto::OauthToken.create(
|
69
|
+
client_id,
|
70
|
+
client_secret,
|
71
|
+
api: Tosuto::API.new("https://example.org")
|
72
|
+
)
|
73
|
+
```
|
74
|
+
|
61
75
|
## Development
|
62
76
|
|
63
77
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/tosuto/api.rb
CHANGED
@@ -5,7 +5,7 @@ require 'forwardable'
|
|
5
5
|
|
6
6
|
module Tosuto
|
7
7
|
class API
|
8
|
-
DEFAULT_HOST = ENV.fetch("TOAST_HOST", "ws-sandbox
|
8
|
+
DEFAULT_HOST = ENV.fetch("TOAST_HOST", "https://ws-sandbox.eng.toasttab.com")
|
9
9
|
|
10
10
|
class Error < Error
|
11
11
|
extend Forwardable
|
@@ -56,7 +56,7 @@ module Tosuto
|
|
56
56
|
body: body,
|
57
57
|
headers: headers,
|
58
58
|
token: token,
|
59
|
-
restaurant_id: restaurant_id
|
59
|
+
restaurant_id: restaurant_id,
|
60
60
|
)
|
61
61
|
)
|
62
62
|
}
|
@@ -65,7 +65,7 @@ module Tosuto
|
|
65
65
|
private
|
66
66
|
|
67
67
|
def build_uri(endpoint, params = nil)
|
68
|
-
URI.parse("
|
68
|
+
URI.parse("#{@host}#{endpoint}").tap { |uri|
|
69
69
|
next if params.nil?
|
70
70
|
|
71
71
|
uri.query = Resource.encode_form_data(params)
|
data/lib/tosuto/dining_option.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Tosuto
|
2
2
|
class DiningOption < Resource
|
3
|
-
ENDPOINT =
|
3
|
+
ENDPOINT = '/config/v2/diningOptions'.freeze
|
4
|
+
DSP_MATCH = %w[delivery grub uber door postmates].freeze
|
5
|
+
CARRYOUT_MATCH = %w[carryout].freeze
|
4
6
|
|
5
7
|
attr_accessor :guid, :entity_type, :external_id, :name, :behavior
|
6
8
|
|
@@ -8,8 +10,7 @@ module Tosuto
|
|
8
10
|
set_attributes(hash)
|
9
11
|
end
|
10
12
|
|
11
|
-
def get_details(token:, restaurant_id:)
|
12
|
-
api = API.new
|
13
|
+
def get_details(token:, restaurant_id:, api: API.new)
|
13
14
|
url = "#{ENDPOINT}/#{guid}"
|
14
15
|
response = api.request(
|
15
16
|
:get,
|
@@ -23,12 +24,20 @@ module Tosuto
|
|
23
24
|
self
|
24
25
|
end
|
25
26
|
|
27
|
+
def dsp?
|
28
|
+
DSP_MATCH.any? { |dsp| name&.downcase&.match?(dsp) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def carryout?
|
32
|
+
CARRYOUT_MATCH.any? { |carryout| name&.downcase&.match?(carryout) }
|
33
|
+
end
|
34
|
+
|
26
35
|
def take_out?
|
27
|
-
behavior ==
|
36
|
+
behavior == 'TAKE_OUT' && (carryout? || !dsp?)
|
28
37
|
end
|
29
38
|
|
30
39
|
def delivery?
|
31
|
-
behavior ==
|
40
|
+
behavior == 'DELIVERY' || (dsp? && !carryout?)
|
32
41
|
end
|
33
42
|
end
|
34
43
|
end
|
data/lib/tosuto/oauth_token.rb
CHANGED
@@ -1,28 +1,29 @@
|
|
1
1
|
module Tosuto
|
2
2
|
class OauthToken < Resource
|
3
|
-
ENDPOINT = "/
|
3
|
+
ENDPOINT = "/authentication/v1/authentication/login".freeze
|
4
4
|
|
5
|
-
attr_accessor :access_token, :token_type, :expires_in, :expires_at, :scope
|
5
|
+
attr_accessor :access_token, :token_type, :expires_in, :expires_at, :scope
|
6
6
|
|
7
|
-
def self.create(client_id, client_secret,
|
8
|
-
api = API.new
|
7
|
+
def self.create(client_id, client_secret, user_access_type: "TOAST_MACHINE_CLIENT", api: API.new)
|
9
8
|
body = {
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
userAccessType: user_access_type,
|
10
|
+
clientId: client_id,
|
11
|
+
clientSecret: client_secret,
|
13
12
|
}
|
14
|
-
response = api.request(:post, ENDPOINT, body:
|
13
|
+
response = api.request(:post, ENDPOINT, body: body)
|
15
14
|
raise response.error unless response.success?
|
16
15
|
|
17
|
-
return
|
16
|
+
return new(response.json_body)
|
18
17
|
end
|
19
18
|
|
20
19
|
def initialize(attributes = {})
|
21
|
-
|
22
|
-
|
20
|
+
return unless (token = attributes['token'])
|
21
|
+
|
22
|
+
self.access_token = token['accessToken']
|
23
|
+
self.expires_in = token['expiresIn'].to_i
|
23
24
|
self.expires_at = Time.now + expires_in
|
24
|
-
self.token_type =
|
25
|
-
self.scope =
|
25
|
+
self.token_type = token['tokenType']
|
26
|
+
self.scope = token['scope']
|
26
27
|
end
|
27
28
|
|
28
29
|
def expired?
|
data/lib/tosuto/order.rb
CHANGED
@@ -14,8 +14,7 @@ module Tosuto
|
|
14
14
|
attr_collections checks: Check
|
15
15
|
attr_objects dining_option: DiningOption
|
16
16
|
|
17
|
-
def self.all(restaurant_id:, token:, date_range: nil, business_date: nil)
|
18
|
-
api = API.new
|
17
|
+
def self.all(restaurant_id:, token:, date_range: nil, business_date: nil, api: API.new)
|
19
18
|
params = {}
|
20
19
|
unless date_range.nil?
|
21
20
|
params["startDate"] = date_range.begin.utc.strftime("%Y-%m-%dT%H:%M:%S.%L%z")
|
@@ -39,8 +38,7 @@ module Tosuto
|
|
39
38
|
}
|
40
39
|
end
|
41
40
|
|
42
|
-
def self.get(guid:, restaurant_id:, token:)
|
43
|
-
api = API.new
|
41
|
+
def self.get(guid:, restaurant_id:, token:, api: API.new)
|
44
42
|
url = "#{ENDPOINT}/#{guid}"
|
45
43
|
response = api.request(
|
46
44
|
:get,
|
@@ -57,8 +55,8 @@ module Tosuto
|
|
57
55
|
set_attributes(hash)
|
58
56
|
end
|
59
57
|
|
60
|
-
def get_details(token:)
|
61
|
-
Order.get(guid: guid, restaurant_id: restaurant_id, token: token)
|
58
|
+
def get_details(token:, api: API.new)
|
59
|
+
Order.get(guid: guid, restaurant_id: restaurant_id, token: token, api: api)
|
62
60
|
end
|
63
61
|
end
|
64
62
|
end
|
data/lib/tosuto/resource.rb
CHANGED
data/lib/tosuto/version.rb
CHANGED
data/tosuto.gemspec
CHANGED
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
|
29
29
|
spec.add_development_dependency "bundler", "~> 2.0"
|
30
|
-
spec.add_development_dependency "rake", "~>
|
30
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
31
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
32
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tosuto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Yoder
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.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: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -104,7 +104,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
|
-
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.7.6
|
108
109
|
signing_key:
|
109
110
|
specification_version: 4
|
110
111
|
summary: A gem for accessing Toast's API
|