tosuto 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +77 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/rspec +29 -0
- data/bin/setup +8 -0
- data/lib/tosuto/api.rb +112 -0
- data/lib/tosuto/applied_tax_rate.rb +9 -0
- data/lib/tosuto/check.rb +15 -0
- data/lib/tosuto/dining_option.rb +34 -0
- data/lib/tosuto/menu_item_selection.rb +15 -0
- data/lib/tosuto/oauth_token.rb +36 -0
- data/lib/tosuto/order.rb +64 -0
- data/lib/tosuto/resource.rb +65 -0
- data/lib/tosuto/version.rb +3 -0
- data/lib/tosuto.rb +15 -0
- data/tosuto.gemspec +32 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a313d9c4f75ea9922782b51700cdb7bc86356c684208f95ab00309c1de68a7cc
|
4
|
+
data.tar.gz: 8621253d05767588e09adb8009dd5a4ddb28baf79fd80b6dd5a9fc15b9b3aea5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 30a132fbdd429d57e0cb10b6a93db365dfcde83a05870cdcd6388fb0a042fdf4b56046c45504e3c0f5054a5bb1adbf95853ecb0a72dd29e7982e482311bae47b
|
7
|
+
data.tar.gz: 9b25643ecd0a146645126788ce46e3094ed9c3fae9e00e0d363a74f781c867bc38a3d02f8dd44beac6c904fd0ee9116b5c345f2ce79e14a96f1e79b09f0b8e71
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at syoder@radiusnetworks.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tosuto (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.9.0)
|
12
|
+
rspec-core (~> 3.9.0)
|
13
|
+
rspec-expectations (~> 3.9.0)
|
14
|
+
rspec-mocks (~> 3.9.0)
|
15
|
+
rspec-core (3.9.0)
|
16
|
+
rspec-support (~> 3.9.0)
|
17
|
+
rspec-expectations (3.9.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.9.0)
|
20
|
+
rspec-mocks (3.9.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-support (3.9.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 2.0)
|
30
|
+
rake (~> 10.0)
|
31
|
+
rspec (~> 3.0)
|
32
|
+
tosuto!
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Scott Yoder
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Tosuto
|
2
|
+
|
3
|
+
Gem for interfacing with Toast's API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'tosuto'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install tosuto
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Get a token
|
24
|
+
```rb
|
25
|
+
token = Tosuto::OauthToken.create(client_id, client_secret)
|
26
|
+
```
|
27
|
+
|
28
|
+
### Get all orders created on a date
|
29
|
+
```rb
|
30
|
+
orders = Tosuto::Order.all(
|
31
|
+
restaurant_id: restaurant_id,
|
32
|
+
token: token,
|
33
|
+
business_date: Date.today,
|
34
|
+
)
|
35
|
+
|
36
|
+
order = orders.first.get_details(token: token)
|
37
|
+
```
|
38
|
+
|
39
|
+
### Get an order by guid
|
40
|
+
```rb
|
41
|
+
order = Tosuto::Orders.get(
|
42
|
+
guid: guid,
|
43
|
+
restaurant_id: restaurant_id,
|
44
|
+
token: token,
|
45
|
+
)
|
46
|
+
```
|
47
|
+
|
48
|
+
### Get an order's dining option
|
49
|
+
```rb
|
50
|
+
order = Tosuto::Orders.get(
|
51
|
+
guid: guid,
|
52
|
+
restaurant_id: restaurant_id,
|
53
|
+
token: token,
|
54
|
+
)
|
55
|
+
order.dining_option.get_details(token: token, restaurant_id: order.restaurant_id)
|
56
|
+
if order.dining_option.take_out?
|
57
|
+
puts "This is a take-out order"
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
## Development
|
62
|
+
|
63
|
+
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.
|
64
|
+
|
65
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/radiusnetworks/tosuto. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
74
|
+
|
75
|
+
## Code of Conduct
|
76
|
+
|
77
|
+
Everyone interacting in the Tosuto project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/radiusnetworks/tosuto/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "tosuto"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/setup
ADDED
data/lib/tosuto/api.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
require 'forwardable'
|
5
|
+
|
6
|
+
module Tosuto
|
7
|
+
class API
|
8
|
+
DEFAULT_HOST = ENV.fetch("TOAST_HOST", "ws-sandbox-api.eng.toasttab.com")
|
9
|
+
|
10
|
+
class Error < Error
|
11
|
+
extend Forwardable
|
12
|
+
attr_reader :response
|
13
|
+
def_delegators :response, :code, :body, :json_body, :uri
|
14
|
+
|
15
|
+
def initialize(message = nil, response:)
|
16
|
+
@response = response
|
17
|
+
@message = message || [response.code, response.message].join(" ")
|
18
|
+
super(@message)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Response
|
23
|
+
extend Forwardable
|
24
|
+
|
25
|
+
attr_reader :original
|
26
|
+
def_delegators :original, :code, :body, :uri, :msg, :message, :inspect, :content_type
|
27
|
+
|
28
|
+
def initialize(obj)
|
29
|
+
@original = obj
|
30
|
+
end
|
31
|
+
|
32
|
+
def json_body
|
33
|
+
@json_body ||= JSON.parse(body)
|
34
|
+
end
|
35
|
+
|
36
|
+
def success?
|
37
|
+
original.is_a?(Net::HTTPSuccess)
|
38
|
+
end
|
39
|
+
|
40
|
+
def error
|
41
|
+
API::Error.new(response: self) unless success?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def initialize(host = DEFAULT_HOST)
|
46
|
+
@host = host
|
47
|
+
end
|
48
|
+
|
49
|
+
def request(method, endpoint, body: nil, params: {}, headers: {}, token: nil, restaurant_id: nil)
|
50
|
+
uri = build_uri(endpoint, params)
|
51
|
+
http_start(uri) { |http|
|
52
|
+
http.request(
|
53
|
+
build_request(
|
54
|
+
method,
|
55
|
+
uri,
|
56
|
+
body: body,
|
57
|
+
headers: headers,
|
58
|
+
token: token,
|
59
|
+
restaurant_id: restaurant_id
|
60
|
+
)
|
61
|
+
)
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def build_uri(endpoint, params = nil)
|
68
|
+
URI.parse("https://#{@host}#{endpoint}").tap { |uri|
|
69
|
+
next if params.nil?
|
70
|
+
|
71
|
+
uri.query = Resource.encode_form_data(params)
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
def build_request(method, uri, body: nil, headers: {}, token: nil, restaurant_id: nil)
|
76
|
+
method_class = case method
|
77
|
+
when :get
|
78
|
+
Net::HTTP::Get
|
79
|
+
when :post
|
80
|
+
Net::HTTP::Post
|
81
|
+
end
|
82
|
+
method_class.new(uri.request_uri).tap { |r|
|
83
|
+
headers.each do |key, value|
|
84
|
+
r.add_field(key, value)
|
85
|
+
end
|
86
|
+
r.add_field "Accept", "application/json"
|
87
|
+
unless token.nil?
|
88
|
+
access_token = token.is_a?(OauthToken) ? token.access_token : token
|
89
|
+
r.add_field "Authorization", "Bearer #{access_token}"
|
90
|
+
end
|
91
|
+
unless restaurant_id.nil?
|
92
|
+
r.add_field "Toast-Restaurant-External-ID", restaurant_id
|
93
|
+
end
|
94
|
+
|
95
|
+
if body.is_a? String
|
96
|
+
r.body = body
|
97
|
+
elsif !body.nil?
|
98
|
+
r.add_field "Content-Type", "application/json"
|
99
|
+
r.body = body.to_json
|
100
|
+
end
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
def http_start(uri, &block)
|
105
|
+
Response.new(Net::HTTP.start(uri.host, uri.port, http_opts, &block))
|
106
|
+
end
|
107
|
+
|
108
|
+
def http_opts
|
109
|
+
{ use_ssl: true }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
data/lib/tosuto/check.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Tosuto
|
2
|
+
class Check < Resource
|
3
|
+
attr_accessor :guid, :external_id, :display_number, :payments, :applied_discounts,
|
4
|
+
:void_date, :paid_date, :applied_loyalty_info, :voided, :payment_status, :amount,
|
5
|
+
:tab_name, :tax_exempt, :opened_date, :total_amount, :void_business_date,
|
6
|
+
:deleted, :closed_date, :deleted_date, :modified_date, :tax_amount,
|
7
|
+
:applied_service_charges, :customer
|
8
|
+
|
9
|
+
attr_collections selections: MenuItemSelection
|
10
|
+
|
11
|
+
def initialize(hash)
|
12
|
+
set_attributes(hash)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Tosuto
|
2
|
+
class DiningOption < Resource
|
3
|
+
ENDPOINT = "/config/v2/diningOptions".freeze
|
4
|
+
|
5
|
+
attr_accessor :guid, :entity_type, :external_id, :name, :behavior
|
6
|
+
|
7
|
+
def initialize(hash)
|
8
|
+
set_attributes(hash)
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_details(token:, restaurant_id:)
|
12
|
+
api = API.new
|
13
|
+
url = "#{ENDPOINT}/#{guid}"
|
14
|
+
response = api.request(
|
15
|
+
:get,
|
16
|
+
url,
|
17
|
+
restaurant_id: restaurant_id,
|
18
|
+
token: token,
|
19
|
+
)
|
20
|
+
raise response.error unless response.success?
|
21
|
+
|
22
|
+
set_attributes(response.json_body)
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def take_out?
|
27
|
+
behavior == "TAKE_OUT"
|
28
|
+
end
|
29
|
+
|
30
|
+
def delivery?
|
31
|
+
behavior == "DELIVERY"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Tosuto
|
2
|
+
class MenuItemSelection < Resource
|
3
|
+
attr_accessor :guid, :external_id, :deferred, :pre_discount_price, :void_reason,
|
4
|
+
:option_group, :display_name, :applied_discounts, :modifiers, :seat_number,
|
5
|
+
:void_date, :fulfillment_status, :selection_type, :price, :voided,
|
6
|
+
:quantity, :unit_of_measure, :tax, :void_business_date, :created_date, :pre_modifier,
|
7
|
+
:modified_date
|
8
|
+
|
9
|
+
attr_collections applied_taxes: AppliedTaxRate
|
10
|
+
|
11
|
+
def initialize(hash)
|
12
|
+
set_attributes(hash)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Tosuto
|
2
|
+
class OauthToken < Resource
|
3
|
+
ENDPOINT = "/usermgmt/v1/oauth/token"
|
4
|
+
|
5
|
+
attr_accessor :access_token, :token_type, :expires_in, :expires_at, :scope,
|
6
|
+
|
7
|
+
def self.create(client_id, client_secret, grant_type: "client_credentials")
|
8
|
+
api = API.new
|
9
|
+
body = {
|
10
|
+
grant_type: grant_type,
|
11
|
+
client_id: client_id,
|
12
|
+
client_secret: client_secret,
|
13
|
+
}
|
14
|
+
response = api.request(:post, ENDPOINT, body: encode_form_data(body))
|
15
|
+
raise response.error unless response.success?
|
16
|
+
|
17
|
+
return self.new(response.json_body)
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(attributes = {})
|
21
|
+
self.access_token = attributes['access_token']
|
22
|
+
self.expires_in = attributes['expires_in'].to_i
|
23
|
+
self.expires_at = Time.now + expires_in
|
24
|
+
self.token_type = attributes['token_type']
|
25
|
+
self.scope = attributes['scope']
|
26
|
+
end
|
27
|
+
|
28
|
+
def expired?
|
29
|
+
expires_at < Time.now
|
30
|
+
end
|
31
|
+
|
32
|
+
def inspect
|
33
|
+
"#<#{self.class} #{access_token&.inspect}>"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/tosuto/order.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Tosuto
|
4
|
+
class Order < Resource
|
5
|
+
ENDPOINT = "/orders/v2/orders"
|
6
|
+
|
7
|
+
attr_accessor :guid, :external_id, :revenue_center, :server, :source, :void_date,
|
8
|
+
:duration, :business_date, :paid_date, :restaurant_service, :voided,
|
9
|
+
:estimated_fulfillment_date, :table, :required_prep_time, :approval_status,
|
10
|
+
:delivery_info, :service_area, :number_of_guests, :opened_date,
|
11
|
+
:void_business_date, :deleted, :closed_date, :deleted_date, :modified_date,
|
12
|
+
:promised_date, :pricing_features, :restaurant_id
|
13
|
+
|
14
|
+
attr_collections checks: Check
|
15
|
+
attr_objects dining_option: DiningOption
|
16
|
+
|
17
|
+
def self.all(restaurant_id:, token:, date_range: nil, business_date: nil)
|
18
|
+
api = API.new
|
19
|
+
params = {}
|
20
|
+
unless date_range.nil?
|
21
|
+
params["startDate"] = date_range.begin.utc.strftime("%Y-%m-%dT%H:%M:%S.%L%z")
|
22
|
+
params["endDate"] = date_range.end.utc.strftime("%Y-%m-%dT%H:%M:%S.%L%z")
|
23
|
+
end
|
24
|
+
unless business_date.nil?
|
25
|
+
params["businessDate"] = business_date.strftime("%Y%m%d")
|
26
|
+
end
|
27
|
+
|
28
|
+
response = api.request(
|
29
|
+
:get,
|
30
|
+
ENDPOINT,
|
31
|
+
params: params,
|
32
|
+
restaurant_id: restaurant_id,
|
33
|
+
token: token
|
34
|
+
)
|
35
|
+
raise response.error unless response.success?
|
36
|
+
|
37
|
+
response.json_body.map { |guid|
|
38
|
+
Order.new(guid: guid, restaurant_id: restaurant_id)
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.get(guid:, restaurant_id:, token:)
|
43
|
+
api = API.new
|
44
|
+
url = "#{ENDPOINT}/#{guid}"
|
45
|
+
response = api.request(
|
46
|
+
:get,
|
47
|
+
url,
|
48
|
+
restaurant_id: restaurant_id,
|
49
|
+
token: token
|
50
|
+
)
|
51
|
+
raise response.error unless response.success?
|
52
|
+
|
53
|
+
return new(response.json_body.merge(restaurant_id: restaurant_id))
|
54
|
+
end
|
55
|
+
|
56
|
+
def initialize(hash)
|
57
|
+
set_attributes(hash)
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_details(token:)
|
61
|
+
Order.get(guid: guid, restaurant_id: restaurant_id, token: token)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
module Tosuto
|
4
|
+
class Resource
|
5
|
+
def self.encode_form_data(body)
|
6
|
+
body.map { |key, value| "#{key}=#{CGI.escape(value)}" }.join("&")
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.attr_objects(hash)
|
10
|
+
hash.each do |name, klass|
|
11
|
+
attr_reader(name)
|
12
|
+
define_method("#{name}=") { |obj|
|
13
|
+
instance_variable_set("@#{name}", parse_object(obj, klass))
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.attr_collections(hash)
|
19
|
+
hash.each do |name, klass|
|
20
|
+
attr_reader(name)
|
21
|
+
define_method("#{name}=") { |ary|
|
22
|
+
instance_variable_set("@#{name}", parse_collection(ary, klass))
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def underscore(value)
|
28
|
+
return value unless /[A-Z-]/.match?(value)
|
29
|
+
word = value.to_s.gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
|
30
|
+
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
31
|
+
word.tr!("-", "_")
|
32
|
+
word.downcase!
|
33
|
+
word
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_attribute(key, value)
|
37
|
+
setter = "#{underscore(key)}="
|
38
|
+
send(setter, value) if respond_to?(setter)
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_attributes(hash)
|
42
|
+
hash.each do |key, value|
|
43
|
+
set_attribute(key, value)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def parse_collection(ary, klass)
|
48
|
+
ary.map { |obj|
|
49
|
+
parse_object(obj, klass)
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def parse_object(obj, klass)
|
54
|
+
if obj.is_a?(klass)
|
55
|
+
obj
|
56
|
+
else
|
57
|
+
klass.new(obj)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def inspect
|
62
|
+
"#<#{self.class} #{[@guid, @name || @display_name].join(" ")}>"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/tosuto.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "tosuto/version"
|
2
|
+
|
3
|
+
module Tosuto
|
4
|
+
class Error < StandardError; end
|
5
|
+
# Your code goes here...
|
6
|
+
end
|
7
|
+
|
8
|
+
require "tosuto/api"
|
9
|
+
require "tosuto/resource"
|
10
|
+
require "tosuto/oauth_token"
|
11
|
+
require "tosuto/applied_tax_rate"
|
12
|
+
require "tosuto/menu_item_selection"
|
13
|
+
require "tosuto/check"
|
14
|
+
require "tosuto/dining_option"
|
15
|
+
require "tosuto/order"
|
data/tosuto.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "tosuto/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "tosuto"
|
7
|
+
spec.version = Tosuto::VERSION
|
8
|
+
spec.authors = ["Scott Yoder"]
|
9
|
+
spec.email = ["syoder@radiusnetworks.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{A gem for accessing Toast's API}
|
12
|
+
spec.description = %q{A gem for accessing Toast's API}
|
13
|
+
spec.homepage = "https://github.com/RadiusNetworks/tosuto"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/RadiusNetworks/tosuto"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/RadiusNetworks/tosuto"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tosuto
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Yoder
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: A gem for accessing Toast's API
|
56
|
+
email:
|
57
|
+
- syoder@radiusnetworks.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/rspec
|
73
|
+
- bin/setup
|
74
|
+
- lib/tosuto.rb
|
75
|
+
- lib/tosuto/api.rb
|
76
|
+
- lib/tosuto/applied_tax_rate.rb
|
77
|
+
- lib/tosuto/check.rb
|
78
|
+
- lib/tosuto/dining_option.rb
|
79
|
+
- lib/tosuto/menu_item_selection.rb
|
80
|
+
- lib/tosuto/oauth_token.rb
|
81
|
+
- lib/tosuto/order.rb
|
82
|
+
- lib/tosuto/resource.rb
|
83
|
+
- lib/tosuto/version.rb
|
84
|
+
- tosuto.gemspec
|
85
|
+
homepage: https://github.com/RadiusNetworks/tosuto
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata:
|
89
|
+
homepage_uri: https://github.com/RadiusNetworks/tosuto
|
90
|
+
source_code_uri: https://github.com/RadiusNetworks/tosuto
|
91
|
+
changelog_uri: https://github.com/RadiusNetworks/tosuto
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubygems_version: 3.0.6
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: A gem for accessing Toast's API
|
111
|
+
test_files: []
|