second_amendment_wholesale 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +42 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +60 -0
- data/LICENSE +21 -0
- data/README.md +3 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/second_amendment_wholesale/api.rb +70 -0
- data/lib/second_amendment_wholesale/attribute.rb +27 -0
- data/lib/second_amendment_wholesale/base.rb +26 -0
- data/lib/second_amendment_wholesale/catalog.rb +96 -0
- data/lib/second_amendment_wholesale/category.rb +56 -0
- data/lib/second_amendment_wholesale/error.rb +11 -0
- data/lib/second_amendment_wholesale/image.rb +24 -0
- data/lib/second_amendment_wholesale/inventory.rb +46 -0
- data/lib/second_amendment_wholesale/order.rb +140 -0
- data/lib/second_amendment_wholesale/response.rb +40 -0
- data/lib/second_amendment_wholesale/shipping.rb +24 -0
- data/lib/second_amendment_wholesale/user.rb +27 -0
- data/lib/second_amendment_wholesale/version.rb +3 -0
- data/lib/second_amendment_wholesale.rb +41 -0
- data/second_amendment_wholesale.gemspec +30 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4c6dc62dec7aaa29aa9f7d791e5b6e2193c2227b00132705c27da2cf6aefd286
|
4
|
+
data.tar.gz: 431681c04ff0ee903be3ea997ded67e2a7b5ffafec75292cff7202148ebf66d0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d42091bad047796546521ffd8f88b1ffc1c6f69f0b14a1213a5c806b742885e5000fa6220daca787e5544ca485a02774935874c9e2ea3696bb9c3b364ee58d3d
|
7
|
+
data.tar.gz: 4cf9df3bf699bcbeac456a651c24d04350f77aced813522bc61ff829dae91435a7eb40607049a7540d166ae0ec1aeea346b9b31fbebdfa947445be7bca2d42e7
|
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
# Ruby CircleCI 2.0 configuration file
|
4
|
+
#
|
5
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
6
|
+
#
|
7
|
+
version: 2
|
8
|
+
jobs:
|
9
|
+
build:
|
10
|
+
docker:
|
11
|
+
# specify the version you desire here
|
12
|
+
- image: circleci/ruby:2.6.6-node-browsers
|
13
|
+
|
14
|
+
working_directory: ~/repo
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- checkout
|
18
|
+
|
19
|
+
# Download and cache dependencies
|
20
|
+
- restore_cache:
|
21
|
+
keys:
|
22
|
+
- v1-dependencies-{{ checksum "second_amendment_wholesale.gemspec" }}
|
23
|
+
# fallback to using the latest cache if no exact match is found
|
24
|
+
- v1-dependencies-
|
25
|
+
|
26
|
+
- run:
|
27
|
+
name: install dependencies
|
28
|
+
command: |
|
29
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
30
|
+
- save_cache:
|
31
|
+
paths:
|
32
|
+
- ./vendor/bundle
|
33
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
34
|
+
|
35
|
+
# run tests!
|
36
|
+
- run:
|
37
|
+
name: run tests
|
38
|
+
command: |
|
39
|
+
mkdir /tmp/test-results
|
40
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
|
41
|
+
|
42
|
+
bundle exec rspec --format documentation $TEST_FILES
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
second_amendment_wholesale
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.6
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
second_amendment_wholesale (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (5.2.8.1)
|
10
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
+
i18n (>= 0.7, < 2)
|
12
|
+
minitest (~> 5.1)
|
13
|
+
tzinfo (~> 1.1)
|
14
|
+
addressable (2.8.1)
|
15
|
+
public_suffix (>= 2.0.2, < 6.0)
|
16
|
+
concurrent-ruby (1.2.0)
|
17
|
+
crack (0.4.5)
|
18
|
+
rexml
|
19
|
+
diff-lcs (1.5.0)
|
20
|
+
hashdiff (1.0.1)
|
21
|
+
i18n (1.12.0)
|
22
|
+
concurrent-ruby (~> 1.0)
|
23
|
+
minitest (5.17.0)
|
24
|
+
public_suffix (5.0.1)
|
25
|
+
rake (10.5.0)
|
26
|
+
rexml (3.2.5)
|
27
|
+
rspec (3.12.0)
|
28
|
+
rspec-core (~> 3.12.0)
|
29
|
+
rspec-expectations (~> 3.12.0)
|
30
|
+
rspec-mocks (~> 3.12.0)
|
31
|
+
rspec-core (3.12.1)
|
32
|
+
rspec-support (~> 3.12.0)
|
33
|
+
rspec-expectations (3.12.2)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.12.0)
|
36
|
+
rspec-mocks (3.12.3)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.12.0)
|
39
|
+
rspec-support (3.12.0)
|
40
|
+
thread_safe (0.3.6)
|
41
|
+
tzinfo (1.2.11)
|
42
|
+
thread_safe (~> 0.1)
|
43
|
+
webmock (2.3.2)
|
44
|
+
addressable (>= 2.3.6)
|
45
|
+
crack (>= 0.3.2)
|
46
|
+
hashdiff
|
47
|
+
|
48
|
+
PLATFORMS
|
49
|
+
ruby
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
activesupport (~> 5)
|
53
|
+
bundler (~> 1.17)
|
54
|
+
rake (~> 10.0)
|
55
|
+
rspec (~> 3.0)
|
56
|
+
second_amendment_wholesale!
|
57
|
+
webmock (~> 2.3)
|
58
|
+
|
59
|
+
BUNDLED WITH
|
60
|
+
1.17.2
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 AmmoReady.com
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "second_amendment_wholesale"
|
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/setup
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module SecondAmendmentWholesale
|
4
|
+
module API
|
5
|
+
|
6
|
+
ROOT_API_URL = 'https://staging.2ndamendmentwholesale.com/rest/V1'.freeze
|
7
|
+
|
8
|
+
def get_request(endpoint, headers = {})
|
9
|
+
request = Net::HTTP::Get.new(request_url(endpoint))
|
10
|
+
|
11
|
+
submit_request(request, {}, headers)
|
12
|
+
end
|
13
|
+
|
14
|
+
def post_request(endpoint, data = {}, headers = {})
|
15
|
+
request = Net::HTTP::Post.new(request_url(endpoint))
|
16
|
+
|
17
|
+
submit_request(request, data, headers)
|
18
|
+
end
|
19
|
+
|
20
|
+
def put_request(endpoint, data = {}, headers = {})
|
21
|
+
request = Net::HTTP::Put.new(request_url(endpoint))
|
22
|
+
|
23
|
+
submit_request(request, data, headers)
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete_request(endpoint, headers = {})
|
27
|
+
request = Net::HTTP::Delete.new(request_url(endpoint))
|
28
|
+
|
29
|
+
submit_request(request, {}, headers)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def submit_request(request, data, headers)
|
35
|
+
set_request_headers(request, headers)
|
36
|
+
|
37
|
+
request.body = data.is_a?(Hash) ? data.to_json : data
|
38
|
+
|
39
|
+
process_request(request)
|
40
|
+
end
|
41
|
+
|
42
|
+
def process_request(request)
|
43
|
+
uri = URI(request.path)
|
44
|
+
|
45
|
+
response = Net::HTTP.start(uri.host, uri.port, SecondAmendmentWholesale.config.proxy_address, SecondAmendmentWholesale.config.proxy_port, use_ssl: true) do |http|
|
46
|
+
http.request(request)
|
47
|
+
end
|
48
|
+
|
49
|
+
SecondAmendmentWholesale::Response.new(response)
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_request_headers(request, headers)
|
53
|
+
request['User-Agent'] = SecondAmendmentWholesale.config.user_agent
|
54
|
+
|
55
|
+
headers.each { |header, value| request[header] = value }
|
56
|
+
end
|
57
|
+
|
58
|
+
def auth_header(token)
|
59
|
+
{ 'Authorization' => "Bearer #{token}" }
|
60
|
+
end
|
61
|
+
|
62
|
+
def content_type_header(type)
|
63
|
+
{ 'Content-Type' => type }
|
64
|
+
end
|
65
|
+
|
66
|
+
def request_url(endpoint)
|
67
|
+
[ROOT_API_URL, endpoint].join('/')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module SecondAmendmentWholesale
|
2
|
+
class Attribute < Base
|
3
|
+
|
4
|
+
include SecondAmendmentWholesale::API
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
requires!(options, :token)
|
8
|
+
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.all(options = {})
|
13
|
+
requires!(options, :token)
|
14
|
+
|
15
|
+
new(options).all
|
16
|
+
end
|
17
|
+
|
18
|
+
def all
|
19
|
+
headers = [
|
20
|
+
*auth_header(@options[:token]),
|
21
|
+
*content_type_header('application/json'),
|
22
|
+
].to_h
|
23
|
+
|
24
|
+
get_request('feed/attributes', headers).body
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SecondAmendmentWholesale
|
2
|
+
class Base
|
3
|
+
|
4
|
+
protected
|
5
|
+
|
6
|
+
def requires!(*args)
|
7
|
+
self.class.requires!(*args)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.requires!(hash, *params)
|
11
|
+
hash_keys = hash.collect { |k, v| v.is_a?(Array) ? [k, v.collect(&:keys)] : k }.flatten
|
12
|
+
|
13
|
+
params.each do |param|
|
14
|
+
if param.is_a?(Array)
|
15
|
+
raise ArgumentError.new("Missing required parameter: #{param.first}") unless hash_keys.include?(param.first)
|
16
|
+
|
17
|
+
valid_options = param[1..-1]
|
18
|
+
raise ArgumentError.new("Parameter: #{param.first} must be one of: #{valid_options.join(', ')}") unless valid_options.include?(hash[param.first])
|
19
|
+
else
|
20
|
+
raise ArgumentError.new("Missing required parameter: #{param}") unless hash_keys.include?(param)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module SecondAmendmentWholesale
|
2
|
+
class Catalog < Base
|
3
|
+
|
4
|
+
include SecondAmendmentWholesale::API
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
requires!(options, :token)
|
8
|
+
|
9
|
+
@options = options
|
10
|
+
@headers = [
|
11
|
+
*auth_header(@options[:token]),
|
12
|
+
*content_type_header('application/json'),
|
13
|
+
].to_h
|
14
|
+
|
15
|
+
@categories = SecondAmendmentWholesale::Category.all(@options)
|
16
|
+
@attributes = SecondAmendmentWholesale::Attribute.all(@options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.all(options = {})
|
20
|
+
requires!(options, :token)
|
21
|
+
|
22
|
+
new(options).all
|
23
|
+
end
|
24
|
+
|
25
|
+
def all
|
26
|
+
products = []
|
27
|
+
|
28
|
+
response = get_request("feed/productV2", @headers)
|
29
|
+
|
30
|
+
response.body.each do |item|
|
31
|
+
products << map_product(item) unless item[:allocated_closeout] == "Allocated"
|
32
|
+
end
|
33
|
+
|
34
|
+
products
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def map_product(item)
|
40
|
+
{
|
41
|
+
name: item[:product_description],
|
42
|
+
model: item[:model],
|
43
|
+
upc: item[:upc],
|
44
|
+
long_description: item[:description],
|
45
|
+
short_description: item[:product_description],
|
46
|
+
category: get_category(item[:category_ids]),
|
47
|
+
price: item[:dealer_price],
|
48
|
+
map_price: item[:retail_map],
|
49
|
+
msrp: item[:retail_price],
|
50
|
+
quantity: item[:inventory_qty],
|
51
|
+
weight: item[:weight],
|
52
|
+
item_identifier: item[:stock_number],
|
53
|
+
brand: item[:manufacturer_name],
|
54
|
+
mfg_number: item[:mpn],
|
55
|
+
features: get_features(item[:stock_number]),
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_category(category_ids)
|
60
|
+
categories = []
|
61
|
+
|
62
|
+
category_ids.each do |category_id|
|
63
|
+
categories << @categories.find { |category| category[:id] == category_id.to_i }
|
64
|
+
end
|
65
|
+
|
66
|
+
categories.compact.pluck(:name).join(" ")
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_features(sku)
|
70
|
+
attributes = @attributes.find{ |attribute| attribute[:sku] == sku }
|
71
|
+
|
72
|
+
{
|
73
|
+
caliber: attributes[:caliber1],
|
74
|
+
action: attributes[:action_type],
|
75
|
+
barrel_type: attributes[:barrel_type],
|
76
|
+
barrel_length: attributes[:barrel_length],
|
77
|
+
capacity: attributes[:capacity],
|
78
|
+
finish: attributes[:finish_color],
|
79
|
+
length: attributes[:size],
|
80
|
+
frame: attributes[:frame_material],
|
81
|
+
safety: attributes[:safety],
|
82
|
+
sights: attributes[:sights],
|
83
|
+
stock_frame_grips: attributes[:stockFrameGrips],
|
84
|
+
magazine: attributes[:magazine],
|
85
|
+
chamber: attributes[:chamber],
|
86
|
+
casing: attributes[:finish_color],
|
87
|
+
feet_per_second: attributes[:feet_per_second],
|
88
|
+
grain: attributes[:grain_weight],
|
89
|
+
hand: attributes[:left],
|
90
|
+
model: attributes[:model1],
|
91
|
+
units_per_box: attributes[:units_per_box],
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module SecondAmendmentWholesale
|
2
|
+
class Category < Base
|
3
|
+
|
4
|
+
include SecondAmendmentWholesale::API
|
5
|
+
|
6
|
+
#Excludes brands and other non-categories returned from 2AW's Categories endpoint
|
7
|
+
EXCLUDED_CATEGORY_IDS = [3, 26, 27]
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
requires!(options, :token)
|
11
|
+
|
12
|
+
@options = options
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.all(options = {})
|
16
|
+
requires!(options, :token)
|
17
|
+
|
18
|
+
new(options).all
|
19
|
+
end
|
20
|
+
|
21
|
+
def all
|
22
|
+
headers = [
|
23
|
+
*auth_header(@options[:token]),
|
24
|
+
*content_type_header('application/json'),
|
25
|
+
].to_h
|
26
|
+
|
27
|
+
response = get_request('categories', headers)
|
28
|
+
|
29
|
+
extract_categories(response.body[:children_data])
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
def extract_categories(response, categories = [])
|
35
|
+
response.each do |category|
|
36
|
+
unless EXCLUDED_CATEGORY_IDS.include?(category[:id])
|
37
|
+
categories << map_hash(category) unless category[:name] == "Firearms"
|
38
|
+
|
39
|
+
if category[:children_data].present?
|
40
|
+
extract_categories(category[:children_data], categories)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
categories
|
46
|
+
end
|
47
|
+
|
48
|
+
def map_hash(hash)
|
49
|
+
{
|
50
|
+
id: hash[:id],
|
51
|
+
name: hash[:name],
|
52
|
+
parent_id: hash[:parent_id],
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module SecondAmendmentWholesale
|
2
|
+
class Error < StandardError
|
3
|
+
|
4
|
+
class BadRequest < SecondAmendmentWholesale::Error; end
|
5
|
+
class NotAuthorized < SecondAmendmentWholesale::Error; end
|
6
|
+
class NotFound < SecondAmendmentWholesale::Error; end
|
7
|
+
class RequestError < SecondAmendmentWholesale::Error; end
|
8
|
+
class TimeoutError < SecondAmendmentWholesale::Error; end
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SecondAmendmentWholesale
|
2
|
+
class Image < Base
|
3
|
+
|
4
|
+
include SecondAmendmentWholesale::API
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
requires!(options, :token)
|
8
|
+
@options = options
|
9
|
+
|
10
|
+
@headers = [
|
11
|
+
*auth_header(@options[:token]),
|
12
|
+
*content_type_header('application/json'),
|
13
|
+
].to_h
|
14
|
+
end
|
15
|
+
|
16
|
+
def url(item_number)
|
17
|
+
response = get_request("products/#{item_number}/media", @headers).body
|
18
|
+
|
19
|
+
return response.first[:file] if response.present?
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module SecondAmendmentWholesale
|
2
|
+
class Inventory < Base
|
3
|
+
|
4
|
+
include SecondAmendmentWholesale::API
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
requires!(options, :token)
|
8
|
+
|
9
|
+
@options = options
|
10
|
+
@headers = [
|
11
|
+
*auth_header(@options[:token]),
|
12
|
+
*content_type_header('application/json'),
|
13
|
+
].to_h
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.all(options = {})
|
17
|
+
requires!(options, :token)
|
18
|
+
|
19
|
+
new(options).all
|
20
|
+
end
|
21
|
+
class << self; alias_method :quantity, :all; end
|
22
|
+
|
23
|
+
def all
|
24
|
+
items = []
|
25
|
+
|
26
|
+
response = get_request("feed/stockV2", @headers)
|
27
|
+
|
28
|
+
response.body.each do |item|
|
29
|
+
items << map_hash(item)
|
30
|
+
end
|
31
|
+
|
32
|
+
items
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def map_hash(item)
|
38
|
+
{
|
39
|
+
item_identifier: item[:sku],
|
40
|
+
quantity: item[:qty],
|
41
|
+
price: item[:dealer_price],
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
module SecondAmendmentWholesale
|
2
|
+
class Order < Base
|
3
|
+
|
4
|
+
include SecondAmendmentWholesale::API
|
5
|
+
|
6
|
+
ENDPOINTS = {
|
7
|
+
billing_address: 'customers/me/billingAddress'.freeze,
|
8
|
+
cart: 'carts/mine'.freeze,
|
9
|
+
customer_note: 'carts/mine/set-customer-note'.freeze,
|
10
|
+
items: 'carts/mine/items'.freeze,
|
11
|
+
licence: "carts/licence".freeze,
|
12
|
+
payment_information: 'carts/mine/payment-information'.freeze,
|
13
|
+
po_number: 'carts/mine/set-po-number'.freeze,
|
14
|
+
regions: 'directory/countries/US'.freeze,
|
15
|
+
shipping_information: 'carts/mine/shipping-information'.freeze,
|
16
|
+
shipping_methods: 'carts/mine/estimate-shipping-methods'.freeze,
|
17
|
+
}
|
18
|
+
|
19
|
+
def initialize(options = {})
|
20
|
+
requires!(options, :token)
|
21
|
+
|
22
|
+
@options = options
|
23
|
+
@headers = [
|
24
|
+
*auth_header(@options[:token]),
|
25
|
+
*content_type_header('application/json'),
|
26
|
+
].to_h
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_cart
|
30
|
+
endpoint = ENDPOINTS[:cart]
|
31
|
+
|
32
|
+
get_request(endpoint, @headers)
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_cart
|
36
|
+
endpoint = ENDPOINTS[:cart]
|
37
|
+
|
38
|
+
post_request(endpoint, {}, @headers)
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete_cart_items(cart_items)
|
42
|
+
responses = []
|
43
|
+
|
44
|
+
cart_items.each do |item|
|
45
|
+
responses << delete_request([ENDPOINTS[:items], item[:item_id]].join("/"), @headers).body
|
46
|
+
end
|
47
|
+
|
48
|
+
responses.all?
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_cart_item(item)
|
52
|
+
endpoint = ENDPOINTS[:items]
|
53
|
+
|
54
|
+
post_request(endpoint, item, @headers)
|
55
|
+
end
|
56
|
+
|
57
|
+
def add_po_number(po_number, quote_id)
|
58
|
+
endpoint = ENDPOINTS[:po_number]
|
59
|
+
|
60
|
+
body = {
|
61
|
+
"cartId": "#{quote_id}",
|
62
|
+
"poNumber": {
|
63
|
+
"poNumber": "#{po_number}"
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
put_request(endpoint, body, @headers)
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_regions
|
71
|
+
endpoint = ENDPOINTS[:regions]
|
72
|
+
|
73
|
+
get_request(endpoint, @headers)[:available_regions]
|
74
|
+
end
|
75
|
+
|
76
|
+
def get_shipping_methods(address)
|
77
|
+
endpoint = ENDPOINTS[:shipping_methods]
|
78
|
+
|
79
|
+
body = {
|
80
|
+
"address": address
|
81
|
+
}
|
82
|
+
|
83
|
+
post_request(endpoint, body, @headers)
|
84
|
+
end
|
85
|
+
|
86
|
+
def get_billing_address
|
87
|
+
endpoint = ENDPOINTS[:billing_address]
|
88
|
+
|
89
|
+
get_request(endpoint, @headers)
|
90
|
+
end
|
91
|
+
|
92
|
+
def add_shipping_information(address_info)
|
93
|
+
endpoint = ENDPOINTS[:shipping_information]
|
94
|
+
|
95
|
+
body = {
|
96
|
+
"address_information": address_info
|
97
|
+
}
|
98
|
+
|
99
|
+
post_request(endpoint, body, @headers)
|
100
|
+
end
|
101
|
+
|
102
|
+
def submit_payment(payment_method)
|
103
|
+
endpoint = ENDPOINTS[:payment_information]
|
104
|
+
|
105
|
+
body = {
|
106
|
+
"payment_method": {
|
107
|
+
"method": payment_method,
|
108
|
+
"extension_attributes": {
|
109
|
+
"agreement_ids": get_agreement_ids
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
post_request(endpoint, body, @headers)
|
115
|
+
end
|
116
|
+
|
117
|
+
def get_increment_id(order_id)
|
118
|
+
get_request("orders/#{order_id}", @headers)
|
119
|
+
end
|
120
|
+
|
121
|
+
def add_customer_note(customer_note)
|
122
|
+
body = {
|
123
|
+
"customerNote": {
|
124
|
+
"customer_note": customer_note
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
put_request(ENDPOINTS[:customer_note], body, @headers)
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def get_agreement_ids
|
134
|
+
endpoint = ENDPOINTS[:licence]
|
135
|
+
|
136
|
+
get_request(endpoint, @headers).body.pluck(:agreement_id)
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module SecondAmendmentWholesale
|
2
|
+
class Response
|
3
|
+
|
4
|
+
def initialize(response)
|
5
|
+
@response = response
|
6
|
+
|
7
|
+
case @response
|
8
|
+
when Net::HTTPUnauthorized
|
9
|
+
raise SecondAmendmentWholesale::Error::NotAuthorized.new(@response.body)
|
10
|
+
when Net::HTTPNotFound
|
11
|
+
raise SecondAmendmentWholesale::Error::NotFound.new(@response.body)
|
12
|
+
when Net::HTTPBadRequest
|
13
|
+
raise SecondAmendmentWholesale::Error::BadRequest.new(@response.body)
|
14
|
+
when Net::HTTPOK, Net::HTTPSuccess
|
15
|
+
_data = (JSON.parse(@response.body) if @response.body.present?)
|
16
|
+
|
17
|
+
@data = case
|
18
|
+
when _data.is_a?(Hash)
|
19
|
+
_data.deep_symbolize_keys
|
20
|
+
when _data.is_a?(Array)
|
21
|
+
_data.map(&:deep_symbolize_keys)
|
22
|
+
else
|
23
|
+
_data
|
24
|
+
end
|
25
|
+
else
|
26
|
+
raise SecondAmendmentWholesale::Error::RequestError.new(@response.body)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](key)
|
32
|
+
@data&.[](key)
|
33
|
+
end
|
34
|
+
|
35
|
+
def body
|
36
|
+
@data
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SecondAmendmentWholesale
|
2
|
+
class Shipping < Base
|
3
|
+
|
4
|
+
include SecondAmendmentWholesale::API
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
requires!(options, :token)
|
8
|
+
|
9
|
+
@options = options
|
10
|
+
@headers = [
|
11
|
+
*auth_header(@options[:token]),
|
12
|
+
*content_type_header('application/json'),
|
13
|
+
].to_h
|
14
|
+
end
|
15
|
+
|
16
|
+
def fetch(since_date = nil)
|
17
|
+
since_date = (since_date || Time.now.prev_day).strftime('%Y/%m/%d')
|
18
|
+
endpoint = "shipmentsInformation/me?fromShipmentCreateAt=#{since_date}"
|
19
|
+
|
20
|
+
orders = get_request(endpoint, @headers)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module SecondAmendmentWholesale
|
2
|
+
class User < Base
|
3
|
+
|
4
|
+
include SecondAmendmentWholesale::API
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
requires!(options, :token)
|
8
|
+
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def authenticated?
|
13
|
+
headers = [
|
14
|
+
*auth_header(@options[:token]),
|
15
|
+
*content_type_header('application/json'),
|
16
|
+
].to_h
|
17
|
+
|
18
|
+
response = get_request(
|
19
|
+
'token/validate',
|
20
|
+
headers
|
21
|
+
)
|
22
|
+
|
23
|
+
response.body.present?
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "second_amendment_wholesale/base"
|
2
|
+
require "second_amendment_wholesale/version"
|
3
|
+
|
4
|
+
require "second_amendment_wholesale/api"
|
5
|
+
require "second_amendment_wholesale/attribute"
|
6
|
+
require "second_amendment_wholesale/catalog"
|
7
|
+
require "second_amendment_wholesale/category"
|
8
|
+
require "second_amendment_wholesale/error"
|
9
|
+
require "second_amendment_wholesale/image"
|
10
|
+
require "second_amendment_wholesale/inventory"
|
11
|
+
require "second_amendment_wholesale/order"
|
12
|
+
require "second_amendment_wholesale/response"
|
13
|
+
require "second_amendment_wholesale/shipping"
|
14
|
+
require "second_amendment_wholesale/user"
|
15
|
+
|
16
|
+
module SecondAmendmentWholesale
|
17
|
+
|
18
|
+
class << self
|
19
|
+
attr_accessor :config
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.config
|
23
|
+
@config ||= Configuration.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.configure
|
27
|
+
yield(config)
|
28
|
+
end
|
29
|
+
|
30
|
+
class Configuration
|
31
|
+
attr_accessor :proxy_address
|
32
|
+
attr_accessor :proxy_port
|
33
|
+
attr_accessor :user_agent
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
@proxy_address ||= nil
|
37
|
+
@proxy_port ||= nil
|
38
|
+
@user_agent ||= "SecondAmendmentWholesaleRubyGem/#{SecondAmendmentWholesale::VERSION}".freeze
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require "second_amendment_wholesale/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "second_amendment_wholesale"
|
8
|
+
spec.version = SecondAmendmentWholesale::VERSION
|
9
|
+
spec.authors = ["Kevin Brown"]
|
10
|
+
spec.email = ["brownkm531@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby library for 2nd Amendment Wholesale's API.}
|
13
|
+
spec.description = %q{}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "activesupport", "~> 5"
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
spec.add_development_dependency "webmock", "~> 2.3"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: second_amendment_wholesale
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin Brown
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-08-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.17'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.17'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.3'
|
83
|
+
description: ''
|
84
|
+
email:
|
85
|
+
- brownkm531@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".circleci/config.yml"
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".ruby-gemset"
|
94
|
+
- ".ruby-version"
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- lib/second_amendment_wholesale.rb
|
103
|
+
- lib/second_amendment_wholesale/api.rb
|
104
|
+
- lib/second_amendment_wholesale/attribute.rb
|
105
|
+
- lib/second_amendment_wholesale/base.rb
|
106
|
+
- lib/second_amendment_wholesale/catalog.rb
|
107
|
+
- lib/second_amendment_wholesale/category.rb
|
108
|
+
- lib/second_amendment_wholesale/error.rb
|
109
|
+
- lib/second_amendment_wholesale/image.rb
|
110
|
+
- lib/second_amendment_wholesale/inventory.rb
|
111
|
+
- lib/second_amendment_wholesale/order.rb
|
112
|
+
- lib/second_amendment_wholesale/response.rb
|
113
|
+
- lib/second_amendment_wholesale/shipping.rb
|
114
|
+
- lib/second_amendment_wholesale/user.rb
|
115
|
+
- lib/second_amendment_wholesale/version.rb
|
116
|
+
- second_amendment_wholesale.gemspec
|
117
|
+
homepage: ''
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubygems_version: 3.4.6
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Ruby library for 2nd Amendment Wholesale's API.
|
140
|
+
test_files: []
|