tophatter-merchant 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -7
  3. data/Gemfile +1 -3
  4. data/README.md +0 -5
  5. data/lib/tophatter_merchant.rb +3 -8
  6. data/lib/tophatter_merchant/metadata.rb +0 -13
  7. data/lib/tophatter_merchant/order.rb +45 -24
  8. data/lib/tophatter_merchant/product.rb +46 -79
  9. data/lib/tophatter_merchant/resource.rb +23 -47
  10. data/lib/tophatter_merchant/variation.rb +15 -15
  11. data/spec/spec_helper.rb +0 -10
  12. data/spec/tophatter_merchant/metadata_spec.rb +12 -20
  13. data/spec/tophatter_merchant/order_spec.rb +4 -11
  14. data/spec/tophatter_merchant/product_spec.rb +11 -27
  15. data/spec/tophatter_merchant/variation_spec.rb +3 -10
  16. data/tophatter-merchant.gemspec +1 -2
  17. metadata +3 -77
  18. data/spec/cassettes/TophatterMerchant_Metadata/_carriers/returns_carriers.yml +0 -87
  19. data/spec/cassettes/TophatterMerchant_Metadata/_categories/returns_categories.yml +0 -131
  20. data/spec/cassettes/TophatterMerchant_Metadata/_colors/returns_colors.yml +0 -50
  21. data/spec/cassettes/TophatterMerchant_Metadata/_conditions/returns_conditions.yml +0 -52
  22. data/spec/cassettes/TophatterMerchant_Metadata/_countries/returns_countries.yml +0 -128
  23. data/spec/cassettes/TophatterMerchant_Metadata/_country_codes/returns_country_codes.yml +0 -161
  24. data/spec/cassettes/TophatterMerchant_Metadata/_materials/returns_materials.yml +0 -69
  25. data/spec/cassettes/TophatterMerchant_Metadata/_metadata/returns_metadata.yml +0 -540
  26. data/spec/cassettes/TophatterMerchant_Metadata/_provinces/returns_provinces.yml +0 -52
  27. data/spec/cassettes/TophatterMerchant_Metadata/_sizes/returns_sizes.yml +0 -58
  28. data/spec/cassettes/TophatterMerchant_Metadata/_states/returns_states.yml +0 -58
  29. data/spec/cassettes/TophatterMerchant_Metadata/_territories/returns_territories.yml +0 -52
  30. data/spec/cassettes/TophatterMerchant_Order/_all/returns_all_orders.yml +0 -56
  31. data/spec/cassettes/TophatterMerchant_Order/_fulfill/fulfills_an_order.yml +0 -53
  32. data/spec/cassettes/TophatterMerchant_Order/_refund/refunds_an_order.yml +0 -53
  33. data/spec/cassettes/TophatterMerchant_Order/_retrieve/retrieves_an_order.yml +0 -53
  34. data/spec/cassettes/TophatterMerchant_Order/_schema/returns_the_schema.yml +0 -81
  35. data/spec/cassettes/TophatterMerchant_Product/_all/returns_all_products.yml +0 -64
  36. data/spec/cassettes/TophatterMerchant_Product/_create/creates_a_product.yml +0 -53
  37. data/spec/cassettes/TophatterMerchant_Product/_delete/deletes_a_product.yml +0 -103
  38. data/spec/cassettes/TophatterMerchant_Product/_disable/disables_a_product.yml +0 -103
  39. data/spec/cassettes/TophatterMerchant_Product/_enable/enables_a_product.yml +0 -103
  40. data/spec/cassettes/TophatterMerchant_Product/_retrieve/retrieves_a_product.yml +0 -53
  41. data/spec/cassettes/TophatterMerchant_Product/_schema/returns_the_schema.yml +0 -124
  42. data/spec/cassettes/TophatterMerchant_Product/_search/returns_products_matching_search_terms.yml +0 -57
  43. data/spec/cassettes/TophatterMerchant_Product/_update/updates_a_product.yml +0 -103
  44. data/spec/cassettes/TophatterMerchant_Variation/_create/creates_a_variation.yml +0 -50
  45. data/spec/cassettes/TophatterMerchant_Variation/_retrieve/retrieves_a_variation.yml +0 -50
  46. data/spec/cassettes/TophatterMerchant_Variation/_schema/returns_the_schema.yml +0 -64
  47. data/spec/cassettes/TophatterMerchant_Variation/_update/updates_a_variation.yml +0 -97
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c832485da45833a3609214742e3d25c2063997e3
4
- data.tar.gz: 84e84519288868338281ec5b7814e3804be57142
3
+ metadata.gz: c091268959e81677d5a6ce347857d13caee1c405
4
+ data.tar.gz: 8d8572b11b67ff92b4bef05a4e35620911fe7590
5
5
  SHA512:
