tophatter-merchant 1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +32 -0
- data/LICENSE +6 -6
- data/README.md +5 -0
- data/VERSION +1 -1
- data/bin/console +5 -2
- data/lib/tophatter_merchant.rb +19 -20
- data/lib/tophatter_merchant/account.rb +1 -7
- data/lib/tophatter_merchant/api_key.rb +0 -3
- data/lib/tophatter_merchant/image.rb +0 -3
- data/lib/tophatter_merchant/metadata.rb +0 -2
- data/lib/tophatter_merchant/order.rb +12 -24
- data/lib/tophatter_merchant/product.rb +19 -34
- data/lib/tophatter_merchant/resource.rb +36 -43
- data/lib/tophatter_merchant/variation.rb +0 -4
- data/lib/tophatter_merchant/version.rb +1 -1
- data/spec/spec_helper.rb +0 -2
- data/spec/tophatter_merchant/metadata_spec.rb +0 -2
- data/spec/tophatter_merchant/product_spec.rb +0 -2
- data/tophatter-merchant.gemspec +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75730e4724f4e6b9227197c0dada5fa3a273118e
|
4
|
+
data.tar.gz: aa6621873c6c3592aa39092166b92204de4bf4d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b414c775476118e1776c34e1b9eb57d70e73f3c8a94ba49c783d08bd2a65e085a2d3e99b9efa00f522ce3a0af7a124b4b115fb669a59e415be68a15996b3d2d
|
7
|
+
data.tar.gz: f616055d289707ca5d633cc624312acf73d66c9c16ad19c9d291d63001398a5d2c0dfb0dcc1b42a1e7ac0036229f6dc62db49018fac884906a9a8091168116b4
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.2
|
3
|
+
|
4
|
+
# [Metrics]
|
5
|
+
|
6
|
+
Metrics/LineLength:
|
7
|
+
Enabled: false
|
8
|
+
Metrics/MethodLength:
|
9
|
+
Enabled: false
|
10
|
+
Metrics/ParameterLists:
|
11
|
+
Enabled: false
|
12
|
+
# Complexity metrics are difficult to understand and fix, so let's ignore them.
|
13
|
+
Metrics/AbcSize:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
# [Lint]
|
17
|
+
|
18
|
+
# http://www.rubydoc.info/github/bbatsov/rubocop/Rubocop/Cop/Lint/EndAlignment
|
19
|
+
Lint/EndAlignment:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
# [Style]
|
23
|
+
|
24
|
+
# http://www.rubydoc.info/github/bbatsov/rubocop/Rubocop/Cop/Style/Documentation
|
25
|
+
Style/Documentation:
|
26
|
+
Enabled: false
|
27
|
+
# http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/ElseAlignment
|
28
|
+
Style/ElseAlignment:
|
29
|
+
Enabled: false
|
30
|
+
# http://www.rubydoc.info/github/bbatsov/rubocop/Rubocop/Cop/Style/IndentationWidth
|
31
|
+
Style/IndentationWidth:
|
32
|
+
Enabled: false
|
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
The MIT License
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2016 Tophatter
|
3
|
+
Copyright (c) 2016 Tophatter
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
9
|
copies of the Software, and to permit persons to whom the Software is
|
10
10
|
furnished to do so, subject to the following conditions:
|
11
11
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
14
|
|
15
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
17
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
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
|
-
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
### Tophatter Merchant API
|
2
2
|
Full documentation is available [here](https://tophatter.readme.io/v1/docs).
|
3
3
|
|
4
|
+
### Installation
|
5
|
+
```ruby
|
6
|
+
gem 'tophatter-merchant', require: 'tophatter_merchant'
|
7
|
+
```
|
8
|
+
|
4
9
|
### Console Testing (Development)
|
5
10
|
```bash
|
6
11
|
echo http://tophatter.dev/merchant_api/v1 > .api_host
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.1
|
data/bin/console
CHANGED
@@ -8,16 +8,19 @@ require 'pry'
|
|
8
8
|
|
9
9
|
begin
|
10
10
|
TophatterMerchant.api_path = File.read('.api_path').chomp
|
11
|
+
puts "TophatterMerchant.api_path: #{TophatterMerchant.api_path}"
|
11
12
|
rescue Errno::ENOENT
|
13
|
+
puts "No .api_path file, using default: #{TophatterMerchant.api_path}"
|
12
14
|
end
|
13
15
|
|
14
16
|
begin
|
15
17
|
TophatterMerchant.access_token = File.read('.access_token').chomp
|
18
|
+
puts "TophatterMerchant.access_token: #{TophatterMerchant.access_token}"
|
16
19
|
rescue Errno::ENOENT
|
20
|
+
puts "No .access_token file - you'll have to set TophatterMerchant.access_token manually from the console."
|
17
21
|
end
|
18
22
|
|
19
|
-
|
20
|
-
puts "TophatterMerchant.access_token: #{TophatterMerchant.access_token}"
|
23
|
+
TophatterMerchant.logger.level = Logger::DEBUG
|
21
24
|
|
22
25
|
Pry.config.color = false
|
23
26
|
Pry.start
|
data/lib/tophatter_merchant.rb
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
require 'active_model'
|
2
2
|
|
3
|
+
module TophatterMerchant
|
4
|
+
class << self
|
5
|
+
attr_accessor :api_path, :access_token, :logger
|
6
|
+
|
7
|
+
def api_path
|
8
|
+
@api_path || 'https://tophatter.com/merchant_api/v1'
|
9
|
+
end
|
10
|
+
|
11
|
+
def logger
|
12
|
+
unless defined?(@logger)
|
13
|
+
@logger = Logger.new(STDOUT)
|
14
|
+
@logger.level = Logger::WARN
|
15
|
+
end
|
16
|
+
|
17
|
+
@logger
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
3
22
|
require File.dirname(__FILE__) + '/tophatter_merchant/version'
|
4
23
|
require File.dirname(__FILE__) + '/tophatter_merchant/exceptions'
|
5
24
|
|
@@ -12,23 +31,3 @@ require File.dirname(__FILE__) + '/tophatter_merchant/metadata'
|
|
12
31
|
require File.dirname(__FILE__) + '/tophatter_merchant/order'
|
13
32
|
require File.dirname(__FILE__) + '/tophatter_merchant/product'
|
14
33
|
require File.dirname(__FILE__) + '/tophatter_merchant/variation'
|
15
|
-
|
16
|
-
module TophatterMerchant
|
17
|
-
|
18
|
-
def self.access_token
|
19
|
-
defined?(@@access_token) ? @@access_token : nil
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.access_token=(token)
|
23
|
-
@@access_token = token
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.api_path
|
27
|
-
defined?(@@api_path) ? @@api_path : 'https://tophatter.com/merchant_api/v1'
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.api_path=(path)
|
31
|
-
@@api_path = path
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module TophatterMerchant
|
2
2
|
class Account < Resource
|
3
|
-
|
4
3
|
attr_accessor :access_token, :first_name, :last_name, :store_name, :email, :country, :time_zone
|
5
4
|
|
6
5
|
def id
|
@@ -8,7 +7,6 @@ module TophatterMerchant
|
|
8
7
|
end
|
9
8
|
|
10
9
|
class << self
|
11
|
-
|
12
10
|
# ap TophatterMerchant::Account.schema
|
13
11
|
def schema
|
14
12
|
get(url: "#{path}/schema.json")
|
@@ -16,10 +14,7 @@ module TophatterMerchant
|
|
16
14
|
|
17
15
|
# ap TophatterMerchant::Account.authenticate(email: 'megatron@autobot.com', password: 'ipipip').to_h
|
18
16
|
def authenticate(email:, password:)
|
19
|
-
Account.new post(url: "#{path}/authenticate.json", params: {
|
20
|
-
email: email,
|
21
|
-
password: password
|
22
|
-
})
|
17
|
+
Account.new post(url: "#{path}/authenticate.json", params: { email: email, password: password })
|
23
18
|
end
|
24
19
|
|
25
20
|
# ap TophatterMerchant::Account.me.to_h
|
@@ -47,7 +42,6 @@ module TophatterMerchant
|
|
47
42
|
def path
|
48
43
|
super + '/account'
|
49
44
|
end
|
50
|
-
|
51
45
|
end
|
52
46
|
end
|
53
47
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module TophatterMerchant
|
2
2
|
class ApiKey < Resource
|
3
|
-
|
4
3
|
attr_accessor :id, :access_token, :created_at
|
5
4
|
|
6
5
|
class << self
|
7
|
-
|
8
6
|
# ap TophatterMerchant::ApiKey.schema
|
9
7
|
def schema
|
10
8
|
get(url: "#{path}/schema.json")
|
@@ -39,7 +37,6 @@ module TophatterMerchant
|
|
39
37
|
def path
|
40
38
|
super + '/api_keys'
|
41
39
|
end
|
42
|
-
|
43
40
|
end
|
44
41
|
end
|
45
42
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module TophatterMerchant
|
2
2
|
class Image < Resource
|
3
|
-
|
4
3
|
attr_accessor :id, :fingerprint, :url
|
5
4
|
|
6
5
|
class << self
|
7
|
-
|
8
6
|
# request = RestClient::Request.new(method: :get, url: 'https://img0.etsystatic.com/101/0/7856452/il_fullxfull.882030160_r0tn.jpg')
|
9
7
|
# response = request.execute
|
10
8
|
# File.open('/tmp/foo.jpg', 'w') { |file| file.write(response.body) }
|
@@ -18,7 +16,6 @@ module TophatterMerchant
|
|
18
16
|
def path
|
19
17
|
super + '/images'
|
20
18
|
end
|
21
|
-
|
22
19
|
end
|
23
20
|
end
|
24
21
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module TophatterMerchant
|
2
2
|
class Metadata < Resource
|
3
3
|
class << self
|
4
|
-
|
5
4
|
# ap TophatterMerchant::Metadata.all
|
6
5
|
def all
|
7
6
|
get(url: "#{path}.json")
|
@@ -70,7 +69,6 @@ module TophatterMerchant
|
|
70
69
|
def path
|
71
70
|
super + '/metadata'
|
72
71
|
end
|
73
|
-
|
74
72
|
end
|
75
73
|
end
|
76
74
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module TophatterMerchant
|
2
2
|
class Order < Resource
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
attr_accessor :order_id, :status,
|
4
|
+
:carrier, :tracking_number,
|
5
|
+
:product_name, :product_identifier, :variation_identifier,
|
6
|
+
:customer_id, :customer_name,
|
7
|
+
:address1, :address2, :city, :state, :postal_code, :country,
|
8
|
+
:available_refunds, :refund_amount,
|
9
|
+
:disbursement_amount, :seller_fees_amount, :seller_fees,
|
10
|
+
:paid_at, :created_at,
|
11
|
+
:ca_acknowledged # @FIXME: This shouldn't be here.
|
11
12
|
|
12
13
|
class << self
|
13
|
-
|
14
14
|
# ap TophatterMerchant::Order.schema
|
15
15
|
def schema
|
16
16
|
get(url: "#{path}/schema.json")
|
@@ -27,18 +27,12 @@ module TophatterMerchant
|
|
27
27
|
|
28
28
|
# ap TophatterMerchant::Order.retrieve(681195262).to_h
|
29
29
|
def retrieve(id)
|
30
|
-
Order.new get(url: "#{path}/retrieve.json", params: {
|
31
|
-
order_id: id
|
32
|
-
})
|
30
|
+
Order.new get(url: "#{path}/retrieve.json", params: { order_id: id })
|
33
31
|
end
|
34
32
|
|
35
33
|
# ap TophatterMerchant::Order.fulfill(417953232, carrier: 'other', tracking_number: 'ABC123').to_h
|
36
34
|
def fulfill(id, carrier:, tracking_number:)
|
37
|
-
Order.new post(url: "#{path}/fulfill.json", params: {
|
38
|
-
order_id: id,
|
39
|
-
carrier: carrier,
|
40
|
-
tracking_number: tracking_number
|
41
|
-
})
|
35
|
+
Order.new post(url: "#{path}/fulfill.json", params: { order_id: id, carrier: carrier, tracking_number: tracking_number })
|
42
36
|
end
|
43
37
|
|
44
38
|
def unfulfill(id)
|
@@ -48,12 +42,7 @@ module TophatterMerchant
|
|
48
42
|
# ap TophatterMerchant::Order.refund(417953232, type: 'full', reason: 'delay_in_shipping').to_h
|
49
43
|
# ap TophatterMerchant::Order.refund(417953232, type: 'partial', reason: 'other', fees: ['shipping_fee']).to_h
|
50
44
|
def refund(id, type:, reason:, fees: [])
|
51
|
-
Order.new post(url: "#{path}/refund.json", params: {
|
52
|
-
order_id: id,
|
53
|
-
type: type,
|
54
|
-
reason: reason,
|
55
|
-
fees: fees
|
56
|
-
})
|
45
|
+
Order.new post(url: "#{path}/refund.json", params: { order_id: id, type: type, reason: reason, fees: fees })
|
57
46
|
end
|
58
47
|
|
59
48
|
protected
|
@@ -61,7 +50,6 @@ module TophatterMerchant
|
|
61
50
|
def path
|
62
51
|
super + '/orders'
|
63
52
|
end
|
64
|
-
|
65
53
|
end
|
66
54
|
end
|
67
55
|
end
|
@@ -1,17 +1,16 @@
|
|
1
1
|
module TophatterMerchant
|
2
2
|
class Product < Resource
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
attr_accessor :blacklisted_at, :admin_hold_at, :slug, :internal_id # Other
|
3
|
+
attr_accessor :identifier,
|
4
|
+
:category, :title, :description, # Basics
|
5
|
+
:condition, :brand, :material, # Facets
|
6
|
+
:available_quantity, :variations, # Variations
|
7
|
+
:starting_bid, :buy_now_price, :retail_price, :cost_basis, :minimum_alerts_needed, # Pricing
|
8
|
+
:shipping_origin, :shipping_price, :expedited_shipping_price, :days_to_fulfill, :days_to_deliver, :expedited_days_to_deliver, :weight, # Shipping
|
9
|
+
:buy_one_get_one_price, :accessory_price, :accessory_description, # Upsells
|
10
|
+
:primary_image, :extra_images, :all_images, # Images
|
11
|
+
:slug, :ratings_average, :ratings_count, # Ratings
|
12
|
+
:created_at, :updated_at, :disabled_at, :deleted_at, # Timestamps
|
13
|
+
:blacklisted_at, :admin_hold_at, :slug, :internal_id # Other
|
15
14
|
|
16
15
|
def id
|
17
16
|
created_at.present? ? identifier : nil
|
@@ -27,15 +26,15 @@ module TophatterMerchant
|
|
27
26
|
end
|
28
27
|
|
29
28
|
def copy
|
30
|
-
|
29
|
+
hash = to_h
|
31
30
|
|
32
|
-
# Delete the
|
33
|
-
%w(identifier primary_image extra_images all_images ratings_average ratings_count created_at updated_at disabled_at deleted_at blacklisted_at slug admin_hold_at).each do |
|
34
|
-
|
35
|
-
|
31
|
+
# Delete the keys that shouldn't be copied.
|
32
|
+
%w(identifier primary_image extra_images all_images ratings_average ratings_count created_at updated_at disabled_at deleted_at blacklisted_at slug admin_hold_at).each do |key|
|
33
|
+
hash.delete(key)
|
34
|
+
hash['variations'].each { |variation| variation.delete(key) }
|
36
35
|
end
|
37
36
|
|
38
|
-
Product.new(
|
37
|
+
Product.new(hash)
|
39
38
|
end
|
40
39
|
|
41
40
|
def to_param
|
@@ -43,19 +42,13 @@ module TophatterMerchant
|
|
43
42
|
end
|
44
43
|
|
45
44
|
class << self
|
46
|
-
|
47
45
|
# ap TophatterMerchant::Product.schema
|
48
46
|
def schema
|
49
47
|
get(url: "#{path}/schema.json")
|
50
48
|
end
|
51
49
|
|
52
50
|
def search(query:, page: 1, per_page: 50, pagination: nil)
|
53
|
-
result = get(url: "#{path}/search.json", params: {
|
54
|
-
query: query,
|
55
|
-
page: page,
|
56
|
-
per_page: per_page,
|
57
|
-
pagination: pagination
|
58
|
-
})
|
51
|
+
result = get(url: "#{path}/search.json", params: { query: query, page: page, per_page: per_page, pagination: pagination })
|
59
52
|
|
60
53
|
if pagination.present?
|
61
54
|
result['results'] = result['results'].map { |hash| Product.new(hash) }
|
@@ -68,14 +61,7 @@ module TophatterMerchant
|
|
68
61
|
|
69
62
|
# ap TophatterMerchant::Product.all.map(&:to_h)
|
70
63
|
def all(status: nil, category: nil, page: 1, per_page: 50, pagination: nil, sort: nil)
|
71
|
-
result = get(url: "#{path}.json", params: {
|
72
|
-
status: status,
|
73
|
-
category: category,
|
74
|
-
page: page,
|
75
|
-
per_page: per_page,
|
76
|
-
pagination: pagination,
|
77
|
-
sort: sort
|
78
|
-
})
|
64
|
+
result = get(url: "#{path}.json", params: { status: status, category: category, page: page, per_page: per_page, pagination: pagination, sort: sort })
|
79
65
|
|
80
66
|
if pagination.present?
|
81
67
|
result['results'] = result['results'].map { |hash| Product.new(hash) }
|
@@ -124,7 +110,6 @@ module TophatterMerchant
|
|
124
110
|
def path
|
125
111
|
super + '/products'
|
126
112
|
end
|
127
|
-
|
128
113
|
end
|
129
114
|
end
|
130
115
|
end
|
@@ -2,48 +2,39 @@ require 'active_model'
|
|
2
2
|
|
3
3
|
module TophatterMerchant
|
4
4
|
class Resource
|
5
|
-
|
6
5
|
include ActiveModel::Model
|
7
6
|
|
8
|
-
def self.attr_accessor(*vars)
|
9
|
-
attributes!(*vars)
|
10
|
-
super(*vars)
|
11
|
-
end
|
12
|
-
|
13
7
|
def initialize(hash)
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def attributes=(hash)
|
8
|
+
# Only honor valid attributes.
|
18
9
|
hash.each do |key, value|
|
19
|
-
if respond_to?(key)
|
20
|
-
self.class.attributes!(key)
|
10
|
+
if respond_to?("#{key}=")
|
21
11
|
send("#{key}=", value)
|
12
|
+
else
|
13
|
+
TophatterMerchant.logger.warn "Invalid attribute #{key} specified for #{self.class.name}"
|
22
14
|
end
|
23
15
|
end
|
24
16
|
end
|
25
17
|
|
26
|
-
def to_h
|
27
|
-
self.class.attributes.keys.collect { |key| [key, send(key)] }.to_h
|
28
|
-
end
|
29
|
-
|
30
18
|
def persisted?
|
31
|
-
id.present?
|
19
|
+
id.present? # @TODO: Should this be internal_id?
|
32
20
|
end
|
33
21
|
|
34
|
-
|
35
|
-
|
36
|
-
def self.attributes
|
37
|
-
@attributes || {}
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.attributes!(*vars)
|
41
|
-
@attributes ||= {}
|
42
|
-
vars.map(&:to_s).each { |var| @attributes[var] = true }
|
43
|
-
@attributes
|
22
|
+
def to_h
|
23
|
+
self.class.attributes.map { |key| [key, send(key)] }.to_h
|
44
24
|
end
|
45
25
|
|
46
26
|
class << self
|
27
|
+
def attr_accessor(*vars)
|
28
|
+
# TophatterMerchant.logger.debug "#{name}: #{vars.inspect} (attr_accessor)"
|
29
|
+
@attributes ||= {}
|
30
|
+
vars.each { |var| @attributes[var.to_s] = true }
|
31
|
+
super(*vars)
|
32
|
+
end
|
33
|
+
|
34
|
+
def attributes
|
35
|
+
@attributes ||= {}
|
36
|
+
@attributes.keys
|
37
|
+
end
|
47
38
|
|
48
39
|
protected
|
49
40
|
|
@@ -64,20 +55,22 @@ module TophatterMerchant
|
|
64
55
|
end
|
65
56
|
|
66
57
|
def execute(request)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
58
|
+
TophatterMerchant.logger.debug "#{request.method.upcase} #{request.url} #{request.payload.inspect}"
|
59
|
+
response = request.execute
|
60
|
+
raise BadContentTypeException.new, "The server didn't return JSON. You probably made a bad request." if response.headers[:content_type] == 'text/html; charset=utf-8'
|
61
|
+
JSON.parse(response.body)
|
62
|
+
rescue RestClient::Request::Unauthorized, RestClient::Forbidden => e
|
63
|
+
TophatterMerchant.logger.debug "#{e.class.name}: #{e.response.code} -> raising UnauthorizedException"
|
64
|
+
raise UnauthorizedException.new, parse_error(e, e.message)
|
65
|
+
rescue RestClient::ResourceNotFound => e
|
66
|
+
TophatterMerchant.logger.debug "#{e.class.name}: #{e.response.code} -> raising NotFoundException"
|
67
|
+
raise NotFoundException.new, parse_error(e, 'The API path you requested does not exist.')
|
68
|
+
rescue RestClient::BadRequest => e
|
69
|
+
TophatterMerchant.logger.debug "#{e.class.name}: #{e.response.code} -> raising BadRequestException"
|
70
|
+
raise BadRequestException.new, parse_error(e, e.message)
|
71
|
+
rescue RestClient::InternalServerError => e
|
72
|
+
TophatterMerchant.logger.debug "#{e.class.name}: #{e.response.code} -> raising ServerErrorException"
|
73
|
+
raise ServerErrorException.new, parse_error(e, 'The server encountered an internal error. This is probably a bug, and you should contact support.')
|
81
74
|
end
|
82
75
|
|
83
76
|
def request(method:, url:, params:)
|
@@ -102,9 +95,9 @@ module TophatterMerchant
|
|
102
95
|
rescue
|
103
96
|
{}
|
104
97
|
end
|
105
|
-
raise BadRequestException.new, error['message'] || fallback
|
106
|
-
end
|
107
98
|
|
99
|
+
error['message'] || fallback
|
100
|
+
end
|
108
101
|
end
|
109
102
|
end
|
110
103
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module TophatterMerchant
|
2
2
|
class Variation < Resource
|
3
|
-
|
4
3
|
attr_accessor :identifier, :size, :color, :quantity, :created_at
|
5
4
|
|
6
5
|
def id
|
@@ -8,7 +7,6 @@ module TophatterMerchant
|
|
8
7
|
end
|
9
8
|
|
10
9
|
class << self
|
11
|
-
|
12
10
|
# ap TophatterMerchant::Variation.schema
|
13
11
|
def schema
|
14
12
|
get(url: "#{path}/schema.json")
|
@@ -34,8 +32,6 @@ module TophatterMerchant
|
|
34
32
|
def path
|
35
33
|
super + '/variations'
|
36
34
|
end
|
37
|
-
|
38
35
|
end
|
39
|
-
|
40
36
|
end
|
41
37
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,7 +6,6 @@ WebMock.disable_net_connect!(allow_localhost: true)
|
|
6
6
|
|
7
7
|
# http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
8
8
|
RSpec.configure do |config|
|
9
|
-
|
10
9
|
config.expect_with :rspec do |expectations|
|
11
10
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
12
11
|
end
|
@@ -20,5 +19,4 @@ RSpec.configure do |config|
|
|
20
19
|
stub_request(:get, /.*conditions\.json/).to_return(File.new(File.dirname(__FILE__) + '/../tmp/stubs/metadata/conditions.json'))
|
21
20
|
stub_request(:get, /.*gemstones\.json/).to_return(File.new(File.dirname(__FILE__) + '/../tmp/stubs/metadata/gemstones.json'))
|
22
21
|
end
|
23
|
-
|
24
22
|
end
|
@@ -2,7 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
# rspec spec/tophatter_merchant/metadata_spec.rb
|
4
4
|
describe TophatterMerchant::Metadata do
|
5
|
-
|
6
5
|
it 'returns metadata' do
|
7
6
|
metadata = TophatterMerchant::Metadata.all
|
8
7
|
expect(metadata.keys.include?('categories')).to be true
|
@@ -34,5 +33,4 @@ describe TophatterMerchant::Metadata do
|
|
34
33
|
expect(gemstones['Gemstones'].include?('Ruby')).to be true
|
35
34
|
expect(gemstones['Gemstones'].include?("Micheal Jackson's Hair Diamond")).to be false
|
36
35
|
end
|
37
|
-
|
38
36
|
end
|
data/tophatter-merchant.gemspec
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
3
3
|
require 'tophatter_merchant/version'
|
4
4
|
|
5
|
+
# To publish the next version:
|
6
|
+
# gem build tophatter-merchant.gemspec
|
7
|
+
# gem push tophatter-merchant-<version>.gem
|
5
8
|
Gem::Specification.new do |s|
|
6
9
|
s.name = 'tophatter-merchant'
|
7
10
|
s.version = TophatterMerchant::VERSION
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tophatter-merchant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Estreich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -49,6 +49,7 @@ extra_rdoc_files: []
|
|
49
49
|
files:
|
50
50
|
- ".gitignore"
|
51
51
|
- ".rspec"
|
52
|
+
- ".rubocop.yml"
|
52
53
|
- CHANGELOG
|
53
54
|
- Gemfile
|
54
55
|
- LICENSE
|