supai 0.2.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 +63 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/rspec +29 -0
- data/bin/setup +8 -0
- data/lib/supai/address.rb +19 -0
- data/lib/supai/api.rb +113 -0
- data/lib/supai/authorization.rb +33 -0
- data/lib/supai/customer.rb +10 -0
- data/lib/supai/order.rb +44 -0
- data/lib/supai/orders_response.rb +36 -0
- data/lib/supai/person.rb +14 -0
- data/lib/supai/phone.rb +13 -0
- data/lib/supai/pickup_window.rb +13 -0
- data/lib/supai/resource.rb +112 -0
- data/lib/supai/united_pickup_order_report.rb +30 -0
- data/lib/supai/user.rb +13 -0
- data/lib/supai/version.rb +3 -0
- data/lib/supai.rb +18 -0
- data/supai.gemspec +32 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3c59a70d01ff7076446af452ddd69bcd069c22d02f00d1670c5be41f3b0266d5
|
4
|
+
data.tar.gz: 73dc570cc931bf4586724fcf30e588239117af5291aa776662c66012410cd054
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8496674fe813855155b46b1f96ced76ddc650e3a9c91bd2bd24083ff71be1e5b55ad7b6496d6f39e6c9eb224dc82790729de61528bb4c08c2c25c430b4dab732
|
7
|
+
data.tar.gz: 329809ba728cce968adf08b51ff76bf0ed4307d8d9e354d7e15ba09334034d99606605d34a51f427702e86c4a7ce2f43b90cbc86b9dc5bbc6bf6c7f8685064a2
|
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
|
+
supai (0.2.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (13.0.1)
|
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.1)
|
16
|
+
rspec-support (~> 3.9.1)
|
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.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-support (3.9.2)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 2.0)
|
30
|
+
rake (~> 13.0)
|
31
|
+
rspec (~> 3.0)
|
32
|
+
supai!
|
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) 2020 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,63 @@
|
|
1
|
+
# Supai
|
2
|
+
|
3
|
+
Gem for interfacing with MyWebGrocer / Mi9's orders API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'supai'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install supai
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```rb
|
24
|
+
auth_token = "XXXX"
|
25
|
+
user = "radiustest"
|
26
|
+
password = "YYYY"
|
27
|
+
store_id = "ZZZZ"
|
28
|
+
chain_id = "XYZXYZ"
|
29
|
+
|
30
|
+
authorization = Supai::Authorization.create(auth_token)
|
31
|
+
user = authorization.authenticate_user(user_name: user, password: password, chain_id: chain_id)
|
32
|
+
|
33
|
+
params = { fulfillmentStartDate: 30.days.ago, sortingOptions: "Descending" }
|
34
|
+
Supai::Order.all_in_batches(
|
35
|
+
chain_id: chain_id,
|
36
|
+
store_id: store_id,
|
37
|
+
params: params,
|
38
|
+
token: authorization.secret,
|
39
|
+
) do |orders|
|
40
|
+
# process each batch
|
41
|
+
orders.each do |order|
|
42
|
+
# TODO: process order here
|
43
|
+
end
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
## Development
|
48
|
+
|
49
|
+
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.
|
50
|
+
|
51
|
+
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).
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/syoder/supai. 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.
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
60
|
+
|
61
|
+
## Code of Conduct
|
62
|
+
|
63
|
+
Everyone interacting in the Supai project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/syoder/supai/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 "supai"
|
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
@@ -0,0 +1,19 @@
|
|
1
|
+
module Supai
|
2
|
+
class Address < Resource
|
3
|
+
attr_accessor :first_name, :last_name, :line1, :line2, :line3, :city,
|
4
|
+
:postal_code, :region_code, :country_code
|
5
|
+
|
6
|
+
attr_objects primary_phone: Phone, secondary_phone: Phone
|
7
|
+
|
8
|
+
def initialize(hash)
|
9
|
+
set_attributes(hash)
|
10
|
+
end
|
11
|
+
|
12
|
+
def inspect
|
13
|
+
display = [line1, line2, line3, city, region_code, country_code].select { |str|
|
14
|
+
str.length > 0
|
15
|
+
}.join(", ")
|
16
|
+
"#<#{self.class} #{display}>"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/supai/api.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
require 'forwardable'
|
5
|
+
|
6
|
+
module Supai
|
7
|
+
class API
|
8
|
+
DEFAULT_HOST = ENV.fetch("SUPAI_HOST", "api-un76stg.shop.staging.theunitedfamily.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)
|
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
|
+
)
|
60
|
+
)
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def build_uri(endpoint, params = nil)
|
67
|
+
URI.parse("https://#{@host}#{endpoint}").tap { |uri|
|
68
|
+
next if params.nil? || params.empty?
|
69
|
+
|
70
|
+
# munge date/times to iso8601 format
|
71
|
+
params.each do |k, v|
|
72
|
+
if v.respond_to?(:iso8601)
|
73
|
+
params[k] = v.iso8601
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
uri.query = URI.encode_www_form(params)
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
def build_request(method, uri, body: nil, headers: {}, token: nil)
|
82
|
+
method_class = case method
|
83
|
+
when :get
|
84
|
+
Net::HTTP::Get
|
85
|
+
when :post
|
86
|
+
Net::HTTP::Post
|
87
|
+
end
|
88
|
+
method_class.new(uri.request_uri).tap { |r|
|
89
|
+
headers.each do |key, value|
|
90
|
+
r[key] = value
|
91
|
+
end
|
92
|
+
unless token.nil?
|
93
|
+
r.add_field "Authorization", token
|
94
|
+
end
|
95
|
+
|
96
|
+
if body.is_a? String
|
97
|
+
r.body = body
|
98
|
+
elsif !body.nil?
|
99
|
+
r.add_field "Content-Type", "application/json"
|
100
|
+
r.body = body.to_json
|
101
|
+
end
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
def http_start(uri, &block)
|
106
|
+
Response.new(Net::HTTP.start(uri.host, uri.port, http_opts, &block))
|
107
|
+
end
|
108
|
+
|
109
|
+
def http_opts
|
110
|
+
{ use_ssl: true }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Supai
|
2
|
+
class Authorization < Resource
|
3
|
+
ENDPOINT = "/api/authorization/v7/authorization"
|
4
|
+
|
5
|
+
attr_accessor :token, :secret, :user_id
|
6
|
+
|
7
|
+
def self.create(authorization)
|
8
|
+
api = API.new
|
9
|
+
response = api.request(:post, ENDPOINT, body: {}, token: authorization)
|
10
|
+
raise response.error unless response.success?
|
11
|
+
|
12
|
+
return self.new(response.json_body)
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(hash)
|
16
|
+
set_attributes(hash)
|
17
|
+
end
|
18
|
+
|
19
|
+
def authenticate_user(user_name:, password:, chain_id:)
|
20
|
+
endpoint = "/api/workbenchentry/v7/chains/#{chain_id}/authentication"
|
21
|
+
api = API.new
|
22
|
+
body = {
|
23
|
+
"SessionToken": token,
|
24
|
+
"UserName": user_name,
|
25
|
+
"Password": password,
|
26
|
+
}
|
27
|
+
response = api.request(:post, endpoint, body: body, token: secret)
|
28
|
+
raise response.error unless response.success?
|
29
|
+
|
30
|
+
return User.new(response.json_body["User"])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/supai/order.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Supai
|
2
|
+
class Order < Resource
|
3
|
+
attr_accessor :id, :fulfillment_type, :status
|
4
|
+
attr_timestamp_accessor :date_placed, :fulfillment_date
|
5
|
+
attr_objects billing_address: Address,
|
6
|
+
shipping_address: Address,
|
7
|
+
customer: Person
|
8
|
+
|
9
|
+
def self.endpoint(chain_id:, store_id:)
|
10
|
+
"/api/ordermanagement/v7/chains/#{chain_id}/stores/#{store_id}/orders"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.all(chain_id:, store_id:, params: {}, token:, api: API.new)
|
14
|
+
response = api.request(
|
15
|
+
:get,
|
16
|
+
endpoint(chain_id: chain_id, store_id: store_id),
|
17
|
+
params: params,
|
18
|
+
headers: { accept: "application/vnd.mywebgrocer.mgmt-orders+json" },
|
19
|
+
token: token,
|
20
|
+
)
|
21
|
+
raise response.error unless response.success?
|
22
|
+
|
23
|
+
OrdersResponse.new(response.json_body, chain_id, store_id, params)
|
24
|
+
end
|
25
|
+
|
26
|
+
# yields batches (no larger than batch_size) of orders fetched from the API
|
27
|
+
def self.all_in_batches(chain_id:, store_id:, params: {}, batch_size: 100, token:, api: API.new)
|
28
|
+
params[:take] = batch_size
|
29
|
+
params[:skip] = 0
|
30
|
+
response = all(chain_id: chain_id, store_id: store_id, params: params, token: token, api: api)
|
31
|
+
yield response
|
32
|
+
loop do
|
33
|
+
response = response.next(token: token, api: api)
|
34
|
+
break if response.nil?
|
35
|
+
|
36
|
+
yield response
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def initialize(hash)
|
41
|
+
set_attributes(hash)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Supai
|
4
|
+
class OrdersResponse < Resource
|
5
|
+
extend Forwardable
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
attr_accessor :total_orders
|
9
|
+
attr_collections orders: Order
|
10
|
+
|
11
|
+
def_delegators :orders, :each
|
12
|
+
|
13
|
+
def initialize(hash, chain_id, store_id, params)
|
14
|
+
set_attributes(hash)
|
15
|
+
@chain_id = chain_id
|
16
|
+
@store_id = store_id
|
17
|
+
@params = params
|
18
|
+
end
|
19
|
+
|
20
|
+
def params
|
21
|
+
@params
|
22
|
+
end
|
23
|
+
|
24
|
+
def next(token:, api: API.new)
|
25
|
+
skip = (@params[:skip] || 0) + count
|
26
|
+
return nil if skip >= total_orders
|
27
|
+
|
28
|
+
@params[:skip] = skip
|
29
|
+
Order.all(chain_id: @chain_id, store_id: @store_id, params: @params, token: token, api: api)
|
30
|
+
end
|
31
|
+
|
32
|
+
def inspect
|
33
|
+
"#<#{self.class} count: #{count}}>"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/supai/person.rb
ADDED
data/lib/supai/phone.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
module Supai
|
5
|
+
class Resource
|
6
|
+
def self.attributes
|
7
|
+
@json_attrs
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.attr_accessor(*attrs)
|
11
|
+
@json_attrs ||= []
|
12
|
+
@json_attrs += attrs
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.attr_objects(hash)
|
17
|
+
@json_attrs ||= []
|
18
|
+
hash.each do |name, klass|
|
19
|
+
@json_attrs << name
|
20
|
+
attr_reader(name)
|
21
|
+
define_method("#{name}=") { |obj|
|
22
|
+
instance_variable_set("@#{name}", parse_object(obj, klass))
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.attr_collections(hash)
|
28
|
+
@json_attrs ||= []
|
29
|
+
hash.each do |name, klass|
|
30
|
+
@json_attrs << name
|
31
|
+
attr_reader(name)
|
32
|
+
define_method("#{name}=") { |ary|
|
33
|
+
instance_variable_set("@#{name}", parse_collection(ary, klass))
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.attr_timestamp_accessor(*attrs)
|
39
|
+
@json_attrs ||= []
|
40
|
+
attrs.each do |name|
|
41
|
+
@json_attrs << name
|
42
|
+
attr_reader(name)
|
43
|
+
define_method("#{name}=") { |value|
|
44
|
+
instance_variable_set("@#{name}", parse_timestamp(value))
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def as_json
|
50
|
+
self.class.attributes.to_h { |attr|
|
51
|
+
value = send(attr)
|
52
|
+
json_value = case
|
53
|
+
when value.respond_to?(:as_json)
|
54
|
+
value.as_json
|
55
|
+
when value.is_a?(Array)
|
56
|
+
value.map(&:as_json)
|
57
|
+
else
|
58
|
+
value
|
59
|
+
end
|
60
|
+
[attr, json_value]
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def underscore(value)
|
65
|
+
return value unless /[A-Z-]/.match?(value)
|
66
|
+
word = value.to_s.gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
|
67
|
+
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
68
|
+
word.tr!("-", "_")
|
69
|
+
word.downcase!
|
70
|
+
word
|
71
|
+
end
|
72
|
+
|
73
|
+
def set_attribute(key, value)
|
74
|
+
setter = "#{underscore(key)}="
|
75
|
+
send(setter, value) if respond_to?(setter)
|
76
|
+
end
|
77
|
+
|
78
|
+
def set_attributes(hash)
|
79
|
+
hash.each do |key, value|
|
80
|
+
set_attribute(key, value)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def parse_collection(ary, klass)
|
85
|
+
ary.map { |obj|
|
86
|
+
parse_object(obj, klass)
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
def parse_object(obj, klass)
|
91
|
+
if obj.is_a?(klass)
|
92
|
+
obj
|
93
|
+
else
|
94
|
+
klass.new(obj)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def parse_timestamp(value)
|
99
|
+
return nil if value.nil?
|
100
|
+
|
101
|
+
if value.is_a? Time
|
102
|
+
value
|
103
|
+
else
|
104
|
+
Time.parse(value)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def inspect
|
109
|
+
"#<#{self.class} #{[@id, @name || @display_name].compact.join(" ")}>"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Supai
|
2
|
+
class UnitedPickupOrderReport < Resource
|
3
|
+
attr_accessor :id, :status, :items_quantity, :totes_quantity, :special_instructions
|
4
|
+
attr_objects shopper_name: Person,
|
5
|
+
shipping_address: Address,
|
6
|
+
pickup_window: PickupWindow
|
7
|
+
|
8
|
+
def self.endpoint(chain_id:, store_id:, order_id:)
|
9
|
+
"/api/ordermanagement/v7/chains/#{chain_id}/stores/#{store_id}/orders/#{order_id}/unitedpickuporderreport"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.get(chain_id:, store_id:, order_id:, params: {}, token:, api: API.new)
|
13
|
+
response = api.request(
|
14
|
+
:get,
|
15
|
+
endpoint(chain_id: chain_id, store_id: store_id, order_id: order_id),
|
16
|
+
params: params,
|
17
|
+
headers: { accept: "application/vnd.mywebgrocer.mgmt-united-order-report+json" },
|
18
|
+
token: token,
|
19
|
+
api: api,
|
20
|
+
)
|
21
|
+
raise response.error unless response.success?
|
22
|
+
|
23
|
+
UnitedPickupOrderReport.new(response.json_body)
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(hash)
|
27
|
+
set_attributes(hash)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/supai/user.rb
ADDED
data/lib/supai.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "supai/version"
|
2
|
+
|
3
|
+
module Supai
|
4
|
+
class Error < StandardError; end
|
5
|
+
# Your code goes here...
|
6
|
+
end
|
7
|
+
|
8
|
+
require "supai/resource"
|
9
|
+
require "supai/api"
|
10
|
+
require "supai/user"
|
11
|
+
require "supai/authorization"
|
12
|
+
require "supai/phone"
|
13
|
+
require "supai/address"
|
14
|
+
require "supai/person"
|
15
|
+
require "supai/order"
|
16
|
+
require "supai/orders_response"
|
17
|
+
require "supai/pickup_window"
|
18
|
+
require "supai/united_pickup_order_report"
|
data/supai.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 "supai/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "supai"
|
7
|
+
spec.version = Supai::VERSION
|
8
|
+
spec.authors = ["Scott Yoder"]
|
9
|
+
spec.email = ["syoder@radiusnetworks.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{A gem for accessing the MyWebGrocer/Mi9 API}
|
12
|
+
spec.description = %q{A gem for accessing the MyWebGrocer/Mi9 API}
|
13
|
+
spec.homepage = "https://github.com/RadiusNetworks/supai"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/RadiusNetworks/supai"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/RadiusNetworks/supai"
|
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", "~> 13.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: supai
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Yoder
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-17 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: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.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 the MyWebGrocer/Mi9 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/supai.rb
|
75
|
+
- lib/supai/address.rb
|
76
|
+
- lib/supai/api.rb
|
77
|
+
- lib/supai/authorization.rb
|
78
|
+
- lib/supai/customer.rb
|
79
|
+
- lib/supai/order.rb
|
80
|
+
- lib/supai/orders_response.rb
|
81
|
+
- lib/supai/person.rb
|
82
|
+
- lib/supai/phone.rb
|
83
|
+
- lib/supai/pickup_window.rb
|
84
|
+
- lib/supai/resource.rb
|
85
|
+
- lib/supai/united_pickup_order_report.rb
|
86
|
+
- lib/supai/user.rb
|
87
|
+
- lib/supai/version.rb
|
88
|
+
- supai.gemspec
|
89
|
+
homepage: https://github.com/RadiusNetworks/supai
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata:
|
93
|
+
homepage_uri: https://github.com/RadiusNetworks/supai
|
94
|
+
source_code_uri: https://github.com/RadiusNetworks/supai
|
95
|
+
changelog_uri: https://github.com/RadiusNetworks/supai
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubygems_version: 3.0.6
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: A gem for accessing the MyWebGrocer/Mi9 API
|
115
|
+
test_files: []
|