silencer_shop 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/.gitignore +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +34 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/silencer_shop.rb +39 -0
- data/lib/silencer_shop/api.rb +123 -0
- data/lib/silencer_shop/base.rb +26 -0
- data/lib/silencer_shop/catalog.rb +55 -0
- data/lib/silencer_shop/client.rb +57 -0
- data/lib/silencer_shop/dealer.rb +25 -0
- data/lib/silencer_shop/error.rb +11 -0
- data/lib/silencer_shop/inventory.rb +32 -0
- data/lib/silencer_shop/order.rb +58 -0
- data/lib/silencer_shop/product_feed.rb +26 -0
- data/lib/silencer_shop/response.rb +45 -0
- data/lib/silencer_shop/user.rb +15 -0
- data/lib/silencer_shop/version.rb +3 -0
- data/silencer_shop.gemspec +30 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0fb38ed07576442bf645ab679d4b0faa38f2de8ed7fcee2bb06ec7f948f82058
|
4
|
+
data.tar.gz: 498e71ac8fb336bafd44c76b3e6efff98029675b210fe5e730398719becdbd1e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 457c9c8bf80466b5e470bed00b1208bb9f1adb974776ed78c624e44d201c6bb0f9bc219b312c8e019232df2b65fe5639133095b8471f361a19c12516f4c3c1cd
|
7
|
+
data.tar.gz: 22a8ea41b9da4ba5adb06f85eb4366fb5c18393e50e87a8582c714749a6ea6a4dec49bc45c1fbe033e9285af099401c6f782eaccd0d2a8914002b0623ef10043
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.DS_Store
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Jeffrey Dill
|
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,34 @@
|
|
1
|
+
# Silencer Shop
|
2
|
+
|
3
|
+
Ruby library for Silencer Shop API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'silencer_shop'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install silencer_shop
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
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.
|
24
|
+
|
25
|
+
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).
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ammoready/silencer_shop.
|
30
|
+
|
31
|
+
|
32
|
+
## License
|
33
|
+
|
34
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "silencer_shop"
|
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
|
data/bin/setup
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'silencer_shop/base'
|
2
|
+
require 'silencer_shop/version'
|
3
|
+
|
4
|
+
require 'silencer_shop/api'
|
5
|
+
require 'silencer_shop/catalog'
|
6
|
+
require 'silencer_shop/client'
|
7
|
+
require 'silencer_shop/dealer'
|
8
|
+
require 'silencer_shop/error'
|
9
|
+
require 'silencer_shop/inventory'
|
10
|
+
require 'silencer_shop/order'
|
11
|
+
require 'silencer_shop/product_feed'
|
12
|
+
require 'silencer_shop/response'
|
13
|
+
require 'silencer_shop/user'
|
14
|
+
|
15
|
+
module SilencerShop
|
16
|
+
|
17
|
+
class << self
|
18
|
+
attr_accessor :config
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.config
|
22
|
+
@config ||= Configuration.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.configure
|
26
|
+
yield(config)
|
27
|
+
end
|
28
|
+
|
29
|
+
class Configuration
|
30
|
+
attr_accessor :proxy_address
|
31
|
+
attr_accessor :proxy_port
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
@proxy_address ||= nil
|
35
|
+
@proxy_port ||= nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module SilencerShop
|
4
|
+
module API
|
5
|
+
|
6
|
+
ROOT_API_URL = 'https://silencershopportaldebug.azurewebsites.net/api'.freeze
|
7
|
+
USER_AGENT = "SilencerShopRubyGem/#{SilencerShop::VERSION}".freeze
|
8
|
+
|
9
|
+
FILE_UPLOAD_ATTRS = {
|
10
|
+
permitted: %i( file_name file_type file_contents ).freeze,
|
11
|
+
reqired: %i( file_type file_contents ).freeze,
|
12
|
+
}
|
13
|
+
|
14
|
+
def get_request(endpoint, headers = {}, root_url = nil)
|
15
|
+
request = Net::HTTP::Get.new(request_url(endpoint, root_url))
|
16
|
+
|
17
|
+
submit_request(request, {}, headers)
|
18
|
+
end
|
19
|
+
|
20
|
+
def post_request(endpoint, data = {}, headers = {}, root_url = nil)
|
21
|
+
request = Net::HTTP::Post.new(request_url(endpoint, root_url))
|
22
|
+
|
23
|
+
submit_request(request, data, headers)
|
24
|
+
end
|
25
|
+
|
26
|
+
def post_file_request(endpoint, file_data, headers = {}, root_url = nil)
|
27
|
+
request = Net::HTTP::Post.new(request_url(endpoint, root_url))
|
28
|
+
|
29
|
+
submit_file_request(request, file_data, 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 submit_file_request(request, file_data, headers)
|
43
|
+
boundary = ::SecureRandom.hex(15)
|
44
|
+
|
45
|
+
headers.merge!(content_type_header("multipart/form-data; boundary=#{boundary}"))
|
46
|
+
|
47
|
+
build_multipart_request_body(request, file_data, boundary)
|
48
|
+
set_request_headers(request, headers)
|
49
|
+
process_request(request)
|
50
|
+
end
|
51
|
+
|
52
|
+
def process_request(request)
|
53
|
+
uri = URI(request.path)
|
54
|
+
|
55
|
+
response = Net::HTTP.start(uri.host, uri.port, SilencerShop.config.proxy_address, SilencerShop.config.proxy_port, use_ssl: true) do |http|
|
56
|
+
http.request(request)
|
57
|
+
end
|
58
|
+
|
59
|
+
SilencerShop::Response.new(response)
|
60
|
+
end
|
61
|
+
|
62
|
+
def build_multipart_request_body(request, file_data, boundary)
|
63
|
+
file_type = file_data[:file_type]
|
64
|
+
file_contents = file_data[:file_contents]
|
65
|
+
file_name = file_data[:file_name] || "ffl-document.#{file_type}"
|
66
|
+
content_type = "application/#{file_data[:file_type]}"
|
67
|
+
|
68
|
+
body = []
|
69
|
+
body << "--#{boundary}\r\n"
|
70
|
+
body << "Content-Disposition: form-data; name=\"file\"; filename=\"#{file_name}\"\r\n"
|
71
|
+
body << "Content-Type: #{content_type}\r\n"
|
72
|
+
body << "\r\n"
|
73
|
+
body << "#{file_contents}\r\n"
|
74
|
+
body << "--#{boundary}--\r\n"
|
75
|
+
|
76
|
+
request.body = body.join
|
77
|
+
end
|
78
|
+
|
79
|
+
def set_request_headers(request, headers)
|
80
|
+
request['User-Agent'] = USER_AGENT
|
81
|
+
|
82
|
+
headers.each { |header, value| request[header] = value }
|
83
|
+
end
|
84
|
+
|
85
|
+
def auth_header(token)
|
86
|
+
{ 'Authorization' => "Bearer #{token}" }
|
87
|
+
end
|
88
|
+
|
89
|
+
def content_type_header(type)
|
90
|
+
{ 'Content-Type' => type }
|
91
|
+
end
|
92
|
+
|
93
|
+
def request_url(endpoint, root_url = nil)
|
94
|
+
root_url ||= ROOT_API_URL
|
95
|
+
|
96
|
+
[root_url, endpoint].join('/')
|
97
|
+
end
|
98
|
+
|
99
|
+
def standardize_body_data(submitted_data, permitted_data_attrs)
|
100
|
+
_submitted_data = submitted_data.deep_transform_keys(&:to_sym)
|
101
|
+
permitted_data = {}
|
102
|
+
|
103
|
+
_submitted_data.each do |k1, v1|
|
104
|
+
if permitted_data_attrs.include?(k1)
|
105
|
+
if v1.is_a?(Array)
|
106
|
+
permitted_data[k1] = []
|
107
|
+
|
108
|
+
v1.each do |sub_data|
|
109
|
+
permitted_sub_data = {}
|
110
|
+
sub_data.each { |k2, v2| permitted_sub_data[k2] = v2 if permitted_data_attrs.include?(k2) }
|
111
|
+
permitted_data[k1] << permitted_sub_data
|
112
|
+
end
|
113
|
+
else
|
114
|
+
permitted_data[k1] = v1
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
permitted_data.deep_transform_keys { |k| k.to_s.camelize(:lower) }
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SilencerShop
|
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,55 @@
|
|
1
|
+
module SilencerShop
|
2
|
+
class Catalog < Base
|
3
|
+
|
4
|
+
def initialize(options = {})
|
5
|
+
requires!(options, :username, :password)
|
6
|
+
|
7
|
+
@client = SilencerShop::Client.new(username: options[:username], password: options[:password])
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.all(options = {})
|
11
|
+
requires!(options, :username, :password)
|
12
|
+
|
13
|
+
new(options).all
|
14
|
+
end
|
15
|
+
|
16
|
+
def all
|
17
|
+
@client.product_feed.catalog.body.map { |item| map_hash(item) }
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def map_hash(item)
|
23
|
+
{
|
24
|
+
name: item[:ShortDescription],
|
25
|
+
model: item[:Model],
|
26
|
+
upc: item[:UniversalProductCode],
|
27
|
+
item_identifier: item[:DealerPartNumber],
|
28
|
+
long_description: item[:LongDescription],
|
29
|
+
short_description: item[:ShortDescription],
|
30
|
+
category: item[:CategoryCode],
|
31
|
+
price: item[:Price],
|
32
|
+
map_price: item[:MARP],
|
33
|
+
msrp: item[:MSRP],
|
34
|
+
quantity: item[:Quantity],
|
35
|
+
weight: item[:Weight],
|
36
|
+
brand: item[:Make],
|
37
|
+
mfg_number: item[:ManufacturerPartNumber],
|
38
|
+
features: {
|
39
|
+
length: item[:Length],
|
40
|
+
width: item[:Width],
|
41
|
+
height: item[:Height],
|
42
|
+
other_info: item[:OtherInfo],
|
43
|
+
firearm_type: item[:FirearmType],
|
44
|
+
allow_backorder: item[:AllowBackorder],
|
45
|
+
restrictions_info: item[:RestrictionsInfo],
|
46
|
+
size_info: item[:SizeInfo],
|
47
|
+
is_restricted: item[:IsRestricted],
|
48
|
+
dropship_ok: item[:DropShipOk],
|
49
|
+
image_name: item[:LargeImagePath].split('/')[-1]
|
50
|
+
}
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'silencer_shop/api'
|
2
|
+
require 'silencer_shop/dealer'
|
3
|
+
require 'silencer_shop/order'
|
4
|
+
require 'silencer_shop/product_feed'
|
5
|
+
|
6
|
+
module SilencerShop
|
7
|
+
class Client < Base
|
8
|
+
|
9
|
+
include SilencerShop::API
|
10
|
+
|
11
|
+
attr_accessor :access_token
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
requires!(options, :username, :password)
|
15
|
+
@options = options
|
16
|
+
|
17
|
+
authenticate!
|
18
|
+
end
|
19
|
+
|
20
|
+
def product_feed
|
21
|
+
@product_feed ||= SilencerShop::ProductFeed.new(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
def order
|
25
|
+
@order ||= SilencerShop::Order.new(self)
|
26
|
+
end
|
27
|
+
|
28
|
+
def dealer
|
29
|
+
@dealer ||= SilencerShop::Dealer.new(self)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def authenticate!
|
35
|
+
request_data = [
|
36
|
+
['resource', CGI.escape('https://silencershopstaging.onmicrosoft.com/SilencerShop.Portal')],
|
37
|
+
['grant_type', 'client_credentials'],
|
38
|
+
['client_id', CGI.escape(@options[:username])],
|
39
|
+
['client_secret', CGI.escape(@options[:password])]
|
40
|
+
].map { |a| a.join('=') }.join('&')
|
41
|
+
|
42
|
+
response = post_request(
|
43
|
+
'silencershopstaging.onmicrosoft.com/oauth2/token',
|
44
|
+
request_data,
|
45
|
+
content_type_header('application/x-www-form-urlencoded'),
|
46
|
+
'https://login.microsoftonline.com'
|
47
|
+
)
|
48
|
+
|
49
|
+
if response[:access_token].present?
|
50
|
+
self.access_token = response[:access_token]
|
51
|
+
else
|
52
|
+
raise SilencerShop::Error::NotAuthorized.new(response.body)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'silencer_shop/api'
|
2
|
+
|
3
|
+
module SilencerShop
|
4
|
+
class Dealer < Base
|
5
|
+
|
6
|
+
include SilencerShop::API
|
7
|
+
|
8
|
+
ENDPOINTS = {
|
9
|
+
confirmed: "dealer/login".freeze
|
10
|
+
}
|
11
|
+
|
12
|
+
def initialize(client)
|
13
|
+
@client = client
|
14
|
+
end
|
15
|
+
|
16
|
+
def confirmed?(dealer_username: '', dealer_password: '')
|
17
|
+
post_request(
|
18
|
+
ENDPOINTS[:confirmed],
|
19
|
+
{ username: dealer_username, password: dealer_password },
|
20
|
+
auth_header(@client.access_token)
|
21
|
+
).success?
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module SilencerShop
|
2
|
+
class Error < StandardError
|
3
|
+
|
4
|
+
class NoContent < SilencerShop::Error; end
|
5
|
+
class NotAuthorized < SilencerShop::Error; end
|
6
|
+
class NotFound < SilencerShop::Error; end
|
7
|
+
class RequestError < SilencerShop::Error; end
|
8
|
+
class TimeoutError < SilencerShop::Error; end
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module SilencerShop
|
2
|
+
class Inventory < Base
|
3
|
+
|
4
|
+
def initialize(options = {})
|
5
|
+
requires!(options, :username, :password)
|
6
|
+
|
7
|
+
@client = SilencerShop::Client.new(username: options[:username], password: options[:password])
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.all(options = {})
|
11
|
+
requires!(options, :username, :password)
|
12
|
+
|
13
|
+
new(options).all
|
14
|
+
end
|
15
|
+
class << self; alias_method :quantity, :all; end
|
16
|
+
|
17
|
+
def all
|
18
|
+
@client.product_feed.availability.body.map { |item| map_hash(item) }
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def map_hash(item)
|
24
|
+
{
|
25
|
+
item_identifier: item[:DealerPartNumber],
|
26
|
+
quantity: item[:Quantity],
|
27
|
+
price: item[:Price],
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'silencer_shop/api'
|
2
|
+
|
3
|
+
module SilencerShop
|
4
|
+
class Order < Base
|
5
|
+
|
6
|
+
include SilencerShop::API
|
7
|
+
|
8
|
+
SUBMIT_ATTRS = {
|
9
|
+
permitted: %i(
|
10
|
+
purchase_order account_number other_information notes customer_email customer_phone
|
11
|
+
customer_name company_name address_line_1 address_line_2 ffl_information city state
|
12
|
+
zip shipping_method sales_tax_collected line_items dealer_part_number quantity price
|
13
|
+
universal_product_code description
|
14
|
+
).freeze,
|
15
|
+
required: %i(
|
16
|
+
purchase_order ffl_information customer_email customer_phone customer_name
|
17
|
+
address_line_1 city state zip line_items dealer_part_number quantity
|
18
|
+
).freeze
|
19
|
+
}
|
20
|
+
|
21
|
+
ENDPOINTS = {
|
22
|
+
submit: "commerce/order".freeze,
|
23
|
+
fetch: "commerce/order/%s?emailAddress=%s".freeze,
|
24
|
+
invoice: "commerce/order/pdf/%s?emailAddress=%s".freeze
|
25
|
+
}
|
26
|
+
|
27
|
+
def initialize(client)
|
28
|
+
@client = client
|
29
|
+
end
|
30
|
+
|
31
|
+
def submit(order_data)
|
32
|
+
requires!(order_data, *SUBMIT_ATTRS[:required])
|
33
|
+
|
34
|
+
endpoint = ENDPOINTS[:submit]
|
35
|
+
headers = [
|
36
|
+
*auth_header(@client.access_token),
|
37
|
+
*content_type_header('application/json'),
|
38
|
+
].to_h
|
39
|
+
|
40
|
+
order_data = standardize_body_data(order_data, SUBMIT_ATTRS[:permitted])
|
41
|
+
|
42
|
+
post_request(endpoint, order_data, headers)
|
43
|
+
end
|
44
|
+
|
45
|
+
def fetch(order_id, customer_email)
|
46
|
+
endpoint = ENDPOINTS[:fetch] % [order_id, customer_email]
|
47
|
+
|
48
|
+
get_request(endpoint, auth_header(@client.access_token))
|
49
|
+
end
|
50
|
+
|
51
|
+
def invoice(order_id, customer_email)
|
52
|
+
endpoint = ENDPOINTS[:invoice] % [order_id, customer_email]
|
53
|
+
|
54
|
+
get_request(endpoint, auth_header(@client.access_token))
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'silencer_shop/api'
|
2
|
+
|
3
|
+
module SilencerShop
|
4
|
+
class ProductFeed < Base
|
5
|
+
|
6
|
+
include SilencerShop::API
|
7
|
+
|
8
|
+
ENDPOINTS = {
|
9
|
+
catalog: "productfeed/catalog".freeze,
|
10
|
+
availability: "productfeed/availability".freeze
|
11
|
+
}
|
12
|
+
|
13
|
+
def initialize(client)
|
14
|
+
@client = client
|
15
|
+
end
|
16
|
+
|
17
|
+
def catalog
|
18
|
+
get_request(ENDPOINTS[:catalog], auth_header(@client.access_token))
|
19
|
+
end
|
20
|
+
|
21
|
+
def availability
|
22
|
+
get_request(ENDPOINTS[:availability], auth_header(@client.access_token))
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module SilencerShop
|
2
|
+
class Response
|
3
|
+
|
4
|
+
def initialize(response)
|
5
|
+
@response = response
|
6
|
+
|
7
|
+
case @response
|
8
|
+
when Net::HTTPUnauthorized
|
9
|
+
SilencerShop::Error::NotAuthorized.new(@response.body)
|
10
|
+
when Net::HTTPNotFound
|
11
|
+
SilencerShop::Error::NotFound.new(@response.body)
|
12
|
+
when Net::HTTPNoContent
|
13
|
+
SilencerShop::Error::NoContent.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
|
+
end
|
23
|
+
else
|
24
|
+
raise SilencerShop::Error::RequestError.new(@response.body)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def [](key)
|
29
|
+
@data&.[](key)
|
30
|
+
end
|
31
|
+
|
32
|
+
def body
|
33
|
+
@data
|
34
|
+
end
|
35
|
+
|
36
|
+
def fetch(key)
|
37
|
+
@data.fetch(key)
|
38
|
+
end
|
39
|
+
|
40
|
+
def success?
|
41
|
+
!!self[:success] && self[:errors].empty?
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SilencerShop
|
2
|
+
class User < Base
|
3
|
+
|
4
|
+
def initialize(options = {})
|
5
|
+
requires!(options, :username, :password)
|
6
|
+
|
7
|
+
@client = SilencerShop::Client.new(username: options[:username], password: options[:password])
|
8
|
+
end
|
9
|
+
|
10
|
+
def authenticated?
|
11
|
+
@client.access_token.present?
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'silencer_shop/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "silencer_shop"
|
8
|
+
spec.version = SilencerShop::VERSION
|
9
|
+
spec.authors = ["Jeffrey Dill"]
|
10
|
+
spec.email = ["jeffdill2@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby library for Silencer Shop 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.12"
|
27
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
spec.add_development_dependency "webmock", "~> 2.3"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: silencer_shop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeffrey Dill
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-05-26 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.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 12.3.3
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 12.3.3
|
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
|
+
- jeffdill2@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- lib/silencer_shop.rb
|
98
|
+
- lib/silencer_shop/api.rb
|
99
|
+
- lib/silencer_shop/base.rb
|
100
|
+
- lib/silencer_shop/catalog.rb
|
101
|
+
- lib/silencer_shop/client.rb
|
102
|
+
- lib/silencer_shop/dealer.rb
|
103
|
+
- lib/silencer_shop/error.rb
|
104
|
+
- lib/silencer_shop/inventory.rb
|
105
|
+
- lib/silencer_shop/order.rb
|
106
|
+
- lib/silencer_shop/product_feed.rb
|
107
|
+
- lib/silencer_shop/response.rb
|
108
|
+
- lib/silencer_shop/user.rb
|
109
|
+
- lib/silencer_shop/version.rb
|
110
|
+
- silencer_shop.gemspec
|
111
|
+
homepage: ''
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubygems_version: 3.1.4
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Ruby library for Silencer Shop API.
|
134
|
+
test_files: []
|