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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a313d9c4f75ea9922782b51700cdb7bc86356c684208f95ab00309c1de68a7cc
4
- data.tar.gz: 8621253d05767588e09adb8009dd5a4ddb28baf79fd80b6dd5a9fc15b9b3aea5
3
+ metadata.gz: e5fb38713a7a05d0cb70b635852e7e1da602a05c6a9d8c5c7ad24580ce2081bf
4
+ data.tar.gz: b869ffbc6334b3b8e72a544943818650c7b8afc53a0fdb7fa579191a0a6e4868
5
5
  SHA512:
6
- metadata.gz: 30a132fbdd429d57e0cb10b6a93db365dfcde83a05870cdcd6388fb0a042fdf4b56046c45504e3c0f5054a5bb1adbf95853ecb0a72dd29e7982e482311bae47b
7
- data.tar.gz: 9b25643ecd0a146645126788ce46e3094ed9c3fae9e00e0d363a74f781c867bc38a3d02f8dd44beac6c904fd0ee9116b5c345f2ce79e14a96f1e79b09f0b8e71
6
+ metadata.gz: ef224d74f269376d835a8ada4d75d1b728d6dc8971fd7fcb5a64dc4a30bffc39799c40926a7ce815d8941012cb4154281e035f5736003037797d1039e280602c
7
+ data.tar.gz: 3154c29c235d1890fdb7c25f6c0b66c5abab9f89a14b32e0839b3bfe0d0bc4f9cc806a5066993417c738bef2b09b24df04066b5e010218ddbe6b0b113cf14498
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tosuto (0.1.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.5.0)
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 (~> 10.0)
30
+ rake (~> 13.0)
31
31
  rspec (~> 3.0)
32
32
  tosuto!
33
33
 
34
34
  BUNDLED WITH
35
- 2.0.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.
@@ -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-api.eng.toasttab.com")
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("https://#{@host}#{endpoint}").tap { |uri|
68
+ URI.parse("#{@host}#{endpoint}").tap { |uri|
69
69
  next if params.nil?
70
70
 
71
71
  uri.query = Resource.encode_form_data(params)
@@ -1,6 +1,8 @@
1
1
  module Tosuto
2
2
  class DiningOption < Resource
3
- ENDPOINT = "/config/v2/diningOptions".freeze
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 == "TAKE_OUT"
36
+ behavior == 'TAKE_OUT' && (carryout? || !dsp?)
28
37
  end
29
38
 
30
39
  def delivery?
31
- behavior == "DELIVERY"
40
+ behavior == 'DELIVERY' || (dsp? && !carryout?)
32
41
  end
33
42
  end
34
43
  end
@@ -1,28 +1,29 @@
1
1
  module Tosuto
2
2
  class OauthToken < Resource
3
- ENDPOINT = "/usermgmt/v1/oauth/token"
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, grant_type: "client_credentials")
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
- grant_type: grant_type,
11
- client_id: client_id,
12
- client_secret: client_secret,
9
+ userAccessType: user_access_type,
10
+ clientId: client_id,
11
+ clientSecret: client_secret,
13
12
  }
14
- response = api.request(:post, ENDPOINT, body: encode_form_data(body))
13
+ response = api.request(:post, ENDPOINT, body: body)
15
14
  raise response.error unless response.success?
16
15
 
17
- return self.new(response.json_body)
16
+ return new(response.json_body)
18
17
  end
19
18
 
20
19
  def initialize(attributes = {})
21
- self.access_token = attributes['access_token']
22
- self.expires_in = attributes['expires_in'].to_i
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 = attributes['token_type']
25
- self.scope = attributes['scope']
25
+ self.token_type = token['tokenType']
26
+ self.scope = token['scope']
26
27
  end
27
28
 
28
29
  def expired?
@@ -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
@@ -39,6 +39,8 @@ module Tosuto
39
39
  end
40
40
 
41
41
  def set_attributes(hash)
42
+ return unless hash.is_a?(Hash)
43
+
42
44
  hash.each do |key, value|
43
45
  set_attribute(key, value)
44
46
  end
@@ -1,3 +1,3 @@
1
1
  module Tosuto
2
- VERSION = "0.1.0"
2
+ VERSION = '0.4.2'.freeze
3
3
  end
@@ -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", "~> 10.0"
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.1.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: 2019-11-21 00:00:00.000000000 Z
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: '10.0'
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: '10.0'
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
- rubygems_version: 3.0.6
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