6
- metadata.gz: 65e372bf3ff1d4c9027ede0e1fee567cf298dd52050cee34827f65e29cbe4648224b5027b2fac0592117cc1028076c9e6c883068c1b13376bc666de65e6efb78
7
- data.tar.gz: ec19156f01994105448b45d9e489b1bac5ecce27b31f69f3046851e448dc6d50ec0772ea80174a11201f1c07232feb9d5457503bae5afdb5de0f939dd2221e2a
6
+ metadata.gz: c326161bedf60af88b1316e4a568435eed8e9cb1794c7a7277e52a3b2921d3518ed74cecfcd215a25d2320d1a9cb992cd98b19137170ea0373280cc6cf909bb5
7
+ data.tar.gz: 0e6d27b39759b3d0d44405699825b5fd7032eba74781520727c00ae2b8649fab36d0b83fa42544dbc2658ba2fbe1d5edbd08f9c7a4f0f0e5328437648355421d
@@ -22,17 +22,14 @@ Metrics/ParameterLists:
22
22
  Lint/EndAlignment:
23
23
  Enabled: false
24
24
 
25
- Style/Documentation:
25
+ Layout/IndentationWidth:
26
26
  Enabled: false
27
- Style/IndentationWidth:
27
+ Layout/ElseAlignment:
28
28
  Enabled: false
29
- Style/ElseAlignment:
29
+
30
+ Style/Documentation:
30
31
  Enabled: false
31
32
  Style/GuardClause:
32
33
  Enabled: false
33
34
  Style/NumericLiterals:
34
35
  Enabled: false
35
-
36
- # This is temporary - it can be remove after updating rubocop to the latest.
37
- Style/PercentLiteralDelimiters:
38
- Enabled: false
data/Gemfile CHANGED
@@ -5,12 +5,10 @@ group :development, :test do
5
5
  gem 'awesome_print'
6
6
  gem 'pry'
7
7
  gem 'rake'
8
- gem 'rubocop', '0.47.1'
8
+ gem 'rubocop', '0.49.0'
9
9
  end
10
10
 
11
11
  group :test do
12
12
  gem 'coveralls', require: false
13
13
  gem 'rspec'
14
- gem 'vcr'
15
- gem 'webmock'
16
14
  end
data/README.md CHANGED
@@ -24,11 +24,6 @@ TophatterMerchant.access_token = <YOUR ACCESS TOKEN>
24
24
 
25
25
  ### Products
26
26
 
27
- #### List the product definition.
28
- ```ruby
29
- TophatterMerchant::Product.schema
30
- ```
31
-
32
27
  #### List all of the products in your inventory.
33
28
  ```ruby
34
29
  TophatterMerchant::Product.all(page: 1, per_page: 100)
@@ -1,6 +1,3 @@
1
- require 'active_model'
2
- require 'json'
3
-
4
1
  module TophatterMerchant
5
2
  class << self
6
3
  attr_accessor :api_path, :access_token, :logger
@@ -20,8 +17,6 @@ module TophatterMerchant
20
17
  end
21
18
  end
22
19
 
23
- require File.dirname(__FILE__) + '/tophatter_merchant/resource'
24
- require File.dirname(__FILE__) + '/tophatter_merchant/metadata'
25
- require File.dirname(__FILE__) + '/tophatter_merchant/order'
26
- require File.dirname(__FILE__) + '/tophatter_merchant/product'
27
- require File.dirname(__FILE__) + '/tophatter_merchant/variation'
20
+ %w[resource metadata order product variation].each do |file|
21
+ require "#{File.dirname(__FILE__)}/tophatter_merchant/#{file}"
22
+ end
@@ -1,67 +1,54 @@
1
1
  module TophatterMerchant
2
2
  class Metadata < Resource
3
3
  class << self
4
- # ap TophatterMerchant::Metadata.all
5
4
  def all
6
5
  get(url: "#{path}.json")
7
6
  end
8
7
 
9
- # ap TophatterMerchant::Metadata.categories
10
8
  def categories
11
9
  get(url: "#{path}/categories.json")
12
10
  end
13
11
 
14
- # ap TophatterMerchant::Metadata.conditions
15
12
  def conditions
16
13
  get(url: "#{path}/conditions.json")
17
14
  end
18
15
 
19
- # ap TophatterMerchant::Metadata.brands
20
16
  def brands
21
17
  get(url: "#{path}/brands.json")
22
18
  end
23
19
 
24
- # ap TophatterMerchant::Metadata.materials
25
20
  def materials
26
21
  get(url: "#{path}/materials.json")
27
22
  end
28
23
 
29
- # ap TophatterMerchant::Metadata.sizes
30
24
  def sizes
31
25
  get(url: "#{path}/sizes.json")
32
26
  end
33
27
 
34
- # ap TophatterMerchant::Metadata.colors
35
28
  def colors
36
29
  get(url: "#{path}/colors.json")
37
30
  end
38
31
 
39
- # ap TophatterMerchant::Metadata.countries
40
32
  def countries
41
33
  get(url: "#{path}/countries.json")
42
34
  end
43
35
 
44
- # ap TophatterMerchant::Metadata.country_codes
45
36
  def country_codes
46
37
  get(url: "#{path}/country_codes.json")
47
38
  end
48
39
 
49
- # ap TophatterMerchant::Metadata.states
50
40
  def states
51
41
  get(url: "#{path}/states.json")
52
42
  end
53
43
 
54
- # ap TophatterMerchant::Metadata.provinces
55
44
  def provinces
56
45
  get(url: "#{path}/provinces.json")
57
46
  end
58
47
 
59
- # ap TophatterMerchant::Metadata.territories
60
48
  def territories
61
49
  get(url: "#{path}/territories.json")
62
50
  end
63
51
 
64
- # ap TophatterMerchant::Metadata.carriers
65
52
  def carriers
66
53
  get(url: "#{path}/carriers.json")
67
54
  end
@@ -1,49 +1,70 @@
1
1
  module TophatterMerchant
2
2
  class Order < Resource
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, :line_items,
9
- :disbursement_amount, :seller_fees_amount, :seller_fees,
10
- :paid_at, :created_at
11
-
12
- def id
13
- created_at.present? ? identifier : nil
14
- end
3
+ # http://merchant-api.tophatter.com/docs/order-schema
4
+ attr_accessor :order_id,
5
+ :status,
6
+ :carrier,
7
+ :tracking_number,
8
+ :product_name,
9
+ :product_identifier,
10
+ :variation_identifier,
11
+ :annotation,
12
+ :customer_id,
13
+ :customer_name,
14
+ :address1,
15
+ :address2,
16
+ :city,
17
+ :state,
18
+ :postal_code,
19
+ :country,
20
+ :available_refunds,
21
+ :refund_amount,
22
+ :disbursement_amount,
23
+ :seller_fees_amount,
24
+ :seller_fees,
25
+ :paid_at,
26
+ :created_at
15
27
 
16
28
  class << self
17
- # ap TophatterMerchant::Order.schema
18
- def schema
19
- get(url: "#{path}/schema.json")
20
- end
21
-
22
- # ap TophatterMerchant::Order.all.map(&:to_h)
23
- # ap TophatterMerchant::Order.all(filter: 'unfulfilled').map(&:to_h)
24
- # ap TophatterMerchant::Order.all(filter: 'fulfilled').map(&:to_h)
29
+ # http://merchant-api.tophatter.com/docs/order-list
30
+ # TophatterMerchant::Order.all(filter: 'unfulfilled')
25
31
  def all(filter: nil, page: 1, per_page: 50)
26
32
  get(url: "#{path}.json", params: { filter: filter, page: page, per_page: per_page }).map do |hash|
27
33
  Order.new(hash)
28
34
  end
29
35
  end
30
36
 
31
- # ap TophatterMerchant::Order.retrieve(681195262).to_h
37
+ # http://merchant-api.tophatter.com/docs/order-retrieve
38
+ # TophatterMerchant::Order.retrieve(60150685)
32
39
  def retrieve(id)
33
40
  Order.new get(url: "#{path}/retrieve.json", params: { order_id: id })
34
41
  end
35
42
 
36
- # ap TophatterMerchant::Order.fulfill(417953232, carrier: 'other', tracking_number: 'ABC123').to_h
43
+ # http://merchant-api.tophatter.com/docs/order-acknowledge
44
+ # TophatterMerchant::Order.acknowledge(60150685).status
45
+ def acknowledge(id)
46
+ Order.new get(url: "#{path}/acknowledge.json", params: { order_id: id })
47
+ end
48
+
49
+ # http://merchant-api.tophatter.com/docs/order-fulfill
50
+ # TophatterMerchant::Order.fulfill(417953232, carrier: 'other', tracking_number: 'ABC123')
37
51
  def fulfill(id, carrier:, tracking_number:)
38
52
  Order.new post(url: "#{path}/fulfill.json", params: { order_id: id, carrier: carrier, tracking_number: tracking_number })
39
53
  end
40
54
 
41
- # ap TophatterMerchant::Order.refund(417953232, type: 'full', reason: 'delay_in_shipping').to_h
42
- # ap TophatterMerchant::Order.refund(417953232, type: 'partial', reason: 'other', fees: ['shipping_fee']).to_h
55
+ # http://merchant-api.tophatter.com/docs/order-refund
56
+ # TophatterMerchant::Order.refund(417953232, type: 'full', reason: 'delay_in_shipping')
57
+ # TophatterMerchant::Order.refund(417953232, type: 'partial', reason: 'other', fees: ['shipping_fee'])
43
58
  def refund(id, type:, reason:, fees: [])
44
59
  Order.new post(url: "#{path}/refund.json", params: { order_id: id, type: type, reason: reason, fees: fees })
45
60
  end
46
61
 
62
+ # http://merchant-api.tophatter.com/docs/order-annotate
63
+ # TophatterMerchant::Order.annotate(60157972, 'Testing...').annotation
64
+ def annotate(id, annotation)
65
+ Order.new post(url: "#{path}/annotate.json", params: { order_id: id, annotation: annotation })
66
+ end
67
+
47
68
  protected
48
69
 
49
70
  def path
@@ -1,73 +1,44 @@
1
1
  module TophatterMerchant
2
2
  class Product < Resource
3
+ # http://merchant-api.tophatter.com/docs/product-schema
3
4
  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, # Pricing
8
- :shipping_price, :days_to_deliver, # Shipping
9
- :expedited_shipping_price, :expedited_days_to_deliver, # Shipping (Expedited)
10
- :days_to_fulfill, :shipping_origin, :weight, # Shipping (Handling)
11
- :buy_one_get_one_price, :accessory_price, :accessory_description, # Upsells
12
- :primary_image, :extra_images, :all_images, # Images
13
- :ratings_average, :ratings_count, # Ratings
14
- :created_at, :updated_at, :disabled_at, :deleted_at, # Timestamps
15
- :catalog_only_at, :in_review_at, :approved_at, :refused_at, :held_at, # SKU Lifecycle
16
- :internal_id, :slug, # Admin
17
- :admin_banned_at, :admin_hold_at, :admin_hold_responded_at, :admin_reason,
18
- :success_fee_bid_enabled, :success_fee_bid,
19
- :health_status, :health_reason
20
-
21
- def id
22
- created_at.present? ? identifier : nil
23
- end
24
-
25
- # Available: thumbnail, square, medium, large, original.
26
- def images(size: 'square')
27
- if persisted?
28
- all_images.collect { |image| image[size] }
29
- else
30
- ([primary_image] + extra_images.to_s.split('|')).compact
31
- end
32
- end
33
-
34
- def copy
35
- hash = to_h
36
-
37
- # Delete the keys that shouldn't be copied.
38
- %w(identifier primary_image extra_images all_images ratings_average ratings_count created_at updated_at disabled_at deleted_at catalog_only_at in_review_at approved_at refused_at held_at blacklisted_at slug admin_hold_at).each do |key|
39
- hash.delete(key)
40
- hash['variations'].each { |variation| variation.delete(key) }
41
- end
42
-
43
- Product.new(hash)
44
- end
45
-
46
- def to_param
47
- slug || identifier
48
- end
5
+ :internal_id,
6
+ :category,
7
+ :title,
8
+ :description,
9
+ :condition,
10
+ :brand,
11
+ :material,
12
+ :available_quantity,
13
+ :variations,
14
+ :buy_now_price,
15
+ :retail_price,
16
+ :cost_basis,
17
+ :shipping_price,
18
+ :shipping_origin,
19
+ :weight,
20
+ :days_to_deliver,
21
+ :days_to_fulfill,
22
+ :expedited_shipping_price,
23
+ :expedited_days_to_deliver,
24
+ :buy_one_get_one_price,
25
+ :primary_image,
26
+ :extra_images,
27
+ :all_images,
28
+ :ratings_count,
29
+ :ratings_average,
30
+ :created_at,
31
+ :updated_at,
32
+ :disabled_at,
33
+ :deleted_at
49
34
 
50
35
  class << self
51
- # ap TophatterMerchant::Product.schema
52
- def schema
53
- get(url: "#{path}/schema.json")
54
- end
55
-
56
- # ap TophatterMerchant::Product.all.map(&:to_h)
36
+ # http://merchant-api.tophatter.com/docs/product-list
37
+ # TophatterMerchant::Product.all(status: 'in_stock')
57
38
  def all(status: nil, category: nil, health_status: nil, page: 1, per_page: 50, pagination: nil, sort: nil)
58
- params = {
59
- status: status,
60
- category: category,
61
- health_status: health_status,
62
- page: page,
63
- per_page: per_page,
64
- pagination: pagination,
65
- sort: sort
66
- }
67
-
68
- result = get(url: "#{path}.json", params: params)
39
+ result = get(url: "#{path}.json", params: { status: status, category: category, health_status: health_status, page: page, per_page: per_page, pagination: pagination, sort: sort }.reject { |_k, v| v.nil? })
69
40
 
70
- if pagination.present?
41
+ if pagination
71
42
  result['results'] = result['results'].map { |hash| Product.new(hash) }
72
43
  else
73
44
  result = result.map { |hash| Product.new(hash) }
@@ -76,10 +47,12 @@ module TophatterMerchant
76
47
  result
77
48
  end
78
49
 
50
+ # http://merchant-api.tophatter.com/docs/product-search
51
+ # TophatterMerchant::Product.search(query: 'Kindle')
79
52
  def search(query:, page: 1, per_page: 50, pagination: nil)
80
53
  result = get(url: "#{path}/search.json", params: { query: query, page: page, per_page: per_page, pagination: pagination })
81
54
 
82
- if pagination.present?
55
+ if pagination
83
56
  result['results'] = result['results'].map { |hash| Product.new(hash) }
84
57
  else
85
58
  result = result.map { |hash| Product.new(hash) }
@@ -88,41 +61,35 @@ module TophatterMerchant
88
61
  result
89
62
  end
90
63
 
64
+ # http://merchant-api.tophatter.com/docs/product-retrieve
65
+ # TophatterMerchant::Product.retrieve('amazon-fire-7')
91
66
  def retrieve(id)
92
67
  Product.new get(url: "#{path}/retrieve.json", params: { identifier: id })
93
68
  end
94
69
 
95
- # ap TophatterMerchant::Product.create(TophatterMerchant::Product.new({}).fill!.to_h).to_h
70
+ # http://merchant-api.tophatter.com/docs/product-create
96
71
  def create(data)
97
72
  Product.new post(url: "#{path}.json", params: data)
98
73
  end
99
74
 
100
- # ap TophatterMerchant::Product.update('FOOBAR', buy_now_price: 11).to_h
75
+ # http://merchant-api.tophatter.com/docs/product-update
76
+ # TophatterMerchant::Product.update('amazon-fire-7', brand: 'Amazon').brand
101
77
  def update(id, data)
102
78
  Product.new post(url: "#{path}/update.json", params: data.merge(identifier: id))
103
79
  end
104
80
 
105
- # ap TophatterMerchant::Product.disable('FOOBAR').to_h
81
+ # http://merchant-api.tophatter.com/docs/product-disable
82
+ # TophatterMerchant::Product.disable('amazon-fire-7').disabled_at
106
83
  def disable(id)
107
84
  Product.new post(url: "#{path}/disable.json", params: { identifier: id })
108
85
  end
109
86
 
110
- # ap TophatterMerchant::Product.enable('FOOBAR').to_h
87
+ # http://merchant-api.tophatter.com/docs/product-enable
88
+ # TophatterMerchant::Product.enable('amazon-fire-7').disabled_at
111
89
  def enable(id)
112
90
  Product.new post(url: "#{path}/enable.json", params: { identifier: id })
113
91
  end
114
92
 
115
- # ap TophatterMerchant::Product.enable_catalog_only('FOOBAR').to_h
116
- def enable_catalog_only(id)
117
- Product.new post(url: "#{path}/enable_catalog_only.json", params: { identifier: id })
118
- end
119
-
120
- # ap TophatterMerchant::Product.delete('FOOBAR').to_h
121
- # NOT DOCUMENTED
122
- def delete(id)
123
- Product.new post(url: "#{path}/delete.json", params: { identifier: id })
124
- end
125
-
126
93
  protected
127
94
 
128
95
  def path
@@ -1,24 +1,13 @@
1
1
  module TophatterMerchant
2
- class BaseException < StandardError; end
2
+ class BaseException < StandardError; end
3
3
  class BadContentTypeException < BaseException; end
4
- class UnauthorizedException < BaseException; end
5
- class BadRequestException < BaseException; end
6
- class NotFoundException < BaseException; end
7
- class ServerErrorException < BaseException; end
4
+ class UnauthorizedException < BaseException; end
5
+ class BadRequestException < BaseException; end
6
+ class NotFoundException < BaseException; end
7
+ class ServerErrorException < BaseException; end
8
8
 
9
9
  class Resource
10
- include ActiveModel::Model
11
-
12
10
  def initialize(hash)
13
- self.attributes = hash
14
- end
15
-
16
- def attributes
17
- self.class.attributes
18
- end
19
-
20
- def attributes=(hash)
21
- # Only honor valid attributes.
22
11
  hash.each do |key, value|
23
12
  if respond_to?("#{key}=")
24
13
  send("#{key}=", value)
@@ -28,26 +17,22 @@ module TophatterMerchant
28
17
  end
29
18
  end
30
19
 
31
- def persisted?
32
- id.present? # @TODO: Should this be internal_id?
33
- end
20
+ def to_hash
21
+ instance_variables.map do |instance_variable|
22
+ key = instance_variable.to_s.delete('@')
23
+ value = instance_variable_get(instance_variable)
24
+
25
+ if value.is_a?(Array) && value.all? { |element| element.respond_to?(:to_hash) }
26
+ value = value.map(&:to_hash)
27
+ elsif value.respond_to?(:to_hash)
28
+ value = value.to_hash
29
+ end
34
30
 
35
- def to_h
36
- self.class.attributes.map { |key| [key, send(key)] }.to_h
31
+ value ? [key, value] : nil
32
+ end.compact.to_h
37
33
  end
38
34
 
39
35
  class << self
40
- def attr_accessor(*vars)
41
- @attributes ||= {}
42
- vars.each { |var| @attributes[var.to_s] = true }
43
- super(*vars)
44
- end
45
-
46
- def attributes
47
- @attributes ||= {}
48
- @attributes.keys
49
- end
50
-
51
36
  protected
52
37
 
53
38
  def get(url:, params: {})
@@ -58,14 +43,6 @@ module TophatterMerchant
58
43
  execute request(method: :post, url: url, params: params)
59
44
  end
60
45
 
61
- def put(url:, params: {})
62
- execute request(method: :put, url: url, params: params)
63
- end
64
-
65
- def delete(url:, params: {})
66
- execute request(method: :delete, url: url, params: params)
67
- end
68
-
69
46
  def execute(request)
70
47
  TophatterMerchant.logger.debug "#{request.method.upcase} #{request.url} #{request.payload.inspect}"
71
48
  response = request.execute
@@ -86,13 +63,12 @@ module TophatterMerchant
86
63
  end
87
64
 
88
65
  def request(method:, url:, params:)
89
- payload = if TophatterMerchant.access_token.present?
90
- params.merge(access_token: TophatterMerchant.access_token)
91
- else
92
- params
93
- end
94
-
95
- RestClient::Request.new(method: method, url: url, payload: payload, accept: :json)
66
+ RestClient::Request.new(
67
+ method: method,
68
+ url: url,
69
+ payload: TophatterMerchant.access_token.empty? ? params : params.merge(access_token: TophatterMerchant.access_token),
70
+ headers: { accept: :json, content_type: :json }
71
+ )
96
72
  end
97
73
 
98
74
  def path