From 49f73cf8917eb890e356f006698ada4928f8b0e9 Mon Sep 17 00:00:00 2001 From: nepalez Date: Tue, 7 Aug 2018 17:34:03 +0300 Subject: [PATCH 01/51] Add model for eBay program types --- config/dictionary.yml | 3 +++ lib/ebay_api/models.rb | 1 + lib/ebay_api/models/program_type.rb | 10 ++++++++++ spec/models/program_type_spec.rb | 21 +++++++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 lib/ebay_api/models/program_type.rb create mode 100644 spec/models/program_type_spec.rb diff --git a/config/dictionary.yml b/config/dictionary.yml index 218e5a7..ae3ed3b 100644 --- a/config/dictionary.yml +++ b/config/dictionary.yml @@ -1016,6 +1016,9 @@ - NONE - PRE_CHECKOUT - DURING_CHECKOUT +:program_type: # https://developer.ebay.com/api-docs/sell/account/types/api:ProgramTypeEnum + - OUT_OF_STOCK_CONTROL + - SELLING_POLICY_MANAGEMENT :refund_status: # https://developer.ebay.com/api-docs/sell/fulfillment/types/sel:RefundStatusEnum - code: FAILED requested: true diff --git a/lib/ebay_api/models.rb b/lib/ebay_api/models.rb index 7549b12..fe471d9 100644 --- a/lib/ebay_api/models.rb +++ b/lib/ebay_api/models.rb @@ -10,3 +10,4 @@ require_relative "models/campaign" require_relative "models/create_campaign_request" require_relative "models/funding_strategy" +require_relative "models/program_type" diff --git a/lib/ebay_api/models/program_type.rb b/lib/ebay_api/models/program_type.rb new file mode 100644 index 0000000..8f6d585 --- /dev/null +++ b/lib/ebay_api/models/program_type.rb @@ -0,0 +1,10 @@ +class EbayAPI + # Key for program types a seller can opt in + class ProgramType < String + extend Evil::Client::Dictionary["#{DICTIONARY_FILE}#program_type"] + + def self.call(value) + super value.to_s.upcase + end + end +end diff --git a/spec/models/program_type_spec.rb b/spec/models/program_type_spec.rb new file mode 100644 index 0000000..ea7aadc --- /dev/null +++ b/spec/models/program_type_spec.rb @@ -0,0 +1,21 @@ +RSpec.describe EbayAPI::ProgramType do + describe "#call, #[]" do + subject(:program_type) { described_class[key] } + + context "by known key" do + let(:key) { :out_of_stock_control } + + it "finds the type" do + expect(subject).to eq "OUT_OF_STOCK_CONTROL" + end + end + + context "by unknown key" do + let(:key) { "AAA" } + + it "raises ArgumentError" do + expect { subject }.to raise_error(StandardError, /AAA/) + end + end + end +end From d5e33129b108233cfcbfe27133a654be932d3cdb Mon Sep 17 00:00:00 2001 From: nepalez Date: Tue, 7 Aug 2018 17:43:45 +0300 Subject: [PATCH 02/51] Add operation account/program/opt_in --- lib/ebay_api/operations/sell/account.rb | 1 + .../operations/sell/account/program.rb | 11 ++++++++++ .../operations/sell/account/program/opt_in.rb | 16 ++++++++++++++ .../sell/account/program/opt_in_spec.rb | 22 +++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 lib/ebay_api/operations/sell/account/program.rb create mode 100644 lib/ebay_api/operations/sell/account/program/opt_in.rb create mode 100644 spec/operations/sell/account/program/opt_in_spec.rb diff --git a/lib/ebay_api/operations/sell/account.rb b/lib/ebay_api/operations/sell/account.rb index b4b3ea5..abd9476 100644 --- a/lib/ebay_api/operations/sell/account.rb +++ b/lib/ebay_api/operations/sell/account.rb @@ -7,6 +7,7 @@ class EbayAPI path { "account/v#{EbayAPI::SELL_ACCOUNT_VERSION[/^\d+/]}" } require_relative "account/privilege" + require_relative "account/program" end end end diff --git a/lib/ebay_api/operations/sell/account/program.rb b/lib/ebay_api/operations/sell/account/program.rb new file mode 100644 index 0000000..0e523b2 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/program.rb @@ -0,0 +1,11 @@ +require_relative "program/opt_in" + +class EbayAPI + scope :sell do + scope :account do + scope :program do + path { "program" } + end + end + end +end diff --git a/lib/ebay_api/operations/sell/account/program/opt_in.rb b/lib/ebay_api/operations/sell/account/program/opt_in.rb new file mode 100644 index 0000000..d93dc11 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/program/opt_in.rb @@ -0,0 +1,16 @@ +class EbayAPI + scope :sell do + scope :account do + scope :program do + # @see https://developer.ebay.com/api-docs/sell/account/resources/program/methods/optInToProgram + operation :opt_in do + option :program, ProgramType + + http_method :post + path { "/opt_in" } + body { { programType: program } } + end + end + end + end +end diff --git a/spec/operations/sell/account/program/opt_in_spec.rb b/spec/operations/sell/account/program/opt_in_spec.rb new file mode 100644 index 0000000..c6beb0e --- /dev/null +++ b/spec/operations/sell/account/program/opt_in_spec.rb @@ -0,0 +1,22 @@ +RSpec.describe EbayAPI, ".sell.account.program.opt_in" do + let(:url) { "https://api.ebay.com/sell/account/v1/program/opt_in" } + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).program } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + let(:request) { { "programType" => "SELLING_POLICY_MANAGEMENT" }.to_json } + + before { stub_request(:post, url) } + subject { scope.opt_in program: :selling_policy_management } + + context "success" do + let(:response) do + open_fixture_file "sell/account/program/opt_in/success" + end + + it "sends a request" do + subject + expect(a_request(:post, url).with(body: request)).to have_been_made + end + end +end From 68fb65b71c02a1bbc1f6b6e43643942833b2bd0e Mon Sep 17 00:00:00 2001 From: nepalez Date: Tue, 7 Aug 2018 18:15:42 +0300 Subject: [PATCH 03/51] Fix security issue in the gemspec --- ebay_api.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ebay_api.gemspec b/ebay_api.gemspec index d3c5f12..23f025e 100644 --- a/ebay_api.gemspec +++ b/ebay_api.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |gem| gem.add_development_dependency "rake", ">= 10" gem.add_development_dependency "rspec", "~> 3.0" gem.add_development_dependency "rspec-its", "~> 1.2" - gem.add_development_dependency "rubocop", "~> 0.42" + gem.add_development_dependency "rubocop", "~> 0.49" gem.add_development_dependency "timecop", "~> 0.9" gem.add_development_dependency "webmock", "~> 2.1" gem.add_development_dependency "httplog" From 994da34c04998adf1abada31ad6a05eb7e1a9949 Mon Sep 17 00:00:00 2001 From: nepalez Date: Thu, 9 Aug 2018 14:11:40 +0300 Subject: [PATCH 04/51] Add fulfillment_policy.delete method call --- lib/ebay_api.rb | 2 ++ lib/ebay_api/operations/sell/account.rb | 1 + .../sell/account/fulfillment_policy.rb | 11 ++++++++++ .../sell/account/fulfillment_policy/delete.rb | 15 +++++++++++++ .../account/fulfillment_policy/delete_spec.rb | 21 +++++++++++++++++++ 5 files changed, 50 insertions(+) create mode 100644 lib/ebay_api/operations/sell/account/fulfillment_policy.rb create mode 100644 lib/ebay_api/operations/sell/account/fulfillment_policy/delete.rb create mode 100644 spec/operations/sell/account/fulfillment_policy/delete_spec.rb diff --git a/lib/ebay_api.rb b/lib/ebay_api.rb index 0e8d15b..3cda7ad 100644 --- a/lib/ebay_api.rb +++ b/lib/ebay_api.rb @@ -63,6 +63,8 @@ class EbayAPI < Evil::Client response(200) { |_, _, (data, *)| data } + response(204) { true } + # https://developer.ebay.com/api-docs/static/handling-error-messages.html response(400, 401, 409) do |_, _, (data, *)| case (code = data.dig("errors", 0, "errorId")) diff --git a/lib/ebay_api/operations/sell/account.rb b/lib/ebay_api/operations/sell/account.rb index abd9476..f0b3f78 100644 --- a/lib/ebay_api/operations/sell/account.rb +++ b/lib/ebay_api/operations/sell/account.rb @@ -8,6 +8,7 @@ class EbayAPI require_relative "account/privilege" require_relative "account/program" + require_relative "account/fulfillment_policy" end end end diff --git a/lib/ebay_api/operations/sell/account/fulfillment_policy.rb b/lib/ebay_api/operations/sell/account/fulfillment_policy.rb new file mode 100644 index 0000000..cc0e8af --- /dev/null +++ b/lib/ebay_api/operations/sell/account/fulfillment_policy.rb @@ -0,0 +1,11 @@ +class EbayAPI + scope :sell do + scope :account do + scope :fulfillment_policy do + path { "fulfillment_policy" } + end + end + end +end + +require_relative "fulfillment_policy/delete" diff --git a/lib/ebay_api/operations/sell/account/fulfillment_policy/delete.rb b/lib/ebay_api/operations/sell/account/fulfillment_policy/delete.rb new file mode 100644 index 0000000..0b2e1f9 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/fulfillment_policy/delete.rb @@ -0,0 +1,15 @@ +class EbayAPI + scope :sell do + scope :account do + scope :fulfillment_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/fulfillment_policy/methods/deleteFulfillmentPolicy + operation :delete do + option :id, proc(&:to_s) + + path { id } + http_method :delete + end + end + end + end +end diff --git a/spec/operations/sell/account/fulfillment_policy/delete_spec.rb b/spec/operations/sell/account/fulfillment_policy/delete_spec.rb new file mode 100644 index 0000000..a085c41 --- /dev/null +++ b/spec/operations/sell/account/fulfillment_policy/delete_spec.rb @@ -0,0 +1,21 @@ +RSpec.describe EbayAPI, ".sell.account.fulfillment_policy.delete" do + let(:url) { "https://api.ebay.com/sell/account/v1/fulfillment_policy/42" } + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).fulfillment_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + + before { stub_request(:delete, url).to_return(status: 204) } + subject { scope.delete id: 42 } + + context "success" do + it "sends a request" do + subject + expect(a_request(:delete, url)).to have_been_made + end + + it "returns true" do + expect(subject).to eq true + end + end +end From 606bbae5d38edb518e1fabe0653539a005b9b5e7 Mon Sep 17 00:00:00 2001 From: nepalez Date: Thu, 9 Aug 2018 15:17:51 +0300 Subject: [PATCH 05/51] Add fulfillment_policy.get method call --- .gitignore | 1 - .../sell/account/fulfillment_policy.rb | 1 + .../sell/account/fulfillment_policy/get.rb | 15 +++++++++ .../account/fulfillment_policy/get/success | 6 ++++ .../fulfillment_policy/get/success.yml | 33 +++++++++++++++++++ .../account/fulfillment_policy/get_spec.rb | 31 +++++++++++++++++ 6 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 lib/ebay_api/operations/sell/account/fulfillment_policy/get.rb create mode 100644 spec/fixtures/sell/account/fulfillment_policy/get/success create mode 100644 spec/fixtures/sell/account/fulfillment_policy/get/success.yml create mode 100644 spec/operations/sell/account/fulfillment_policy/get_spec.rb diff --git a/.gitignore b/.gitignore index a2807f6..e0afc44 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,3 @@ /tmp/ *.gem .rspec_status -*.yml diff --git a/lib/ebay_api/operations/sell/account/fulfillment_policy.rb b/lib/ebay_api/operations/sell/account/fulfillment_policy.rb index cc0e8af..ecb5f18 100644 --- a/lib/ebay_api/operations/sell/account/fulfillment_policy.rb +++ b/lib/ebay_api/operations/sell/account/fulfillment_policy.rb @@ -9,3 +9,4 @@ class EbayAPI end require_relative "fulfillment_policy/delete" +require_relative "fulfillment_policy/get" diff --git a/lib/ebay_api/operations/sell/account/fulfillment_policy/get.rb b/lib/ebay_api/operations/sell/account/fulfillment_policy/get.rb new file mode 100644 index 0000000..8e62910 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/fulfillment_policy/get.rb @@ -0,0 +1,15 @@ +class EbayAPI + scope :sell do + scope :account do + scope :fulfillment_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/fulfillment_policy/methods/getFulfillmentPolicy + operation :get do + option :id, proc(&:to_s) + + path { id } + http_method :get + end + end + end + end +end diff --git a/spec/fixtures/sell/account/fulfillment_policy/get/success b/spec/fixtures/sell/account/fulfillment_policy/get/success new file mode 100644 index 0000000..9d7ad70 --- /dev/null +++ b/spec/fixtures/sell/account/fulfillment_policy/get/success @@ -0,0 +1,6 @@ +HTTP/1.1 200 OK +Content-Length: 724 +Content-Type: application/json + +{"name":"Domestic free shipping","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":false}],"handlingTime":{"value":1,"unit":"DAY"},"shippingOptions":[{"optionType":"DOMESTIC","costType":"FLAT_RATE","shippingServices":[{"sortOrder":1,"shippingCarrierCode":"USPS","shippingServiceCode":"USPSPriorityFlatRateBox","shippingCost":{"value":0.0,"currency":"USD"},"additionalShippingCost":{"value":0.0,"currency":"USD"},"freeShipping":true,"buyerResponsibleForShipping":false,"buyerResponsibleForPickup":false}],"insuranceOffered":false,"insuranceFee":{"value":0.0,"currency":"USD"}}],"globalShipping":false,"pickupDropOff":false,"freightShipping":false,"fulfillmentPolicyId":"5733588000"} + diff --git a/spec/fixtures/sell/account/fulfillment_policy/get/success.yml b/spec/fixtures/sell/account/fulfillment_policy/get/success.yml new file mode 100644 index 0000000..1319be3 --- /dev/null +++ b/spec/fixtures/sell/account/fulfillment_policy/get/success.yml @@ -0,0 +1,33 @@ +--- +name: "Domestic free shipping" +marketplaceId: "EBAY_US" +categoryTypes: + - name: "ALL_EXCLUDING_MOTORS_VEHICLES" + default: false +handlingTime: + value: 1 + unit: "DAY" +shippingOptions: + - optionType: "DOMESTIC" + costType: "FLAT_RATE" + shippingServices: + - sortOrder: 1 + shippingCarrierCode: "USPS" + shippingServiceCode: "USPSPriorityFlatRateBox" + shippingCost: + value: 0.0 + currency: "USD" + additionalShippingCost: + value: 0.0 + currency: "USD" + freeShipping: true + buyerResponsibleForShipping: false + buyerResponsibleForPickup: false + insuranceOffered: false + insuranceFee: + value: 0.0 + currency: "USD" +globalShipping: false +pickupDropOff: false +freightShipping: false +fulfillmentPolicyId: "5733588000" diff --git a/spec/operations/sell/account/fulfillment_policy/get_spec.rb b/spec/operations/sell/account/fulfillment_policy/get_spec.rb new file mode 100644 index 0000000..8fb0a51 --- /dev/null +++ b/spec/operations/sell/account/fulfillment_policy/get_spec.rb @@ -0,0 +1,31 @@ +RSpec.describe EbayAPI, ".sell.account.fulfillment_policy.get" do + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).fulfillment_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + let(:url) do + "https://api.ebay.com/sell/account/v1/fulfillment_policy/5733588000" + end + + before { stub_request(:get, url).to_return(response) } + subject { scope.get id: "5733588000" } + + context "success" do + let(:response) do + open_fixture_file "sell/account/fulfillment_policy/get/success" + end + + let(:policy) do + yaml_fixture_file "sell/account/fulfillment_policy/get/success.yml" + end + + it "sends a request" do + subject + expect(a_request(:get, url)).to have_been_made + end + + it "returns the policy" do + expect(subject).to eq policy + end + end +end From cb2527b53ce3472dcd011c1e0df19c0703ce42d4 Mon Sep 17 00:00:00 2001 From: nepalez Date: Thu, 9 Aug 2018 17:17:08 +0300 Subject: [PATCH 06/51] Add fulfillment_policy.get_by_name method call --- .../sell/account/fulfillment_policy.rb | 1 + .../account/fulfillment_policy/get_by_name.rb | 17 ++++++ .../fulfillment_policy/get_by_name/success | 6 +++ .../get_by_name/success.yml | 53 +++++++++++++++++++ .../fulfillment_policy/get_by_name_spec.rb | 33 ++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 lib/ebay_api/operations/sell/account/fulfillment_policy/get_by_name.rb create mode 100644 spec/fixtures/sell/account/fulfillment_policy/get_by_name/success create mode 100644 spec/fixtures/sell/account/fulfillment_policy/get_by_name/success.yml create mode 100644 spec/operations/sell/account/fulfillment_policy/get_by_name_spec.rb diff --git a/lib/ebay_api/operations/sell/account/fulfillment_policy.rb b/lib/ebay_api/operations/sell/account/fulfillment_policy.rb index ecb5f18..ce212ae 100644 --- a/lib/ebay_api/operations/sell/account/fulfillment_policy.rb +++ b/lib/ebay_api/operations/sell/account/fulfillment_policy.rb @@ -10,3 +10,4 @@ class EbayAPI require_relative "fulfillment_policy/delete" require_relative "fulfillment_policy/get" +require_relative "fulfillment_policy/get_by_name" diff --git a/lib/ebay_api/operations/sell/account/fulfillment_policy/get_by_name.rb b/lib/ebay_api/operations/sell/account/fulfillment_policy/get_by_name.rb new file mode 100644 index 0000000..4dc0cd5 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/fulfillment_policy/get_by_name.rb @@ -0,0 +1,17 @@ +class EbayAPI + scope :sell do + scope :account do + scope :fulfillment_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/fulfillment_policy/methods/getFulfillmentPolicyByName + operation :get_by_name do + option :site, Site + option :name, proc(&:to_s) + + path { "/" } + query { { marketplace_id: site.key, name: name } } + http_method :get + end + end + end + end +end diff --git a/spec/fixtures/sell/account/fulfillment_policy/get_by_name/success b/spec/fixtures/sell/account/fulfillment_policy/get_by_name/success new file mode 100644 index 0000000..1e6155f --- /dev/null +++ b/spec/fixtures/sell/account/fulfillment_policy/get_by_name/success @@ -0,0 +1,6 @@ +HTTP/1.1 200 OK +Content-Length: 1249 +Content-Type: application/json + +{"name":"Worldwide shipping options: Free domestic, CALCULATED int'l","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":false}],"handlingTime":{"value":1,"unit":"DAY"},"shipToLocations":{"regionIncluded":[{"regionName":"Worldwide"}],"regionExcluded":[]},"shippingOptions":[{"optionType":"DOMESTIC","costType":"FLAT_RATE","shippingServices":[{"sortOrder":1,"shippingCarrierCode":"USPS","shippingServiceCode":"USPSPriorityFlatRateBox","shippingCost":{"value":0.0,"currency":"USD"},"additionalShippingCost":{"value":0.0,"currency":"USD"},"freeShipping":true,"buyerResponsibleForShipping":false,"buyerResponsibleForPickup":false}],"insuranceOffered":false,"insuranceFee":{"value":0.0,"currency":"USD"}},{"optionType":"INTERNATIONAL","costType":"CALCULATED","shippingServices":[{"sortOrder":1,"shippingCarrierCode":"USPS","shippingServiceCode":"USPSPriorityMailInternational","freeShipping":false,"shipToLocations":{"regionIncluded":[{"regionName":"Worldwide"}]},"buyerResponsibleForShipping":true,"buyerResponsibleForPickup":false}],"insuranceOffered":false,"insuranceFee":{"value":0.0,"currency":"USD"}}],"globalShipping":false,"pickupDropOff":false,"freightShipping":false,"fulfillmentPolicyId":"5733606000"} + diff --git a/spec/fixtures/sell/account/fulfillment_policy/get_by_name/success.yml b/spec/fixtures/sell/account/fulfillment_policy/get_by_name/success.yml new file mode 100644 index 0000000..5ceab01 --- /dev/null +++ b/spec/fixtures/sell/account/fulfillment_policy/get_by_name/success.yml @@ -0,0 +1,53 @@ +--- +name: "Worldwide shipping options: Free domestic, CALCULATED int'l" +marketplaceId: "EBAY_US" +categoryTypes: + - name: "ALL_EXCLUDING_MOTORS_VEHICLES" + default: false +handlingTime: + value: 1 + unit: "DAY" +shipToLocations: + regionIncluded: + - regionName: "Worldwide" + regionExcluded: [] +shippingOptions: + - optionType: "DOMESTIC" + costType: "FLAT_RATE" + shippingServices: + - sortOrder: 1 + shippingCarrierCode: "USPS" + shippingServiceCode: "USPSPriorityFlatRateBox" + shippingCost: + value: 0.0 + currency: "USD" + additionalShippingCost: + value: 0.0 + currency: "USD" + freeShipping: true + buyerResponsibleForShipping: false + buyerResponsibleForPickup: false + insuranceOffered: false + insuranceFee: + value: 0.0 + currency: "USD" + - optionType: "INTERNATIONAL" + costType: "CALCULATED" + shippingServices: + - sortOrder: 1 + shippingCarrierCode: "USPS" + shippingServiceCode: "USPSPriorityMailInternational" + freeShipping: false + shipToLocations: + regionIncluded: + - regionName: "Worldwide" + buyerResponsibleForShipping: true + buyerResponsibleForPickup: false + insuranceOffered: false + insuranceFee: + value: 0.0 + currency: "USD" +globalShipping: false +pickupDropOff: false +freightShipping: false +fulfillmentPolicyId: "5733606000" diff --git a/spec/operations/sell/account/fulfillment_policy/get_by_name_spec.rb b/spec/operations/sell/account/fulfillment_policy/get_by_name_spec.rb new file mode 100644 index 0000000..bc3b778 --- /dev/null +++ b/spec/operations/sell/account/fulfillment_policy/get_by_name_spec.rb @@ -0,0 +1,33 @@ +RSpec.describe EbayAPI, ".sell.account.fulfillment_policy.get_by_name" do + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).fulfillment_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + let(:url) do + "https://api.ebay.com/sell/account/v1/fulfillment_policy/" \ + "?marketplace_id=EBAY_US&name=postcards" + end + + before { stub_request(:get, url).to_return(response) } + subject { scope.get_by_name site: 0, name: "postcards" } + + context "success" do + let(:response) do + open_fixture_file "sell/account/fulfillment_policy/get_by_name/success" + end + + let(:policy) do + yaml_fixture_file \ + "sell/account/fulfillment_policy/get_by_name/success.yml" + end + + it "sends a request" do + subject + expect(a_request(:get, url)).to have_been_made + end + + it "returns the policy" do + expect(subject).to eq policy + end + end +end From 9eaab94d77b1b610b24f4389f0429bf9fd32961b Mon Sep 17 00:00:00 2001 From: nepalez Date: Thu, 9 Aug 2018 17:31:30 +0300 Subject: [PATCH 07/51] Add fulfillment_policy.index method call --- .../sell/account/fulfillment_policy.rb | 1 + .../sell/account/fulfillment_policy/index.rb | 16 ++++ .../account/fulfillment_policy/index/success | 6 ++ .../fulfillment_policy/index/success.yml | 87 +++++++++++++++++++ .../account/fulfillment_policy/index_spec.rb | 32 +++++++ 5 files changed, 142 insertions(+) create mode 100644 lib/ebay_api/operations/sell/account/fulfillment_policy/index.rb create mode 100644 spec/fixtures/sell/account/fulfillment_policy/index/success create mode 100644 spec/fixtures/sell/account/fulfillment_policy/index/success.yml create mode 100644 spec/operations/sell/account/fulfillment_policy/index_spec.rb diff --git a/lib/ebay_api/operations/sell/account/fulfillment_policy.rb b/lib/ebay_api/operations/sell/account/fulfillment_policy.rb index ce212ae..d55dac6 100644 --- a/lib/ebay_api/operations/sell/account/fulfillment_policy.rb +++ b/lib/ebay_api/operations/sell/account/fulfillment_policy.rb @@ -11,3 +11,4 @@ class EbayAPI require_relative "fulfillment_policy/delete" require_relative "fulfillment_policy/get" require_relative "fulfillment_policy/get_by_name" +require_relative "fulfillment_policy/index" diff --git a/lib/ebay_api/operations/sell/account/fulfillment_policy/index.rb b/lib/ebay_api/operations/sell/account/fulfillment_policy/index.rb new file mode 100644 index 0000000..857a7d6 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/fulfillment_policy/index.rb @@ -0,0 +1,16 @@ +class EbayAPI + scope :sell do + scope :account do + scope :fulfillment_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/fulfillment_policy/methods/getFulfillmentPolicies + operation :index do + option :site, Site + + path { "/" } + query { { marketplace_id: site.key } } + http_method :get + end + end + end + end +end diff --git a/spec/fixtures/sell/account/fulfillment_policy/index/success b/spec/fixtures/sell/account/fulfillment_policy/index/success new file mode 100644 index 0000000..969b4a0 --- /dev/null +++ b/spec/fixtures/sell/account/fulfillment_policy/index/success @@ -0,0 +1,6 @@ +HTTP/1.1 200 OK +Content-Length: 2010 +Content-Type: application/json + +{"total":2,"fulfillmentPolicies":[{"name":"Domestic free shipping","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":false}],"handlingTime":{"value":1,"unit":"DAY"},"shippingOptions":[{"optionType":"DOMESTIC","costType":"FLAT_RATE","shippingServices":[{"sortOrder":1,"shippingCarrierCode":"USPS","shippingServiceCode":"USPSPriorityFlatRateBox","shippingCost":{"value":0.0,"currency":"USD"},"additionalShippingCost":{"value":0.0,"currency":"USD"},"freeShipping":true,"buyerResponsibleForShipping":false,"buyerResponsibleForPickup":false}],"insuranceOffered":false,"insuranceFee":{"value":0.0,"currency":"USD"}}],"globalShipping":false,"pickupDropOff":false,"freightShipping":false,"fulfillmentPolicyId":"5733588000"},{"name":"Worldwide shipping options: Free domestic, CALCULATED int'l","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":false}],"handlingTime":{"value":1,"unit":"DAY"},"shipToLocations":{"regionIncluded":[{"regionName":"Worldwide"}],"regionExcluded":[]},"shippingOptions":[{"optionType":"DOMESTIC","costType":"FLAT_RATE","shippingServices":[{"sortOrder":1,"shippingCarrierCode":"USPS","shippingServiceCode":"USPSPriorityFlatRateBox","shippingCost":{"value":0.0,"currency":"USD"},"additionalShippingCost":{"value":0.0,"currency":"USD"},"freeShipping":true,"buyerResponsibleForShipping":false,"buyerResponsibleForPickup":false}],"insuranceOffered":false,"insuranceFee":{"value":0.0,"currency":"USD"}},{"optionType":"INTERNATIONAL","costType":"CALCULATED","shippingServices":[{"sortOrder":1,"shippingCarrierCode":"USPS","shippingServiceCode":"USPSPriorityMailInternational","freeShipping":false,"shipToLocations":{"regionIncluded":[{"regionName":"Worldwide"}]},"buyerResponsibleForShipping":true,"buyerResponsibleForPickup":false}],"insuranceOffered":false,"insuranceFee":{"value":0.0,"currency":"USD"}}],"globalShipping":false,"pickupDropOff":false,"freightShipping":false,"fulfillmentPolicyId":"5733606000"}]} + diff --git a/spec/fixtures/sell/account/fulfillment_policy/index/success.yml b/spec/fixtures/sell/account/fulfillment_policy/index/success.yml new file mode 100644 index 0000000..977488e --- /dev/null +++ b/spec/fixtures/sell/account/fulfillment_policy/index/success.yml @@ -0,0 +1,87 @@ +--- +total: 2 +fulfillmentPolicies: +- name: Domestic free shipping + marketplaceId: EBAY_US + categoryTypes: + - name: ALL_EXCLUDING_MOTORS_VEHICLES + default: false + handlingTime: + value: 1 + unit: DAY + shippingOptions: + - optionType: DOMESTIC + costType: FLAT_RATE + shippingServices: + - sortOrder: 1 + shippingCarrierCode: USPS + shippingServiceCode: USPSPriorityFlatRateBox + shippingCost: + value: 0.0 + currency: USD + additionalShippingCost: + value: 0.0 + currency: USD + freeShipping: true + buyerResponsibleForShipping: false + buyerResponsibleForPickup: false + insuranceOffered: false + insuranceFee: + value: 0.0 + currency: USD + globalShipping: false + pickupDropOff: false + freightShipping: false + fulfillmentPolicyId: '5733588000' +- name: 'Worldwide shipping options: Free domestic, CALCULATED int''l' + marketplaceId: EBAY_US + categoryTypes: + - name: ALL_EXCLUDING_MOTORS_VEHICLES + default: false + handlingTime: + value: 1 + unit: DAY + shipToLocations: + regionIncluded: + - regionName: Worldwide + regionExcluded: [] + shippingOptions: + - optionType: DOMESTIC + costType: FLAT_RATE + shippingServices: + - sortOrder: 1 + shippingCarrierCode: USPS + shippingServiceCode: USPSPriorityFlatRateBox + shippingCost: + value: 0.0 + currency: USD + additionalShippingCost: + value: 0.0 + currency: USD + freeShipping: true + buyerResponsibleForShipping: false + buyerResponsibleForPickup: false + insuranceOffered: false + insuranceFee: + value: 0.0 + currency: USD + - optionType: INTERNATIONAL + costType: CALCULATED + shippingServices: + - sortOrder: 1 + shippingCarrierCode: USPS + shippingServiceCode: USPSPriorityMailInternational + freeShipping: false + shipToLocations: + regionIncluded: + - regionName: Worldwide + buyerResponsibleForShipping: true + buyerResponsibleForPickup: false + insuranceOffered: false + insuranceFee: + value: 0.0 + currency: USD + globalShipping: false + pickupDropOff: false + freightShipping: false + fulfillmentPolicyId: '5733606000' diff --git a/spec/operations/sell/account/fulfillment_policy/index_spec.rb b/spec/operations/sell/account/fulfillment_policy/index_spec.rb new file mode 100644 index 0000000..5fd0398 --- /dev/null +++ b/spec/operations/sell/account/fulfillment_policy/index_spec.rb @@ -0,0 +1,32 @@ +RSpec.describe EbayAPI, ".sell.account.fulfillment_policy.index" do + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).fulfillment_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + let(:url) do + "https://api.ebay.com/sell/account/v1/fulfillment_policy/" \ + "?marketplace_id=EBAY_US" + end + + before { stub_request(:get, url).to_return(response) } + subject { scope.index id: "5733588000" } + + context "success" do + let(:response) do + open_fixture_file "sell/account/fulfillment_policy/get/success" + end + + let(:policy) do + yaml_fixture_file "sell/account/fulfillment_policy/get/success.yml" + end + + it "sends a request" do + subject + expect(a_request(:get, url)).to have_been_made + end + + it "returns the policy" do + expect(subject).to eq policy + end + end +end From de6dd909d38df3a9611125aea0a3428befa0beaa Mon Sep 17 00:00:00 2001 From: nepalez Date: Thu, 9 Aug 2018 18:23:37 +0300 Subject: [PATCH 08/51] Add fulfillment_policy.create method call --- lib/ebay_api.rb | 2 +- .../sell/account/fulfillment_policy.rb | 1 + .../sell/account/fulfillment_policy/create.rb | 16 +++++++++ .../fulfillment_policy/create/request.yml | 16 +++++++++ .../account/fulfillment_policy/create/success | 6 ++++ .../fulfillment_policy/create/success.yml | 34 ++++++++++++++++++ .../account/fulfillment_policy/create_spec.rb | 36 +++++++++++++++++++ 7 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 lib/ebay_api/operations/sell/account/fulfillment_policy/create.rb create mode 100644 spec/fixtures/sell/account/fulfillment_policy/create/request.yml create mode 100644 spec/fixtures/sell/account/fulfillment_policy/create/success create mode 100644 spec/fixtures/sell/account/fulfillment_policy/create/success.yml create mode 100644 spec/operations/sell/account/fulfillment_policy/create_spec.rb diff --git a/lib/ebay_api.rb b/lib/ebay_api.rb index 3cda7ad..51040b5 100644 --- a/lib/ebay_api.rb +++ b/lib/ebay_api.rb @@ -61,7 +61,7 @@ class EbayAPI < Evil::Client }.compact end - response(200) { |_, _, (data, *)| data } + response(200, 201) { |_, _, (data, *)| data } response(204) { true } diff --git a/lib/ebay_api/operations/sell/account/fulfillment_policy.rb b/lib/ebay_api/operations/sell/account/fulfillment_policy.rb index d55dac6..f1b0e59 100644 --- a/lib/ebay_api/operations/sell/account/fulfillment_policy.rb +++ b/lib/ebay_api/operations/sell/account/fulfillment_policy.rb @@ -12,3 +12,4 @@ class EbayAPI require_relative "fulfillment_policy/get" require_relative "fulfillment_policy/get_by_name" require_relative "fulfillment_policy/index" +require_relative "fulfillment_policy/create" diff --git a/lib/ebay_api/operations/sell/account/fulfillment_policy/create.rb b/lib/ebay_api/operations/sell/account/fulfillment_policy/create.rb new file mode 100644 index 0000000..63aafb0 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/fulfillment_policy/create.rb @@ -0,0 +1,16 @@ +class EbayAPI + scope :sell do + scope :account do + scope :fulfillment_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/fulfillment_policy/methods/createFulfillmentPolicy + operation :create do + option :policy, proc(&:to_h) # TODO: add model to validate input + + path { "/" } + http_method :post + body { policy } + end + end + end + end +end diff --git a/spec/fixtures/sell/account/fulfillment_policy/create/request.yml b/spec/fixtures/sell/account/fulfillment_policy/create/request.yml new file mode 100644 index 0000000..77a7607 --- /dev/null +++ b/spec/fixtures/sell/account/fulfillment_policy/create/request.yml @@ -0,0 +1,16 @@ +--- +categoryTypes: + - name: ALL_EXCLUDING_MOTORS_VEHICLES +marketplaceId: EBAY_US +name: Domestic free shipping +handlingTime: + unit: DAY + value: 1 +shippingOptions: + - costType: FLAT_RATE + optionType: DOMESTIC + shippingServices: + - buyerResponsibleForShipping: false + freeShipping: true + shippingCarrierCode: USPS + shippingServiceCode: USPSPriorityFlatRateBox diff --git a/spec/fixtures/sell/account/fulfillment_policy/create/success b/spec/fixtures/sell/account/fulfillment_policy/create/success new file mode 100644 index 0000000..4022949 --- /dev/null +++ b/spec/fixtures/sell/account/fulfillment_policy/create/success @@ -0,0 +1,6 @@ +HTTP/1.1 201 Created +Content-Length: 738 +Content-Type: application/json + +{"name":"Domestic free shipping","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":false}],"handlingTime":{"value":1,"unit":"DAY"},"shippingOptions":[{"optionType":"DOMESTIC","costType":"FLAT_RATE","shippingServices":[{"sortOrder":1,"shippingCarrierCode":"USPS","shippingServiceCode":"USPSPriorityFlatRateBox","shippingCost":{"value":0.0,"currency":"USD"},"additionalShippingCost":{"value":0.0,"currency":"USD"},"freeShipping":true,"buyerResponsibleForShipping":false,"buyerResponsibleForPickup":false}],"insuranceOffered":false,"insuranceFee":{"value":0.0,"currency":"USD"}}],"globalShipping":false,"pickupDropOff":false,"freightShipping":false,"fulfillmentPolicyId":"5733588000","warnings":[]} + diff --git a/spec/fixtures/sell/account/fulfillment_policy/create/success.yml b/spec/fixtures/sell/account/fulfillment_policy/create/success.yml new file mode 100644 index 0000000..10377b1 --- /dev/null +++ b/spec/fixtures/sell/account/fulfillment_policy/create/success.yml @@ -0,0 +1,34 @@ +--- +name: Domestic free shipping +marketplaceId: EBAY_US +categoryTypes: + - name: ALL_EXCLUDING_MOTORS_VEHICLES + default: false +handlingTime: + value: 1 + unit: DAY +shippingOptions: + - optionType: DOMESTIC + costType: FLAT_RATE + shippingServices: + - sortOrder: 1 + shippingCarrierCode: USPS + shippingServiceCode: USPSPriorityFlatRateBox + shippingCost: + value: 0.0 + currency: USD + additionalShippingCost: + value: 0.0 + currency: USD + freeShipping: true + buyerResponsibleForShipping: false + buyerResponsibleForPickup: false + insuranceOffered: false + insuranceFee: + value: 0.0 + currency: USD +globalShipping: false +pickupDropOff: false +freightShipping: false +fulfillmentPolicyId: '5733588000' +warnings: [] diff --git a/spec/operations/sell/account/fulfillment_policy/create_spec.rb b/spec/operations/sell/account/fulfillment_policy/create_spec.rb new file mode 100644 index 0000000..7814dae --- /dev/null +++ b/spec/operations/sell/account/fulfillment_policy/create_spec.rb @@ -0,0 +1,36 @@ +RSpec.describe EbayAPI, ".sell.account.fulfillment_policy.create" do + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).fulfillment_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + + let(:url) do + "https://api.ebay.com/sell/account/v1/fulfillment_policy/" + end + + let(:payload) do + yaml_fixture_file "sell/account/fulfillment_policy/create/request.yml" + end + + before { stub_request(:post, url).to_return(response) } + subject { scope.create policy: payload } + + context "success" do + let(:response) do + open_fixture_file "sell/account/fulfillment_policy/create/success" + end + + let(:policy) do + yaml_fixture_file "sell/account/fulfillment_policy/create/success.yml" + end + + it "sends a request" do + subject + expect(a_request(:post, url)).to have_been_made + end + + it "returns the policy" do + expect(subject).to eq policy + end + end +end From 5f47149e3e7460c16c434f1d61a48c0d3db9a2c8 Mon Sep 17 00:00:00 2001 From: nepalez Date: Thu, 9 Aug 2018 18:48:26 +0300 Subject: [PATCH 09/51] Add fulfillment_policy.update method call --- .../sell/account/fulfillment_policy.rb | 1 + .../sell/account/fulfillment_policy/update.rb | 17 ++++++ .../fulfillment_policy/update/request.yml | 34 ++++++++++++ .../account/fulfillment_policy/update/success | 6 +++ .../fulfillment_policy/update/success.yml | 54 +++++++++++++++++++ .../account/fulfillment_policy/update_spec.rb | 36 +++++++++++++ 6 files changed, 148 insertions(+) create mode 100644 lib/ebay_api/operations/sell/account/fulfillment_policy/update.rb create mode 100644 spec/fixtures/sell/account/fulfillment_policy/update/request.yml create mode 100644 spec/fixtures/sell/account/fulfillment_policy/update/success create mode 100644 spec/fixtures/sell/account/fulfillment_policy/update/success.yml create mode 100644 spec/operations/sell/account/fulfillment_policy/update_spec.rb diff --git a/lib/ebay_api/operations/sell/account/fulfillment_policy.rb b/lib/ebay_api/operations/sell/account/fulfillment_policy.rb index f1b0e59..558c769 100644 --- a/lib/ebay_api/operations/sell/account/fulfillment_policy.rb +++ b/lib/ebay_api/operations/sell/account/fulfillment_policy.rb @@ -13,3 +13,4 @@ class EbayAPI require_relative "fulfillment_policy/get_by_name" require_relative "fulfillment_policy/index" require_relative "fulfillment_policy/create" +require_relative "fulfillment_policy/update" diff --git a/lib/ebay_api/operations/sell/account/fulfillment_policy/update.rb b/lib/ebay_api/operations/sell/account/fulfillment_policy/update.rb new file mode 100644 index 0000000..0997f73 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/fulfillment_policy/update.rb @@ -0,0 +1,17 @@ +class EbayAPI + scope :sell do + scope :account do + scope :fulfillment_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/fulfillment_policy/methods/updateFulfillmentPolicy + operation :update do + option :id, proc(&:to_s) + option :policy, proc(&:to_h) # TODO: add model to validate input + + path { id } + http_method :post + body { policy } + end + end + end + end +end diff --git a/spec/fixtures/sell/account/fulfillment_policy/update/request.yml b/spec/fixtures/sell/account/fulfillment_policy/update/request.yml new file mode 100644 index 0000000..864f004 --- /dev/null +++ b/spec/fixtures/sell/account/fulfillment_policy/update/request.yml @@ -0,0 +1,34 @@ +--- +categoryTypes: + - name: ALL_EXCLUDING_MOTORS_VEHICLES +marketplaceId: EBAY_US +name: "Worldwide shipping options: Free domestic, CALCULATED int'l" +globalShipping: false +handlingTime: + unit: DAY + value: 1 +shippingOptions: + - costType: FLAT_RATE + optionType: DOMESTIC + shippingServices: + - buyerResponsibleForShipping: false + freeShipping: true + shippingCarrierCode: USPS + shippingServiceCode: USPSPriorityFlatRateBox + shippingCost: + currency: USD + value: 0.0 + - costType: CALCULATED + optionType: INTERNATIONAL + insuranceOffered: true + insuranceFee: + value: 10.0 + currency: USD + shippingServices: + - buyerResponsibleForShipping: true + freeShipping: false + shippingCarrierCode: USPS + shippingServiceCode: USPSPriorityMailInternational + shipToLocations: + regionIncluded: + - regionName: Worldwide diff --git a/spec/fixtures/sell/account/fulfillment_policy/update/success b/spec/fixtures/sell/account/fulfillment_policy/update/success new file mode 100644 index 0000000..7a5b5d0 --- /dev/null +++ b/spec/fixtures/sell/account/fulfillment_policy/update/success @@ -0,0 +1,6 @@ +HTTP/1.1 200 OK +Content-Length: 1263 +Content-Type: application/json + +{"name":"Worldwide shipping options: Free domestic, CALCULATED int'l","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":false}],"handlingTime":{"value":1,"unit":"DAY"},"shipToLocations":{"regionIncluded":[{"regionName":"Worldwide"}],"regionExcluded":[]},"shippingOptions":[{"optionType":"DOMESTIC","costType":"FLAT_RATE","shippingServices":[{"sortOrder":1,"shippingCarrierCode":"USPS","shippingServiceCode":"USPSPriorityFlatRateBox","shippingCost":{"value":0.0,"currency":"USD"},"additionalShippingCost":{"value":0.0,"currency":"USD"},"freeShipping":true,"buyerResponsibleForShipping":false,"buyerResponsibleForPickup":false}],"insuranceOffered":false,"insuranceFee":{"value":0.0,"currency":"USD"}},{"optionType":"INTERNATIONAL","costType":"CALCULATED","shippingServices":[{"sortOrder":1,"shippingCarrierCode":"USPS","shippingServiceCode":"USPSPriorityMailInternational","freeShipping":false,"shipToLocations":{"regionIncluded":[{"regionName":"Worldwide"}]},"buyerResponsibleForShipping":true,"buyerResponsibleForPickup":false}],"insuranceOffered":true,"insuranceFee":{"value":10.0,"currency":"USD"}}],"globalShipping":false,"pickupDropOff":false,"freightShipping":false,"fulfillmentPolicyId":"5733606000","warnings":[]} + diff --git a/spec/fixtures/sell/account/fulfillment_policy/update/success.yml b/spec/fixtures/sell/account/fulfillment_policy/update/success.yml new file mode 100644 index 0000000..2823734 --- /dev/null +++ b/spec/fixtures/sell/account/fulfillment_policy/update/success.yml @@ -0,0 +1,54 @@ +--- +name: "Worldwide shipping options: Free domestic, CALCULATED int'l" +marketplaceId: EBAY_US +categoryTypes: + - name: ALL_EXCLUDING_MOTORS_VEHICLES + default: false +handlingTime: + value: 1 + unit: DAY +shipToLocations: + regionIncluded: + - regionName: Worldwide + regionExcluded: [] +shippingOptions: + - optionType: DOMESTIC + costType: FLAT_RATE + shippingServices: + - sortOrder: 1 + shippingCarrierCode: USPS + shippingServiceCode: USPSPriorityFlatRateBox + shippingCost: + value: 0.0 + currency: USD + additionalShippingCost: + value: 0.0 + currency: USD + freeShipping: true + buyerResponsibleForShipping: false + buyerResponsibleForPickup: false + insuranceOffered: false + insuranceFee: + value: 0.0 + currency: USD + - optionType: INTERNATIONAL + costType: CALCULATED + shippingServices: + - sortOrder: 1 + shippingCarrierCode: USPS + shippingServiceCode: USPSPriorityMailInternational + freeShipping: false + shipToLocations: + regionIncluded: + - regionName: Worldwide + buyerResponsibleForShipping: true + buyerResponsibleForPickup: false + insuranceOffered: true + insuranceFee: + value: 10.0 + currency: USD +globalShipping: false +pickupDropOff: false +freightShipping: false +fulfillmentPolicyId: '5733606000' +warnings: [] diff --git a/spec/operations/sell/account/fulfillment_policy/update_spec.rb b/spec/operations/sell/account/fulfillment_policy/update_spec.rb new file mode 100644 index 0000000..60657ed --- /dev/null +++ b/spec/operations/sell/account/fulfillment_policy/update_spec.rb @@ -0,0 +1,36 @@ +RSpec.describe EbayAPI, ".sell.account.fulfillment_policy.update" do + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).fulfillment_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + + let(:url) do + "https://api.ebay.com/sell/account/v1/fulfillment_policy/5733606000" + end + + let(:payload) do + yaml_fixture_file "sell/account/fulfillment_policy/update/request.yml" + end + + before { stub_request(:post, url).to_return(response) } + subject { scope.update id: "5733606000", policy: payload } + + context "success" do + let(:response) do + open_fixture_file "sell/account/fulfillment_policy/update/success" + end + + let(:policy) do + yaml_fixture_file "sell/account/fulfillment_policy/update/success.yml" + end + + it "sends a request" do + subject + expect(a_request(:post, url)).to have_been_made + end + + it "returns the policy" do + expect(subject).to eq policy + end + end +end From ff1f3fb3273219cd084fa0c41d258f1645f351f5 Mon Sep 17 00:00:00 2001 From: nepalez Date: Thu, 9 Aug 2018 19:37:02 +0300 Subject: [PATCH 10/51] Add all operations for account.return_policy --- lib/ebay_api/operations/sell/account.rb | 1 + .../operations/sell/account/return_policy.rb | 16 +++++++ .../sell/account/return_policy/create.rb | 16 +++++++ .../sell/account/return_policy/delete.rb | 15 +++++++ .../sell/account/return_policy/get.rb | 15 +++++++ .../sell/account/return_policy/get_by_name.rb | 17 ++++++++ .../sell/account/return_policy/index.rb | 16 +++++++ .../sell/account/return_policy/update.rb | 17 ++++++++ .../account/return_policy/create/request.yml | 17 ++++++++ .../sell/account/return_policy/create/success | 6 +++ .../account/return_policy/create/success.yml | 22 ++++++++++ .../sell/account/return_policy/get/success | 6 +++ .../account/return_policy/get/success.yml | 22 ++++++++++ .../account/return_policy/get_by_name/success | 6 +++ .../return_policy/get_by_name/success.yml | 13 ++++++ .../sell/account/return_policy/index/success | 6 +++ .../account/return_policy/index/success.yml | 42 +++++++++++++++++++ .../account/return_policy/update/request.yml | 20 +++++++++ .../sell/account/return_policy/update/success | 6 +++ .../account/return_policy/update/success.yml | 22 ++++++++++ .../sell/account/return_policy/create_spec.rb | 36 ++++++++++++++++ .../sell/account/return_policy/delete_spec.rb | 21 ++++++++++ .../account/return_policy/get_by_name_spec.rb | 33 +++++++++++++++ .../sell/account/return_policy/get_spec.rb | 31 ++++++++++++++ .../sell/account/return_policy/index_spec.rb | 32 ++++++++++++++ .../sell/account/return_policy/update_spec.rb | 36 ++++++++++++++++ 26 files changed, 490 insertions(+) create mode 100644 lib/ebay_api/operations/sell/account/return_policy.rb create mode 100644 lib/ebay_api/operations/sell/account/return_policy/create.rb create mode 100644 lib/ebay_api/operations/sell/account/return_policy/delete.rb create mode 100644 lib/ebay_api/operations/sell/account/return_policy/get.rb create mode 100644 lib/ebay_api/operations/sell/account/return_policy/get_by_name.rb create mode 100644 lib/ebay_api/operations/sell/account/return_policy/index.rb create mode 100644 lib/ebay_api/operations/sell/account/return_policy/update.rb create mode 100644 spec/fixtures/sell/account/return_policy/create/request.yml create mode 100644 spec/fixtures/sell/account/return_policy/create/success create mode 100644 spec/fixtures/sell/account/return_policy/create/success.yml create mode 100644 spec/fixtures/sell/account/return_policy/get/success create mode 100644 spec/fixtures/sell/account/return_policy/get/success.yml create mode 100644 spec/fixtures/sell/account/return_policy/get_by_name/success create mode 100644 spec/fixtures/sell/account/return_policy/get_by_name/success.yml create mode 100644 spec/fixtures/sell/account/return_policy/index/success create mode 100644 spec/fixtures/sell/account/return_policy/index/success.yml create mode 100644 spec/fixtures/sell/account/return_policy/update/request.yml create mode 100644 spec/fixtures/sell/account/return_policy/update/success create mode 100644 spec/fixtures/sell/account/return_policy/update/success.yml create mode 100644 spec/operations/sell/account/return_policy/create_spec.rb create mode 100644 spec/operations/sell/account/return_policy/delete_spec.rb create mode 100644 spec/operations/sell/account/return_policy/get_by_name_spec.rb create mode 100644 spec/operations/sell/account/return_policy/get_spec.rb create mode 100644 spec/operations/sell/account/return_policy/index_spec.rb create mode 100644 spec/operations/sell/account/return_policy/update_spec.rb diff --git a/lib/ebay_api/operations/sell/account.rb b/lib/ebay_api/operations/sell/account.rb index f0b3f78..0c04e8b 100644 --- a/lib/ebay_api/operations/sell/account.rb +++ b/lib/ebay_api/operations/sell/account.rb @@ -9,6 +9,7 @@ class EbayAPI require_relative "account/privilege" require_relative "account/program" require_relative "account/fulfillment_policy" + require_relative "account/return_policy" end end end diff --git a/lib/ebay_api/operations/sell/account/return_policy.rb b/lib/ebay_api/operations/sell/account/return_policy.rb new file mode 100644 index 0000000..781ff53 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/return_policy.rb @@ -0,0 +1,16 @@ +class EbayAPI + scope :sell do + scope :account do + scope :return_policy do + path { "return_policy" } + end + end + end +end + +require_relative "return_policy/delete" +require_relative "return_policy/get" +require_relative "return_policy/get_by_name" +require_relative "return_policy/index" +require_relative "return_policy/create" +require_relative "return_policy/update" diff --git a/lib/ebay_api/operations/sell/account/return_policy/create.rb b/lib/ebay_api/operations/sell/account/return_policy/create.rb new file mode 100644 index 0000000..c9bc3b3 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/return_policy/create.rb @@ -0,0 +1,16 @@ +class EbayAPI + scope :sell do + scope :account do + scope :return_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/return_policy/methods/createReturnPolicy + operation :create do + option :policy, proc(&:to_h) # TODO: add model to validate input + + path { "/" } + http_method :post + body { policy } + end + end + end + end +end diff --git a/lib/ebay_api/operations/sell/account/return_policy/delete.rb b/lib/ebay_api/operations/sell/account/return_policy/delete.rb new file mode 100644 index 0000000..9f0c677 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/return_policy/delete.rb @@ -0,0 +1,15 @@ +class EbayAPI + scope :sell do + scope :account do + scope :return_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/return_policy/methods/deleteReturnPolicy + operation :delete do + option :id, proc(&:to_s) + + path { id } + http_method :delete + end + end + end + end +end diff --git a/lib/ebay_api/operations/sell/account/return_policy/get.rb b/lib/ebay_api/operations/sell/account/return_policy/get.rb new file mode 100644 index 0000000..329678c --- /dev/null +++ b/lib/ebay_api/operations/sell/account/return_policy/get.rb @@ -0,0 +1,15 @@ +class EbayAPI + scope :sell do + scope :account do + scope :return_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/return_policy/methods/getReturnPolicy + operation :get do + option :id, proc(&:to_s) + + path { id } + http_method :get + end + end + end + end +end diff --git a/lib/ebay_api/operations/sell/account/return_policy/get_by_name.rb b/lib/ebay_api/operations/sell/account/return_policy/get_by_name.rb new file mode 100644 index 0000000..46705a3 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/return_policy/get_by_name.rb @@ -0,0 +1,17 @@ +class EbayAPI + scope :sell do + scope :account do + scope :return_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/return_policy/methods/getReturnPolicyByName + operation :get_by_name do + option :site, Site + option :name, proc(&:to_s) + + path { "/" } + query { { marketplace_id: site.key, name: name } } + http_method :get + end + end + end + end +end diff --git a/lib/ebay_api/operations/sell/account/return_policy/index.rb b/lib/ebay_api/operations/sell/account/return_policy/index.rb new file mode 100644 index 0000000..07002e6 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/return_policy/index.rb @@ -0,0 +1,16 @@ +class EbayAPI + scope :sell do + scope :account do + scope :return_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/return_policy/methods/getReturnPolicies + operation :index do + option :site, Site + + path { "/" } + query { { marketplace_id: site.key } } + http_method :get + end + end + end + end +end diff --git a/lib/ebay_api/operations/sell/account/return_policy/update.rb b/lib/ebay_api/operations/sell/account/return_policy/update.rb new file mode 100644 index 0000000..e39a83a --- /dev/null +++ b/lib/ebay_api/operations/sell/account/return_policy/update.rb @@ -0,0 +1,17 @@ +class EbayAPI + scope :sell do + scope :account do + scope :return_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/return_policy/methods/updateReturnPolicy + operation :update do + option :id, proc(&:to_s) + option :policy, proc(&:to_h) # TODO: add model to validate input + + path { id } + http_method :post + body { policy } + end + end + end + end +end diff --git a/spec/fixtures/sell/account/return_policy/create/request.yml b/spec/fixtures/sell/account/return_policy/create/request.yml new file mode 100644 index 0000000..04d467a --- /dev/null +++ b/spec/fixtures/sell/account/return_policy/create/request.yml @@ -0,0 +1,17 @@ +--- +name: 30-day domestic and international return policy +marketplaceId: EBAY_US +description: Policy specifies an international return policy in addition to the domestic + return policy. +refundMethod: MONEY_BACK +returnsAccepted: true +returnPeriod: + value: 30 + unit: DAY +returnShippingCostPayer: SELLER +internationalOverride: + returnsAccepted: true + returnPeriod: + unit: DAY + value: 30 + returnShippingCostPayer: BUYER diff --git a/spec/fixtures/sell/account/return_policy/create/success b/spec/fixtures/sell/account/return_policy/create/success new file mode 100644 index 0000000..bae2be3 --- /dev/null +++ b/spec/fixtures/sell/account/return_policy/create/success @@ -0,0 +1,6 @@ +HTTP/1.1 201 Created +Content-Length: 561 +Content-Type: application/json + +{"name":"30-day domestic and international return policy","description":"Policy specifies an international return policy in addition to the domestic return policy.","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":false}],"returnsAccepted":true,"returnPeriod":{"value":30,"unit":"DAY"},"refundMethod":"MONEY_BACK","returnShippingCostPayer":"SELLER","internationalOverride":{"returnsAccepted":true,"returnPeriod":{"value":30,"unit":"DAY"},"returnShippingCostPayer":"BUYER"},"returnPolicyId":"5790479000","warnings":[]} + diff --git a/spec/fixtures/sell/account/return_policy/create/success.yml b/spec/fixtures/sell/account/return_policy/create/success.yml new file mode 100644 index 0000000..334ee12 --- /dev/null +++ b/spec/fixtures/sell/account/return_policy/create/success.yml @@ -0,0 +1,22 @@ +--- +name: 30-day domestic and international return policy +description: Policy specifies an international return policy in addition to the domestic + return policy. +marketplaceId: EBAY_US +categoryTypes: +- name: ALL_EXCLUDING_MOTORS_VEHICLES + default: false +returnsAccepted: true +returnPeriod: + value: 30 + unit: DAY +refundMethod: MONEY_BACK +returnShippingCostPayer: SELLER +internationalOverride: + returnsAccepted: true + returnPeriod: + value: 30 + unit: DAY + returnShippingCostPayer: BUYER +returnPolicyId: '5790479000' +warnings: [] diff --git a/spec/fixtures/sell/account/return_policy/get/success b/spec/fixtures/sell/account/return_policy/get/success new file mode 100644 index 0000000..9ad6db5 --- /dev/null +++ b/spec/fixtures/sell/account/return_policy/get/success @@ -0,0 +1,6 @@ +HTTP/1.1 200 OK +Content-Length: 572 +Content-Type: application/json + +{"name":"30-day domestic and international return policy","description":"Policy specifies an international return policy in addition to the domestic return policy.","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":true}],"returnsAccepted":true,"returnPeriod":{"value":30,"unit":"DAY"},"refundMethod":"MONEY_BACK","returnMethod":"EXCHANGE","returnShippingCostPayer":"SELLER","internationalOverride":{"returnsAccepted":true,"returnPeriod":{"value":60,"unit":"DAY"},"returnShippingCostPayer":"BUYER"},"returnPolicyId":"5790479000"} + diff --git a/spec/fixtures/sell/account/return_policy/get/success.yml b/spec/fixtures/sell/account/return_policy/get/success.yml new file mode 100644 index 0000000..0af1d8a --- /dev/null +++ b/spec/fixtures/sell/account/return_policy/get/success.yml @@ -0,0 +1,22 @@ +--- +name: 30-day domestic and international return policy +description: Policy specifies an international return policy in addition to the domestic + return policy. +marketplaceId: EBAY_US +categoryTypes: +- name: ALL_EXCLUDING_MOTORS_VEHICLES + default: true +returnsAccepted: true +returnPeriod: + value: 30 + unit: DAY +refundMethod: MONEY_BACK +returnMethod: EXCHANGE +returnShippingCostPayer: SELLER +internationalOverride: + returnsAccepted: true + returnPeriod: + value: 60 + unit: DAY + returnShippingCostPayer: BUYER +returnPolicyId: '5790479000' diff --git a/spec/fixtures/sell/account/return_policy/get_by_name/success b/spec/fixtures/sell/account/return_policy/get_by_name/success new file mode 100644 index 0000000..cb63ab2 --- /dev/null +++ b/spec/fixtures/sell/account/return_policy/get_by_name/success @@ -0,0 +1,6 @@ +HTTP/1.1 200 OK +Content-Length: 306 +Content-Type: application/json + +{"name":"minimal return policy, US marketplace","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":false}],"returnsAccepted":true,"returnPeriod":{"value":30,"unit":"DAY"},"refundMethod":"MONEY_BACK","returnShippingCostPayer":"SELLER","returnPolicyId":"5792219000"} + diff --git a/spec/fixtures/sell/account/return_policy/get_by_name/success.yml b/spec/fixtures/sell/account/return_policy/get_by_name/success.yml new file mode 100644 index 0000000..e1a68b2 --- /dev/null +++ b/spec/fixtures/sell/account/return_policy/get_by_name/success.yml @@ -0,0 +1,13 @@ +--- +name: minimal return policy, US marketplace +marketplaceId: EBAY_US +categoryTypes: +- name: ALL_EXCLUDING_MOTORS_VEHICLES + default: false +returnsAccepted: true +returnPeriod: + value: 30 + unit: DAY +refundMethod: MONEY_BACK +returnShippingCostPayer: SELLER +returnPolicyId: '5792219000' diff --git a/spec/fixtures/sell/account/return_policy/index/success b/spec/fixtures/sell/account/return_policy/index/success new file mode 100644 index 0000000..dd96231 --- /dev/null +++ b/spec/fixtures/sell/account/return_policy/index/success @@ -0,0 +1,6 @@ +HTTP/1.1 200 OK +Content-Length: 1101 +Content-Type: application/json + +{"total":3,"returnPolicies":[{"name":"30-day domestic and international return policy","description":"Policy specifies an international return policy in addition to the domestic return policy.","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":true}],"returnsAccepted":true,"returnPeriod":{"value":30,"unit":"DAY"},"refundMethod":"MONEY_BACK","returnMethod":"EXCHANGE","returnShippingCostPayer":"SELLER","internationalOverride":{"returnsAccepted":true,"returnPeriod":{"value":60,"unit":"DAY"},"returnShippingCostPayer":"BUYER"},"returnPolicyId":"5790479000"},{"name":"no returns return policy","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":false}],"returnsAccepted":false,"returnPolicyId":"5790474000"},{"name":"minimal return policy, US marketplace","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":false}],"returnsAccepted":true,"returnPeriod":{"value":30,"unit":"DAY"},"refundMethod":"MONEY_BACK","returnShippingCostPayer":"SELLER","returnPolicyId":"5792219000"}]} + diff --git a/spec/fixtures/sell/account/return_policy/index/success.yml b/spec/fixtures/sell/account/return_policy/index/success.yml new file mode 100644 index 0000000..315a576 --- /dev/null +++ b/spec/fixtures/sell/account/return_policy/index/success.yml @@ -0,0 +1,42 @@ +--- +total: 3 +returnPolicies: +- name: 30-day domestic and international return policy + description: Policy specifies an international return policy in addition to the domestic return policy. + marketplaceId: EBAY_US + categoryTypes: + - name: ALL_EXCLUDING_MOTORS_VEHICLES + default: true + returnsAccepted: true + returnPeriod: + value: 30 + unit: DAY + refundMethod: MONEY_BACK + returnMethod: EXCHANGE + returnShippingCostPayer: SELLER + internationalOverride: + returnsAccepted: true + returnPeriod: + value: 60 + unit: DAY + returnShippingCostPayer: BUYER + returnPolicyId: '5790479000' +- name: no returns return policy + marketplaceId: EBAY_US + categoryTypes: + - name: ALL_EXCLUDING_MOTORS_VEHICLES + default: false + returnsAccepted: false + returnPolicyId: '5790474000' +- name: minimal return policy, US marketplace + marketplaceId: EBAY_US + categoryTypes: + - name: ALL_EXCLUDING_MOTORS_VEHICLES + default: false + returnsAccepted: true + returnPeriod: + value: 30 + unit: DAY + refundMethod: MONEY_BACK + returnShippingCostPayer: SELLER + returnPolicyId: '5792219000' diff --git a/spec/fixtures/sell/account/return_policy/update/request.yml b/spec/fixtures/sell/account/return_policy/update/request.yml new file mode 100644 index 0000000..629adc2 --- /dev/null +++ b/spec/fixtures/sell/account/return_policy/update/request.yml @@ -0,0 +1,20 @@ +--- +name: 30-day domestic and international return policy +marketplaceId: EBAY_US +categoryTypes: +- name: ALL_EXCLUDING_MOTORS_VEHICLES + default: 'true' +description: Policy specifies an international return policy in addition to the domestic return policy. +refundMethod: MONEY_BACK +returnsAccepted: true +returnMethod: EXCHANGE +returnPeriod: + value: 30 + unit: DAY +returnShippingCostPayer: SELLER +internationalOverride: + returnsAccepted: true + returnPeriod: + unit: DAY + value: 60 + returnShippingCostPayer: BUYER diff --git a/spec/fixtures/sell/account/return_policy/update/success b/spec/fixtures/sell/account/return_policy/update/success new file mode 100644 index 0000000..7482352 --- /dev/null +++ b/spec/fixtures/sell/account/return_policy/update/success @@ -0,0 +1,6 @@ +HTTP/1.1 200 OK +Content-Length: 586 +Content-Type: application/json + +{"name":"30-day domestic and international return policy","description":"Policy specifies an international return policy in addition to the domestic return policy.","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":true}],"returnsAccepted":true,"returnPeriod":{"value":30,"unit":"DAY"},"refundMethod":"MONEY_BACK","returnMethod":"EXCHANGE","returnShippingCostPayer":"SELLER","internationalOverride":{"returnsAccepted":true,"returnPeriod":{"value":60,"unit":"DAY"},"returnShippingCostPayer":"BUYER"},"returnPolicyId":"5790479000","warnings":[]} + diff --git a/spec/fixtures/sell/account/return_policy/update/success.yml b/spec/fixtures/sell/account/return_policy/update/success.yml new file mode 100644 index 0000000..dde66df --- /dev/null +++ b/spec/fixtures/sell/account/return_policy/update/success.yml @@ -0,0 +1,22 @@ +--- +name: 30-day domestic and international return policy +description: Policy specifies an international return policy in addition to the domestic return policy. +marketplaceId: EBAY_US +categoryTypes: +- name: ALL_EXCLUDING_MOTORS_VEHICLES + default: true +returnsAccepted: true +returnPeriod: + value: 30 + unit: DAY +refundMethod: MONEY_BACK +returnMethod: EXCHANGE +returnShippingCostPayer: SELLER +internationalOverride: + returnsAccepted: true + returnPeriod: + value: 60 + unit: DAY + returnShippingCostPayer: BUYER +returnPolicyId: '5790479000' +warnings: [] diff --git a/spec/operations/sell/account/return_policy/create_spec.rb b/spec/operations/sell/account/return_policy/create_spec.rb new file mode 100644 index 0000000..5f3c109 --- /dev/null +++ b/spec/operations/sell/account/return_policy/create_spec.rb @@ -0,0 +1,36 @@ +RSpec.describe EbayAPI, ".sell.account.return_policy.create" do + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).return_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + + let(:url) do + "https://api.ebay.com/sell/account/v1/return_policy/" + end + + let(:payload) do + yaml_fixture_file "sell/account/return_policy/create/request.yml" + end + + before { stub_request(:post, url).to_return(response) } + subject { scope.create policy: payload } + + context "success" do + let(:response) do + open_fixture_file "sell/account/return_policy/create/success" + end + + let(:policy) do + yaml_fixture_file "sell/account/return_policy/create/success.yml" + end + + it "sends a request" do + subject + expect(a_request(:post, url)).to have_been_made + end + + it "returns the policy" do + expect(subject).to eq policy + end + end +end diff --git a/spec/operations/sell/account/return_policy/delete_spec.rb b/spec/operations/sell/account/return_policy/delete_spec.rb new file mode 100644 index 0000000..46d0ba4 --- /dev/null +++ b/spec/operations/sell/account/return_policy/delete_spec.rb @@ -0,0 +1,21 @@ +RSpec.describe EbayAPI, ".sell.account.return_policy.delete" do + let(:url) { "https://api.ebay.com/sell/account/v1/return_policy/42" } + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).return_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + + before { stub_request(:delete, url).to_return(status: 204) } + subject { scope.delete id: 42 } + + context "success" do + it "sends a request" do + subject + expect(a_request(:delete, url)).to have_been_made + end + + it "returns true" do + expect(subject).to eq true + end + end +end diff --git a/spec/operations/sell/account/return_policy/get_by_name_spec.rb b/spec/operations/sell/account/return_policy/get_by_name_spec.rb new file mode 100644 index 0000000..ce5df80 --- /dev/null +++ b/spec/operations/sell/account/return_policy/get_by_name_spec.rb @@ -0,0 +1,33 @@ +RSpec.describe EbayAPI, ".sell.account.return_policy.get_by_name" do + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).return_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + let(:url) do + "https://api.ebay.com/sell/account/v1/return_policy/" \ + "?marketplace_id=EBAY_US&name=postcards" + end + + before { stub_request(:get, url).to_return(response) } + subject { scope.get_by_name site: 0, name: "postcards" } + + context "success" do + let(:response) do + open_fixture_file "sell/account/return_policy/get_by_name/success" + end + + let(:policy) do + yaml_fixture_file \ + "sell/account/return_policy/get_by_name/success.yml" + end + + it "sends a request" do + subject + expect(a_request(:get, url)).to have_been_made + end + + it "returns the policy" do + expect(subject).to eq policy + end + end +end diff --git a/spec/operations/sell/account/return_policy/get_spec.rb b/spec/operations/sell/account/return_policy/get_spec.rb new file mode 100644 index 0000000..bd40b52 --- /dev/null +++ b/spec/operations/sell/account/return_policy/get_spec.rb @@ -0,0 +1,31 @@ +RSpec.describe EbayAPI, ".sell.account.return_policy.get" do + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).return_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + let(:url) do + "https://api.ebay.com/sell/account/v1/return_policy/5733588000" + end + + before { stub_request(:get, url).to_return(response) } + subject { scope.get id: "5733588000" } + + context "success" do + let(:response) do + open_fixture_file "sell/account/return_policy/get/success" + end + + let(:policy) do + yaml_fixture_file "sell/account/return_policy/get/success.yml" + end + + it "sends a request" do + subject + expect(a_request(:get, url)).to have_been_made + end + + it "returns the policy" do + expect(subject).to eq policy + end + end +end diff --git a/spec/operations/sell/account/return_policy/index_spec.rb b/spec/operations/sell/account/return_policy/index_spec.rb new file mode 100644 index 0000000..c13bdaf --- /dev/null +++ b/spec/operations/sell/account/return_policy/index_spec.rb @@ -0,0 +1,32 @@ +RSpec.describe EbayAPI, ".sell.account.return_policy.index" do + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).return_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + let(:url) do + "https://api.ebay.com/sell/account/v1/return_policy/" \ + "?marketplace_id=EBAY_US" + end + + before { stub_request(:get, url).to_return(response) } + subject { scope.index id: "5733588000" } + + context "success" do + let(:response) do + open_fixture_file "sell/account/return_policy/get/success" + end + + let(:policy) do + yaml_fixture_file "sell/account/return_policy/get/success.yml" + end + + it "sends a request" do + subject + expect(a_request(:get, url)).to have_been_made + end + + it "returns the policy" do + expect(subject).to eq policy + end + end +end diff --git a/spec/operations/sell/account/return_policy/update_spec.rb b/spec/operations/sell/account/return_policy/update_spec.rb new file mode 100644 index 0000000..71a2549 --- /dev/null +++ b/spec/operations/sell/account/return_policy/update_spec.rb @@ -0,0 +1,36 @@ +RSpec.describe EbayAPI, ".sell.account.return_policy.update" do + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).return_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + + let(:url) do + "https://api.ebay.com/sell/account/v1/return_policy/5733606000" + end + + let(:payload) do + yaml_fixture_file "sell/account/return_policy/update/request.yml" + end + + before { stub_request(:post, url).to_return(response) } + subject { scope.update id: "5733606000", policy: payload } + + context "success" do + let(:response) do + open_fixture_file "sell/account/return_policy/update/success" + end + + let(:policy) do + yaml_fixture_file "sell/account/return_policy/update/success.yml" + end + + it "sends a request" do + subject + expect(a_request(:post, url)).to have_been_made + end + + it "returns the policy" do + expect(subject).to eq policy + end + end +end From 0bb993c4cf444654ea28e79d4239ce8f3bfd4804 Mon Sep 17 00:00:00 2001 From: nepalez Date: Fri, 10 Aug 2018 18:57:00 +0300 Subject: [PATCH 11/51] Send the site and data separated to policies create/update methods --- .../operations/sell/account/fulfillment_policy/create.rb | 5 +++-- .../operations/sell/account/fulfillment_policy/update.rb | 7 ++++--- .../operations/sell/account/return_policy/create.rb | 5 +++-- .../operations/sell/account/return_policy/update.rb | 7 ++++--- .../sell/account/fulfillment_policy/create/request.yml | 4 ++-- .../sell/account/fulfillment_policy/create_spec.rb | 8 ++++++-- .../sell/account/fulfillment_policy/update_spec.rb | 6 +++++- spec/operations/sell/account/return_policy/create_spec.rb | 8 ++++++-- spec/operations/sell/account/return_policy/update_spec.rb | 6 ++++-- 9 files changed, 37 insertions(+), 19 deletions(-) diff --git a/lib/ebay_api/operations/sell/account/fulfillment_policy/create.rb b/lib/ebay_api/operations/sell/account/fulfillment_policy/create.rb index 63aafb0..c8556c1 100644 --- a/lib/ebay_api/operations/sell/account/fulfillment_policy/create.rb +++ b/lib/ebay_api/operations/sell/account/fulfillment_policy/create.rb @@ -4,11 +4,12 @@ class EbayAPI scope :fulfillment_policy do # @see https://developer.ebay.com/api-docs/sell/account/resources/fulfillment_policy/methods/createFulfillmentPolicy operation :create do - option :policy, proc(&:to_h) # TODO: add model to validate input + option :site, Site + option :data, proc(&:to_h) # TODO: add model to validate input path { "/" } http_method :post - body { policy } + body { data.merge("marketplaceId" => site.key) } end end end diff --git a/lib/ebay_api/operations/sell/account/fulfillment_policy/update.rb b/lib/ebay_api/operations/sell/account/fulfillment_policy/update.rb index 0997f73..c5d7764 100644 --- a/lib/ebay_api/operations/sell/account/fulfillment_policy/update.rb +++ b/lib/ebay_api/operations/sell/account/fulfillment_policy/update.rb @@ -4,12 +4,13 @@ class EbayAPI scope :fulfillment_policy do # @see https://developer.ebay.com/api-docs/sell/account/resources/fulfillment_policy/methods/updateFulfillmentPolicy operation :update do - option :id, proc(&:to_s) - option :policy, proc(&:to_h) # TODO: add model to validate input + option :id, proc(&:to_s) + option :site, Site + option :data, proc(&:to_h) # TODO: add model to validate input path { id } http_method :post - body { policy } + body { data.merge("marketplaceId" => site.key) } end end end diff --git a/lib/ebay_api/operations/sell/account/return_policy/create.rb b/lib/ebay_api/operations/sell/account/return_policy/create.rb index c9bc3b3..feae29e 100644 --- a/lib/ebay_api/operations/sell/account/return_policy/create.rb +++ b/lib/ebay_api/operations/sell/account/return_policy/create.rb @@ -4,11 +4,12 @@ class EbayAPI scope :return_policy do # @see https://developer.ebay.com/api-docs/sell/account/resources/return_policy/methods/createReturnPolicy operation :create do - option :policy, proc(&:to_h) # TODO: add model to validate input + option :site, Site + option :data, proc(&:to_h) # TODO: add model to validate input path { "/" } http_method :post - body { policy } + body { data.merge "marketplaceId" => site.key } end end end diff --git a/lib/ebay_api/operations/sell/account/return_policy/update.rb b/lib/ebay_api/operations/sell/account/return_policy/update.rb index e39a83a..611c0e2 100644 --- a/lib/ebay_api/operations/sell/account/return_policy/update.rb +++ b/lib/ebay_api/operations/sell/account/return_policy/update.rb @@ -4,12 +4,13 @@ class EbayAPI scope :return_policy do # @see https://developer.ebay.com/api-docs/sell/account/resources/return_policy/methods/updateReturnPolicy operation :update do - option :id, proc(&:to_s) - option :policy, proc(&:to_h) # TODO: add model to validate input + option :id, proc(&:to_s) + option :site, Site + option :data, proc(&:to_h) # TODO: add model to validate input path { id } http_method :post - body { policy } + body { data.merge("marketplaceId" => site.key) } end end end diff --git a/spec/fixtures/sell/account/fulfillment_policy/create/request.yml b/spec/fixtures/sell/account/fulfillment_policy/create/request.yml index 77a7607..e1d1fbc 100644 --- a/spec/fixtures/sell/account/fulfillment_policy/create/request.yml +++ b/spec/fixtures/sell/account/fulfillment_policy/create/request.yml @@ -1,8 +1,8 @@ --- +name: Domestic free shipping +marketplaceId: EBAY_US categoryTypes: - name: ALL_EXCLUDING_MOTORS_VEHICLES -marketplaceId: EBAY_US -name: Domestic free shipping handlingTime: unit: DAY value: 1 diff --git a/spec/operations/sell/account/fulfillment_policy/create_spec.rb b/spec/operations/sell/account/fulfillment_policy/create_spec.rb index 7814dae..6822b8c 100644 --- a/spec/operations/sell/account/fulfillment_policy/create_spec.rb +++ b/spec/operations/sell/account/fulfillment_policy/create_spec.rb @@ -12,8 +12,12 @@ yaml_fixture_file "sell/account/fulfillment_policy/create/request.yml" end - before { stub_request(:post, url).to_return(response) } - subject { scope.create policy: payload } + let(:data) do + payload.reject { |key| key == "marketplaceId" } + end + + before { stub_request(:post, url).with(body: payload).to_return(response) } + subject { scope.create site: 0, data: data } context "success" do let(:response) do diff --git a/spec/operations/sell/account/fulfillment_policy/update_spec.rb b/spec/operations/sell/account/fulfillment_policy/update_spec.rb index 60657ed..24cce20 100644 --- a/spec/operations/sell/account/fulfillment_policy/update_spec.rb +++ b/spec/operations/sell/account/fulfillment_policy/update_spec.rb @@ -12,8 +12,12 @@ yaml_fixture_file "sell/account/fulfillment_policy/update/request.yml" end + let(:data) do + payload.reject { |key| key == "marketplaceId" } + end + before { stub_request(:post, url).to_return(response) } - subject { scope.update id: "5733606000", policy: payload } + subject { scope.update id: "5733606000", site: 0, data: data } context "success" do let(:response) do diff --git a/spec/operations/sell/account/return_policy/create_spec.rb b/spec/operations/sell/account/return_policy/create_spec.rb index 5f3c109..df93a7b 100644 --- a/spec/operations/sell/account/return_policy/create_spec.rb +++ b/spec/operations/sell/account/return_policy/create_spec.rb @@ -12,8 +12,12 @@ yaml_fixture_file "sell/account/return_policy/create/request.yml" end - before { stub_request(:post, url).to_return(response) } - subject { scope.create policy: payload } + let(:data) do + payload.reject { |key| key == "marketplaceId" } + end + + before { stub_request(:post, url).with(body: payload).to_return(response) } + subject { scope.create site: 0, data: data } context "success" do let(:response) do diff --git a/spec/operations/sell/account/return_policy/update_spec.rb b/spec/operations/sell/account/return_policy/update_spec.rb index 71a2549..79a806a 100644 --- a/spec/operations/sell/account/return_policy/update_spec.rb +++ b/spec/operations/sell/account/return_policy/update_spec.rb @@ -12,8 +12,10 @@ yaml_fixture_file "sell/account/return_policy/update/request.yml" end + let(:data) { payload.reject { |k| k == "marketplaceId" } } + before { stub_request(:post, url).to_return(response) } - subject { scope.update id: "5733606000", policy: payload } + subject { scope.update id: "5733606000", data: data, site: 0 } context "success" do let(:response) do @@ -26,7 +28,7 @@ it "sends a request" do subject - expect(a_request(:post, url)).to have_been_made + expect(a_request(:post, url).with(body: payload)).to have_been_made end it "returns the policy" do From c68b830807622caf4e9d1f5a35b981fb1dacb689 Mon Sep 17 00:00:00 2001 From: nepalez Date: Tue, 21 Aug 2018 18:05:27 +0300 Subject: [PATCH 12/51] Fix rubocop --- .rubocop.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d855f51..4568cf7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,6 +12,9 @@ Metrics/LineLength: - http - https +Layout/SpaceInLambdaLiteral: + Enabled: false + Style/CaseEquality: Enabled: false @@ -36,8 +39,5 @@ Style/PercentLiteralDelimiters: Style/RaiseArgs: Enabled: false -Style/SpaceInLambdaLiteral: - Enabled: false - Style/StringLiterals: EnforcedStyle: double_quotes From 4cb90aafba36ddf564d799dcef9609d707f44f1e Mon Sep 17 00:00:00 2001 From: nepalez Date: Tue, 21 Aug 2018 18:05:51 +0300 Subject: [PATCH 13/51] Fix keys of multilanguage sites --- config/sites.yml | 6 +++--- spec/models/site_spec.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/sites.yml b/config/sites.yml index 30ee8a6..638e552 100644 --- a/config/sites.yml +++ b/config/sites.yml @@ -43,7 +43,7 @@ :country: BE :currencies: [EUR] :host: www.ebay.be - :key: EBAY_BE_FR + :key: EBAY_BE :languages: [fr-BE] - :id: 71 :code: EBAY-FR @@ -78,7 +78,7 @@ :country: BE :currencies: [EUR] :host: www.ebay.be - :key: EBAY_BE_NL + :key: EBAY_BE :languages: [nl-BE] - :id: 146 :code: EBAY-NL @@ -148,7 +148,7 @@ :country: CA :currencies: [USD, CAD] :host: www.cafr.ebay.ca - :key: EBAY_CA_FR + :key: EBAY_CA :languages: [fr-CA] - :id: 211 :code: EBAY-PH diff --git a/spec/models/site_spec.rb b/spec/models/site_spec.rb index 547a3fa..d58c174 100644 --- a/spec/models/site_spec.rb +++ b/spec/models/site_spec.rb @@ -25,7 +25,7 @@ let(:id) { "EBAY_CA" } it "return a proper site" do - expect(subject.options).to eq options.merge(id: 2, languages: %w[en-CA]) + expect(subject.options).to eq options.merge(languages: %w[en-CA fr-CA]) end end From caec776d62587c1c6447ef2d33421f7ab68ac4c7 Mon Sep 17 00:00:00 2001 From: nepalez Date: Tue, 21 Aug 2018 18:06:29 +0300 Subject: [PATCH 14/51] Add logger --- lib/ebay_api.rb | 10 +++++-- lib/ebay_api/middlewares.rb | 1 + lib/ebay_api/middlewares/log_request.rb | 40 +++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 lib/ebay_api/middlewares/log_request.rb diff --git a/lib/ebay_api.rb b/lib/ebay_api.rb index 51040b5..c8d622e 100644 --- a/lib/ebay_api.rb +++ b/lib/ebay_api.rb @@ -27,6 +27,10 @@ class EbayAPI < Evil::Client require_relative "ebay_api/middlewares" require_relative "ebay_api/exceptions" + class << self + attr_accessor :logger + end + option :token option :site, Site, optional: true option :language, Language, optional: true @@ -41,10 +45,10 @@ class EbayAPI < Evil::Client errors.add :wrong_language, language: language, site: site end - format "json" - path { "https://api#{".sandbox" if sandbox}.ebay.com/" } + format "json" + path { "https://api#{".sandbox" if sandbox}.ebay.com/" } - middleware JSONResponse + middleware { [LogRequest, JSONResponse] } security do token_value = token.respond_to?(:call) ? token.call : token diff --git a/lib/ebay_api/middlewares.rb b/lib/ebay_api/middlewares.rb index 4ce44de..297e5f6 100644 --- a/lib/ebay_api/middlewares.rb +++ b/lib/ebay_api/middlewares.rb @@ -1,2 +1,3 @@ require_relative "middlewares/json_response" require_relative "middlewares/paginated_collection" +require_relative "middlewares/log_request" diff --git a/lib/ebay_api/middlewares/log_request.rb b/lib/ebay_api/middlewares/log_request.rb new file mode 100644 index 0000000..8c7654c --- /dev/null +++ b/lib/ebay_api/middlewares/log_request.rb @@ -0,0 +1,40 @@ +class EbayAPI + class LogRequest + def initialize(app) + @app = app + end + + def call(env) + log_request(env) + @app.call(env).tap { |output| log_response(output) } + end + + private + + def logger + @logger ||= EbayAPI.logger + end + + def log_info(key, data = nil) + logger.info "[EbayAPI] | #{format('%9s', key)} | #{data}" + end + + def log_request(env) + return unless logger + log_info "REQUEST:" + log_info "Url", env["PATH_INFO"] + log_info "Method", env["REQUEST_METHOD"] + log_info "Headers", env["HTTP_Variables"] + log_info "Body", env["rack.input"] + end + + def log_response(output) + return unless logger + status, headers, body = output + log_info "RESPONSE:" + log_info "Status", status + log_info "Headers", headers + log_info "Body", body + end + end +end From 523fbfad8b66756764f95cac695209814c0b1cbb Mon Sep 17 00:00:00 2001 From: nepalez Date: Mon, 3 Sep 2018 15:58:57 +0300 Subject: [PATCH 15/51] Fix update policy methods from POST to PUT --- .../operations/sell/account/fulfillment_policy/update.rb | 2 +- lib/ebay_api/operations/sell/account/return_policy/update.rb | 2 +- .../operations/sell/account/fulfillment_policy/update_spec.rb | 4 ++-- spec/operations/sell/account/return_policy/update_spec.rb | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/ebay_api/operations/sell/account/fulfillment_policy/update.rb b/lib/ebay_api/operations/sell/account/fulfillment_policy/update.rb index c5d7764..aea2cb4 100644 --- a/lib/ebay_api/operations/sell/account/fulfillment_policy/update.rb +++ b/lib/ebay_api/operations/sell/account/fulfillment_policy/update.rb @@ -9,7 +9,7 @@ class EbayAPI option :data, proc(&:to_h) # TODO: add model to validate input path { id } - http_method :post + http_method :put body { data.merge("marketplaceId" => site.key) } end end diff --git a/lib/ebay_api/operations/sell/account/return_policy/update.rb b/lib/ebay_api/operations/sell/account/return_policy/update.rb index 611c0e2..2f82163 100644 --- a/lib/ebay_api/operations/sell/account/return_policy/update.rb +++ b/lib/ebay_api/operations/sell/account/return_policy/update.rb @@ -9,7 +9,7 @@ class EbayAPI option :data, proc(&:to_h) # TODO: add model to validate input path { id } - http_method :post + http_method :put body { data.merge("marketplaceId" => site.key) } end end diff --git a/spec/operations/sell/account/fulfillment_policy/update_spec.rb b/spec/operations/sell/account/fulfillment_policy/update_spec.rb index 24cce20..b220786 100644 --- a/spec/operations/sell/account/fulfillment_policy/update_spec.rb +++ b/spec/operations/sell/account/fulfillment_policy/update_spec.rb @@ -16,7 +16,7 @@ payload.reject { |key| key == "marketplaceId" } end - before { stub_request(:post, url).to_return(response) } + before { stub_request(:put, url).to_return(response) } subject { scope.update id: "5733606000", site: 0, data: data } context "success" do @@ -30,7 +30,7 @@ it "sends a request" do subject - expect(a_request(:post, url)).to have_been_made + expect(a_request(:put, url)).to have_been_made end it "returns the policy" do diff --git a/spec/operations/sell/account/return_policy/update_spec.rb b/spec/operations/sell/account/return_policy/update_spec.rb index 79a806a..b0d4750 100644 --- a/spec/operations/sell/account/return_policy/update_spec.rb +++ b/spec/operations/sell/account/return_policy/update_spec.rb @@ -14,7 +14,7 @@ let(:data) { payload.reject { |k| k == "marketplaceId" } } - before { stub_request(:post, url).to_return(response) } + before { stub_request(:put, url).to_return(response) } subject { scope.update id: "5733606000", data: data, site: 0 } context "success" do @@ -28,7 +28,7 @@ it "sends a request" do subject - expect(a_request(:post, url).with(body: payload)).to have_been_made + expect(a_request(:put, url).with(body: payload)).to have_been_made end it "returns the policy" do From 574f0e9939e2025aa1af2bdcc8d17304232f9b11 Mon Sep 17 00:00:00 2001 From: Andrey Novikov Date: Tue, 18 Sep 2018 14:36:13 +0300 Subject: [PATCH 16/51] Increase maximum allowed PL ad bid value to 100% It is change from Sell Marketing API new version 1.4 --- config/locales/en.yml | 2 +- config/versions.yml | 2 +- lib/ebay_api/models/bid_percentage.rb | 2 +- .../sell/marketing/ads/bulk_create_by_listing_id/invalid | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 5234e5a..96d8f01 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -24,7 +24,7 @@ en: unsupported_marketplace: You can't use Promoted Listings at %{site} ebay_api/funding_strategy: bid_wrong_format: Promoted listing ad fee can only contain 1 fractional digit, you provided %(value) - bid_out_of_range: Promoted listing ad fee must be from 1% to 20%, you provided %(value) + bid_out_of_range: Promoted listing ad fee must be from 1% to 100%, you provided %(value) unsupported_funding_model: You can't use %(model) funding model, only COST_PER_SALE is allowed sites: 'EBAY-AT': 'Austrian' diff --git a/config/versions.yml b/config/versions.yml index 866d6bb..a7223eb 100644 --- a/config/versions.yml +++ b/config/versions.yml @@ -12,5 +12,5 @@ sell: analytics: "1.0.0" fullfillemt: "1.2.0" inventory: "1.1.0" - marketing: "1.3.0" + marketing: "1.4.0" metadata: "1.1.0" diff --git a/lib/ebay_api/models/bid_percentage.rb b/lib/ebay_api/models/bid_percentage.rb index 6b19af0..4bcb9ab 100644 --- a/lib/ebay_api/models/bid_percentage.rb +++ b/lib/ebay_api/models/bid_percentage.rb @@ -6,7 +6,7 @@ class BidPercentage < Evil::Client::Model unless /\A\d{1,2}(?:\.\d)?\z/ =~ value.to_s next errors.add :bid_wrong_format, value: value end - unless (1..20).cover?(BigDecimal(value)) + unless (1..100).cover?(BigDecimal(value)) errors.add :bid_out_of_range, value: value end end diff --git a/spec/fixtures/sell/marketing/ads/bulk_create_by_listing_id/invalid b/spec/fixtures/sell/marketing/ads/bulk_create_by_listing_id/invalid index 79e1d88..acb657e 100644 --- a/spec/fixtures/sell/marketing/ads/bulk_create_by_listing_id/invalid +++ b/spec/fixtures/sell/marketing/ads/bulk_create_by_listing_id/invalid @@ -1,6 +1,6 @@ HTTP/1.1 400 Bad Request -Content-Length: 487 +Content-Length: 489 Content-Type: application/json -{"errors":[{"errorId":35007,"domain":"API_MARKETING","category":"REQUEST","message":"The 'bidPercentage' null is not valid. The bid percentage should be a single precision value. Minimum value: 1.0 , Maximum value:20.0. Example of valid values: 4.1, 4.10, 5.5, 5.0, etc. Invalid values: 4.44, 8.11, etc.","inputRefIds":["$.requests[0].bidPercentage"],"parameters":[{"name":"bidPercentage","value":"null"},{"name":"minBidPercent","value":"1.0"},{"name":"maxBidPercent","value":"20.0"}]}]} +{"errors":[{"errorId":35007,"domain":"API_MARKETING","category":"REQUEST","message":"The 'bidPercentage' null is not valid. The bid percentage should be a single precision value. Minimum value: 1.0 , Maximum value:100.0. Example of valid values: 4.1, 4.10, 5.5, 5.0, etc. Invalid values: 4.44, 8.11, etc.","inputRefIds":["$.requests[0].bidPercentage"],"parameters":[{"name":"bidPercentage","value":"null"},{"name":"minBidPercent","value":"1.0"},{"name":"maxBidPercent","value":"100.0"}]}]} From 2a467a23fb2d88b990d1a619904b2771411a512e Mon Sep 17 00:00:00 2001 From: nepalez Date: Mon, 8 Oct 2018 09:21:06 +0300 Subject: [PATCH 17/51] Fix the case when eBay responds with empty body --- lib/ebay_api.rb | 1 + spec/fixtures/sell/account/privilege/get/bad_request | 5 +++++ spec/operations/sell/account/privilege/get_spec.rb | 10 ++++++++++ 3 files changed, 16 insertions(+) create mode 100644 spec/fixtures/sell/account/privilege/get/bad_request diff --git a/lib/ebay_api.rb b/lib/ebay_api.rb index c8d622e..140583c 100644 --- a/lib/ebay_api.rb +++ b/lib/ebay_api.rb @@ -71,6 +71,7 @@ class << self # https://developer.ebay.com/api-docs/static/handling-error-messages.html response(400, 401, 409) do |_, _, (data, *)| + data = data.to_h case (code = data.dig("errors", 0, "errorId")) when 1001 message = data.dig("errors", 0, "longMessage") diff --git a/spec/fixtures/sell/account/privilege/get/bad_request b/spec/fixtures/sell/account/privilege/get/bad_request new file mode 100644 index 0000000..1ebde43 --- /dev/null +++ b/spec/fixtures/sell/account/privilege/get/bad_request @@ -0,0 +1,5 @@ +HTTP/1.1 400 Bad Request +Content-Length: 0 +Content-Type: application/json + + diff --git a/spec/operations/sell/account/privilege/get_spec.rb b/spec/operations/sell/account/privilege/get_spec.rb index a1d0f56..6316708 100644 --- a/spec/operations/sell/account/privilege/get_spec.rb +++ b/spec/operations/sell/account/privilege/get_spec.rb @@ -25,4 +25,14 @@ ) end end + + context "bad request" do + let(:response) do + open_fixture_file "sell/account/privilege/get/bad_request" + end + + it "raises an exception" do + expect { subject }.to raise_error EbayAPI::Error + end + end end From 4f17e951adb8c890ee70378399e0d31d0bdf4b24 Mon Sep 17 00:00:00 2001 From: nepalez Date: Mon, 8 Oct 2018 09:47:41 +0300 Subject: [PATCH 18/51] Add optional #data information to EbayAPI::Error exception --- lib/ebay_api.rb | 4 +++- lib/ebay_api/exceptions.rb | 5 +++-- .../sell/account/privilege/get/bad_request | 5 +++-- .../sell/account/privilege/get/server_error | 5 +++++ .../sell/account/privilege/get_spec.rb | 19 +++++++++++++++++++ 5 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 spec/fixtures/sell/account/privilege/get/server_error diff --git a/lib/ebay_api.rb b/lib/ebay_api.rb index 140583c..4dde319 100644 --- a/lib/ebay_api.rb +++ b/lib/ebay_api.rb @@ -77,12 +77,13 @@ class << self message = data.dig("errors", 0, "longMessage") raise InvalidAccessToken.new(code: code), message else - raise Error.new(code: code), data.dig("errors", 0, "message") + raise Error.new(code: code, data: data), data.dig("errors", 0, "message") end end # https://go.developer.ebay.com/api-call-limits response(429) do |_, _, (data, *)| + data = data.to_h error = data.dig("errors", 0) || {} code = error["errorId"] message = error["longMessage"] || error["message"] @@ -90,6 +91,7 @@ class << self end response(500) do |_, _, (data, *)| + data = data.to_h code = data.dig("errors", 0, "errorId") message = data.dig("errors", 0, "longMessage") || data.dig("errors", 0, "message") diff --git a/lib/ebay_api/exceptions.rb b/lib/ebay_api/exceptions.rb index 3a6997b..477d7e1 100644 --- a/lib/ebay_api/exceptions.rb +++ b/lib/ebay_api/exceptions.rb @@ -1,10 +1,11 @@ class EbayAPI class Error < RuntimeError - attr_reader :code + attr_reader :code, :data - def initialize(*args, code: nil, **) + def initialize(*args, code: nil, data: nil, **) super(*args) @code = code + @data = data end end diff --git a/spec/fixtures/sell/account/privilege/get/bad_request b/spec/fixtures/sell/account/privilege/get/bad_request index 1ebde43..79b9c09 100644 --- a/spec/fixtures/sell/account/privilege/get/bad_request +++ b/spec/fixtures/sell/account/privilege/get/bad_request @@ -1,5 +1,6 @@ HTTP/1.1 400 Bad Request -Content-Length: 0 -Content-Type: application/json +Content-Length: 182 +Content-Type: text/html +{"errors":[{"errorId":1002,"domain":"OAuth","category":"REQUEST","message":"Missing access token","longMessage":"Access token is missing in the Authorization HTTP request header."}]} diff --git a/spec/fixtures/sell/account/privilege/get/server_error b/spec/fixtures/sell/account/privilege/get/server_error new file mode 100644 index 0000000..9420ebf --- /dev/null +++ b/spec/fixtures/sell/account/privilege/get/server_error @@ -0,0 +1,5 @@ +HTTP/1.1 500 Server Error +Content-Length: 0 +Content-Type: application/json + + diff --git a/spec/operations/sell/account/privilege/get_spec.rb b/spec/operations/sell/account/privilege/get_spec.rb index 6316708..228f556 100644 --- a/spec/operations/sell/account/privilege/get_spec.rb +++ b/spec/operations/sell/account/privilege/get_spec.rb @@ -34,5 +34,24 @@ it "raises an exception" do expect { subject }.to raise_error EbayAPI::Error end + + it "carries error message" do + begin + subject + rescue => err + expect(err.code).to eq 1002 + expect(err.data).not_to be_empty + end + end + end + + context "server error" do + let(:response) do + open_fixture_file "sell/account/privilege/get/server_error" + end + + it "raises an exception" do + expect { subject }.to raise_error EbayAPI::Error + end end end From af53508aeb76430a6072ace1b6701d5df552b1d4 Mon Sep 17 00:00:00 2001 From: Andrey Novikov Date: Wed, 7 Nov 2018 18:00:46 +0300 Subject: [PATCH 19/51] More verbose exception messages on access token refresh failures --- lib/ebay_api/token_manager.rb | 12 +++++++----- spec/token_manager_spec.rb | 19 +++++++++++++++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/ebay_api/token_manager.rb b/lib/ebay_api/token_manager.rb index 35b173a..ec78034 100644 --- a/lib/ebay_api/token_manager.rb +++ b/lib/ebay_api/token_manager.rb @@ -66,18 +66,20 @@ def refresh_token_request! return body if response.is_a? Net::HTTPSuccess handle_errors!(body) rescue JSON::ParserError - raise EbayAPI::Error, "Can't refresh access token: #{response.body}" + message = "Response isn't JSON: #{response.code} - #{response.body}" + raise EbayAPI::Error, "Can't refresh access token: #{message}" end def handle_errors!(response) - message = response["error_description"] + cause = response.values_at("error", "error_description").compact.join(" - ") + cause = response if cause.length.zero? case response["error"] when "server_error" - raise EbayAPI::InternalServerError, message + raise EbayAPI::InternalServerError, cause when "invalid_grant" - raise RefreshTokenInvalid, message + raise RefreshTokenInvalid, cause else - raise EbayAPI::Error, "Can't refresh access token: #{message}" + raise EbayAPI::Error, "Can't refresh access token: #{cause}" end end diff --git a/spec/token_manager_spec.rb b/spec/token_manager_spec.rb index 0c919ae..f96bafd 100644 --- a/spec/token_manager_spec.rb +++ b/spec/token_manager_spec.rb @@ -105,13 +105,13 @@ let(:refresh_response) do { status: 400, - body: '{"error":"invalid_grant","error_description":"fiasco"}', + body: '{"error":"invalid_grant","error_description":"fiasco"}' } end it "raises exception" do expect { subject.refresh! }.to raise_error( - EbayAPI::TokenManager::RefreshTokenInvalid, "fiasco" + EbayAPI::TokenManager::RefreshTokenInvalid, "invalid_grant - fiasco" ) end end @@ -120,13 +120,24 @@ let(:refresh_response) do { status: 500, - body: '{"error":"server_error","error_description":"this is fiasco"}', + body: '{"error":"server_error","error_description":"this is fiasco"}' } end it "raises exception" do expect { subject.refresh! }.to raise_error \ - EbayAPI::InternalServerError, /this is fiasco/ + EbayAPI::InternalServerError, /server_error - this is fiasco/ + end + end + + context "when server returns nonparseable result" do + let(:refresh_response) do + { status: 502, body: "

Gateway timeout

" } + end + + it "raises exception" do + expect { subject.refresh! }.to raise_error \ + EbayAPI::Error, /isn't JSON: 502 .*Gateway timeout/ end end end From 534185552fd253d48d03bfc1303a5d692e1aad80 Mon Sep 17 00:00:00 2001 From: Andrey Novikov Date: Thu, 8 Nov 2018 12:57:40 +0300 Subject: [PATCH 20/51] Add support for eBay Developer APIs https://developer.ebay.com/api-docs/developer/static/developer-landing.html --- config/versions.yml | 2 ++ lib/ebay_api/operations.rb | 1 + lib/ebay_api/operations/developer.rb | 12 ++++++++++++ lib/ebay_api/operations/developer/analytics.rb | 15 +++++++++++++++ .../developer/analytics/rate_limit.rb | 11 +++++++++++ .../developer/analytics/rate_limit/get.rb | 17 +++++++++++++++++ .../developer/analytics/user_rate_limit.rb | 11 +++++++++++ .../developer/analytics/user_rate_limit/get.rb | 17 +++++++++++++++++ 8 files changed, 86 insertions(+) create mode 100644 lib/ebay_api/operations/developer.rb create mode 100644 lib/ebay_api/operations/developer/analytics.rb create mode 100644 lib/ebay_api/operations/developer/analytics/rate_limit.rb create mode 100644 lib/ebay_api/operations/developer/analytics/rate_limit/get.rb create mode 100644 lib/ebay_api/operations/developer/analytics/user_rate_limit.rb create mode 100644 lib/ebay_api/operations/developer/analytics/user_rate_limit/get.rb diff --git a/config/versions.yml b/config/versions.yml index a7223eb..90c19ae 100644 --- a/config/versions.yml +++ b/config/versions.yml @@ -14,3 +14,5 @@ sell: inventory: "1.1.0" marketing: "1.4.0" metadata: "1.1.0" +developer: + analytics: "1_beta.0.0" diff --git a/lib/ebay_api/operations.rb b/lib/ebay_api/operations.rb index 6fc01e1..2e03207 100644 --- a/lib/ebay_api/operations.rb +++ b/lib/ebay_api/operations.rb @@ -1 +1,2 @@ require_relative "operations/sell" +require_relative "operations/developer" diff --git a/lib/ebay_api/operations/developer.rb b/lib/ebay_api/operations/developer.rb new file mode 100644 index 0000000..1b3628d --- /dev/null +++ b/lib/ebay_api/operations/developer.rb @@ -0,0 +1,12 @@ +class EbayAPI + # + # eBay Developer APIs + # + # @see https://developer.ebay.com/api-docs/developer/static/developer-landing.html + # + scope :developer do + path "developer" + + require_relative "developer/analytics" + end +end diff --git a/lib/ebay_api/operations/developer/analytics.rb b/lib/ebay_api/operations/developer/analytics.rb new file mode 100644 index 0000000..14f74de --- /dev/null +++ b/lib/ebay_api/operations/developer/analytics.rb @@ -0,0 +1,15 @@ +class EbayAPI + scope :developer do + # + # eBay Developer Analytics API + # + # @see https://developer.ebay.com/api-docs/developer/analytics/static/overview.html + # + scope :analytics do + path { "analytics/v#{EbayAPI::DEVELOPER_ANALYTICS_VERSION[/^\d[\w]+/]}" } + + require_relative "analytics/rate_limit" + require_relative "analytics/user_rate_limit" + end + end +end diff --git a/lib/ebay_api/operations/developer/analytics/rate_limit.rb b/lib/ebay_api/operations/developer/analytics/rate_limit.rb new file mode 100644 index 0000000..0b705c1 --- /dev/null +++ b/lib/ebay_api/operations/developer/analytics/rate_limit.rb @@ -0,0 +1,11 @@ +class EbayAPI + scope :developer do + scope :analytics do + scope :rate_limit do + path "rate_limit" + + require_relative "rate_limit/get" + end + end + end +end diff --git a/lib/ebay_api/operations/developer/analytics/rate_limit/get.rb b/lib/ebay_api/operations/developer/analytics/rate_limit/get.rb new file mode 100644 index 0000000..0284666 --- /dev/null +++ b/lib/ebay_api/operations/developer/analytics/rate_limit/get.rb @@ -0,0 +1,17 @@ +class EbayAPI + scope :developer do + scope :analytics do + scope :rate_limit do + # @see https://developer.ebay.com/api-docs/developer/analytics/resources/rate_limit/methods/getRateLimits + operation :get do + http_method :get + path { "/" } + + response(200) do |_, _, (data, *)| + data["rateLimits"] + end + end + end + end + end +end diff --git a/lib/ebay_api/operations/developer/analytics/user_rate_limit.rb b/lib/ebay_api/operations/developer/analytics/user_rate_limit.rb new file mode 100644 index 0000000..1b97b65 --- /dev/null +++ b/lib/ebay_api/operations/developer/analytics/user_rate_limit.rb @@ -0,0 +1,11 @@ +class EbayAPI + scope :developer do + scope :analytics do + scope :user_rate_limit do + path "user_rate_limit" + + require_relative "user_rate_limit/get" + end + end + end +end diff --git a/lib/ebay_api/operations/developer/analytics/user_rate_limit/get.rb b/lib/ebay_api/operations/developer/analytics/user_rate_limit/get.rb new file mode 100644 index 0000000..bad4f86 --- /dev/null +++ b/lib/ebay_api/operations/developer/analytics/user_rate_limit/get.rb @@ -0,0 +1,17 @@ +class EbayAPI + scope :developer do + scope :analytics do + scope :user_rate_limit do + # @see https://developer.ebay.com/api-docs/developer/analytics/resources/user_rate_limit/methods/getUserRateLimits + operation :get do + http_method :get + path { "/" } + + response(200) do |_, _, (data, *)| + data["rateLimits"] + end + end + end + end + end +end From df3ba9e38eae2c67e558ae5ad245811e763d5289 Mon Sep 17 00:00:00 2001 From: nepalez Date: Tue, 18 Jun 2019 12:03:42 +0300 Subject: [PATCH 21/51] Add RubyMine .idea folder to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e0afc44..ba5ea1d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ /tmp/ *.gem .rspec_status +.idea/ From db277d71ad7fdc050265f0cf54287a256e0eff4e Mon Sep 17 00:00:00 2001 From: nepalez Date: Tue, 18 Jun 2019 12:05:19 +0300 Subject: [PATCH 22/51] Update processing of business error 35077 --- lib/ebay_api/operations/sell/marketing/ads.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ebay_api/operations/sell/marketing/ads.rb b/lib/ebay_api/operations/sell/marketing/ads.rb index ffce504..a40de57 100644 --- a/lib/ebay_api/operations/sell/marketing/ads.rb +++ b/lib/ebay_api/operations/sell/marketing/ads.rb @@ -21,7 +21,7 @@ class EbayAPI code = data.dig("errors", 0, "errorId") message = data.dig("errors", 0, "message") case code - when 35_060, 35_067 + when 35_060, 35_067, 35_077 raise EbayAPI::UserActionRequired.new(code: code), message else super! From 8fe2510df770709123998c72d0f8e73157ebdc82 Mon Sep 17 00:00:00 2001 From: nepalez Date: Tue, 18 Jun 2019 18:06:08 +0300 Subject: [PATCH 23/51] Handle errors in responses to marketing campaings --- lib/ebay_api/operations/sell/marketing/campaigns.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ebay_api/operations/sell/marketing/campaigns.rb b/lib/ebay_api/operations/sell/marketing/campaigns.rb index b2b0683..05f7798 100644 --- a/lib/ebay_api/operations/sell/marketing/campaigns.rb +++ b/lib/ebay_api/operations/sell/marketing/campaigns.rb @@ -22,7 +22,7 @@ class EbayAPI code = data.dig("errors", 0, "errorId") message = data.dig("errors", 0, "message") case code - when 35_060 + when 35_060, 35_067, 35_077 raise EbayAPI::UserActionRequired.new(code: code), message else super! From b2719b8107864ad78ede2de420e6d4b31ebb7b5d Mon Sep 17 00:00:00 2001 From: nepalez Date: Mon, 23 Sep 2019 10:56:08 +0300 Subject: [PATCH 24/51] Handle unauthorized_client error with RefreshTokenInvalid exception --- lib/ebay_api/token_manager.rb | 2 +- spec/token_manager_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/ebay_api/token_manager.rb b/lib/ebay_api/token_manager.rb index ec78034..ad04ae9 100644 --- a/lib/ebay_api/token_manager.rb +++ b/lib/ebay_api/token_manager.rb @@ -76,7 +76,7 @@ def handle_errors!(response) case response["error"] when "server_error" raise EbayAPI::InternalServerError, cause - when "invalid_grant" + when "invalid_grant", "unauthorized_client" raise RefreshTokenInvalid, cause else raise EbayAPI::Error, "Can't refresh access token: #{cause}" diff --git a/spec/token_manager_spec.rb b/spec/token_manager_spec.rb index f96bafd..81e14ff 100644 --- a/spec/token_manager_spec.rb +++ b/spec/token_manager_spec.rb @@ -116,6 +116,22 @@ end end + context "with client not authorized" do + let(:refresh_response) do + { + status: 400, + body: '{"error":"unauthorized_client","error_description":"fiasco"}' + } + end + + it "raises exception" do + expect { subject.refresh! }.to raise_error( + EbayAPI::TokenManager::RefreshTokenInvalid, + "unauthorized_client - fiasco" + ) + end + end + context "on eBay's internal server error" do let(:refresh_response) do { From d6725d35e501daa3a819aa9f0e2458945381733b Mon Sep 17 00:00:00 2001 From: "Andrew Kozin (nepalez)" Date: Tue, 16 Feb 2021 09:34:34 +0300 Subject: [PATCH 25/51] Implement payments_program --- lib/ebay_api/operations/sell/account.rb | 1 + .../sell/account/payments_program.rb | 11 ++++ .../sell/account/payments_program/get.rb | 16 ++++++ .../operations/sell/account/program/get.rb | 13 +++++ .../account/payments_program/get/bad_request | 6 ++ .../account/payments_program/get/server_error | 5 ++ .../sell/account/payments_program/get/success | 6 ++ .../sell/account/payments_program/get_spec.rb | 56 +++++++++++++++++++ 8 files changed, 114 insertions(+) create mode 100644 lib/ebay_api/operations/sell/account/payments_program.rb create mode 100644 lib/ebay_api/operations/sell/account/payments_program/get.rb create mode 100644 lib/ebay_api/operations/sell/account/program/get.rb create mode 100644 spec/fixtures/sell/account/payments_program/get/bad_request create mode 100644 spec/fixtures/sell/account/payments_program/get/server_error create mode 100644 spec/fixtures/sell/account/payments_program/get/success create mode 100644 spec/operations/sell/account/payments_program/get_spec.rb diff --git a/lib/ebay_api/operations/sell/account.rb b/lib/ebay_api/operations/sell/account.rb index 0c04e8b..1bfcd51 100644 --- a/lib/ebay_api/operations/sell/account.rb +++ b/lib/ebay_api/operations/sell/account.rb @@ -10,6 +10,7 @@ class EbayAPI require_relative "account/program" require_relative "account/fulfillment_policy" require_relative "account/return_policy" + require_relative "account/payments_program" end end end diff --git a/lib/ebay_api/operations/sell/account/payments_program.rb b/lib/ebay_api/operations/sell/account/payments_program.rb new file mode 100644 index 0000000..07c7d62 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/payments_program.rb @@ -0,0 +1,11 @@ +require_relative "payments_program/get" + +class EbayAPI + scope :sell do + scope :account do + scope :payments_program do + path { "payments_program" } + end + end + end +end diff --git a/lib/ebay_api/operations/sell/account/payments_program/get.rb b/lib/ebay_api/operations/sell/account/payments_program/get.rb new file mode 100644 index 0000000..3a8cd11 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/payments_program/get.rb @@ -0,0 +1,16 @@ +class EbayAPI + scope :sell do + scope :account do + scope :payments_program do + # @see https://developer.ebay.com/api-docs/sell/account/resources/payments_program/methods/getPaymentsProgram + operation :get do + option :site, Site + option :type, proc(&:to_s), default: -> { "EBAY_PAYMENTS" } + + http_method :get + path { "/#{site.key}/#{type}" } + end + end + end + end +end diff --git a/lib/ebay_api/operations/sell/account/program/get.rb b/lib/ebay_api/operations/sell/account/program/get.rb new file mode 100644 index 0000000..df873c3 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/program/get.rb @@ -0,0 +1,13 @@ +class EbayAPI + scope :sell do + scope :account do + scope :program do + # @see https://developer.ebay.com/api-docs/sell/account/resources/program/methods/getOptedInPrograms + operation :get do + http_method :get + path { "get_opted_in_programs" } + end + end + end + end +end diff --git a/spec/fixtures/sell/account/payments_program/get/bad_request b/spec/fixtures/sell/account/payments_program/get/bad_request new file mode 100644 index 0000000..79b9c09 --- /dev/null +++ b/spec/fixtures/sell/account/payments_program/get/bad_request @@ -0,0 +1,6 @@ +HTTP/1.1 400 Bad Request +Content-Length: 182 +Content-Type: text/html + +{"errors":[{"errorId":1002,"domain":"OAuth","category":"REQUEST","message":"Missing access token","longMessage":"Access token is missing in the Authorization HTTP request header."}]} + diff --git a/spec/fixtures/sell/account/payments_program/get/server_error b/spec/fixtures/sell/account/payments_program/get/server_error new file mode 100644 index 0000000..9420ebf --- /dev/null +++ b/spec/fixtures/sell/account/payments_program/get/server_error @@ -0,0 +1,5 @@ +HTTP/1.1 500 Server Error +Content-Length: 0 +Content-Type: application/json + + diff --git a/spec/fixtures/sell/account/payments_program/get/success b/spec/fixtures/sell/account/payments_program/get/success new file mode 100644 index 0000000..9580b47 --- /dev/null +++ b/spec/fixtures/sell/account/payments_program/get/success @@ -0,0 +1,6 @@ +HTTP/1.1 200 OK +Content-Length: 113 +Content-Type: application/json + +{"marketplaceId":"EBAY_US","paymentProgramType":"EBAY_PAYMENTS","status":"OPTED_IN","wasPreviouslyOptedIn":false} + diff --git a/spec/operations/sell/account/payments_program/get_spec.rb b/spec/operations/sell/account/payments_program/get_spec.rb new file mode 100644 index 0000000..84b5223 --- /dev/null +++ b/spec/operations/sell/account/payments_program/get_spec.rb @@ -0,0 +1,56 @@ +RSpec.describe EbayAPI, ".sell.account.payments_program.get" do + let(:url) { "https://api.ebay.com/sell/account/v1/payments_program/EBAY_US/EBAY_PAYMENTS" } + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).payments_program } + let(:settings) { yaml_fixture_file(settings_file) } + let(:version) { "1.2.0" } + let(:settings_file) { "settings.valid.yml" } + + before { stub_request(:get, url).to_return(response) } + subject { scope.get(site: 0) } + + context "success" do + let(:response) do + open_fixture_file "sell/account/payments_program/get/success" + end + + it "returns just parsed JSON with data about payments program" do + expect(subject).to \ + eq( + "marketplaceId" => "EBAY_US", + "paymentProgramType" => "EBAY_PAYMENTS", + "status" => "OPTED_IN", + "wasPreviouslyOptedIn" => false + ) + end + end + + context "bad request" do + let(:response) do + open_fixture_file "sell/account/payments_program/get/bad_request" + end + + it "raises an exception" do + expect { subject }.to raise_error EbayAPI::Error + end + + it "carries error message" do + begin + subject + rescue => err + expect(err.code).to eq 1002 + expect(err.data).not_to be_empty + end + end + end + + context "server error" do + let(:response) do + open_fixture_file "sell/account/payments_program/get/server_error" + end + + it "raises an exception" do + expect { subject }.to raise_error EbayAPI::Error + end + end +end From 29b1770f52ce34d25a2397c2957d97f0b92bd219 Mon Sep 17 00:00:00 2001 From: "Andrew Kozin (nepalez)" Date: Tue, 16 Feb 2021 09:37:10 +0300 Subject: [PATCH 26/51] Fix rubocop issues --- .rubocop.yml | 10 +++++++++- lib/ebay_api/paginated_collection.rb | 6 +++--- .../sell/account/payments_program/get_spec.rb | 10 ++++------ spec/operations/sell/account/privilege/get_spec.rb | 10 ++++------ 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 4568cf7..ca95559 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,7 +3,8 @@ AllCops: DisplayCopNames: true DisplayStyleGuide: true StyleGuideCopsOnly: true - TargetRubyVersion: 2.3 + TargetRubyVersion: 2.6 + NewCops: enable Metrics/LineLength: AllowHeredoc: true @@ -41,3 +42,10 @@ Style/RaiseArgs: Style/StringLiterals: EnforcedStyle: double_quotes + +Style/IfUnlessModifier: + Enabled: false + +Lint/ConstantDefinitionInBlock: + Exclude: + - spec/**/* diff --git a/lib/ebay_api/paginated_collection.rb b/lib/ebay_api/paginated_collection.rb index b2cb3f7..eab09a8 100644 --- a/lib/ebay_api/paginated_collection.rb +++ b/lib/ebay_api/paginated_collection.rb @@ -38,12 +38,12 @@ def initialize(handler, response, key) @initial_next = @next end - def each - return to_enum unless block_given? + def each(&block) + return to_enum unless block @collection = @initial_collection @next = @initial_next loop do - @collection.each { |element| yield(element) } + @collection.each { |element| block.call(element) } raise StopIteration if all_records_loaded? load_next! end diff --git a/spec/operations/sell/account/payments_program/get_spec.rb b/spec/operations/sell/account/payments_program/get_spec.rb index 84b5223..fcc2d02 100644 --- a/spec/operations/sell/account/payments_program/get_spec.rb +++ b/spec/operations/sell/account/payments_program/get_spec.rb @@ -35,12 +35,10 @@ end it "carries error message" do - begin - subject - rescue => err - expect(err.code).to eq 1002 - expect(err.data).not_to be_empty - end + subject + rescue => err + expect(err.code).to eq 1002 + expect(err.data).not_to be_empty end end diff --git a/spec/operations/sell/account/privilege/get_spec.rb b/spec/operations/sell/account/privilege/get_spec.rb index 228f556..cb27b64 100644 --- a/spec/operations/sell/account/privilege/get_spec.rb +++ b/spec/operations/sell/account/privilege/get_spec.rb @@ -36,12 +36,10 @@ end it "carries error message" do - begin - subject - rescue => err - expect(err.code).to eq 1002 - expect(err.data).not_to be_empty - end + subject + rescue => err + expect(err.code).to eq 1002 + expect(err.data).not_to be_empty end end From f2d2c8236a07b9760617b7f3fac51b8988eb0621 Mon Sep 17 00:00:00 2001 From: "Andrew Kozin (nepalez)" Date: Tue, 16 Feb 2021 09:43:05 +0300 Subject: [PATCH 27/51] Bump v0.0.2 --- ebay_api.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ebay_api.gemspec b/ebay_api.gemspec index 23f025e..6172432 100644 --- a/ebay_api.gemspec +++ b/ebay_api.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |gem| gem.name = "ebay_api" - gem.version = "0.0.1" + gem.version = "0.0.2" gem.author = "Andrew Kozin (nepalez)" gem.email = "andrew.kozin@gmail.com" gem.homepage = "https://github.com/nepalez/sms_aero" From e0e86ab6fc44983210f84a6a81bb5a1631448b2f Mon Sep 17 00:00:00 2001 From: Valentin Kiselev Date: Wed, 28 Apr 2021 12:27:34 +0300 Subject: [PATCH 28/51] Add application token retrieving Signed-off-by: Valentin Kiselev --- ebay_api.gemspec | 2 +- lib/ebay_api/token_manager.rb | 25 ++++++++++++++------ spec/token_manager_spec.rb | 43 +++++++++++++++++++++++++---------- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/ebay_api.gemspec b/ebay_api.gemspec index 6172432..b769f6e 100644 --- a/ebay_api.gemspec +++ b/ebay_api.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |gem| gem.name = "ebay_api" - gem.version = "0.0.2" + gem.version = "0.0.3" gem.author = "Andrew Kozin (nepalez)" gem.email = "andrew.kozin@gmail.com" gem.homepage = "https://github.com/nepalez/sms_aero" diff --git a/lib/ebay_api/token_manager.rb b/lib/ebay_api/token_manager.rb index ad04ae9..3ccfa4d 100644 --- a/lib/ebay_api/token_manager.rb +++ b/lib/ebay_api/token_manager.rb @@ -11,10 +11,10 @@ class EbayAPI::TokenManager class RefreshTokenExpired < EbayAPI::Error; end class RefreshTokenInvalid < EbayAPI::Error; end - option :access_token - option :access_token_expires_at - option :refresh_token - option :refresh_token_expires_at + option :access_token, optional: true + option :access_token_expires_at, optional: true + option :refresh_token, optional: true + option :refresh_token_expires_at, optional: true option :appid option :certid option :on_refresh, optional: true @@ -37,6 +37,15 @@ class RefreshTokenInvalid < EbayAPI::Error; end # Callback. Will be called after successful renewal with two arguments: # new access token and its expiration time + # Returns application access token + # https://apitut.com/ebay/api/oauth-application-token.html + def application_token + request_token!( + grant_type: "client_credentials", + scope: "https://api.ebay.com/oauth/api_scope" + )["access_token"] + end + # Returns access token (retrieves and returns new one if it has expired) def access_token refresh! if access_token_expires_at&.<= Time.now + 60 # time drift margin @@ -59,9 +68,11 @@ def refresh! private def refresh_token_request! - response = - request! token_endpoint, - grant_type: "refresh_token", refresh_token: refresh_token + request_token!(grant_type: "refresh_token", refresh_token: refresh_token) + end + + def request_token!(options) + response = request!(token_endpoint, **options) body = JSON.parse(response.body) return body if response.is_a? Net::HTTPSuccess handle_errors!(body) diff --git a/spec/token_manager_spec.rb b/spec/token_manager_spec.rb index 81e14ff..aefb080 100644 --- a/spec/token_manager_spec.rb +++ b/spec/token_manager_spec.rb @@ -4,18 +4,6 @@ require "ebay_api/token_manager" describe EbayAPI::TokenManager do - let(:refresh_response) do - { status: 200, body: '{"access_token":"new_token","expires_in":7200}' } - end - let!(:api) do - stub_request(:post, "https://api.sandbox.ebay.com/identity/v1/oauth2/token") - .with( - body: { grant_type: "refresh_token", refresh_token: "refreshing" }, - basic_auth: %w[1 2] - ) - .to_return(refresh_response) - end - let(:access_token) { "old_token" } let(:refresh_token) { "refreshing" } let(:access_expire) { Time.now + 120 } @@ -31,6 +19,18 @@ ) end + let(:refresh_response) do + { status: 200, body: '{"access_token":"new_token","expires_in":7200}' } + end + let!(:api) do + stub_request(:post, "https://api.sandbox.ebay.com/identity/v1/oauth2/token") + .with( + body: { grant_type: "refresh_token", refresh_token: "refreshing" }, + basic_auth: %w[1 2] + ) + .to_return(refresh_response) + end + before do Timecop.freeze allow(callback).to receive(:call).with("new_token", Time.now + 7200) @@ -38,6 +38,25 @@ after { Timecop.return } + describe "#application_token" do + let!(:api) do + stub_request(:post, "https://api.sandbox.ebay.com/identity/v1/oauth2/token") + .with( + body: { + grant_type: "client_credentials", + scope: "https://api.ebay.com/oauth/api_scope" + }, + basic_auth: %w[1 2] + ) + .to_return(refresh_response) + end + + it "returns application token" do + expect(subject.application_token).to eq("new_token") + expect(api).to have_been_requested + end + end + describe "#access_token" do context "with valid access_token" do it "returns access_token" do From 496cfe34a7c00eb5384216c76f451210c7427a5d Mon Sep 17 00:00:00 2001 From: Valentin Kiselev Date: Thu, 29 Apr 2021 11:02:19 +0300 Subject: [PATCH 29/51] Add commerce/notifications/public_key operation Signed-off-by: Valentin Kiselev --- config/versions.yml | 1 + lib/ebay_api/operations.rb | 1 + lib/ebay_api/operations/commerce.rb | 12 ++++++++ .../operations/commerce/notifications.rb | 14 +++++++++ .../commerce/notifications/public_key.rb | 11 +++++++ .../commerce/notifications/public_key/get.rb | 15 ++++++++++ .../notifications/public_key/get/success | 5 ++++ .../notifications/public_key/get/success.yml | 5 ++++ .../notifications/public_key/get_spec.rb | 30 +++++++++++++++++++ 9 files changed, 94 insertions(+) create mode 100644 lib/ebay_api/operations/commerce.rb create mode 100644 lib/ebay_api/operations/commerce/notifications.rb create mode 100644 lib/ebay_api/operations/commerce/notifications/public_key.rb create mode 100644 lib/ebay_api/operations/commerce/notifications/public_key/get.rb create mode 100644 spec/fixtures/commerce/notifications/public_key/get/success create mode 100644 spec/fixtures/commerce/notifications/public_key/get/success.yml create mode 100644 spec/operations/commerce/notifications/public_key/get_spec.rb diff --git a/config/versions.yml b/config/versions.yml index 90c19ae..d5f7214 100644 --- a/config/versions.yml +++ b/config/versions.yml @@ -7,6 +7,7 @@ buy: order: "1_beta.7.0" commerce: taxonomy: "1_beta.0.0" + notifications: "1.0.0" sell: account: "1.1.0" analytics: "1.0.0" diff --git a/lib/ebay_api/operations.rb b/lib/ebay_api/operations.rb index 2e03207..ed2095a 100644 --- a/lib/ebay_api/operations.rb +++ b/lib/ebay_api/operations.rb @@ -1,2 +1,3 @@ require_relative "operations/sell" require_relative "operations/developer" +require_relative "operations/commerce" diff --git a/lib/ebay_api/operations/commerce.rb b/lib/ebay_api/operations/commerce.rb new file mode 100644 index 0000000..e0e13f5 --- /dev/null +++ b/lib/ebay_api/operations/commerce.rb @@ -0,0 +1,12 @@ +class EbayAPI + # + # eBay Commerce APIs + # + # @see https://developer.ebay.com/api-docs/commerce/static/commerce-landing.html + # + scope :commerce do + path "commerce" + + require_relative "commerce/notifications" + end +end diff --git a/lib/ebay_api/operations/commerce/notifications.rb b/lib/ebay_api/operations/commerce/notifications.rb new file mode 100644 index 0000000..3542f9d --- /dev/null +++ b/lib/ebay_api/operations/commerce/notifications.rb @@ -0,0 +1,14 @@ +class EbayAPI + scope :commerce do + # + # eBay Commerce Notifications API + # + # @see https://developer.ebay.com/api-docs/commerce/notification/overview.html + # + scope :notifications do + path { "notifications/v#{EbayAPI::COMMERCE_NOTIFICATIONS_VERSION[/^\d+/]}" } + + require_relative "notifications/public_key" + end + end +end diff --git a/lib/ebay_api/operations/commerce/notifications/public_key.rb b/lib/ebay_api/operations/commerce/notifications/public_key.rb new file mode 100644 index 0000000..6113269 --- /dev/null +++ b/lib/ebay_api/operations/commerce/notifications/public_key.rb @@ -0,0 +1,11 @@ +class EbayAPI + scope :commerce do + scope :notifications do + scope :public_key do + path "public_key" + + require_relative "public_key/get" + end + end + end +end diff --git a/lib/ebay_api/operations/commerce/notifications/public_key/get.rb b/lib/ebay_api/operations/commerce/notifications/public_key/get.rb new file mode 100644 index 0000000..caf9fae --- /dev/null +++ b/lib/ebay_api/operations/commerce/notifications/public_key/get.rb @@ -0,0 +1,15 @@ +class EbayAPI + scope :commerce do + scope :notifications do + # @see https://developer.ebay.com/api-docs/commerce/notification/resources/public_key/methods/getPublicKey + scope :public_key do + operation :get do + option :key_id, proc(&:to_s) + + path { key_id } + http_method :get + end + end + end + end +end diff --git a/spec/fixtures/commerce/notifications/public_key/get/success b/spec/fixtures/commerce/notifications/public_key/get/success new file mode 100644 index 0000000..1a8b801 --- /dev/null +++ b/spec/fixtures/commerce/notifications/public_key/get/success @@ -0,0 +1,5 @@ +HTTP/1.1 200 OK +Content-Length: 220 +Content-Type: application/json + +{"algorithm":"ECDSA","digest":"SHA1","key":"-----BEGIN PUBLIC KEY-----MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEZhhxXKtR+TOvtDbgTPCkSof02qgBB7IsYOyf76ilExJ/upAa/vKIKheOoCyOpcLmi4t0b4uepb7LLjmMr90FUg==-----END PUBLIC KEY-----"} \ No newline at end of file diff --git a/spec/fixtures/commerce/notifications/public_key/get/success.yml b/spec/fixtures/commerce/notifications/public_key/get/success.yml new file mode 100644 index 0000000..473a51f --- /dev/null +++ b/spec/fixtures/commerce/notifications/public_key/get/success.yml @@ -0,0 +1,5 @@ +--- +algorithm: "ECDSA" +digest: "SHA1" +key: "-----BEGIN PUBLIC KEY-----MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEZhhxXKtR+TOvtDbgTPCkSof02qgBB7IsYOyf76ilExJ/upAa/vKIKheOoCyOpcLmi4t0b4uepb7LLjmMr90FUg==-----END + PUBLIC KEY-----" diff --git a/spec/operations/commerce/notifications/public_key/get_spec.rb b/spec/operations/commerce/notifications/public_key/get_spec.rb new file mode 100644 index 0000000..055a590 --- /dev/null +++ b/spec/operations/commerce/notifications/public_key/get_spec.rb @@ -0,0 +1,30 @@ +RSpec.describe EbayAPI, ".commerce.notifications.public_key.get" do + let(:client) { described_class.new(settings) } + let(:scope) { client.commerce.notifications.public_key } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:url) do + "https://api.ebay.com/commerce/notifications/v1/public_key/042" + end + + before { stub_request(:get, url).to_return(response) } + subject { scope.get key_id: "042" } + + context "success" do + let(:response) do + open_fixture_file "commerce/notifications/public_key/get/success" + end + + let(:public_key) do + yaml_fixture_file "commerce/notifications/public_key/get/success.yml" + end + + it "sends a request" do + subject + expect(a_request(:get, url)).to have_been_made + end + + it "returns the policy" do + expect(subject).to eq public_key + end + end +end From 4f8e84823ba2817782a56260e16f3cd6ceda59a1 Mon Sep 17 00:00:00 2001 From: Valentin Kiselev Date: Tue, 11 May 2021 14:03:15 +0300 Subject: [PATCH 30/51] Fix typo with notification url --- lib/ebay_api/operations/commerce.rb | 2 +- .../commerce/{notifications.rb => notification.rb} | 4 ++-- .../commerce/{notifications => notification}/public_key.rb | 0 .../{notifications => notification}/public_key/get.rb | 0 .../{notifications => notification}/public_key/get/success | 0 .../public_key/get/success.yml | 0 .../{notifications => notification}/public_key/get_spec.rb | 6 +++--- 7 files changed, 6 insertions(+), 6 deletions(-) rename lib/ebay_api/operations/commerce/{notifications.rb => notification.rb} (62%) rename lib/ebay_api/operations/commerce/{notifications => notification}/public_key.rb (100%) rename lib/ebay_api/operations/commerce/{notifications => notification}/public_key/get.rb (100%) rename spec/fixtures/commerce/{notifications => notification}/public_key/get/success (100%) rename spec/fixtures/commerce/{notifications => notification}/public_key/get/success.yml (100%) rename spec/operations/commerce/{notifications => notification}/public_key/get_spec.rb (74%) diff --git a/lib/ebay_api/operations/commerce.rb b/lib/ebay_api/operations/commerce.rb index e0e13f5..ab5ec36 100644 --- a/lib/ebay_api/operations/commerce.rb +++ b/lib/ebay_api/operations/commerce.rb @@ -7,6 +7,6 @@ class EbayAPI scope :commerce do path "commerce" - require_relative "commerce/notifications" + require_relative "commerce/notification" end end diff --git a/lib/ebay_api/operations/commerce/notifications.rb b/lib/ebay_api/operations/commerce/notification.rb similarity index 62% rename from lib/ebay_api/operations/commerce/notifications.rb rename to lib/ebay_api/operations/commerce/notification.rb index 3542f9d..6e31069 100644 --- a/lib/ebay_api/operations/commerce/notifications.rb +++ b/lib/ebay_api/operations/commerce/notification.rb @@ -6,9 +6,9 @@ class EbayAPI # @see https://developer.ebay.com/api-docs/commerce/notification/overview.html # scope :notifications do - path { "notifications/v#{EbayAPI::COMMERCE_NOTIFICATIONS_VERSION[/^\d+/]}" } + path { "notification/v#{EbayAPI::COMMERCE_NOTIFICATIONS_VERSION[/^\d+/]}" } - require_relative "notifications/public_key" + require_relative "notification/public_key" end end end diff --git a/lib/ebay_api/operations/commerce/notifications/public_key.rb b/lib/ebay_api/operations/commerce/notification/public_key.rb similarity index 100% rename from lib/ebay_api/operations/commerce/notifications/public_key.rb rename to lib/ebay_api/operations/commerce/notification/public_key.rb diff --git a/lib/ebay_api/operations/commerce/notifications/public_key/get.rb b/lib/ebay_api/operations/commerce/notification/public_key/get.rb similarity index 100% rename from lib/ebay_api/operations/commerce/notifications/public_key/get.rb rename to lib/ebay_api/operations/commerce/notification/public_key/get.rb diff --git a/spec/fixtures/commerce/notifications/public_key/get/success b/spec/fixtures/commerce/notification/public_key/get/success similarity index 100% rename from spec/fixtures/commerce/notifications/public_key/get/success rename to spec/fixtures/commerce/notification/public_key/get/success diff --git a/spec/fixtures/commerce/notifications/public_key/get/success.yml b/spec/fixtures/commerce/notification/public_key/get/success.yml similarity index 100% rename from spec/fixtures/commerce/notifications/public_key/get/success.yml rename to spec/fixtures/commerce/notification/public_key/get/success.yml diff --git a/spec/operations/commerce/notifications/public_key/get_spec.rb b/spec/operations/commerce/notification/public_key/get_spec.rb similarity index 74% rename from spec/operations/commerce/notifications/public_key/get_spec.rb rename to spec/operations/commerce/notification/public_key/get_spec.rb index 055a590..ab6e44a 100644 --- a/spec/operations/commerce/notifications/public_key/get_spec.rb +++ b/spec/operations/commerce/notification/public_key/get_spec.rb @@ -3,7 +3,7 @@ let(:scope) { client.commerce.notifications.public_key } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:url) do - "https://api.ebay.com/commerce/notifications/v1/public_key/042" + "https://api.ebay.com/commerce/notification/v1/public_key/042" end before { stub_request(:get, url).to_return(response) } @@ -11,11 +11,11 @@ context "success" do let(:response) do - open_fixture_file "commerce/notifications/public_key/get/success" + open_fixture_file "commerce/notification/public_key/get/success" end let(:public_key) do - yaml_fixture_file "commerce/notifications/public_key/get/success.yml" + yaml_fixture_file "commerce/notification/public_key/get/success.yml" end it "sends a request" do From 8e7b011c83d8bdc7fb84c708408dd16f77a80112 Mon Sep 17 00:00:00 2001 From: Valentin Kiselev Date: Tue, 11 May 2021 16:24:52 +0300 Subject: [PATCH 31/51] Update CHANGELOG Signed-off-by: Valentin Kiselev --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db89610..c7632b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.0.3] + +### Added + + - Method to retrieve Application token + - [getPublicKey](https://developer.ebay.com/api-docs/commerce/notification/resources/public_key/methods/getPublicKey) request. + ## [0.0.1] - To be released This is a first public release. From ceb2da8665b333b3da5da19cf26edb7842d30419 Mon Sep 17 00:00:00 2001 From: Valentine Kiselev Date: Wed, 1 Dec 2021 14:01:32 +0300 Subject: [PATCH 32/51] Add taxonomy API (#12) * Add taxonomy API v1.0.0 Signed-off-by: Valentin Kiselev * Bump version to 0.0.4 Signed-off-by: Valentin Kiselev * Rename marketplace_id to site option Signed-off-by: Valentin Kiselev * Add handling gzipped response Signed-off-by: Valentin Kiselev --- config/versions.yml | 2 +- ebay_api.gemspec | 2 +- lib/ebay_api/middlewares.rb | 1 + lib/ebay_api/middlewares/gzipped_response.rb | 26 +++++++++++++++ lib/ebay_api/middlewares/json_response.rb | 12 ++++++- lib/ebay_api/operations/commerce.rb | 1 + lib/ebay_api/operations/commerce/taxonomy.rb | 15 +++++++++ .../commerce/taxonomy/category_tree.rb | 21 ++++++++++++ .../category_tree/fetch_item_aspects.rb | 15 +++++++++ .../commerce/taxonomy/category_tree/get.rb | 13 ++++++++ .../category_tree/get_category_subtree.rb | 16 ++++++++++ .../category_tree/get_category_suggestions.rb | 16 ++++++++++ .../get_item_aspects_for_category.rb | 16 ++++++++++ .../taxonomy/get_default_category_tree_id.rb | 14 ++++++++ .../fetch_item_aspects/success.json | 1 + .../taxonomy/category_tree/get/success | 5 +++ .../get_category_subtree/success | 5 +++ .../get_category_suggestions/success | 5 +++ .../get_item_aspects_for_category/success | 5 +++ .../get_default_category_tree_id/success | 5 +++ .../category_tree/fetch_item_aspects_spec.rb | 32 +++++++++++++++++++ .../get_category_subtree_spec.rb | 24 ++++++++++++++ .../get_category_suggestions_spec.rb | 24 ++++++++++++++ .../get_item_aspects_for_category_spec.rb | 24 ++++++++++++++ .../taxonomy/category_tree/get_spec.rb | 24 ++++++++++++++ .../get_default_category_tree_id_spec.rb | 24 ++++++++++++++ 26 files changed, 345 insertions(+), 3 deletions(-) create mode 100644 lib/ebay_api/middlewares/gzipped_response.rb create mode 100644 lib/ebay_api/operations/commerce/taxonomy.rb create mode 100644 lib/ebay_api/operations/commerce/taxonomy/category_tree.rb create mode 100644 lib/ebay_api/operations/commerce/taxonomy/category_tree/fetch_item_aspects.rb create mode 100644 lib/ebay_api/operations/commerce/taxonomy/category_tree/get.rb create mode 100644 lib/ebay_api/operations/commerce/taxonomy/category_tree/get_category_subtree.rb create mode 100644 lib/ebay_api/operations/commerce/taxonomy/category_tree/get_category_suggestions.rb create mode 100644 lib/ebay_api/operations/commerce/taxonomy/category_tree/get_item_aspects_for_category.rb create mode 100644 lib/ebay_api/operations/commerce/taxonomy/get_default_category_tree_id.rb create mode 100644 spec/fixtures/commerce/taxonomy/category_tree/fetch_item_aspects/success.json create mode 100644 spec/fixtures/commerce/taxonomy/category_tree/get/success create mode 100644 spec/fixtures/commerce/taxonomy/category_tree/get_category_subtree/success create mode 100644 spec/fixtures/commerce/taxonomy/category_tree/get_category_suggestions/success create mode 100644 spec/fixtures/commerce/taxonomy/category_tree/get_item_aspects_for_category/success create mode 100644 spec/fixtures/commerce/taxonomy/get_default_category_tree_id/success create mode 100644 spec/operations/commerce/taxonomy/category_tree/fetch_item_aspects_spec.rb create mode 100644 spec/operations/commerce/taxonomy/category_tree/get_category_subtree_spec.rb create mode 100644 spec/operations/commerce/taxonomy/category_tree/get_category_suggestions_spec.rb create mode 100644 spec/operations/commerce/taxonomy/category_tree/get_item_aspects_for_category_spec.rb create mode 100644 spec/operations/commerce/taxonomy/category_tree/get_spec.rb create mode 100644 spec/operations/commerce/taxonomy/get_default_category_tree_id_spec.rb diff --git a/config/versions.yml b/config/versions.yml index d5f7214..af5a692 100644 --- a/config/versions.yml +++ b/config/versions.yml @@ -6,7 +6,7 @@ buy: marketing: "1_beta.0.0" order: "1_beta.7.0" commerce: - taxonomy: "1_beta.0.0" + taxonomy: "1.0.0" notifications: "1.0.0" sell: account: "1.1.0" diff --git a/ebay_api.gemspec b/ebay_api.gemspec index b769f6e..a3c3863 100644 --- a/ebay_api.gemspec +++ b/ebay_api.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |gem| gem.name = "ebay_api" - gem.version = "0.0.3" + gem.version = "0.0.4" gem.author = "Andrew Kozin (nepalez)" gem.email = "andrew.kozin@gmail.com" gem.homepage = "https://github.com/nepalez/sms_aero" diff --git a/lib/ebay_api/middlewares.rb b/lib/ebay_api/middlewares.rb index 297e5f6..a4b04aa 100644 --- a/lib/ebay_api/middlewares.rb +++ b/lib/ebay_api/middlewares.rb @@ -1,3 +1,4 @@ require_relative "middlewares/json_response" +require_relative "middlewares/gzipped_response" require_relative "middlewares/paginated_collection" require_relative "middlewares/log_request" diff --git a/lib/ebay_api/middlewares/gzipped_response.rb b/lib/ebay_api/middlewares/gzipped_response.rb new file mode 100644 index 0000000..35c0ae4 --- /dev/null +++ b/lib/ebay_api/middlewares/gzipped_response.rb @@ -0,0 +1,26 @@ +require "zlib" +require "stringio" + +# Parses gzipped response +class EbayAPI + class GzippedResponse + def initialize(app) + @app = app + end + + def call(env) + status, headers, gz_body = @app.call(env) + + [status, headers, gz_body.map { |b| unzip(b) }] + end + + private + + def unzip(body) + return unless body + return if body.empty? + + Zlib::GzipReader.new(StringIO.new(body.to_s)).read + end + end +end diff --git a/lib/ebay_api/middlewares/json_response.rb b/lib/ebay_api/middlewares/json_response.rb index 1640924..7dec4fd 100644 --- a/lib/ebay_api/middlewares/json_response.rb +++ b/lib/ebay_api/middlewares/json_response.rb @@ -7,7 +7,17 @@ def initialize(app) def call(env) status, headers, body = @app.call(env) - [status, headers, body.map { |b| JSON.parse(b) unless b&.empty? }] + + [status, headers, body.map { |b| parse(b) }] + end + + private + + def parse(body) + return unless body + return if body.empty? + + JSON.parse(body) end end end diff --git a/lib/ebay_api/operations/commerce.rb b/lib/ebay_api/operations/commerce.rb index ab5ec36..cd80922 100644 --- a/lib/ebay_api/operations/commerce.rb +++ b/lib/ebay_api/operations/commerce.rb @@ -8,5 +8,6 @@ class EbayAPI path "commerce" require_relative "commerce/notification" + require_relative "commerce/taxonomy" end end diff --git a/lib/ebay_api/operations/commerce/taxonomy.rb b/lib/ebay_api/operations/commerce/taxonomy.rb new file mode 100644 index 0000000..8ed0fd6 --- /dev/null +++ b/lib/ebay_api/operations/commerce/taxonomy.rb @@ -0,0 +1,15 @@ +class EbayAPI + scope :commerce do + # + # eBay Commerce Notifications API + # + # @see https://developer.ebay.com/api-docs/commerce/notification/overview.html + # + scope :taxonomy do + path { "taxonomy/v#{EbayAPI::COMMERCE_TAXONOMY_VERSION[/^\d+/]}" } + + require_relative "taxonomy/category_tree" + require_relative "taxonomy/get_default_category_tree_id" + end + end +end diff --git a/lib/ebay_api/operations/commerce/taxonomy/category_tree.rb b/lib/ebay_api/operations/commerce/taxonomy/category_tree.rb new file mode 100644 index 0000000..82afabc --- /dev/null +++ b/lib/ebay_api/operations/commerce/taxonomy/category_tree.rb @@ -0,0 +1,21 @@ +class EbayAPI + scope :commerce do + # + # eBay Commerce Notifications API + # + # @see https://developer.ebay.com/api-docs/commerce/taxonomy/overview.html + # + scope :taxonomy do + scope :category_tree do + path { "category_tree/#{category_tree_id}" } + option :category_tree_id + + require_relative "category_tree/get" + require_relative "category_tree/get_category_subtree" + require_relative "category_tree/get_category_suggestions" + require_relative "category_tree/get_item_aspects_for_category" + require_relative "category_tree/fetch_item_aspects" + end + end + end +end diff --git a/lib/ebay_api/operations/commerce/taxonomy/category_tree/fetch_item_aspects.rb b/lib/ebay_api/operations/commerce/taxonomy/category_tree/fetch_item_aspects.rb new file mode 100644 index 0000000..de7b921 --- /dev/null +++ b/lib/ebay_api/operations/commerce/taxonomy/category_tree/fetch_item_aspects.rb @@ -0,0 +1,15 @@ +class EbayAPI + scope :commerce do + scope :taxonomy do + scope :category_tree do + # @see https://developer.ebay.com/api-docs/commerce/taxonomy/resources/category_tree/methods/fetchItemAspects + operation :fetch_item_aspects do + middleware { [GzippedResponse] } + + path { "fetch_item_aspects" } + http_method :get + end + end + end + end +end diff --git a/lib/ebay_api/operations/commerce/taxonomy/category_tree/get.rb b/lib/ebay_api/operations/commerce/taxonomy/category_tree/get.rb new file mode 100644 index 0000000..15bb351 --- /dev/null +++ b/lib/ebay_api/operations/commerce/taxonomy/category_tree/get.rb @@ -0,0 +1,13 @@ +class EbayAPI + scope :commerce do + scope :taxonomy do + scope :category_tree do + # @see https://developer.ebay.com/api-docs/commerce/taxonomy/resources/category_tree/methods/getCategoryTree + operation :get do + path { "/" } + http_method :get + end + end + end + end +end diff --git a/lib/ebay_api/operations/commerce/taxonomy/category_tree/get_category_subtree.rb b/lib/ebay_api/operations/commerce/taxonomy/category_tree/get_category_subtree.rb new file mode 100644 index 0000000..ceca090 --- /dev/null +++ b/lib/ebay_api/operations/commerce/taxonomy/category_tree/get_category_subtree.rb @@ -0,0 +1,16 @@ +class EbayAPI + scope :commerce do + scope :taxonomy do + scope :category_tree do + # @see https://developer.ebay.com/api-docs/commerce/taxonomy/resources/category_tree/methods/getCategorySubtree + operation :get_category_subtree do + option :category_id, proc(&:to_s) + + path { "get_category_subtree" } + query { { category_id: category_id } } + http_method :get + end + end + end + end +end diff --git a/lib/ebay_api/operations/commerce/taxonomy/category_tree/get_category_suggestions.rb b/lib/ebay_api/operations/commerce/taxonomy/category_tree/get_category_suggestions.rb new file mode 100644 index 0000000..79c57f8 --- /dev/null +++ b/lib/ebay_api/operations/commerce/taxonomy/category_tree/get_category_suggestions.rb @@ -0,0 +1,16 @@ +class EbayAPI + scope :commerce do + scope :taxonomy do + scope :category_tree do + # @see https://developer.ebay.com/api-docs/commerce/taxonomy/resources/category_tree/methods/getCategorySuggestions + operation :get_category_suggestions do + option :query, proc(&:to_s) + + path { "get_category_suggestions" } + query { { q: query } } + http_method :get + end + end + end + end +end diff --git a/lib/ebay_api/operations/commerce/taxonomy/category_tree/get_item_aspects_for_category.rb b/lib/ebay_api/operations/commerce/taxonomy/category_tree/get_item_aspects_for_category.rb new file mode 100644 index 0000000..829ea8e --- /dev/null +++ b/lib/ebay_api/operations/commerce/taxonomy/category_tree/get_item_aspects_for_category.rb @@ -0,0 +1,16 @@ +class EbayAPI + scope :commerce do + scope :taxonomy do + scope :category_tree do + # @see https://developer.ebay.com/api-docs/commerce/taxonomy/resources/category_tree/methods/getItemAspectsForCategory + operation :get_item_aspects_for_category do + option :category_id, proc(&:to_s) + + path { "get_item_aspects_for_category" } + query { { category_id: category_id } } + http_method :get + end + end + end + end +end diff --git a/lib/ebay_api/operations/commerce/taxonomy/get_default_category_tree_id.rb b/lib/ebay_api/operations/commerce/taxonomy/get_default_category_tree_id.rb new file mode 100644 index 0000000..be83601 --- /dev/null +++ b/lib/ebay_api/operations/commerce/taxonomy/get_default_category_tree_id.rb @@ -0,0 +1,14 @@ +class EbayAPI + scope :commerce do + scope :taxonomy do + # @see https://developer.ebay.com/api-docs/commerce/taxonomy/resources/category_tree/methods/getDefaultCategoryTreeId + operation :get_default_category_tree_id do + option :site, Site + + path { "get_default_category_tree_id" } + query { { marketplace_id: site.key } } + http_method :get + end + end + end +end diff --git a/spec/fixtures/commerce/taxonomy/category_tree/fetch_item_aspects/success.json b/spec/fixtures/commerce/taxonomy/category_tree/fetch_item_aspects/success.json new file mode 100644 index 0000000..31470c7 --- /dev/null +++ b/spec/fixtures/commerce/taxonomy/category_tree/fetch_item_aspects/success.json @@ -0,0 +1 @@ +{"categoryTreeId": "string", "categoryTreeVersion": "string", "categoryAspects": [{"category": {"categoryId": "string", "categoryName": "string"}, "aspects": [{"aspectConstraint": {"aspectApplicableTo": ["AspectApplicableToEnum"], "aspectDataType": "AspectDataTypeEnum : [DATE,NUMBER,STRING,STRING_ARRAY]", "aspectEnabledForVariations": "boolean", "aspectFormat": "string", "aspectMaxLength": "integer", "aspectMode": "AspectModeEnum : [FREE_TEXT,SELECTION_ONLY]", "aspectRequired": "boolean", "aspectUsage": "AspectUsageEnum : [RECOMMENDED,OPTIONAL]", "expectedRequiredByDate": "string", "itemToAspectCardinality": "ItemToAspectCardinalityEnum : [MULTI,SINGLE]"}, "aspectValues": [{"localizedValue": "string", "valueConstraints": [{"applicableForLocalizedAspectName": "string", "applicableForLocalizedAspectValues": ["string"]}]}], "localizedAspectName": "string", "relevanceIndicator": {"searchCount": "integer"}}]}]} \ No newline at end of file diff --git a/spec/fixtures/commerce/taxonomy/category_tree/get/success b/spec/fixtures/commerce/taxonomy/category_tree/get/success new file mode 100644 index 0000000..5aa3401 --- /dev/null +++ b/spec/fixtures/commerce/taxonomy/category_tree/get/success @@ -0,0 +1,5 @@ +HTTP/1.1 200 OK +Content-Length: 751 +Content-Type: application/json + +{"applicableMarketplaceIds": ["MarketplaceIdEnum"], "categoryTreeId": "string", "categoryTreeVersion": "string", "rootCategoryNode": {"category": {"categoryId": "string", "categoryName": "string"}, "categoryTreeNodeLevel": "integer", "childCategoryTreeNodes": [{"category": {"categoryId": "string", "categoryName": "string"}, "categoryTreeNodeLevel": "integer", "childCategoryTreeNodes": [{"category": {"categoryId": "string", "categoryName": "string"}, "categoryTreeNodeLevel": "integer", "childCategoryTreeNodes": [{}], "leafCategoryTreeNode": "boolean", "parentCategoryTreeNodeHref": "string"}], "leafCategoryTreeNode": "boolean", "parentCategoryTreeNodeHref": "string"}], "leafCategoryTreeNode": "boolean", "parentCategoryTreeNodeHref": "string"}} \ No newline at end of file diff --git a/spec/fixtures/commerce/taxonomy/category_tree/get_category_subtree/success b/spec/fixtures/commerce/taxonomy/category_tree/get_category_subtree/success new file mode 100644 index 0000000..751de64 --- /dev/null +++ b/spec/fixtures/commerce/taxonomy/category_tree/get_category_subtree/success @@ -0,0 +1,5 @@ +HTTP/1.1 200 OK +Content-Length: 703 +Content-Type: application/json + +{"categorySubtreeNode": {"category": {"categoryId": "string", "categoryName": "string"}, "categoryTreeNodeLevel": "integer", "childCategoryTreeNodes": [{"category": {"categoryId": "string", "categoryName": "string"}, "categoryTreeNodeLevel": "integer", "childCategoryTreeNodes": [{"category": {"categoryId": "string", "categoryName": "string"}, "categoryTreeNodeLevel": "integer", "childCategoryTreeNodes": [{}], "leafCategoryTreeNode": "boolean", "parentCategoryTreeNodeHref": "string"}], "leafCategoryTreeNode": "boolean", "parentCategoryTreeNodeHref": "string"}], "leafCategoryTreeNode": "boolean", "parentCategoryTreeNodeHref": "string"}, "categoryTreeId": "string", "categoryTreeVersion": "string"} \ No newline at end of file diff --git a/spec/fixtures/commerce/taxonomy/category_tree/get_category_suggestions/success b/spec/fixtures/commerce/taxonomy/category_tree/get_category_suggestions/success new file mode 100644 index 0000000..3e2b8db --- /dev/null +++ b/spec/fixtures/commerce/taxonomy/category_tree/get_category_suggestions/success @@ -0,0 +1,5 @@ +HTTP/1.1 200 OK +Content-Length: 367 +Content-Type: application/json + +{"categorySuggestions": [{"category": {"categoryId": "string", "categoryName": "string"}, "categoryTreeNodeAncestors": [{"categoryId": "string", "categoryName": "string", "categorySubtreeNodeHref": "string", "categoryTreeNodeLevel": "integer"}], "categoryTreeNodeLevel": "integer", "relevancy": "string"}], "categoryTreeId": "string", "categoryTreeVersion": "string"} \ No newline at end of file diff --git a/spec/fixtures/commerce/taxonomy/category_tree/get_item_aspects_for_category/success b/spec/fixtures/commerce/taxonomy/category_tree/get_item_aspects_for_category/success new file mode 100644 index 0000000..9b5fa80 --- /dev/null +++ b/spec/fixtures/commerce/taxonomy/category_tree/get_item_aspects_for_category/success @@ -0,0 +1,5 @@ +HTTP/1.1 200 OK +Content-Length: 771 +Content-Type: application/json + +{"aspects": [{"aspectConstraint": {"aspectApplicableTo": ["AspectApplicableToEnum"], "aspectDataType": "AspectDataTypeEnum : [DATE,NUMBER,STRING,STRING_ARRAY]", "aspectEnabledForVariations": "boolean", "aspectFormat": "string", "aspectMaxLength": "integer", "aspectMode": "AspectModeEnum : [FREE_TEXT,SELECTION_ONLY]", "aspectRequired": "boolean", "aspectUsage": "AspectUsageEnum : [RECOMMENDED,OPTIONAL]", "expectedRequiredByDate": "string", "itemToAspectCardinality": "ItemToAspectCardinalityEnum : [MULTI,SINGLE]"}, "aspectValues": [{"localizedValue": "string", "valueConstraints": [{"applicableForLocalizedAspectName": "string", "applicableForLocalizedAspectValues": ["string"]}]}], "localizedAspectName": "string", "relevanceIndicator": {"searchCount": "integer"}}]} \ No newline at end of file diff --git a/spec/fixtures/commerce/taxonomy/get_default_category_tree_id/success b/spec/fixtures/commerce/taxonomy/get_default_category_tree_id/success new file mode 100644 index 0000000..eaa275e --- /dev/null +++ b/spec/fixtures/commerce/taxonomy/get_default_category_tree_id/success @@ -0,0 +1,5 @@ +HTTP/1.1 200 OK +Content-Length: 220 +Content-Type: application/json + +{"categoryTreeId": "string", "categoryTreeVersion": "string"} \ No newline at end of file diff --git a/spec/operations/commerce/taxonomy/category_tree/fetch_item_aspects_spec.rb b/spec/operations/commerce/taxonomy/category_tree/fetch_item_aspects_spec.rb new file mode 100644 index 0000000..0f09237 --- /dev/null +++ b/spec/operations/commerce/taxonomy/category_tree/fetch_item_aspects_spec.rb @@ -0,0 +1,32 @@ +RSpec.describe EbayAPI, ".commerce.taxonomy.category_tree.fetch_item_aspects" do + let(:client) { described_class.new(settings) } + let(:scope) { client.commerce.taxonomy.category_tree(category_tree_id: 41) } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:url) do + "https://api.ebay.com/commerce/taxonomy/v1/category_tree/41/fetch_item_aspects" + end + + before { stub_request(:get, url).to_return(response) } + subject do + scope.fetch_item_aspects + end + + context "success" do + let(:response) do + body = StringIO.new + gzipper = Zlib::GzipWriter.new(body) + gzipper.write(read_fixture_file("commerce/taxonomy/category_tree/fetch_item_aspects/success.json")) + gzipper.close + + { + status: 200, + body: body.string, + } + end + + it "sends a request" do + subject + expect(a_request(:get, url)).to have_been_made + end + end +end diff --git a/spec/operations/commerce/taxonomy/category_tree/get_category_subtree_spec.rb b/spec/operations/commerce/taxonomy/category_tree/get_category_subtree_spec.rb new file mode 100644 index 0000000..31fa63c --- /dev/null +++ b/spec/operations/commerce/taxonomy/category_tree/get_category_subtree_spec.rb @@ -0,0 +1,24 @@ +RSpec.describe EbayAPI, ".commerce.taxonomy.category_tree.get_category_subtree" do + let(:client) { described_class.new(settings) } + let(:scope) { client.commerce.taxonomy.category_tree(category_tree_id: 41) } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:url) do + "https://api.ebay.com/commerce/taxonomy/v1/category_tree/41/get_category_subtree?category_id=42" + end + + before { stub_request(:get, url).to_return(response) } + subject do + scope.get_category_subtree category_id: 42 + end + + context "success" do + let(:response) do + open_fixture_file "commerce/taxonomy/category_tree/get_category_subtree/success" + end + + it "sends a request" do + subject + expect(a_request(:get, url)).to have_been_made + end + end +end diff --git a/spec/operations/commerce/taxonomy/category_tree/get_category_suggestions_spec.rb b/spec/operations/commerce/taxonomy/category_tree/get_category_suggestions_spec.rb new file mode 100644 index 0000000..521afc6 --- /dev/null +++ b/spec/operations/commerce/taxonomy/category_tree/get_category_suggestions_spec.rb @@ -0,0 +1,24 @@ +RSpec.describe EbayAPI, ".commerce.taxonomy.category_tree.get_category_suggestions" do + let(:client) { described_class.new(settings) } + let(:scope) { client.commerce.taxonomy.category_tree(category_tree_id: 41) } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:url) do + "https://api.ebay.com/commerce/taxonomy/v1/category_tree/41/get_category_suggestions?q=android" + end + + before { stub_request(:get, url).to_return(response) } + subject do + scope.get_category_suggestions query: "android" + end + + context "success" do + let(:response) do + open_fixture_file "commerce/taxonomy/category_tree/get_category_suggestions/success" + end + + it "sends a request" do + subject + expect(a_request(:get, url)).to have_been_made + end + end +end diff --git a/spec/operations/commerce/taxonomy/category_tree/get_item_aspects_for_category_spec.rb b/spec/operations/commerce/taxonomy/category_tree/get_item_aspects_for_category_spec.rb new file mode 100644 index 0000000..bc16dba --- /dev/null +++ b/spec/operations/commerce/taxonomy/category_tree/get_item_aspects_for_category_spec.rb @@ -0,0 +1,24 @@ +RSpec.describe EbayAPI, ".commerce.taxonomy.category_tree.get_item_aspects_for_category" do + let(:client) { described_class.new(settings) } + let(:scope) { client.commerce.taxonomy.category_tree(category_tree_id: 41) } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:url) do + "https://api.ebay.com/commerce/taxonomy/v1/category_tree/41/get_item_aspects_for_category?category_id=42" + end + + before { stub_request(:get, url).to_return(response) } + subject do + scope.get_item_aspects_for_category category_id: 42 + end + + context "success" do + let(:response) do + open_fixture_file "commerce/taxonomy/category_tree/get_item_aspects_for_category/success" + end + + it "sends a request" do + subject + expect(a_request(:get, url)).to have_been_made + end + end +end diff --git a/spec/operations/commerce/taxonomy/category_tree/get_spec.rb b/spec/operations/commerce/taxonomy/category_tree/get_spec.rb new file mode 100644 index 0000000..2577cd8 --- /dev/null +++ b/spec/operations/commerce/taxonomy/category_tree/get_spec.rb @@ -0,0 +1,24 @@ +RSpec.describe EbayAPI, ".commerce.taxonomy.category_tree.get" do + let(:client) { described_class.new(settings) } + let(:scope) { client.commerce.taxonomy.category_tree(category_tree_id: 41) } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:url) do + "https://api.ebay.com/commerce/taxonomy/v1/category_tree/41/" + end + + before { stub_request(:get, url).to_return(response) } + subject do + scope.get + end + + context "success" do + let(:response) do + open_fixture_file "commerce/taxonomy/category_tree/get/success" + end + + it "sends a request" do + subject + expect(a_request(:get, url)).to have_been_made + end + end +end diff --git a/spec/operations/commerce/taxonomy/get_default_category_tree_id_spec.rb b/spec/operations/commerce/taxonomy/get_default_category_tree_id_spec.rb new file mode 100644 index 0000000..e04f262 --- /dev/null +++ b/spec/operations/commerce/taxonomy/get_default_category_tree_id_spec.rb @@ -0,0 +1,24 @@ +RSpec.describe EbayAPI, ".commerce.taxonomy.get_default_category_tree_id" do + let(:client) { described_class.new(settings) } + let(:scope) { client.commerce.taxonomy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:url) do + "https://api.ebay.com/commerce/taxonomy/v1/get_default_category_tree_id?marketplace_id=EBAY_US" + end + + before { stub_request(:get, url).to_return(response) } + subject do + scope.get_default_category_tree_id site: 0 + end + + context "success" do + let(:response) do + open_fixture_file "commerce/taxonomy/get_default_category_tree_id/success" + end + + it "sends a request" do + subject + expect(a_request(:get, url)).to have_been_made + end + end +end From d6dce110b31c0fda93aef3b19e64b3a8ef9d3bad Mon Sep 17 00:00:00 2001 From: Valentine Kiselev Date: Mon, 13 Dec 2021 17:46:42 +0300 Subject: [PATCH 33/51] Save heavy responses to a file for fetch_item_aspects (#13) * Save heavy responses to a file for fetch_item_aspects Signed-off-by: Valentin Kiselev * Update lib/ebay_api/middlewares/save_to_file_response.rb Co-authored-by: Andrey Novikov * Bump version Co-authored-by: Andrey Novikov --- ebay_api.gemspec | 2 +- lib/ebay_api/middlewares.rb | 2 +- lib/ebay_api/middlewares/gzipped_response.rb | 26 ----------------- .../middlewares/save_to_file_response.rb | 29 +++++++++++++++++++ .../category_tree/fetch_item_aspects.rb | 2 +- 5 files changed, 32 insertions(+), 29 deletions(-) delete mode 100644 lib/ebay_api/middlewares/gzipped_response.rb create mode 100644 lib/ebay_api/middlewares/save_to_file_response.rb diff --git a/ebay_api.gemspec b/ebay_api.gemspec index a3c3863..7dd518c 100644 --- a/ebay_api.gemspec +++ b/ebay_api.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |gem| gem.name = "ebay_api" - gem.version = "0.0.4" + gem.version = "0.0.5" gem.author = "Andrew Kozin (nepalez)" gem.email = "andrew.kozin@gmail.com" gem.homepage = "https://github.com/nepalez/sms_aero" diff --git a/lib/ebay_api/middlewares.rb b/lib/ebay_api/middlewares.rb index a4b04aa..31fb13f 100644 --- a/lib/ebay_api/middlewares.rb +++ b/lib/ebay_api/middlewares.rb @@ -1,4 +1,4 @@ require_relative "middlewares/json_response" -require_relative "middlewares/gzipped_response" +require_relative "middlewares/save_to_file_response" require_relative "middlewares/paginated_collection" require_relative "middlewares/log_request" diff --git a/lib/ebay_api/middlewares/gzipped_response.rb b/lib/ebay_api/middlewares/gzipped_response.rb deleted file mode 100644 index 35c0ae4..0000000 --- a/lib/ebay_api/middlewares/gzipped_response.rb +++ /dev/null @@ -1,26 +0,0 @@ -require "zlib" -require "stringio" - -# Parses gzipped response -class EbayAPI - class GzippedResponse - def initialize(app) - @app = app - end - - def call(env) - status, headers, gz_body = @app.call(env) - - [status, headers, gz_body.map { |b| unzip(b) }] - end - - private - - def unzip(body) - return unless body - return if body.empty? - - Zlib::GzipReader.new(StringIO.new(body.to_s)).read - end - end -end diff --git a/lib/ebay_api/middlewares/save_to_file_response.rb b/lib/ebay_api/middlewares/save_to_file_response.rb new file mode 100644 index 0000000..221f57a --- /dev/null +++ b/lib/ebay_api/middlewares/save_to_file_response.rb @@ -0,0 +1,29 @@ +require "securerandom" + +# Parses gzipped response +class EbayAPI + class SaveToFileResponse + def initialize(app) + @app = app + end + + def call(env) + status, headers, body = @app.call(env) + + [status, headers, body.map { |b| save(b) }] + end + + private + + def save(body) + return unless body + return if body.empty? + + file = File.new("/tmp/ebay-api-response-#{SecureRandom.hex}", "w+b") + file.write(body) + file.flush + file.close + { "filename" => file.path }.to_json + end + end +end diff --git a/lib/ebay_api/operations/commerce/taxonomy/category_tree/fetch_item_aspects.rb b/lib/ebay_api/operations/commerce/taxonomy/category_tree/fetch_item_aspects.rb index de7b921..647511b 100644 --- a/lib/ebay_api/operations/commerce/taxonomy/category_tree/fetch_item_aspects.rb +++ b/lib/ebay_api/operations/commerce/taxonomy/category_tree/fetch_item_aspects.rb @@ -4,7 +4,7 @@ class EbayAPI scope :category_tree do # @see https://developer.ebay.com/api-docs/commerce/taxonomy/resources/category_tree/methods/fetchItemAspects operation :fetch_item_aspects do - middleware { [GzippedResponse] } + middleware { SaveToFileResponse } # returns { "filename": "..." } path { "fetch_item_aspects" } http_method :get From 52d18f6d6c0bcbfa79e5469d3841ca8a0b63a12c Mon Sep 17 00:00:00 2001 From: Denis Lifanov Date: Fri, 10 Dec 2021 01:44:05 +0300 Subject: [PATCH 34/51] Add payment policy operations --- lib/ebay_api/operations/sell/account.rb | 1 + .../operations/sell/account/payment_policy.rb | 16 ++++++++++++++++ .../sell/account/payment_policy/create.rb | 17 +++++++++++++++++ .../sell/account/payment_policy/delete.rb | 15 +++++++++++++++ .../sell/account/payment_policy/get.rb | 15 +++++++++++++++ .../sell/account/payment_policy/get_by_name.rb | 17 +++++++++++++++++ .../sell/account/payment_policy/index.rb | 16 ++++++++++++++++ .../sell/account/payment_policy/update.rb | 18 ++++++++++++++++++ 8 files changed, 115 insertions(+) create mode 100644 lib/ebay_api/operations/sell/account/payment_policy.rb create mode 100644 lib/ebay_api/operations/sell/account/payment_policy/create.rb create mode 100644 lib/ebay_api/operations/sell/account/payment_policy/delete.rb create mode 100644 lib/ebay_api/operations/sell/account/payment_policy/get.rb create mode 100644 lib/ebay_api/operations/sell/account/payment_policy/get_by_name.rb create mode 100644 lib/ebay_api/operations/sell/account/payment_policy/index.rb create mode 100644 lib/ebay_api/operations/sell/account/payment_policy/update.rb diff --git a/lib/ebay_api/operations/sell/account.rb b/lib/ebay_api/operations/sell/account.rb index 1bfcd51..10e2596 100644 --- a/lib/ebay_api/operations/sell/account.rb +++ b/lib/ebay_api/operations/sell/account.rb @@ -10,6 +10,7 @@ class EbayAPI require_relative "account/program" require_relative "account/fulfillment_policy" require_relative "account/return_policy" + require_relative "account/payment_policy" require_relative "account/payments_program" end end diff --git a/lib/ebay_api/operations/sell/account/payment_policy.rb b/lib/ebay_api/operations/sell/account/payment_policy.rb new file mode 100644 index 0000000..01fa0da --- /dev/null +++ b/lib/ebay_api/operations/sell/account/payment_policy.rb @@ -0,0 +1,16 @@ +class EbayAPI + scope :sell do + scope :account do + scope :payment_policy do + path { "payment_policy" } + end + end + end +end + +require_relative "payment_policy/delete" +require_relative "payment_policy/get" +require_relative "payment_policy/get_by_name" +require_relative "payment_policy/index" +require_relative "payment_policy/create" +require_relative "payment_policy/update" diff --git a/lib/ebay_api/operations/sell/account/payment_policy/create.rb b/lib/ebay_api/operations/sell/account/payment_policy/create.rb new file mode 100644 index 0000000..1924498 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/payment_policy/create.rb @@ -0,0 +1,17 @@ +class EbayAPI + scope :sell do + scope :account do + scope :payment_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/payment_policy/methods/createPaymentPolicy + operation :create do + option :site, Site + option :data, proc(&:to_h) # TODO: add model to validate input + + path { "/" } + http_method :post + body { data.merge("marketplaceId" => site.key) } + end + end + end + end +end diff --git a/lib/ebay_api/operations/sell/account/payment_policy/delete.rb b/lib/ebay_api/operations/sell/account/payment_policy/delete.rb new file mode 100644 index 0000000..25bb7ea --- /dev/null +++ b/lib/ebay_api/operations/sell/account/payment_policy/delete.rb @@ -0,0 +1,15 @@ +class EbayAPI + scope :sell do + scope :account do + scope :payment_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/payment_policy/methods/deletePaymentPolicy + operation :delete do + option :id, proc(&:to_s) + + path { id } + http_method :delete + end + end + end + end +end diff --git a/lib/ebay_api/operations/sell/account/payment_policy/get.rb b/lib/ebay_api/operations/sell/account/payment_policy/get.rb new file mode 100644 index 0000000..cf35ac4 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/payment_policy/get.rb @@ -0,0 +1,15 @@ +class EbayAPI + scope :sell do + scope :account do + scope :payment_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/payment_policy/methods/getPaymentPolicy + operation :get do + option :id, proc(&:to_s) + + path { id } + http_method :get + end + end + end + end +end diff --git a/lib/ebay_api/operations/sell/account/payment_policy/get_by_name.rb b/lib/ebay_api/operations/sell/account/payment_policy/get_by_name.rb new file mode 100644 index 0000000..ce9edc9 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/payment_policy/get_by_name.rb @@ -0,0 +1,17 @@ +class EbayAPI + scope :sell do + scope :account do + scope :payment_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/payment_policy/methods/getPaymentPolicyByName + operation :get_by_name do + option :site, Site + option :name, proc(&:to_s) + + path { "/get_by_policy_name" } + query { { marketplace_id: site.key, name: name } } + http_method :get + end + end + end + end +end diff --git a/lib/ebay_api/operations/sell/account/payment_policy/index.rb b/lib/ebay_api/operations/sell/account/payment_policy/index.rb new file mode 100644 index 0000000..4aa6c93 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/payment_policy/index.rb @@ -0,0 +1,16 @@ +class EbayAPI + scope :sell do + scope :account do + scope :payment_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/payment_policy/methods/getPaymentPolicies + operation :index do + option :site, Site + + path { "/" } + query { { marketplace_id: site.key } } + http_method :get + end + end + end + end +end diff --git a/lib/ebay_api/operations/sell/account/payment_policy/update.rb b/lib/ebay_api/operations/sell/account/payment_policy/update.rb new file mode 100644 index 0000000..f30a08c --- /dev/null +++ b/lib/ebay_api/operations/sell/account/payment_policy/update.rb @@ -0,0 +1,18 @@ +class EbayAPI + scope :sell do + scope :account do + scope :payment_policy do + # @see https://developer.ebay.com/api-docs/sell/account/resources/payment_policy/methods/updatePaymentPolicy + operation :update do + option :id, proc(&:to_s) + option :site, Site + option :data, proc(&:to_h) # TODO: add model to validate input + + path { id } + http_method :put + body { data.merge("marketplaceId" => site.key) } + end + end + end + end +end From 9e544a205f14755cbb5f6c2ec807e2c4e7b58c3e Mon Sep 17 00:00:00 2001 From: Denis Lifanov Date: Fri, 10 Dec 2021 15:11:07 +0300 Subject: [PATCH 35/51] Add payment policy operations specs --- .../account/payment_policy/create/request.yml | 7 ++++ .../account/payment_policy/create/success | 5 +++ .../account/payment_policy/create/success.yml | 10 +++++ .../sell/account/payment_policy/get/success | 5 +++ .../account/payment_policy/get/success.yml | 10 +++++ .../payment_policy/get_by_name/success | 5 +++ .../payment_policy/get_by_name/success.yml | 9 ++++ .../sell/account/payment_policy/index/success | 5 +++ .../account/payment_policy/index/success.yml | 36 ++++++++++++++++ .../account/payment_policy/update/request.yml | 7 ++++ .../account/payment_policy/update/success | 5 +++ .../account/payment_policy/update/success.yml | 10 +++++ .../account/payment_policy/create_spec.rb | 42 +++++++++++++++++++ .../account/payment_policy/delete_spec.rb | 21 ++++++++++ .../payment_policy/get_by_name_spec.rb | 33 +++++++++++++++ .../sell/account/payment_policy/get_spec.rb | 31 ++++++++++++++ .../sell/account/payment_policy/index_spec.rb | 32 ++++++++++++++ .../account/payment_policy/update_spec.rb | 40 ++++++++++++++++++ 18 files changed, 313 insertions(+) create mode 100644 spec/fixtures/sell/account/payment_policy/create/request.yml create mode 100644 spec/fixtures/sell/account/payment_policy/create/success create mode 100644 spec/fixtures/sell/account/payment_policy/create/success.yml create mode 100644 spec/fixtures/sell/account/payment_policy/get/success create mode 100644 spec/fixtures/sell/account/payment_policy/get/success.yml create mode 100644 spec/fixtures/sell/account/payment_policy/get_by_name/success create mode 100644 spec/fixtures/sell/account/payment_policy/get_by_name/success.yml create mode 100644 spec/fixtures/sell/account/payment_policy/index/success create mode 100644 spec/fixtures/sell/account/payment_policy/index/success.yml create mode 100644 spec/fixtures/sell/account/payment_policy/update/request.yml create mode 100644 spec/fixtures/sell/account/payment_policy/update/success create mode 100644 spec/fixtures/sell/account/payment_policy/update/success.yml create mode 100644 spec/operations/sell/account/payment_policy/create_spec.rb create mode 100644 spec/operations/sell/account/payment_policy/delete_spec.rb create mode 100644 spec/operations/sell/account/payment_policy/get_by_name_spec.rb create mode 100644 spec/operations/sell/account/payment_policy/get_spec.rb create mode 100644 spec/operations/sell/account/payment_policy/index_spec.rb create mode 100644 spec/operations/sell/account/payment_policy/update_spec.rb diff --git a/spec/fixtures/sell/account/payment_policy/create/request.yml b/spec/fixtures/sell/account/payment_policy/create/request.yml new file mode 100644 index 0000000..9d06788 --- /dev/null +++ b/spec/fixtures/sell/account/payment_policy/create/request.yml @@ -0,0 +1,7 @@ +--- +immediatePay: false +categoryTypes: +- name: ALL_EXCLUDING_MOTORS_VEHICLES +marketplaceId: EBAY_US +paymentMethods: [] +name: Managed Payments \ No newline at end of file diff --git a/spec/fixtures/sell/account/payment_policy/create/success b/spec/fixtures/sell/account/payment_policy/create/success new file mode 100644 index 0000000..923b6cc --- /dev/null +++ b/spec/fixtures/sell/account/payment_policy/create/success @@ -0,0 +1,5 @@ +HTTP/1.1 201 Created +Content-Length: 216 +Content-Type: application/json + +{"name":"Managed Payments","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":false}],"paymentMethods":[],"immediatePay":false,"paymentPolicyId":"185091636024","warnings":[]} diff --git a/spec/fixtures/sell/account/payment_policy/create/success.yml b/spec/fixtures/sell/account/payment_policy/create/success.yml new file mode 100644 index 0000000..6ba2faa --- /dev/null +++ b/spec/fixtures/sell/account/payment_policy/create/success.yml @@ -0,0 +1,10 @@ +--- +name: Managed Payments +marketplaceId: EBAY_US +categoryTypes: +- name: ALL_EXCLUDING_MOTORS_VEHICLES + default: false +paymentMethods: [] +immediatePay: false +paymentPolicyId: "185091636024" +warnings: [] \ No newline at end of file diff --git a/spec/fixtures/sell/account/payment_policy/get/success b/spec/fixtures/sell/account/payment_policy/get/success new file mode 100644 index 0000000..24c62bb --- /dev/null +++ b/spec/fixtures/sell/account/payment_policy/get/success @@ -0,0 +1,5 @@ +HTTP/1.1 200 OK +Content-Length: 232 +Content-Type: application/json + +{"name":"Managed Payments","description":"eBay Payments","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":false}],"paymentMethods":[],"immediatePay":false,"paymentPolicyId":"184528067024"} \ No newline at end of file diff --git a/spec/fixtures/sell/account/payment_policy/get/success.yml b/spec/fixtures/sell/account/payment_policy/get/success.yml new file mode 100644 index 0000000..84097eb --- /dev/null +++ b/spec/fixtures/sell/account/payment_policy/get/success.yml @@ -0,0 +1,10 @@ +--- +name: Managed Payments +description: eBay Payments +marketplaceId: EBAY_US +categoryTypes: +- name: ALL_EXCLUDING_MOTORS_VEHICLES + default: false +paymentMethods: [] +immediatePay: false +paymentPolicyId: "184528067024" \ No newline at end of file diff --git a/spec/fixtures/sell/account/payment_policy/get_by_name/success b/spec/fixtures/sell/account/payment_policy/get_by_name/success new file mode 100644 index 0000000..a0bcfcd --- /dev/null +++ b/spec/fixtures/sell/account/payment_policy/get_by_name/success @@ -0,0 +1,5 @@ +HTTP/1.1 200 OK +Content-Length: 202 +Content-Type: application/json + +{"name":"Managed Payments","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":false}],"paymentMethods":[],"immediatePay":false,"paymentPolicyId":"185091636024"} diff --git a/spec/fixtures/sell/account/payment_policy/get_by_name/success.yml b/spec/fixtures/sell/account/payment_policy/get_by_name/success.yml new file mode 100644 index 0000000..b63dddb --- /dev/null +++ b/spec/fixtures/sell/account/payment_policy/get_by_name/success.yml @@ -0,0 +1,9 @@ +--- +name: Managed Payments +marketplaceId: EBAY_US +categoryTypes: +- name: ALL_EXCLUDING_MOTORS_VEHICLES + default: false +paymentMethods: [] +immediatePay: false +paymentPolicyId: "185091636024" \ No newline at end of file diff --git a/spec/fixtures/sell/account/payment_policy/index/success b/spec/fixtures/sell/account/payment_policy/index/success new file mode 100644 index 0000000..b346251 --- /dev/null +++ b/spec/fixtures/sell/account/payment_policy/index/success @@ -0,0 +1,5 @@ +HTTP/1.1 200 OK +Content-Length: 2010 +Content-Type: application/json + +{"total":3,"paymentPolicies":[{"name":"PayPal#1","description":"PayPal, userpaypal1@gmail.com","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":true}],"paymentMethods":[{"paymentMethodType":"PAYPAL","recipientAccountReference":{"referenceType":"PAYPAL_EMAIL","referenceId":"userpaypal1@gmail.com"}}],"immediatePay":false,"paymentPolicyId":"103323093024"},{"name":"PayPal#2","description":"PayPal, userpaypal2@gmail.com","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":false}],"paymentMethods":[{"paymentMethodType":"PAYPAL","recipientAccountReference":{"referenceType":"PAYPAL_EMAIL","referenceId":"userpaypal2@gmail.com"}}],"immediatePay":false,"paymentPolicyId":"117938331024"},{"name":"Managed Payments","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":false}],"paymentMethods":[],"immediatePay":false,"paymentPolicyId":"185091636024"}]} diff --git a/spec/fixtures/sell/account/payment_policy/index/success.yml b/spec/fixtures/sell/account/payment_policy/index/success.yml new file mode 100644 index 0000000..d5160d4 --- /dev/null +++ b/spec/fixtures/sell/account/payment_policy/index/success.yml @@ -0,0 +1,36 @@ +total: 3 +paymentPolicies: +- name: PayPal#1 + description: PayPal, userpaypal1@gmail.com + marketplaceId: EBAY_US + categoryTypes: + - name: ALL_EXCLUDING_MOTORS_VEHICLES + default: true + paymentMethods: + - paymentMethodType: PAYPAL + recipientAccountReference: + referenceType: PAYPAL_EMAIL + referenceId: userpaypal1@gmail.com + immediatePay: false + paymentPolicyId: "103323093024" +- name: PayPal#2 + description: PayPal, userpaypal2@gmail.com + marketplaceId: EBAY_US + categoryTypes: + - name: ALL_EXCLUDING_MOTORS_VEHICLES + default: false + paymentMethods: + - paymentMethodType: PAYPAL + recipientAccountReference: + referenceType: PAYPAL_EMAIL + referenceId: userpaypal2@gmail.com + immediatePay: false + paymentPolicyId: "117938331024" +- name: Managed Payments + marketplaceId: EBAY_US + categoryTypes: + - name: ALL_EXCLUDING_MOTORS_VEHICLES + default: false + paymentMethods: [] + immediatePay: false + paymentPolicyId: "185091636024" \ No newline at end of file diff --git a/spec/fixtures/sell/account/payment_policy/update/request.yml b/spec/fixtures/sell/account/payment_policy/update/request.yml new file mode 100644 index 0000000..9d06788 --- /dev/null +++ b/spec/fixtures/sell/account/payment_policy/update/request.yml @@ -0,0 +1,7 @@ +--- +immediatePay: false +categoryTypes: +- name: ALL_EXCLUDING_MOTORS_VEHICLES +marketplaceId: EBAY_US +paymentMethods: [] +name: Managed Payments \ No newline at end of file diff --git a/spec/fixtures/sell/account/payment_policy/update/success b/spec/fixtures/sell/account/payment_policy/update/success new file mode 100644 index 0000000..db79fa0 --- /dev/null +++ b/spec/fixtures/sell/account/payment_policy/update/success @@ -0,0 +1,5 @@ +HTTP/1.1 200 OK +Content-Length: 216 +Content-Type: application/json + +{"name":"Managed Payments","marketplaceId":"EBAY_US","categoryTypes":[{"name":"ALL_EXCLUDING_MOTORS_VEHICLES","default":false}],"paymentMethods":[],"immediatePay":false,"paymentPolicyId":"184528067024","warnings":[]} \ No newline at end of file diff --git a/spec/fixtures/sell/account/payment_policy/update/success.yml b/spec/fixtures/sell/account/payment_policy/update/success.yml new file mode 100644 index 0000000..e07a7fe --- /dev/null +++ b/spec/fixtures/sell/account/payment_policy/update/success.yml @@ -0,0 +1,10 @@ +--- +name: Managed Payments +marketplaceId: EBAY_US +categoryTypes: +- name: ALL_EXCLUDING_MOTORS_VEHICLES + default: false +paymentMethods: [] +immediatePay: false +paymentPolicyId: "184528067024" +warnings: [] \ No newline at end of file diff --git a/spec/operations/sell/account/payment_policy/create_spec.rb b/spec/operations/sell/account/payment_policy/create_spec.rb new file mode 100644 index 0000000..4c8b942 --- /dev/null +++ b/spec/operations/sell/account/payment_policy/create_spec.rb @@ -0,0 +1,42 @@ +HashDiff = Hashdiff + +RSpec.describe EbayAPI, ".sell.account.payment_policy.create" do + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).payment_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + + let(:url) do + "https://api.ebay.com/sell/account/v1/payment_policy/" + end + + let(:payload) do + yaml_fixture_file "sell/account/payment_policy/create/request.yml" + end + + let(:data) do + payload.reject { |key| key == "marketplaceId" } + end + + before { stub_request(:post, url).with(body: payload).to_return(response) } + subject { scope.create site: 0, data: data } + + context "success" do + let(:response) do + open_fixture_file "sell/account/payment_policy/create/success" + end + + let(:policy) do + yaml_fixture_file "sell/account/payment_policy/create/success.yml" + end + + it "sends a request" do + subject + expect(a_request(:post, url)).to have_been_made + end + + it "returns the policy" do + expect(subject).to eq policy + end + end +end diff --git a/spec/operations/sell/account/payment_policy/delete_spec.rb b/spec/operations/sell/account/payment_policy/delete_spec.rb new file mode 100644 index 0000000..55be1ec --- /dev/null +++ b/spec/operations/sell/account/payment_policy/delete_spec.rb @@ -0,0 +1,21 @@ +RSpec.describe EbayAPI, ".sell.account.payment_policy.delete" do + let(:url) { "https://api.ebay.com/sell/account/v1/payment_policy/184528067024" } + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).payment_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + + before { stub_request(:delete, url).to_return(status: 204) } + subject { scope.delete id: "184528067024" } + + context "success" do + it "sends a request" do + subject + expect(a_request(:delete, url)).to have_been_made + end + + it "returns true" do + expect(subject).to eq true + end + end +end diff --git a/spec/operations/sell/account/payment_policy/get_by_name_spec.rb b/spec/operations/sell/account/payment_policy/get_by_name_spec.rb new file mode 100644 index 0000000..3e5f422 --- /dev/null +++ b/spec/operations/sell/account/payment_policy/get_by_name_spec.rb @@ -0,0 +1,33 @@ +RSpec.describe EbayAPI, ".sell.account.payment_policy.get_by_name" do + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).payment_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + let(:url) do + "https://api.ebay.com/sell/account/v1/payment_policy/get_by_policy_name" \ + "?marketplace_id=EBAY_US&name=Managed%20Payments" + end + + before { stub_request(:get, url).to_return(response) } + subject { scope.get_by_name site: 0, name: "Managed Payments" } + + context "success" do + let(:response) do + open_fixture_file "sell/account/payment_policy/get_by_name/success" + end + + let(:policy) do + yaml_fixture_file \ + "sell/account/payment_policy/get_by_name/success.yml" + end + + it "sends a request" do + subject + expect(a_request(:get, url)).to have_been_made + end + + it "returns the policy" do + expect(subject).to eq policy + end + end +end diff --git a/spec/operations/sell/account/payment_policy/get_spec.rb b/spec/operations/sell/account/payment_policy/get_spec.rb new file mode 100644 index 0000000..c729d45 --- /dev/null +++ b/spec/operations/sell/account/payment_policy/get_spec.rb @@ -0,0 +1,31 @@ +RSpec.describe EbayAPI, ".sell.account.payment_policy.get" do + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).payment_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + let(:url) do + "https://api.ebay.com/sell/account/v1/payment_policy/184528067024" + end + + before { stub_request(:get, url).to_return(response) } + subject { scope.get id: "184528067024" } + + context "success" do + let(:response) do + open_fixture_file "sell/account/payment_policy/get/success" + end + + let(:policy) do + yaml_fixture_file "sell/account/payment_policy/get/success.yml" + end + + it "sends a request" do + subject + expect(a_request(:get, url)).to have_been_made + end + + it "returns the policy" do + expect(subject).to eq policy + end + end +end diff --git a/spec/operations/sell/account/payment_policy/index_spec.rb b/spec/operations/sell/account/payment_policy/index_spec.rb new file mode 100644 index 0000000..12ec5b5 --- /dev/null +++ b/spec/operations/sell/account/payment_policy/index_spec.rb @@ -0,0 +1,32 @@ +RSpec.describe EbayAPI, ".sell.account.payment_policy.index" do + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).payment_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + let(:url) do + "https://api.ebay.com/sell/account/v1/payment_policy/" \ + "?marketplace_id=EBAY_US" + end + + before { stub_request(:get, url).to_return(response) } + subject { scope.index } + + context "success" do + let(:response) do + open_fixture_file "sell/account/payment_policy/get/success" + end + + let(:policy) do + yaml_fixture_file "sell/account/payment_policy/get/success.yml" + end + + it "sends a request" do + subject + expect(a_request(:get, url)).to have_been_made + end + + it "returns the policy" do + expect(subject).to eq policy + end + end +end diff --git a/spec/operations/sell/account/payment_policy/update_spec.rb b/spec/operations/sell/account/payment_policy/update_spec.rb new file mode 100644 index 0000000..bed6094 --- /dev/null +++ b/spec/operations/sell/account/payment_policy/update_spec.rb @@ -0,0 +1,40 @@ +RSpec.describe EbayAPI, ".sell.account.payment_policy.update" do + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).payment_policy } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:version) { "1.2.0" } + + let(:url) do + "https://api.ebay.com/sell/account/v1/payment_policy/184528067024" + end + + let(:payload) do + yaml_fixture_file "sell/account/payment_policy/update/request.yml" + end + + let(:data) do + payload.reject { |key| key == "marketplaceId" } + end + + before { stub_request(:put, url).to_return(response) } + subject { scope.update id: "184528067024", site: 0, data: data } + + context "success" do + let(:response) do + open_fixture_file "sell/account/payment_policy/update/success" + end + + let(:policy) do + yaml_fixture_file "sell/account/payment_policy/update/success.yml" + end + + it "sends a request" do + subject + expect(a_request(:put, url)).to have_been_made + end + + it "returns the policy" do + expect(subject).to eq policy + end + end +end From aa76249899aa4a148509f83a1df8d720eed2b68b Mon Sep 17 00:00:00 2001 From: Denis Lifanov Date: Fri, 10 Dec 2021 15:12:43 +0300 Subject: [PATCH 36/51] Fix 'get_by_name' policy operation paths, fix broken specs --- .../operations/sell/account/fulfillment_policy/get_by_name.rb | 2 +- .../operations/sell/account/return_policy/get_by_name.rb | 2 +- .../sell/account/fulfillment_policy/get_by_name_spec.rb | 2 +- spec/operations/sell/account/fulfillment_policy/index_spec.rb | 2 +- spec/operations/sell/account/return_policy/get_by_name_spec.rb | 2 +- spec/operations/sell/account/return_policy/index_spec.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/ebay_api/operations/sell/account/fulfillment_policy/get_by_name.rb b/lib/ebay_api/operations/sell/account/fulfillment_policy/get_by_name.rb index 4dc0cd5..3d485bf 100644 --- a/lib/ebay_api/operations/sell/account/fulfillment_policy/get_by_name.rb +++ b/lib/ebay_api/operations/sell/account/fulfillment_policy/get_by_name.rb @@ -7,7 +7,7 @@ class EbayAPI option :site, Site option :name, proc(&:to_s) - path { "/" } + path { "/get_by_policy_name" } query { { marketplace_id: site.key, name: name } } http_method :get end diff --git a/lib/ebay_api/operations/sell/account/return_policy/get_by_name.rb b/lib/ebay_api/operations/sell/account/return_policy/get_by_name.rb index 46705a3..b7c9246 100644 --- a/lib/ebay_api/operations/sell/account/return_policy/get_by_name.rb +++ b/lib/ebay_api/operations/sell/account/return_policy/get_by_name.rb @@ -7,7 +7,7 @@ class EbayAPI option :site, Site option :name, proc(&:to_s) - path { "/" } + path { "/get_by_policy_name" } query { { marketplace_id: site.key, name: name } } http_method :get end diff --git a/spec/operations/sell/account/fulfillment_policy/get_by_name_spec.rb b/spec/operations/sell/account/fulfillment_policy/get_by_name_spec.rb index bc3b778..6d3d57b 100644 --- a/spec/operations/sell/account/fulfillment_policy/get_by_name_spec.rb +++ b/spec/operations/sell/account/fulfillment_policy/get_by_name_spec.rb @@ -4,7 +4,7 @@ let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } let(:url) do - "https://api.ebay.com/sell/account/v1/fulfillment_policy/" \ + "https://api.ebay.com/sell/account/v1/fulfillment_policy/get_by_policy_name" \ "?marketplace_id=EBAY_US&name=postcards" end diff --git a/spec/operations/sell/account/fulfillment_policy/index_spec.rb b/spec/operations/sell/account/fulfillment_policy/index_spec.rb index 5fd0398..9ffc041 100644 --- a/spec/operations/sell/account/fulfillment_policy/index_spec.rb +++ b/spec/operations/sell/account/fulfillment_policy/index_spec.rb @@ -9,7 +9,7 @@ end before { stub_request(:get, url).to_return(response) } - subject { scope.index id: "5733588000" } + subject { scope.index } context "success" do let(:response) do diff --git a/spec/operations/sell/account/return_policy/get_by_name_spec.rb b/spec/operations/sell/account/return_policy/get_by_name_spec.rb index ce5df80..b403341 100644 --- a/spec/operations/sell/account/return_policy/get_by_name_spec.rb +++ b/spec/operations/sell/account/return_policy/get_by_name_spec.rb @@ -4,7 +4,7 @@ let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } let(:url) do - "https://api.ebay.com/sell/account/v1/return_policy/" \ + "https://api.ebay.com/sell/account/v1/return_policy/get_by_policy_name" \ "?marketplace_id=EBAY_US&name=postcards" end diff --git a/spec/operations/sell/account/return_policy/index_spec.rb b/spec/operations/sell/account/return_policy/index_spec.rb index c13bdaf..95f1066 100644 --- a/spec/operations/sell/account/return_policy/index_spec.rb +++ b/spec/operations/sell/account/return_policy/index_spec.rb @@ -9,7 +9,7 @@ end before { stub_request(:get, url).to_return(response) } - subject { scope.index id: "5733588000" } + subject { scope.index } context "success" do let(:response) do From cbac0d21e92bc8b1369d29f51737a529622c6094 Mon Sep 17 00:00:00 2001 From: Denis Lifanov Date: Fri, 10 Dec 2021 15:14:57 +0300 Subject: [PATCH 37/51] Try use longMessage on some 4xx errors --- lib/ebay_api.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ebay_api.rb b/lib/ebay_api.rb index 4dde319..26afe31 100644 --- a/lib/ebay_api.rb +++ b/lib/ebay_api.rb @@ -72,12 +72,15 @@ class << self # https://developer.ebay.com/api-docs/static/handling-error-messages.html response(400, 401, 409) do |_, _, (data, *)| data = data.to_h - case (code = data.dig("errors", 0, "errorId")) + error = data.dig("errors", 0) || {} + code = error["errorId"] + message = error["longMessage"] || error["message"] + + case code when 1001 - message = data.dig("errors", 0, "longMessage") raise InvalidAccessToken.new(code: code), message else - raise Error.new(code: code, data: data), data.dig("errors", 0, "message") + raise Error.new(code: code, data: data), message end end From ab2b3e121ba921b8e9b8115cfba8ec0d20331e3f Mon Sep 17 00:00:00 2001 From: Denis Lifanov Date: Fri, 10 Dec 2021 17:06:53 +0300 Subject: [PATCH 38/51] Remove strange to_h to to_s aliases from BidPercentage model --- lib/ebay_api/models/bid_percentage.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/ebay_api/models/bid_percentage.rb b/lib/ebay_api/models/bid_percentage.rb index 4bcb9ab..c4edecc 100644 --- a/lib/ebay_api/models/bid_percentage.rb +++ b/lib/ebay_api/models/bid_percentage.rb @@ -18,7 +18,5 @@ def self.call(raw) def to_s @value end - alias to_h to_s - alias to_hash to_s end end From 5b06c6b590d5948f2966120404bedd0c55a436e4 Mon Sep 17 00:00:00 2001 From: Denis Lifanov Date: Fri, 10 Dec 2021 17:41:28 +0300 Subject: [PATCH 39/51] Bump webmock to 3.14 --- ebay_api.gemspec | 2 +- spec/operations/sell/account/payment_policy/create_spec.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/ebay_api.gemspec b/ebay_api.gemspec index 7dd518c..23a4e94 100644 --- a/ebay_api.gemspec +++ b/ebay_api.gemspec @@ -21,6 +21,6 @@ Gem::Specification.new do |gem| gem.add_development_dependency "rspec-its", "~> 1.2" gem.add_development_dependency "rubocop", "~> 0.49" gem.add_development_dependency "timecop", "~> 0.9" - gem.add_development_dependency "webmock", "~> 2.1" + gem.add_development_dependency "webmock", "~> 3.14" gem.add_development_dependency "httplog" end diff --git a/spec/operations/sell/account/payment_policy/create_spec.rb b/spec/operations/sell/account/payment_policy/create_spec.rb index 4c8b942..e334ec6 100644 --- a/spec/operations/sell/account/payment_policy/create_spec.rb +++ b/spec/operations/sell/account/payment_policy/create_spec.rb @@ -1,5 +1,3 @@ -HashDiff = Hashdiff - RSpec.describe EbayAPI, ".sell.account.payment_policy.create" do let(:client) { described_class.new(settings) } let(:scope) { client.sell.account(version: version).payment_policy } From 0abdd43ab338d5210638c1867689053f2975e385 Mon Sep 17 00:00:00 2001 From: Denis Lifanov Date: Wed, 22 Dec 2021 04:56:30 +0300 Subject: [PATCH 40/51] Bump gem version to 0.0.6 --- ebay_api.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ebay_api.gemspec b/ebay_api.gemspec index 23a4e94..1e90c5e 100644 --- a/ebay_api.gemspec +++ b/ebay_api.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |gem| gem.name = "ebay_api" - gem.version = "0.0.5" + gem.version = "0.0.6" gem.author = "Andrew Kozin (nepalez)" gem.email = "andrew.kozin@gmail.com" gem.homepage = "https://github.com/nepalez/sms_aero" From d1330c9be584b598cf0e47a238bff5ffa7635df1 Mon Sep 17 00:00:00 2001 From: Ulan Djamanbalaev Date: Wed, 25 Apr 2018 14:17:41 +0600 Subject: [PATCH 41/51] Add ability to request to product searching of CatalogAPI --- config/versions.yml | 1 + lib/ebay_api/operations/commerce.rb | 1 + lib/ebay_api/operations/commerce/catalog.rb | 12 ++++ .../commerce/catalog/product_summary.rb | 22 +++++++ .../catalog/product_summary/search.rb | 35 ++++++++++++ .../search/matched-with-keywords | 4 ++ .../product_summary/search/no-matching | 2 + .../product_summary/search/without-params | 4 ++ .../catalog/product_summary/search_spec.rb | 57 +++++++++++++++++++ 9 files changed, 138 insertions(+) create mode 100644 lib/ebay_api/operations/commerce/catalog.rb create mode 100644 lib/ebay_api/operations/commerce/catalog/product_summary.rb create mode 100644 lib/ebay_api/operations/commerce/catalog/product_summary/search.rb create mode 100644 spec/fixtures/commerce/catalog/product_summary/search/matched-with-keywords create mode 100644 spec/fixtures/commerce/catalog/product_summary/search/no-matching create mode 100644 spec/fixtures/commerce/catalog/product_summary/search/without-params create mode 100644 spec/operations/commerce/catalog/product_summary/search_spec.rb diff --git a/config/versions.yml b/config/versions.yml index af5a692..7ce488b 100644 --- a/config/versions.yml +++ b/config/versions.yml @@ -8,6 +8,7 @@ buy: commerce: taxonomy: "1.0.0" notifications: "1.0.0" + catalog: "1_beta.1.0" sell: account: "1.1.0" analytics: "1.0.0" diff --git a/lib/ebay_api/operations/commerce.rb b/lib/ebay_api/operations/commerce.rb index cd80922..4e0729a 100644 --- a/lib/ebay_api/operations/commerce.rb +++ b/lib/ebay_api/operations/commerce.rb @@ -7,6 +7,7 @@ class EbayAPI scope :commerce do path "commerce" + require_relative "commerce/catalog" require_relative "commerce/notification" require_relative "commerce/taxonomy" end diff --git a/lib/ebay_api/operations/commerce/catalog.rb b/lib/ebay_api/operations/commerce/catalog.rb new file mode 100644 index 0000000..db09390 --- /dev/null +++ b/lib/ebay_api/operations/commerce/catalog.rb @@ -0,0 +1,12 @@ +# +# Commerce Catalog API +# +class EbayAPI + scope :commerce do + scope :catalog do + path { "catalog/v#{EbayAPI::COMMERCE_CATALOG_VERSION.split(/\s|\./).first}" } + + require_relative "catalog/product_summary" + end + end +end diff --git a/lib/ebay_api/operations/commerce/catalog/product_summary.rb b/lib/ebay_api/operations/commerce/catalog/product_summary.rb new file mode 100644 index 0000000..0d11f09 --- /dev/null +++ b/lib/ebay_api/operations/commerce/catalog/product_summary.rb @@ -0,0 +1,22 @@ +require_relative "product_summary/search" + +class EbayAPI + scope :commerce do + scope :catalog do + scope :product_summary do + path "product_summary" + + response(400, 409) do |_, _, (data, *)| + code = data.dig("errors", 0, "errorId") + message = data.dig("errors", 0, "message") + case code + when 35_060 + raise EbayAPI::UserActionRequired.new(code: code), message + else + super! + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/ebay_api/operations/commerce/catalog/product_summary/search.rb b/lib/ebay_api/operations/commerce/catalog/product_summary/search.rb new file mode 100644 index 0000000..f70fb4c --- /dev/null +++ b/lib/ebay_api/operations/commerce/catalog/product_summary/search.rb @@ -0,0 +1,35 @@ +class EbayAPI + scope :commerce do + scope :catalog do + scope :product_summary do + # @see https://developer.ebay.com/api-docs/commerce/catalog/resources/product_summary/methods/search + operation :search do + http_method :get + path { :search } + + query do + { + q: keywords, + gtin: gtin, + mpn: mpn, + category_ids: category_ids, + limit: limit, + offset: offset + }.compact + end + + option :keywords, optional: true + option :gtin, optional: true + option :mpn, optional: true + option :category_ids, optional: true + option :offset, optional: true + option :limit, default: proc { 20 }, optional: true + + response(200) { |_, _, (data, *)| data } + response(204) { {} } + response(404) { {} } + end + end + end + end +end diff --git a/spec/fixtures/commerce/catalog/product_summary/search/matched-with-keywords b/spec/fixtures/commerce/catalog/product_summary/search/matched-with-keywords new file mode 100644 index 0000000..e842c1b --- /dev/null +++ b/spec/fixtures/commerce/catalog/product_summary/search/matched-with-keywords @@ -0,0 +1,4 @@ +HTTP/1.1 200 OK +Content-Type: application/json + +{"productSummaries":[{"epid":"241996593","gtin":["0888462068420"],"brand":"Apple","mpn":["MH1G2CL/A"],"image":{"imageUrl":"https://i.ebayimg.com/00/s/NjAwWDgwMA==/z/~V8AAOSwi4laZFiI/$_6.JPG?set_id=89040003C1"},"aspects":[{"localizedName":"Brand","localizedValues":["Apple"]},{"localizedName":"Hardware Connectivity","localizedValues":["Bluetooth","Wi-Fi"]},{"localizedName":"Type","localizedValues":["Tablet"]},{"localizedName":"Internet Connectivity","localizedValues":["Wi-Fi + Cellular"]},{"localizedName":"Carrier","localizedValues":["Rogers Wireless"]},{"localizedName":"Storage Capacity","localizedValues":["128GB"]},{"localizedName":"Resolution","localizedValues":["2048 x 1536"]},{"localizedName":"Screen Size","localizedValues":["9.7in."]},{"localizedName":"Processor","localizedValues":["Triple Core"]},{"localizedName":"Model","localizedValues":["Apple iPad Air 2"]},{"localizedName":"Processor Speed","localizedValues":["1.5GHz"]},{"localizedName":"RAM","localizedValues":["2GB"]},{"localizedName":"Color","localizedValues":["Gold"]},{"localizedName":"Product Information","localizedValues":["With an integrated memory of 128 GB the Apple iPad Air 2 Wi-Fi + Cellular makes storing user data and downloaded content easy. Running on iOS operating system, this Apple tablet offers a variety of handy features, as well as Wi-Fi + 4G connectivity. Additionally, this Apple iPad Air 2 weighs 0.44 kg (1 lb.) and comes in gold color with 9.7in (24.64 cm) display, ensuring convenient usage and menu navigation."]},{"localizedName":"Display Size","localizedValues":["9.7in (24.64cm)"]},{"localizedName":"Operating System","localizedValues":["iOS"]},{"localizedName":"Exterior Color","localizedValues":["Gold"]},{"localizedName":"Processor Manufacturer","localizedValues":["Apple"]},{"localizedName":"Processor Type","localizedValues":["Apple A8X"]},{"localizedName":"Display Tech","localizedValues":["Retina Display"]},{"localizedName":"Max. Video Resolution","localizedValues":["1920 x 1080"]},{"localizedName":"Touch Screen Technology","localizedValues":["Multi-Touch"]},{"localizedName":"Rear Camera Resolution","localizedValues":["8 Megapixel"]},{"localizedName":"Front Camera Resolution","localizedValues":["1.2 Channel Megapixel"]},{"localizedName":"RAM Technology","localizedValues":["LPDDR3 RAM"]},{"localizedName":"Installed RAM","localizedValues":["2 ChannelGB"]},{"localizedName":"Networking Type","localizedValues":["3G","4G","Bluetooth","Integrated Wireless LAN"]},{"localizedName":"Expansion Ports","localizedValues":["Lightning connector"]},{"localizedName":"PC Interface","localizedValues":["Bluetooth","Wi-Fi"]},{"localizedName":"Wireless capabilities","localizedValues":["Bluetooth","WLAN 802.11a","WLAN 802.11b","WLAN 802.11g","WLAN 802.11n"]},{"localizedName":"Audio Input","localizedValues":["Microphone"]},{"localizedName":"Audio Output","localizedValues":["Headphones","Speaker(s)"]},{"localizedName":"Height","localizedValues":["9.4in (24cm)"]},{"localizedName":"Width","localizedValues":["6.6in (16.95cm)"]},{"localizedName":"Depth","localizedValues":["0.24in (0.61cm)"]},{"localizedName":"Weight","localizedValues":["0.98lb. (0.44kg)"]},{"localizedName":"Battery Technology","localizedValues":["Rechargeable Lithium-Polymer"]},{"localizedName":"Battery Run Time","localizedValues":["UP to 9hr."]},{"localizedName":"Input Method","localizedValues":["Touch-Screen"]},{"localizedName":"Platform","localizedValues":["Mac","PC"]},{"localizedName":"Release Date","localizedValues":["10/16/2014"]},{"localizedName":"Security Features","localizedValues":["Finger Print Sensor","Quick Lock"]},{"localizedName":"Special Features","localizedValues":["Backlight","Bluetooth","Built-In Front Camera","Built-In Rear Camera","HD","Retina Display","Touch Screen","Web Browser"]}],"ean":["0888462068420"],"upc":["0888462068420"],"productHref":"https://api.sandbox.ebay.com/commerce/catalog/v1_beta/product/241996593","title":"Apple iPad Air 2 128GB, Wi-Fi + Cellular (Rogers Wireless), 9.7in - Gold (CA)","productWebUrl":"https://www.ebay.com/p/Apple-iPad-Air-2-128GB-Wi-Fi-Cellular-Rogers-Wireless-9-7in-Gold-CA/241996593?src=urllib"},{"epid":"241922865","gtin":["0888462535502"],"brand":"Apple","mpn":["ML2N2CL/A"],"image":{"imageUrl":"https://i.ebayimg.com/00/s/ODU0WDYxNg==/z/xsoAAOSwjytaZFi2/$_6.JPG?set_id=89040003C1"},"aspects":[{"localizedName":"Brand","localizedValues":["Apple"]},{"localizedName":"Hardware Connectivity","localizedValues":["Bluetooth","Wi-Fi"]},{"localizedName":"Type","localizedValues":["Tablet"]},{"localizedName":"Internet Connectivity","localizedValues":["Wi-Fi + Cellular"]},{"localizedName":"Carrier","localizedValues":["Telus"]},{"localizedName":"Storage Capacity","localizedValues":["256GB"]},{"localizedName":"Resolution","localizedValues":["2732 x 2048"]},{"localizedName":"Screen Size","localizedValues":["12.9in."]},{"localizedName":"Processor","localizedValues":["Dual Core"]},{"localizedName":"Model","localizedValues":["Apple iPad Pro (1st Generation)"]},{"localizedName":"Processor Speed","localizedValues":["2.26GHz"]},{"localizedName":"RAM","localizedValues":["4GB"]},{"localizedName":"Color","localizedValues":["Gold"]},{"localizedName":"Product Information","localizedValues":["Simple to use and highly portable, Apple’s iPad Pro is a powerful tablet, which impresses with the combination of efficient operation and stylish exterior. This gold tablet offers multiple connection options and its fast 2.16 GHz processor makes apps run smoothly. The large 12.9-inch Retina display with a resolution of 2732 x 2048 pixels makes images and video appear bright and crisp with fantastic contrast, while its responsiveness opens up a variety of creative possibilities. This Apple iPad Pro has 256GB of storage to effortlessly accommodate all your data. The device is available with the services of Telus and features Wi-Fi + Cellular connectivity for fast and simple Internet browsing."]},{"localizedName":"Display Size","localizedValues":["12.9in (32.77cm)"]},{"localizedName":"Operating System","localizedValues":["iOS"]},{"localizedName":"Exterior Color","localizedValues":["Gold"]},{"localizedName":"Processor Manufacturer","localizedValues":["Apple"]},{"localizedName":"Processor Type","localizedValues":["Apple A9X"]},{"localizedName":"Display Tech","localizedValues":["Retina Display"]},{"localizedName":"Max. Video Resolution","localizedValues":["1920 x 1080"]},{"localizedName":"Touch Screen Technology","localizedValues":["Multi-Touch"]},{"localizedName":"Rear Camera Resolution","localizedValues":["8 Megapixel"]},{"localizedName":"Front Camera Resolution","localizedValues":["1.2 Channel Megapixel"]},{"localizedName":"RAM Technology","localizedValues":["LPDDR4 SDRAM"]},{"localizedName":"Installed RAM","localizedValues":["4GB"]},{"localizedName":"Networking Type","localizedValues":["3G","4G","Bluetooth","Integrated Wireless LAN"]},{"localizedName":"Expansion Ports","localizedValues":["Lightning connector"]},{"localizedName":"PC Interface","localizedValues":["Bluetooth","Wi-Fi"]},{"localizedName":"Interface","localizedValues":["Camera","USB"]},{"localizedName":"Wireless capabilities","localizedValues":["Bluetooth","Built-in Wireless","WLAN 802.11a","WLAN 802.11ac","WLAN 802.11b","WLAN 802.11g","WLAN 802.11n","dual channel (2.4GHz and 5GHz) and MIMO"]},{"localizedName":"Audio Input","localizedValues":["Microphone"]},{"localizedName":"Audio Output","localizedValues":["Headphones","Speaker(s)"]},{"localizedName":"Height","localizedValues":["12in (30.57cm)"]},{"localizedName":"Width","localizedValues":["8.68in (22.06cm)"]},{"localizedName":"Depth","localizedValues":["0.27in (0.69cm)"]},{"localizedName":"Weight","localizedValues":["1.59lb. (0.72kg)"]},{"localizedName":"Battery Technology","localizedValues":["Rechargeable Lithium-Polymer"]},{"localizedName":"Battery Run Time","localizedValues":["UP to 10hr."]},{"localizedName":"Input Method","localizedValues":["Camera","Touch-Screen"]},{"localizedName":"Platform","localizedValues":["Mac","PC"]},{"localizedName":"Release Date","localizedValues":["9/9/2015"]},{"localizedName":"Security Features","localizedValues":["Quick Lock"]},{"localizedName":"Special Features","localizedValues":["Backlight","Bluetooth","Built-In Front Camera","Built-In Rear Camera","HD","Retina Display","Touch Screen","Web Browser"]}],"ean":["0888462535502"],"upc":["0888462535502"],"productHref":"https://api.sandbox.ebay.com/commerce/catalog/v1_beta/product/241922865","title":"Apple iPad Pro 256GB, Wi-Fi + Cellular (Telus), 12.9in - Gold (CA)","productWebUrl":"https://www.ebay.com/p/Apple-iPad-Pro-256GB-Wi-Fi-Cellular-Telus-12-9in-Gold-CA/241922865?src=urllib"}],"limit":10} \ No newline at end of file diff --git a/spec/fixtures/commerce/catalog/product_summary/search/no-matching b/spec/fixtures/commerce/catalog/product_summary/search/no-matching new file mode 100644 index 0000000..f6cb45b --- /dev/null +++ b/spec/fixtures/commerce/catalog/product_summary/search/no-matching @@ -0,0 +1,2 @@ +HTTP/1.1 204 OK +Content-Type: application/json diff --git a/spec/fixtures/commerce/catalog/product_summary/search/without-params b/spec/fixtures/commerce/catalog/product_summary/search/without-params new file mode 100644 index 0000000..9c43745 --- /dev/null +++ b/spec/fixtures/commerce/catalog/product_summary/search/without-params @@ -0,0 +1,4 @@ +HTTP/1.1 400 Bad Request +Content-Type: application/json + +{"errors":[{"errorId":75001,"domain":"API_CATALOG","category":"REQUEST","message":" The call must have a valid 'q', or 'category_ids' or 'gtin' or 'mpn' query parameter. "}]} diff --git a/spec/operations/commerce/catalog/product_summary/search_spec.rb b/spec/operations/commerce/catalog/product_summary/search_spec.rb new file mode 100644 index 0000000..5622e92 --- /dev/null +++ b/spec/operations/commerce/catalog/product_summary/search_spec.rb @@ -0,0 +1,57 @@ +RSpec.describe EbayAPI, ".commerce.catalog.product_summary.search" do + let(:url) do + Addressable::Template.new <<~URL.strip + https://api.ebay.com/commerce/catalog/v1_beta/product_summary/search{?params*} + URL + end + let(:client) { described_class.new(settings) } + let(:scope) { client.commerce.catalog.product_summary } + let(:settings) { yaml_fixture_file(settings_file) } + let(:version) { "1_beta.1.0" } + let(:settings_file) { "settings.valid.yml" } + let(:params) { {} } + before do + stub_request(:get, url).to_return {|request| response} + end + + subject { scope.search(**params) } + + context "success" do + context "without params" do + let(:response) { open_fixture_file("commerce/catalog/product_summary/search/without-params") } + + it do + expect { subject }.to raise_error(EbayAPI::Error) do |ex| + expect(ex.code).to eq 75_001 + expect(ex.message).to match \ + /The call must have a valid 'q'/ + end + end + end + + context "with keywords" do + let(:response) { open_fixture_file("commerce/catalog/product_summary/search/matched-with-keywords") } + let(:params) { { keywords: "ipad" } } + + it "returns list of catalog products" do + expect(subject["productSummaries"].count).to eq(2) + end + + describe "#a catalog product" do + let(:catalog_product) { subject["productSummaries"].first } + + it "has proper attributes" do + expect(catalog_product["epid"]).to eq("241996593") + expect(catalog_product["brand"]).to eq("Apple") + end + end + end + end + + context "when not found any catalog products" do + let(:response) { open_fixture_file("commerce/catalog/product_summary/search/no-matching") } + let(:params) { { keywords: "blabla" } } + + it { is_expected.to be_empty } + end +end From e694fac5bb6649ea5ff2419261103ff59222f1ec Mon Sep 17 00:00:00 2001 From: Anton Pershakov Date: Mon, 10 Oct 2022 17:11:47 +0100 Subject: [PATCH 42/51] Fix failing specs --- spec/error_handling_spec.rb | 10 +++-- spec/models/pricing_summary_spec.rb | 44 +++++++++---------- .../sell/marketing/campaigns/create_spec.rb | 8 ++-- spec/paginated_collection_spec.rb | 25 ++++++----- 4 files changed, 45 insertions(+), 42 deletions(-) diff --git a/spec/error_handling_spec.rb b/spec/error_handling_spec.rb index 4dd5566..20edfa8 100644 --- a/spec/error_handling_spec.rb +++ b/spec/error_handling_spec.rb @@ -1,9 +1,11 @@ RSpec.describe EbayAPI, "error handling" do let!(:operation) do class EbayAPI - operation :test_error_handling do - http_method :get - path "sell/marketing/v1/ad_campaign" + scope :error_handling do + operation :test_error_handling do + http_method :get + path "sell/marketing/v1/ad_campaign" + end end end end @@ -16,7 +18,7 @@ class EbayAPI stub_request(:get, uri).to_return(response) end - subject { client.test_error_handling } + subject { client.error_handling.test_error_handling } context "on eBay's internal server error" do let(:response) do diff --git a/spec/models/pricing_summary_spec.rb b/spec/models/pricing_summary_spec.rb index 2fbdb82..8e0f9eb 100644 --- a/spec/models/pricing_summary_spec.rb +++ b/spec/models/pricing_summary_spec.rb @@ -3,12 +3,12 @@ let(:source) do { - "currency" => "USD", - "price" => 49.99, - "pricingVisibility" => "PRE_CHECKOUT", - "minimumAdvertisedPrice" => 50.0, - "originallySoldForRetailPriceOn" => "ON_EBAY", - "originalRetailPrice" => 50.01 + currency: "USD", + price: 49.99, + pricingVisibility: "PRE_CHECKOUT", + minimumAdvertisedPrice: 50.0, + originallySoldForRetailPriceOn: "ON_EBAY", + originalRetailPrice: 50.01 } end @@ -30,9 +30,9 @@ context "with hash prices" do before do - source.update "price" => { "value" => "49.99", currency: "USD" }, - "originalRetailPrice" => { value: 50.01, currency: "USD" }, - "minimumAdvertisedPrice" => { value: "50", currency: "USD" } + source.update price: { value: "49.99", currency: "USD" }, + originalRetailPrice: { value: 50.01, currency: "USD" }, + minimumAdvertisedPrice: { value: "50", currency: "USD" } end it { is_expected.to eq target } @@ -40,8 +40,8 @@ context "without price" do before do - source.delete "price" target.delete :price + source.delete :price end it { is_expected.to eq target } @@ -49,8 +49,8 @@ context "without map params" do before do - source.delete "minimumAdvertisedPrice" - source.delete "pricingVisibility" + source.delete :minimumAdvertisedPrice + source.delete :pricingVisibility target.delete :minimumAdvertisedPrice target.delete :pricingVisibility end @@ -59,7 +59,7 @@ end context "with map price only" do - before { source.delete "pricingVisibility" } + before { source.delete :pricingVisibility } it "raises StandardError" do expect { subject }.to raise_error StandardError, /MAP/ @@ -67,7 +67,7 @@ end context "with map visibility only" do - before { source.delete "minimumAdvertisedPrice" } + before { source.delete :minimumAdvertisedPrice } it "raises StandardError" do expect { subject }.to raise_error StandardError, /MAP/ @@ -75,7 +75,7 @@ end context "with wrong visibility" do - before { source["pricingVisibility"] = "FOO" } + before { source[:pricingVisibility] = "FOO" } it "raises StandardError" do expect { subject }.to raise_error StandardError, /FOO/ @@ -84,8 +84,8 @@ context "without stp params" do before do - source.delete "originalRetailPrice" - source.delete "originallySoldForRetailPriceOn" + source.delete :originalRetailPrice + source.delete :originallySoldForRetailPriceOn target.delete :originallySoldForRetailPriceOn target.delete :originalRetailPrice end @@ -94,7 +94,7 @@ end context "with stp price only" do - before { source.delete "originallySoldForRetailPriceOn" } + before { source.delete :originallySoldForRetailPriceOn } it "raises StandardError" do expect { subject }.to raise_error StandardError, /STP/ @@ -102,7 +102,7 @@ end context "with stp type only" do - before { source.delete "originalRetailPrice" } + before { source.delete :originalRetailPrice } it "raises StandardError" do expect { subject }.to raise_error StandardError, /STP/ @@ -110,7 +110,7 @@ end context "with wrong stp_type" do - before { source["originallySoldForRetailPriceOn"] = "FOO" } + before { source[:originallySoldForRetailPriceOn] = "FOO" } it "raises StandardError" do expect { subject }.to raise_error StandardError, /FOO/ @@ -118,7 +118,7 @@ end context "without currency" do - before { source.delete "currency" } + before { source.delete :currency } it "raises StandardError" do expect { subject } @@ -127,7 +127,7 @@ end context "with wrong currency" do - before { source["currency"] = "FOO" } + before { source[:currency] = "FOO" } it "raises StandardError" do expect { subject }.to raise_error StandardError, /FOO/ diff --git a/spec/operations/sell/marketing/campaigns/create_spec.rb b/spec/operations/sell/marketing/campaigns/create_spec.rb index 374d305..fecbd1c 100644 --- a/spec/operations/sell/marketing/campaigns/create_spec.rb +++ b/spec/operations/sell/marketing/campaigns/create_spec.rb @@ -7,12 +7,12 @@ let(:settings_file) { "settings.valid.yml" } let(:params) do { - "campaignName" => "eBay Mag GB", + campaignName: "eBay Mag GB", fundingStrategy: { - "bidPercentage" => "5.0", - "fundingModel" => "COST_PER_SALE" + bidPercentage: "5.0", + fundingModel: "COST_PER_SALE" }, - "marketplaceId": "EBAY_GB", + marketplaceId: "EBAY_GB", startDate: Time.now.iso8601 } end diff --git a/spec/paginated_collection_spec.rb b/spec/paginated_collection_spec.rb index 8059535..a5ec018 100644 --- a/spec/paginated_collection_spec.rb +++ b/spec/paginated_collection_spec.rb @@ -4,21 +4,22 @@ require "ebay_api/paginated_collection" RSpec.describe EbayAPI::PaginatedCollection do - let!(:operation) do + let!(:new_operation) do class EbayAPI - operation :test_paginated_operation do - http_method :get - path "sell/marketing/v1/ad_campaign" + scope :paginated do + operation :test_paginated_operation do + http_method :get + path { "sell/marketing/v1/ad_campaign" } - option :limit, optional: true - option :offset, optional: true + option :limit, optional: true + option :offset, optional: true - query { { limit: limit, offset: offset }.compact } + query { { limit: limit, offset: offset }.compact } + middleware { PaginatedCollection::MiddlewareBuilder.call(max_limit: 2) } - middleware { PaginatedCollection::MiddlewareBuilder.call(max_limit: 2) } - - response(200) do |*response| - EbayAPI::PaginatedCollection.new(self, response, "campaigns") + response(200) do |*response| + EbayAPI::PaginatedCollection.new(self, response, "campaigns") + end end end end @@ -58,7 +59,7 @@ class EbayAPI let(:params) { {} } - subject { client.test_paginated_operation(**params) } + subject { client.paginated.test_paginated_operation(**params) } it "retrieves all pages" do expect(subject.to_a).to eq(Array.new(5) { |i| { "id" => i } }) From e03784f27a81dff4bf9dfa67639b60ececa9080c Mon Sep 17 00:00:00 2001 From: Anton Pershakov Date: Wed, 15 Nov 2023 14:34:19 +0000 Subject: [PATCH 43/51] Add a method that returns full response of application access token request --- lib/ebay_api/token_manager.rb | 9 +++++++-- spec/token_manager_spec.rb | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/ebay_api/token_manager.rb b/lib/ebay_api/token_manager.rb index 3ccfa4d..66a2c73 100644 --- a/lib/ebay_api/token_manager.rb +++ b/lib/ebay_api/token_manager.rb @@ -37,13 +37,18 @@ class RefreshTokenInvalid < EbayAPI::Error; end # Callback. Will be called after successful renewal with two arguments: # new access token and its expiration time - # Returns application access token + # Returns new application access token # https://apitut.com/ebay/api/oauth-application-token.html def application_token + request_application_token!["access_token"] + end + + # Requests new application access token and returns raw data + def request_application_token! request_token!( grant_type: "client_credentials", scope: "https://api.ebay.com/oauth/api_scope" - )["access_token"] + ) end # Returns access token (retrieves and returns new one if it has expired) diff --git a/spec/token_manager_spec.rb b/spec/token_manager_spec.rb index aefb080..13431dd 100644 --- a/spec/token_manager_spec.rb +++ b/spec/token_manager_spec.rb @@ -57,6 +57,25 @@ end end + describe "#request_application_token!" do + let!(:api) do + stub_request(:post, "https://api.sandbox.ebay.com/identity/v1/oauth2/token") + .with( + body: { + grant_type: "client_credentials", + scope: "https://api.ebay.com/oauth/api_scope" + }, + basic_auth: %w[1 2] + ) + .to_return(refresh_response) + end + + it "returns application token" do + expect(subject.request_application_token!).to eq(JSON.parse(refresh_response[:body])) + expect(api).to have_been_requested + end + end + describe "#access_token" do context "with valid access_token" do it "returns access_token" do From 483738c112324ab231ecec5fef076c6cf5ca6180 Mon Sep 17 00:00:00 2001 From: Anton Pershakov Date: Mon, 20 Nov 2023 16:58:04 +0000 Subject: [PATCH 44/51] Allow sending params api_context and api_name to getRateLimits endpoint of Developer Analytics API --- .../developer/analytics/rate_limit/get.rb | 7 +- .../get/api_context_and_name_response | 4 + .../rate_limit/get/api_context_response | 4 + .../rate_limit/get/api_name_response | 4 + .../analytics/rate_limit/get/no_data_response | 4 + .../rate_limit/get/no_params_response | 4 + .../analytics/rate_limit/get_spec.rb | 110 ++++++++++++++++++ 7 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/developer/analytics/rate_limit/get/api_context_and_name_response create mode 100644 spec/fixtures/developer/analytics/rate_limit/get/api_context_response create mode 100644 spec/fixtures/developer/analytics/rate_limit/get/api_name_response create mode 100644 spec/fixtures/developer/analytics/rate_limit/get/no_data_response create mode 100644 spec/fixtures/developer/analytics/rate_limit/get/no_params_response create mode 100644 spec/operations/developer/analytics/rate_limit/get_spec.rb diff --git a/lib/ebay_api/operations/developer/analytics/rate_limit/get.rb b/lib/ebay_api/operations/developer/analytics/rate_limit/get.rb index 0284666..62de6ba 100644 --- a/lib/ebay_api/operations/developer/analytics/rate_limit/get.rb +++ b/lib/ebay_api/operations/developer/analytics/rate_limit/get.rb @@ -4,8 +4,13 @@ class EbayAPI scope :rate_limit do # @see https://developer.ebay.com/api-docs/developer/analytics/resources/rate_limit/methods/getRateLimits operation :get do + option :api_context, optional: true + option :api_name, optional: true + http_method :get - path { "/" } + query do + { api_context: api_context, api_name: api_name }.compact + end response(200) do |_, _, (data, *)| data["rateLimits"] diff --git a/spec/fixtures/developer/analytics/rate_limit/get/api_context_and_name_response b/spec/fixtures/developer/analytics/rate_limit/get/api_context_and_name_response new file mode 100644 index 0000000..35827ce --- /dev/null +++ b/spec/fixtures/developer/analytics/rate_limit/get/api_context_and_name_response @@ -0,0 +1,4 @@ +HTTP/1.1 200 OK +Content-Type: application/json + +{"rateLimits":[{"apiContext":"sell","apiName":"Negotiation","apiVersion":"v1","resources":[{"name":"sell.negotiation"}]}]} diff --git a/spec/fixtures/developer/analytics/rate_limit/get/api_context_response b/spec/fixtures/developer/analytics/rate_limit/get/api_context_response new file mode 100644 index 0000000..31e8f33 --- /dev/null +++ b/spec/fixtures/developer/analytics/rate_limit/get/api_context_response @@ -0,0 +1,4 @@ +HTTP/1.1 200 OK +Content-Type: application/json + +{"rateLimits":[{"apiContext":"sell","apiName":"Negotiation","apiVersion":"v1","resources":[{"name":"sell.negotiation"}]},{"apiContext":"sell","apiName":"listingapi","apiVersion":"v1_beta","resources":[{"name":"createListingDraft"}]},{"apiContext":"sell","apiName":"logistics","apiVersion":"v1","resources":[{"name":"sell.logistics"}]},{"apiContext":"sell","apiName":"recommendation","apiVersion":"v1","resources":[{"name":"DELETE"}, {"name":"POST"}, {"name":"GET"}, {"name":"PUT"}]},{"apiContext":"sell","apiName":"research","apiVersion":"v1","resources":[{"name":"sell.research.product_insight"}]}]} diff --git a/spec/fixtures/developer/analytics/rate_limit/get/api_name_response b/spec/fixtures/developer/analytics/rate_limit/get/api_name_response new file mode 100644 index 0000000..35827ce --- /dev/null +++ b/spec/fixtures/developer/analytics/rate_limit/get/api_name_response @@ -0,0 +1,4 @@ +HTTP/1.1 200 OK +Content-Type: application/json + +{"rateLimits":[{"apiContext":"sell","apiName":"Negotiation","apiVersion":"v1","resources":[{"name":"sell.negotiation"}]}]} diff --git a/spec/fixtures/developer/analytics/rate_limit/get/no_data_response b/spec/fixtures/developer/analytics/rate_limit/get/no_data_response new file mode 100644 index 0000000..9670778 --- /dev/null +++ b/spec/fixtures/developer/analytics/rate_limit/get/no_data_response @@ -0,0 +1,4 @@ +HTTP/1.1 204 No Content +Content-Type: application/json + +{"rateLimits":[]} diff --git a/spec/fixtures/developer/analytics/rate_limit/get/no_params_response b/spec/fixtures/developer/analytics/rate_limit/get/no_params_response new file mode 100644 index 0000000..410f68c --- /dev/null +++ b/spec/fixtures/developer/analytics/rate_limit/get/no_params_response @@ -0,0 +1,4 @@ +HTTP/1.1 200 OK +Content-Type: application/json + +{"rateLimits":[{"apiContext":"buy","apiName":"Browse","apiVersion":"v1","resources":[{"name":"buy.browse"},{"name":"buy.browse.item.bulk"}]},{"apiContext":"commerce","apiName":"translation","apiVersion":"v1_beta","resources":[{"name":"commerce.translation.translate"}]},{"apiContext":"sell","apiName":"Negotiation","apiVersion":"v1","resources":[{"name":"sell.negotiation"}]},{"apiContext":"sell","apiName":"listingapi","apiVersion":"v1_beta","resources":[{"name":"createListingDraft"}]},{"apiContext":"sell","apiName":"logistics","apiVersion":"v1","resources":[{"name":"sell.logistics"}]},{"apiContext":"sell","apiName":"recommendation","apiVersion":"v1","resources":[{"name":"DELETE"},{"name":"POST"},{"name":"GET"},{"name":"PUT"}]},{"apiContext":"sell","apiName":"research","apiVersion":"v1","resources":[{"name":"sell.research.product_insight"}]}]} diff --git a/spec/operations/developer/analytics/rate_limit/get_spec.rb b/spec/operations/developer/analytics/rate_limit/get_spec.rb new file mode 100644 index 0000000..3f9ba54 --- /dev/null +++ b/spec/operations/developer/analytics/rate_limit/get_spec.rb @@ -0,0 +1,110 @@ +# frozen_string_literal: true + +RSpec.describe EbayAPI, '.developer.analytics.rate_limit.get' do + let(:client) { described_class.new(settings) } + let(:settings) { yaml_fixture_file('settings.valid.yml') } + + before { stub_request(:get, url).to_return(response) } + + shared_examples_for 'requesting corresponding data' do + it 'returns data for all APIs' do + expect(subject).to be_an(Array) + + subject.each do |api_usage_stats| + expect(api_usage_stats.keys) + .to match_array(%w[apiContext apiName apiVersion resources]) + end + + expect(subject.map { |api_usage_stats| api_usage_stats['apiContext'] }.uniq) + .to match_array(expected_api_contexts) + + expect(a_request(:get, expected_url)).to have_been_made + end + end + + context 'when api_context is passed' do + subject { client.developer.analytics.rate_limit.get(api_context: 'sell') } + + let(:url) do + 'https://api.ebay.com/developer/analytics/v1_beta/rate_limit?api_context=sell' + end + + let(:response) do + open_fixture_file 'developer/analytics/rate_limit/get/api_context_response' + end + + it_behaves_like 'requesting corresponding data' do + let(:expected_url) { url } + let(:expected_api_contexts) { %w[sell] } + end + end + + context 'when api_name is passed' do + subject { client.developer.analytics.rate_limit.get(api_name: 'Negotiation') } + + let(:url) do + 'https://api.ebay.com/developer/analytics/v1_beta/rate_limit?api_name=Negotiation' + end + + let(:response) do + open_fixture_file 'developer/analytics/rate_limit/get/api_name_response' + end + + it_behaves_like 'requesting corresponding data' do + let(:expected_url) { url } + let(:expected_api_contexts) { %w[sell] } + end + end + + context 'when both api_name and api_context are passed' do + subject { client.developer.analytics.rate_limit.get(api_context: 'sell', api_name: 'Negotiation') } + + let(:url) do + 'https://api.ebay.com/developer/analytics/v1_beta/rate_limit?api_context=sell&api_name=Negotiation' + end + + let(:response) do + open_fixture_file 'developer/analytics/rate_limit/get/api_context_and_name_response' + end + + it_behaves_like 'requesting corresponding data' do + let(:expected_url) { url } + let(:expected_api_contexts) { %w[sell] } + end + end + + context 'when no additional paras are passed' do + subject { client.developer.analytics.rate_limit.get } + + let(:url) do + 'https://api.ebay.com/developer/analytics/v1_beta/rate_limit' + end + + let(:response) do + open_fixture_file 'developer/analytics/rate_limit/get/no_params_response' + end + + it_behaves_like 'requesting corresponding data' do + let(:expected_url) { url } + let(:expected_api_contexts) { %w[buy commerce sell] } + end + end + + context 'when no data is found for the given params' do + subject { client.developer.analytics.rate_limit.get(api_context: 'random') } + + let(:url) do + 'https://api.ebay.com/developer/analytics/v1_beta/rate_limit?api_context=random' + end + + let(:response) do + open_fixture_file 'developer/analytics/rate_limit/get/no_data_response' + end + + it 'returns true' do + is_expected.to be_truthy + + expect(a_request(:get, url)).to have_been_made + end + end +end From 50747d14aabffa674396923f8c54d5dbef9bc588 Mon Sep 17 00:00:00 2001 From: Ulan Djamanbalaev Date: Thu, 20 Nov 2025 05:28:52 +0000 Subject: [PATCH 45/51] Fix Site initialization to handle hash arguments from Evil::Client::Dictionary --- lib/ebay_api/models/site.rb | 9 ++++++++ spec/models/site_spec.rb | 43 +++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/lib/ebay_api/models/site.rb b/lib/ebay_api/models/site.rb index 5f95ee8..a251b72 100644 --- a/lib/ebay_api/models/site.rb +++ b/lib/ebay_api/models/site.rb @@ -44,6 +44,15 @@ def merge(other) # Enumberable collection of the eBay marketplaces class << self + # Override new to handle hash argument from Evil::Client::Dictionary + def new(attributes = {}) + if attributes.is_a?(Hash) && !attributes.empty? + super(**attributes) + else + super + end + end + sites_file = File.join(GEM_ROOT, %w[config sites.yml]) include Evil::Client::Dictionary[sites_file] diff --git a/spec/models/site_spec.rb b/spec/models/site_spec.rb index d58c174..f9dcbfb 100644 --- a/spec/models/site_spec.rb +++ b/spec/models/site_spec.rb @@ -73,4 +73,47 @@ expect(subject).to eq "Canadian" end end + + describe ".new" do + context "when initialized with a hash argument" do + let(:hash_attrs) do + { + id: 0, + code: "EBAY-US", + country: "US", + host: "www.ebay.com", + key: "EBAY_US", + currencies: ["USD"], + languages: ["en-US"] + } + end + + it "properly initializes attributes from hash" do + site = described_class.new(hash_attrs) + expect(site.id).to eq(0) + expect(site.code).to eq("EBAY-US") + expect(site.country).to eq("US") + expect(site.host).to eq("www.ebay.com") + expect(site.key).to eq("EBAY_US") + expect(site.currencies.first.code).to eq("USD") + expect(site.languages.first).to eq("en-US") + end + end + + context "when initialized with keyword arguments" do + it "properly initializes attributes from keywords" do + site = described_class.new( + id: 0, + code: "EBAY-US", + country: "US", + host: "www.ebay.com", + key: "EBAY_US" + ) + expect(site.id).to eq(0) + expect(site.code).to eq("EBAY-US") + expect(site.country).to eq("US") + expect(site.host).to eq("www.ebay.com") + end + end + end end From 9b724d1037869bfa1502901b7907bd53007d4cef Mon Sep 17 00:00:00 2001 From: Ulan Djamanbalaev Date: Thu, 20 Nov 2025 05:31:12 +0000 Subject: [PATCH 46/51] Configure I18n load path for eBay API locale files --- lib/ebay_api.rb | 2 ++ spec/spec_helper.rb | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/ebay_api.rb b/lib/ebay_api.rb index 26afe31..3628be7 100644 --- a/lib/ebay_api.rb +++ b/lib/ebay_api.rb @@ -27,6 +27,8 @@ class EbayAPI < Evil::Client require_relative "ebay_api/middlewares" require_relative "ebay_api/exceptions" + I18n.load_path += Dir[File.join(GEM_ROOT, *%w[config locales ** *.{yml,yaml}])] + class << self attr_accessor :logger end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 44c0fcb..24d7bd9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,7 +16,3 @@ config.filter_run focus: true config.run_all_when_everything_filtered = true end - -I18n.available_locales = %i[en] -I18n.locale = :en -I18n.load_path += ["config/locales/en.yml"] From 6b6138133770a7a1f33d2e8f5ac7eb10758d6f60 Mon Sep 17 00:00:00 2001 From: Ulan Djamanbalaev Date: Thu, 4 Dec 2025 16:56:49 +0000 Subject: [PATCH 47/51] Fix site code type for Russia --- config/sites.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/sites.yml b/config/sites.yml index 638e552..4503f33 100644 --- a/config/sites.yml +++ b/config/sites.yml @@ -165,7 +165,7 @@ :key: EBAY_PL :languages: [pl-PL] - :id: 215 - :code: EBAY-US + :code: EBAY-RU :country: RU :currencies: [RUB] :host: ebay.com/sch/Russia From 765e9275a4aa2b1f9d3562d1139e85a4fcebb242 Mon Sep 17 00:00:00 2001 From: Ulan Djamanbalaev Date: Thu, 4 Dec 2025 18:04:53 +0000 Subject: [PATCH 48/51] Fix Ruby 3.0+ keyword argument issues and fix tests --- lib/ebay_api/models/amount.rb | 2 +- lib/ebay_api/paginated_collection.rb | 6 +++++- spec/error_handling_spec.rb | 2 +- .../commerce/catalog/product_summary/search_spec.rb | 2 +- .../operations/commerce/notification/public_key/get_spec.rb | 4 ++-- .../taxonomy/category_tree/fetch_item_aspects_spec.rb | 2 +- .../taxonomy/category_tree/get_category_subtree_spec.rb | 2 +- .../taxonomy/category_tree/get_category_suggestions_spec.rb | 2 +- .../category_tree/get_item_aspects_for_category_spec.rb | 2 +- spec/operations/commerce/taxonomy/category_tree/get_spec.rb | 2 +- .../commerce/taxonomy/get_default_category_tree_id_spec.rb | 2 +- spec/operations/developer/analytics/rate_limit/get_spec.rb | 2 +- .../sell/account/fulfillment_policy/create_spec.rb | 2 +- .../sell/account/fulfillment_policy/delete_spec.rb | 2 +- .../sell/account/fulfillment_policy/get_by_name_spec.rb | 2 +- spec/operations/sell/account/fulfillment_policy/get_spec.rb | 2 +- .../sell/account/fulfillment_policy/index_spec.rb | 2 +- .../sell/account/fulfillment_policy/update_spec.rb | 2 +- spec/operations/sell/account/payment_policy/create_spec.rb | 2 +- spec/operations/sell/account/payment_policy/delete_spec.rb | 2 +- .../sell/account/payment_policy/get_by_name_spec.rb | 2 +- spec/operations/sell/account/payment_policy/get_spec.rb | 2 +- spec/operations/sell/account/payment_policy/index_spec.rb | 2 +- spec/operations/sell/account/payment_policy/update_spec.rb | 2 +- spec/operations/sell/account/payments_program/get_spec.rb | 2 +- spec/operations/sell/account/privilege/get_spec.rb | 2 +- spec/operations/sell/account/program/opt_in_spec.rb | 2 +- spec/operations/sell/account/return_policy/create_spec.rb | 2 +- spec/operations/sell/account/return_policy/delete_spec.rb | 2 +- .../sell/account/return_policy/get_by_name_spec.rb | 2 +- spec/operations/sell/account/return_policy/get_spec.rb | 2 +- spec/operations/sell/account/return_policy/index_spec.rb | 2 +- spec/operations/sell/account/return_policy/update_spec.rb | 2 +- .../sell/inventory/offers/get_listing_fees_spec.rb | 2 +- .../sell/marketing/ads/bulk_create_by_listing_id_spec.rb | 2 +- .../sell/marketing/ads/bulk_delete_by_listing_id_spec.rb | 2 +- .../sell/marketing/ads/create_by_listing_id_spec.rb | 2 +- spec/operations/sell/marketing/ads/list_spec.rb | 2 +- spec/operations/sell/marketing/campaigns/create_spec.rb | 2 +- spec/paginated_collection_spec.rb | 2 +- 40 files changed, 45 insertions(+), 41 deletions(-) diff --git a/lib/ebay_api/models/amount.rb b/lib/ebay_api/models/amount.rb index 09c04a1..2c5bb9d 100644 --- a/lib/ebay_api/models/amount.rb +++ b/lib/ebay_api/models/amount.rb @@ -6,7 +6,7 @@ class Amount < Evil::Client::Model option :value, ->(v) { v.to_f.round(2) } option :currency, Currency - validate { errors.add :negative_value, to_h if value.negative? } + validate { errors.add :negative_value, **to_h if value.negative? } def to_h { value: value.to_s, currency: currency.code } diff --git a/lib/ebay_api/paginated_collection.rb b/lib/ebay_api/paginated_collection.rb index eab09a8..6e0fefb 100644 --- a/lib/ebay_api/paginated_collection.rb +++ b/lib/ebay_api/paginated_collection.rb @@ -4,6 +4,10 @@ class EbayAPI class PaginatedCollection class Request < Evil::Client::Resolver::Request + def self.call(schema, settings, **options) + new(schema, settings, **options) + end + def initialize(schema, settings, uri:, limit: nil) super(schema, settings) @uri = URI(uri) @@ -62,7 +66,7 @@ def load_next! middleware = Evil::Client::Resolver::Middleware.call(@schema, @settings) connection = @schema.client.connection stack = middleware.inject(connection) { |app, layer| layer.new app } - handle_response(*stack.call(request)) + handle_response(*stack.call(request.environment)) end def handle_response(status, _headers, (data, *)) diff --git a/spec/error_handling_spec.rb b/spec/error_handling_spec.rb index 20edfa8..732db8f 100644 --- a/spec/error_handling_spec.rb +++ b/spec/error_handling_spec.rb @@ -10,7 +10,7 @@ class EbayAPI end end - let(:client) { EbayAPI.new(yaml_fixture_file(settings_file)) } + let(:client) { EbayAPI.new(**yaml_fixture_file(settings_file)) } let(:settings_file) { "settings.valid.yml" } let!(:request) do diff --git a/spec/operations/commerce/catalog/product_summary/search_spec.rb b/spec/operations/commerce/catalog/product_summary/search_spec.rb index 5622e92..fe40d2d 100644 --- a/spec/operations/commerce/catalog/product_summary/search_spec.rb +++ b/spec/operations/commerce/catalog/product_summary/search_spec.rb @@ -4,7 +4,7 @@ https://api.ebay.com/commerce/catalog/v1_beta/product_summary/search{?params*} URL end - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.commerce.catalog.product_summary } let(:settings) { yaml_fixture_file(settings_file) } let(:version) { "1_beta.1.0" } diff --git a/spec/operations/commerce/notification/public_key/get_spec.rb b/spec/operations/commerce/notification/public_key/get_spec.rb index ab6e44a..7413110 100644 --- a/spec/operations/commerce/notification/public_key/get_spec.rb +++ b/spec/operations/commerce/notification/public_key/get_spec.rb @@ -1,5 +1,5 @@ -RSpec.describe EbayAPI, ".commerce.notifications.public_key.get" do - let(:client) { described_class.new(settings) } +RSpec.describe EbayAPI, ".commerce.notification.public_key.get" do + let(:client) { described_class.new(**settings) } let(:scope) { client.commerce.notifications.public_key } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:url) do diff --git a/spec/operations/commerce/taxonomy/category_tree/fetch_item_aspects_spec.rb b/spec/operations/commerce/taxonomy/category_tree/fetch_item_aspects_spec.rb index 0f09237..e173eda 100644 --- a/spec/operations/commerce/taxonomy/category_tree/fetch_item_aspects_spec.rb +++ b/spec/operations/commerce/taxonomy/category_tree/fetch_item_aspects_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".commerce.taxonomy.category_tree.fetch_item_aspects" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.commerce.taxonomy.category_tree(category_tree_id: 41) } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:url) do diff --git a/spec/operations/commerce/taxonomy/category_tree/get_category_subtree_spec.rb b/spec/operations/commerce/taxonomy/category_tree/get_category_subtree_spec.rb index 31fa63c..56b728c 100644 --- a/spec/operations/commerce/taxonomy/category_tree/get_category_subtree_spec.rb +++ b/spec/operations/commerce/taxonomy/category_tree/get_category_subtree_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".commerce.taxonomy.category_tree.get_category_subtree" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.commerce.taxonomy.category_tree(category_tree_id: 41) } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:url) do diff --git a/spec/operations/commerce/taxonomy/category_tree/get_category_suggestions_spec.rb b/spec/operations/commerce/taxonomy/category_tree/get_category_suggestions_spec.rb index 521afc6..b018fbd 100644 --- a/spec/operations/commerce/taxonomy/category_tree/get_category_suggestions_spec.rb +++ b/spec/operations/commerce/taxonomy/category_tree/get_category_suggestions_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".commerce.taxonomy.category_tree.get_category_suggestions" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.commerce.taxonomy.category_tree(category_tree_id: 41) } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:url) do diff --git a/spec/operations/commerce/taxonomy/category_tree/get_item_aspects_for_category_spec.rb b/spec/operations/commerce/taxonomy/category_tree/get_item_aspects_for_category_spec.rb index bc16dba..6a656e4 100644 --- a/spec/operations/commerce/taxonomy/category_tree/get_item_aspects_for_category_spec.rb +++ b/spec/operations/commerce/taxonomy/category_tree/get_item_aspects_for_category_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".commerce.taxonomy.category_tree.get_item_aspects_for_category" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.commerce.taxonomy.category_tree(category_tree_id: 41) } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:url) do diff --git a/spec/operations/commerce/taxonomy/category_tree/get_spec.rb b/spec/operations/commerce/taxonomy/category_tree/get_spec.rb index 2577cd8..f813b41 100644 --- a/spec/operations/commerce/taxonomy/category_tree/get_spec.rb +++ b/spec/operations/commerce/taxonomy/category_tree/get_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".commerce.taxonomy.category_tree.get" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.commerce.taxonomy.category_tree(category_tree_id: 41) } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:url) do diff --git a/spec/operations/commerce/taxonomy/get_default_category_tree_id_spec.rb b/spec/operations/commerce/taxonomy/get_default_category_tree_id_spec.rb index e04f262..18ccaab 100644 --- a/spec/operations/commerce/taxonomy/get_default_category_tree_id_spec.rb +++ b/spec/operations/commerce/taxonomy/get_default_category_tree_id_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".commerce.taxonomy.get_default_category_tree_id" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.commerce.taxonomy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:url) do diff --git a/spec/operations/developer/analytics/rate_limit/get_spec.rb b/spec/operations/developer/analytics/rate_limit/get_spec.rb index 3f9ba54..e0f6eeb 100644 --- a/spec/operations/developer/analytics/rate_limit/get_spec.rb +++ b/spec/operations/developer/analytics/rate_limit/get_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe EbayAPI, '.developer.analytics.rate_limit.get' do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:settings) { yaml_fixture_file('settings.valid.yml') } before { stub_request(:get, url).to_return(response) } diff --git a/spec/operations/sell/account/fulfillment_policy/create_spec.rb b/spec/operations/sell/account/fulfillment_policy/create_spec.rb index 6822b8c..1817e3c 100644 --- a/spec/operations/sell/account/fulfillment_policy/create_spec.rb +++ b/spec/operations/sell/account/fulfillment_policy/create_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".sell.account.fulfillment_policy.create" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).fulfillment_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/fulfillment_policy/delete_spec.rb b/spec/operations/sell/account/fulfillment_policy/delete_spec.rb index a085c41..55a58a4 100644 --- a/spec/operations/sell/account/fulfillment_policy/delete_spec.rb +++ b/spec/operations/sell/account/fulfillment_policy/delete_spec.rb @@ -1,6 +1,6 @@ RSpec.describe EbayAPI, ".sell.account.fulfillment_policy.delete" do let(:url) { "https://api.ebay.com/sell/account/v1/fulfillment_policy/42" } - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).fulfillment_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/fulfillment_policy/get_by_name_spec.rb b/spec/operations/sell/account/fulfillment_policy/get_by_name_spec.rb index 6d3d57b..9f703ef 100644 --- a/spec/operations/sell/account/fulfillment_policy/get_by_name_spec.rb +++ b/spec/operations/sell/account/fulfillment_policy/get_by_name_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".sell.account.fulfillment_policy.get_by_name" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).fulfillment_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/fulfillment_policy/get_spec.rb b/spec/operations/sell/account/fulfillment_policy/get_spec.rb index 8fb0a51..55c470d 100644 --- a/spec/operations/sell/account/fulfillment_policy/get_spec.rb +++ b/spec/operations/sell/account/fulfillment_policy/get_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".sell.account.fulfillment_policy.get" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).fulfillment_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/fulfillment_policy/index_spec.rb b/spec/operations/sell/account/fulfillment_policy/index_spec.rb index 9ffc041..6805b27 100644 --- a/spec/operations/sell/account/fulfillment_policy/index_spec.rb +++ b/spec/operations/sell/account/fulfillment_policy/index_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".sell.account.fulfillment_policy.index" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).fulfillment_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/fulfillment_policy/update_spec.rb b/spec/operations/sell/account/fulfillment_policy/update_spec.rb index b220786..8b78db5 100644 --- a/spec/operations/sell/account/fulfillment_policy/update_spec.rb +++ b/spec/operations/sell/account/fulfillment_policy/update_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".sell.account.fulfillment_policy.update" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).fulfillment_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/payment_policy/create_spec.rb b/spec/operations/sell/account/payment_policy/create_spec.rb index e334ec6..9bf44c0 100644 --- a/spec/operations/sell/account/payment_policy/create_spec.rb +++ b/spec/operations/sell/account/payment_policy/create_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".sell.account.payment_policy.create" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).payment_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/payment_policy/delete_spec.rb b/spec/operations/sell/account/payment_policy/delete_spec.rb index 55be1ec..72a8c0d 100644 --- a/spec/operations/sell/account/payment_policy/delete_spec.rb +++ b/spec/operations/sell/account/payment_policy/delete_spec.rb @@ -1,6 +1,6 @@ RSpec.describe EbayAPI, ".sell.account.payment_policy.delete" do let(:url) { "https://api.ebay.com/sell/account/v1/payment_policy/184528067024" } - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).payment_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/payment_policy/get_by_name_spec.rb b/spec/operations/sell/account/payment_policy/get_by_name_spec.rb index 3e5f422..46d29c3 100644 --- a/spec/operations/sell/account/payment_policy/get_by_name_spec.rb +++ b/spec/operations/sell/account/payment_policy/get_by_name_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".sell.account.payment_policy.get_by_name" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).payment_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/payment_policy/get_spec.rb b/spec/operations/sell/account/payment_policy/get_spec.rb index c729d45..2d8487d 100644 --- a/spec/operations/sell/account/payment_policy/get_spec.rb +++ b/spec/operations/sell/account/payment_policy/get_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".sell.account.payment_policy.get" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).payment_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/payment_policy/index_spec.rb b/spec/operations/sell/account/payment_policy/index_spec.rb index 12ec5b5..99d7c1f 100644 --- a/spec/operations/sell/account/payment_policy/index_spec.rb +++ b/spec/operations/sell/account/payment_policy/index_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".sell.account.payment_policy.index" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).payment_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/payment_policy/update_spec.rb b/spec/operations/sell/account/payment_policy/update_spec.rb index bed6094..5c24134 100644 --- a/spec/operations/sell/account/payment_policy/update_spec.rb +++ b/spec/operations/sell/account/payment_policy/update_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".sell.account.payment_policy.update" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).payment_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/payments_program/get_spec.rb b/spec/operations/sell/account/payments_program/get_spec.rb index fcc2d02..c974eee 100644 --- a/spec/operations/sell/account/payments_program/get_spec.rb +++ b/spec/operations/sell/account/payments_program/get_spec.rb @@ -1,6 +1,6 @@ RSpec.describe EbayAPI, ".sell.account.payments_program.get" do let(:url) { "https://api.ebay.com/sell/account/v1/payments_program/EBAY_US/EBAY_PAYMENTS" } - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).payments_program } let(:settings) { yaml_fixture_file(settings_file) } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/privilege/get_spec.rb b/spec/operations/sell/account/privilege/get_spec.rb index cb27b64..0062e1a 100644 --- a/spec/operations/sell/account/privilege/get_spec.rb +++ b/spec/operations/sell/account/privilege/get_spec.rb @@ -1,6 +1,6 @@ RSpec.describe EbayAPI, ".sell.account.privilege.get" do let(:url) { "https://api.ebay.com/sell/account/v1/privilege/" } - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).privilege } let(:settings) { yaml_fixture_file(settings_file) } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/program/opt_in_spec.rb b/spec/operations/sell/account/program/opt_in_spec.rb index c6beb0e..e4609ec 100644 --- a/spec/operations/sell/account/program/opt_in_spec.rb +++ b/spec/operations/sell/account/program/opt_in_spec.rb @@ -1,6 +1,6 @@ RSpec.describe EbayAPI, ".sell.account.program.opt_in" do let(:url) { "https://api.ebay.com/sell/account/v1/program/opt_in" } - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).program } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/return_policy/create_spec.rb b/spec/operations/sell/account/return_policy/create_spec.rb index df93a7b..ef59424 100644 --- a/spec/operations/sell/account/return_policy/create_spec.rb +++ b/spec/operations/sell/account/return_policy/create_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".sell.account.return_policy.create" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).return_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/return_policy/delete_spec.rb b/spec/operations/sell/account/return_policy/delete_spec.rb index 46d0ba4..f05e54e 100644 --- a/spec/operations/sell/account/return_policy/delete_spec.rb +++ b/spec/operations/sell/account/return_policy/delete_spec.rb @@ -1,6 +1,6 @@ RSpec.describe EbayAPI, ".sell.account.return_policy.delete" do let(:url) { "https://api.ebay.com/sell/account/v1/return_policy/42" } - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).return_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/return_policy/get_by_name_spec.rb b/spec/operations/sell/account/return_policy/get_by_name_spec.rb index b403341..44438ca 100644 --- a/spec/operations/sell/account/return_policy/get_by_name_spec.rb +++ b/spec/operations/sell/account/return_policy/get_by_name_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".sell.account.return_policy.get_by_name" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).return_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/return_policy/get_spec.rb b/spec/operations/sell/account/return_policy/get_spec.rb index bd40b52..7ab54d8 100644 --- a/spec/operations/sell/account/return_policy/get_spec.rb +++ b/spec/operations/sell/account/return_policy/get_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".sell.account.return_policy.get" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).return_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/return_policy/index_spec.rb b/spec/operations/sell/account/return_policy/index_spec.rb index 95f1066..8b2f745 100644 --- a/spec/operations/sell/account/return_policy/index_spec.rb +++ b/spec/operations/sell/account/return_policy/index_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".sell.account.return_policy.index" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).return_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/account/return_policy/update_spec.rb b/spec/operations/sell/account/return_policy/update_spec.rb index b0d4750..00f99dd 100644 --- a/spec/operations/sell/account/return_policy/update_spec.rb +++ b/spec/operations/sell/account/return_policy/update_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".sell.account.return_policy.update" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.account(version: version).return_policy } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:version) { "1.2.0" } diff --git a/spec/operations/sell/inventory/offers/get_listing_fees_spec.rb b/spec/operations/sell/inventory/offers/get_listing_fees_spec.rb index 38eb87f..453a663 100644 --- a/spec/operations/sell/inventory/offers/get_listing_fees_spec.rb +++ b/spec/operations/sell/inventory/offers/get_listing_fees_spec.rb @@ -1,5 +1,5 @@ RSpec.describe EbayAPI, ".sell.inventory.offer.get_listing_fees" do - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.inventory(version: version).offers } let(:response) { yaml_fixture_file(response_file).to_json } let(:request) { yaml_fixture_file(request_file).to_json } diff --git a/spec/operations/sell/marketing/ads/bulk_create_by_listing_id_spec.rb b/spec/operations/sell/marketing/ads/bulk_create_by_listing_id_spec.rb index 01b97b0..db16cc5 100644 --- a/spec/operations/sell/marketing/ads/bulk_create_by_listing_id_spec.rb +++ b/spec/operations/sell/marketing/ads/bulk_create_by_listing_id_spec.rb @@ -4,7 +4,7 @@ https://api.ebay.com/sell/marketing/v1/ad_campaign/1/bulk_create_ads_by_listing_id URL end - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.marketing(version: version).ads(campaign_id: 1) } let(:settings) { yaml_fixture_file(settings_file) } let(:version) { "1.1.0" } diff --git a/spec/operations/sell/marketing/ads/bulk_delete_by_listing_id_spec.rb b/spec/operations/sell/marketing/ads/bulk_delete_by_listing_id_spec.rb index 378fbc5..757ec9b 100644 --- a/spec/operations/sell/marketing/ads/bulk_delete_by_listing_id_spec.rb +++ b/spec/operations/sell/marketing/ads/bulk_delete_by_listing_id_spec.rb @@ -4,7 +4,7 @@ https://api.ebay.com/sell/marketing/v1/ad_campaign/1/bulk_delete_ads_by_listing_id URL end - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.marketing(version: version).ads(campaign_id: 1) } let(:settings) { yaml_fixture_file(settings_file) } let(:version) { "1.1.0" } diff --git a/spec/operations/sell/marketing/ads/create_by_listing_id_spec.rb b/spec/operations/sell/marketing/ads/create_by_listing_id_spec.rb index acd0fbe..ab4b7b3 100644 --- a/spec/operations/sell/marketing/ads/create_by_listing_id_spec.rb +++ b/spec/operations/sell/marketing/ads/create_by_listing_id_spec.rb @@ -1,6 +1,6 @@ RSpec.describe EbayAPI, ".sell.marketing.ads.create_by_listing_id" do let(:url) { "https://api.ebay.com/sell/marketing/v1/ad_campaign/1/ad" } - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.marketing(version: version).ads(campaign_id: 1) } let(:settings) { yaml_fixture_file(settings_file) } let(:version) { "1.1.0" } diff --git a/spec/operations/sell/marketing/ads/list_spec.rb b/spec/operations/sell/marketing/ads/list_spec.rb index 11d6be1..84a28ed 100644 --- a/spec/operations/sell/marketing/ads/list_spec.rb +++ b/spec/operations/sell/marketing/ads/list_spec.rb @@ -4,7 +4,7 @@ https://api.ebay.com/sell/marketing/v1/ad_campaign/1/ad{?params*} URL end - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.marketing(version: version).ads(campaign_id: 1) } let(:settings) { yaml_fixture_file(settings_file) } let(:version) { "1.1.0" } diff --git a/spec/operations/sell/marketing/campaigns/create_spec.rb b/spec/operations/sell/marketing/campaigns/create_spec.rb index fecbd1c..d3a7405 100644 --- a/spec/operations/sell/marketing/campaigns/create_spec.rb +++ b/spec/operations/sell/marketing/campaigns/create_spec.rb @@ -1,6 +1,6 @@ RSpec.describe EbayAPI, ".sell.marketing.campaign.create" do let(:url) { "https://api.ebay.com/sell/marketing/v1/ad_campaign" } - let(:client) { described_class.new(settings) } + let(:client) { described_class.new(**settings) } let(:scope) { client.sell.marketing(version: version).campaigns } let(:settings) { yaml_fixture_file(settings_file) } let(:version) { "1.1.0" } diff --git a/spec/paginated_collection_spec.rb b/spec/paginated_collection_spec.rb index a5ec018..5a1a5ba 100644 --- a/spec/paginated_collection_spec.rb +++ b/spec/paginated_collection_spec.rb @@ -25,7 +25,7 @@ class EbayAPI end end - let(:client) { EbayAPI.new(settings) } + let(:client) { EbayAPI.new(**settings) } let(:settings) { yaml_fixture_file(settings_file) } let(:settings_file) { "settings.valid.yml" } From 7485daafc1b2e0c8493f9d2de69d762e4f4f08ec Mon Sep 17 00:00:00 2001 From: Ulan Djamanbalaev Date: Thu, 4 Dec 2025 18:16:41 +0000 Subject: [PATCH 49/51] Add Metadata `item_condition_policies` API --- config/versions.yml | 1 + lib/ebay_api/operations/commerce.rb | 1 + lib/ebay_api/operations/commerce/metadata.rb | 13 ++++++ .../commerce/metadata/marketplace.rb | 12 +++++ .../get_item_condition_policies.rb | 12 +++++ .../get_item_condition_policies/success | 24 ++++++++++ .../get_item_condition_policies_spec.rb | 46 +++++++++++++++++++ 7 files changed, 109 insertions(+) create mode 100644 lib/ebay_api/operations/commerce/metadata.rb create mode 100644 lib/ebay_api/operations/commerce/metadata/marketplace.rb create mode 100644 lib/ebay_api/operations/commerce/metadata/marketplace/get_item_condition_policies.rb create mode 100644 spec/fixtures/commerce/metadata/marketplace/get_item_condition_policies/success create mode 100644 spec/operations/commerce/metadata/marketplace/get_item_condition_policies_spec.rb diff --git a/config/versions.yml b/config/versions.yml index 7ce488b..5d86e29 100644 --- a/config/versions.yml +++ b/config/versions.yml @@ -9,6 +9,7 @@ commerce: taxonomy: "1.0.0" notifications: "1.0.0" catalog: "1_beta.1.0" + metadata: "1.0.0" sell: account: "1.1.0" analytics: "1.0.0" diff --git a/lib/ebay_api/operations/commerce.rb b/lib/ebay_api/operations/commerce.rb index 4e0729a..e4493ca 100644 --- a/lib/ebay_api/operations/commerce.rb +++ b/lib/ebay_api/operations/commerce.rb @@ -10,5 +10,6 @@ class EbayAPI require_relative "commerce/catalog" require_relative "commerce/notification" require_relative "commerce/taxonomy" + require_relative "commerce/metadata" end end diff --git a/lib/ebay_api/operations/commerce/metadata.rb b/lib/ebay_api/operations/commerce/metadata.rb new file mode 100644 index 0000000..35e2a31 --- /dev/null +++ b/lib/ebay_api/operations/commerce/metadata.rb @@ -0,0 +1,13 @@ +# +# eBay Metadata API +# @see https://developer.ebay.com/api-docs/sell/metadata/overview.html +# +class EbayAPI + scope :commerce do + scope :metadata do + path { "catalog/v#{EbayAPI::COMMERCE_METADATA_VERSION.split(/\s|\./).first}" } + + require_relative "metadata/marketplace" + end + end +end diff --git a/lib/ebay_api/operations/commerce/metadata/marketplace.rb b/lib/ebay_api/operations/commerce/metadata/marketplace.rb new file mode 100644 index 0000000..43bf4d2 --- /dev/null +++ b/lib/ebay_api/operations/commerce/metadata/marketplace.rb @@ -0,0 +1,12 @@ +class EbayAPI + scope :commerce do + scope :metadata do + scope :marketplace do + path { "marketplace/#{marketplace_id}" } + option :marketplace_id + + require_relative "marketplace/get_item_condition_policies" + end + end + end +end diff --git a/lib/ebay_api/operations/commerce/metadata/marketplace/get_item_condition_policies.rb b/lib/ebay_api/operations/commerce/metadata/marketplace/get_item_condition_policies.rb new file mode 100644 index 0000000..074f89e --- /dev/null +++ b/lib/ebay_api/operations/commerce/metadata/marketplace/get_item_condition_policies.rb @@ -0,0 +1,12 @@ +class EbayAPI + scope :commerce do + scope :metadata do + scope :marketplace do + operation :get_item_condition_policies do + path { "get_item_condition_policies" } + http_method :get + end + end + end + end +end diff --git a/spec/fixtures/commerce/metadata/marketplace/get_item_condition_policies/success b/spec/fixtures/commerce/metadata/marketplace/get_item_condition_policies/success new file mode 100644 index 0000000..d2e8a4b --- /dev/null +++ b/spec/fixtures/commerce/metadata/marketplace/get_item_condition_policies/success @@ -0,0 +1,24 @@ +HTTP/1.1 200 OK +Content-Length: 500 +Content-Type: application/json + +{ + "itemConditionPolicies": [ + { + "categoryId": "625", + "categoryTreeId": "0", + "itemConditionRequired": true, + "itemConditions": [ + { + "conditionDescription": "Brand new, unused, and unworn", + "conditionId": "1000" + }, + { + "conditionDescription": "Pre-owned but in excellent condition", + "conditionId": "3000" + } + ] + } + ] +} + diff --git a/spec/operations/commerce/metadata/marketplace/get_item_condition_policies_spec.rb b/spec/operations/commerce/metadata/marketplace/get_item_condition_policies_spec.rb new file mode 100644 index 0000000..89d1f43 --- /dev/null +++ b/spec/operations/commerce/metadata/marketplace/get_item_condition_policies_spec.rb @@ -0,0 +1,46 @@ + +RSpec.describe EbayAPI, ".commerce.metadata.marketplace.get_item_condition_policies" do + let(:client) { described_class.new(**settings) } + let(:scope) { client.commerce.metadata.marketplace(marketplace_id: "EBAY_US") } + let(:settings) { yaml_fixture_file("settings.valid.yml") } + let(:url) do + "https://api.ebay.com/commerce/catalog/v1/marketplace/EBAY_US/get_item_condition_policies" + end + + before { stub_request(:get, url).to_return(response) } + subject { scope.get_item_condition_policies } + + context "success" do + let(:response) do + open_fixture_file "commerce/metadata/marketplace/get_item_condition_policies/success" + end + + it "sends a request" do + subject + expect(a_request(:get, url)).to have_been_made + end + + it "returns item condition policies" do + expect(subject["itemConditionPolicies"]).to be_an(Array) + expect(subject["itemConditionPolicies"].count).to eq(1) + end + + describe "item condition policy" do + let(:policy) { subject["itemConditionPolicies"].first } + + it "has proper attributes" do + expect(policy["categoryId"]).to eq("625") + expect(policy["categoryTreeId"]).to eq("0") + expect(policy["itemConditionRequired"]).to eq(true) + expect(policy["itemConditions"]).to be_an(Array) + end + + it "has item conditions with proper attributes" do + condition = policy["itemConditions"].first + expect(condition["conditionId"]).to eq("1000") + expect(condition["conditionDescription"]).to eq("Brand new, unused, and unworn") + end + end + end +end + From 94a4ad36dd1da0faa4165892d5fc62f8d9254e41 Mon Sep 17 00:00:00 2001 From: Ulan Djamanbalaev Date: Fri, 5 Dec 2025 10:22:12 +0000 Subject: [PATCH 50/51] Add a GitHub action for running tests and update the minimum supported Ruby version to 3.0 --- .github/workflows/test.yml | 39 ++++++++++++++++++++++++++++++++++++++ README.md | 1 + ebay_api.gemspec | 4 ++-- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..d16117a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,39 @@ +name: CI + +on: + push: + branches: + - '**' + pull_request: + branches: + - '**' + +jobs: + test: + name: Ruby ${{ matrix.ruby }} Tests + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + ruby: + - '3.0' + - '3.1' + - '3.2' + - '3.3' + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + + - name: Install dependencies + run: bundle install --jobs 4 --retry 3 + + - name: Run tests + run: bundle exec rake spec diff --git a/README.md b/README.md index c0be67e..ce669d3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # [WIP] EbayAPI +[![Build Status](https://github.com/main24/ebay_api/actions/workflows/test.yml/badge.svg?branch=support-catalog-product-search)](https://github.com/main24/ebay_api/actions/workflows/test.yml) Ruby client to eBay RESTful JSON API diff --git a/ebay_api.gemspec b/ebay_api.gemspec index 1e90c5e..49a3a7e 100644 --- a/ebay_api.gemspec +++ b/ebay_api.gemspec @@ -11,9 +11,9 @@ Gem::Specification.new do |gem| gem.test_files = gem.files.grep(/^spec/) gem.extra_rdoc_files = Dir["README.md", "LICENSE", "CHANGELOG.md"] - gem.required_ruby_version = ">= 2.2" + gem.required_ruby_version = ">= 3.0" - gem.add_runtime_dependency "evil-client", "~> 3.0", ">= 3.0.1" + gem.add_runtime_dependency "evil-client", "~> 3.2", ">= 3.2.0" gem.add_runtime_dependency "dry-equalizer" gem.add_development_dependency "rake", ">= 10" From 7983c675e2ccb301b60cdbd2427b6b1aa59c8099 Mon Sep 17 00:00:00 2001 From: Ulan Djamanbalaev Date: Wed, 10 Dec 2025 10:10:17 +0000 Subject: [PATCH 51/51] Fix get_item_condition_policies Metadata endpoint location --- config/versions.yml | 1 - lib/ebay_api/operations/commerce.rb | 1 - lib/ebay_api/operations/sell.rb | 1 + lib/ebay_api/operations/{commerce => sell}/metadata.rb | 4 ++-- .../{commerce => sell}/metadata/marketplace.rb | 2 +- .../metadata/marketplace/get_item_condition_policies.rb | 4 +++- .../marketplace/get_item_condition_policies/success | 0 .../marketplace/get_item_condition_policies_spec.rb | 9 ++++----- 8 files changed, 11 insertions(+), 11 deletions(-) rename lib/ebay_api/operations/{commerce => sell}/metadata.rb (65%) rename lib/ebay_api/operations/{commerce => sell}/metadata/marketplace.rb (91%) rename lib/ebay_api/operations/{commerce => sell}/metadata/marketplace/get_item_condition_policies.rb (63%) rename spec/fixtures/{commerce => sell}/metadata/marketplace/get_item_condition_policies/success (100%) rename spec/operations/{commerce => sell}/metadata/marketplace/get_item_condition_policies_spec.rb (77%) diff --git a/config/versions.yml b/config/versions.yml index 5d86e29..7ce488b 100644 --- a/config/versions.yml +++ b/config/versions.yml @@ -9,7 +9,6 @@ commerce: taxonomy: "1.0.0" notifications: "1.0.0" catalog: "1_beta.1.0" - metadata: "1.0.0" sell: account: "1.1.0" analytics: "1.0.0" diff --git a/lib/ebay_api/operations/commerce.rb b/lib/ebay_api/operations/commerce.rb index e4493ca..4e0729a 100644 --- a/lib/ebay_api/operations/commerce.rb +++ b/lib/ebay_api/operations/commerce.rb @@ -10,6 +10,5 @@ class EbayAPI require_relative "commerce/catalog" require_relative "commerce/notification" require_relative "commerce/taxonomy" - require_relative "commerce/metadata" end end diff --git a/lib/ebay_api/operations/sell.rb b/lib/ebay_api/operations/sell.rb index b4a68bf..ee8d1c7 100644 --- a/lib/ebay_api/operations/sell.rb +++ b/lib/ebay_api/operations/sell.rb @@ -8,5 +8,6 @@ class EbayAPI require_relative "sell/account" require_relative "sell/inventory" require_relative "sell/marketing" + require_relative "sell/metadata" end end diff --git a/lib/ebay_api/operations/commerce/metadata.rb b/lib/ebay_api/operations/sell/metadata.rb similarity index 65% rename from lib/ebay_api/operations/commerce/metadata.rb rename to lib/ebay_api/operations/sell/metadata.rb index 35e2a31..d5b7e86 100644 --- a/lib/ebay_api/operations/commerce/metadata.rb +++ b/lib/ebay_api/operations/sell/metadata.rb @@ -3,9 +3,9 @@ # @see https://developer.ebay.com/api-docs/sell/metadata/overview.html # class EbayAPI - scope :commerce do + scope :sell do scope :metadata do - path { "catalog/v#{EbayAPI::COMMERCE_METADATA_VERSION.split(/\s|\./).first}" } + path { "metadata/v#{EbayAPI::SELL_METADATA_VERSION.split(/\s|\./).first}" } require_relative "metadata/marketplace" end diff --git a/lib/ebay_api/operations/commerce/metadata/marketplace.rb b/lib/ebay_api/operations/sell/metadata/marketplace.rb similarity index 91% rename from lib/ebay_api/operations/commerce/metadata/marketplace.rb rename to lib/ebay_api/operations/sell/metadata/marketplace.rb index 43bf4d2..93add5f 100644 --- a/lib/ebay_api/operations/commerce/metadata/marketplace.rb +++ b/lib/ebay_api/operations/sell/metadata/marketplace.rb @@ -1,5 +1,5 @@ class EbayAPI - scope :commerce do + scope :sell do scope :metadata do scope :marketplace do path { "marketplace/#{marketplace_id}" } diff --git a/lib/ebay_api/operations/commerce/metadata/marketplace/get_item_condition_policies.rb b/lib/ebay_api/operations/sell/metadata/marketplace/get_item_condition_policies.rb similarity index 63% rename from lib/ebay_api/operations/commerce/metadata/marketplace/get_item_condition_policies.rb rename to lib/ebay_api/operations/sell/metadata/marketplace/get_item_condition_policies.rb index 074f89e..9d5c38c 100644 --- a/lib/ebay_api/operations/commerce/metadata/marketplace/get_item_condition_policies.rb +++ b/lib/ebay_api/operations/sell/metadata/marketplace/get_item_condition_policies.rb @@ -1,5 +1,7 @@ +# @see https://developer.ebay.com/api-docs/sell/metadata/resources/marketplace/methods/getItemConditionPolicies + class EbayAPI - scope :commerce do + scope :sell do scope :metadata do scope :marketplace do operation :get_item_condition_policies do diff --git a/spec/fixtures/commerce/metadata/marketplace/get_item_condition_policies/success b/spec/fixtures/sell/metadata/marketplace/get_item_condition_policies/success similarity index 100% rename from spec/fixtures/commerce/metadata/marketplace/get_item_condition_policies/success rename to spec/fixtures/sell/metadata/marketplace/get_item_condition_policies/success diff --git a/spec/operations/commerce/metadata/marketplace/get_item_condition_policies_spec.rb b/spec/operations/sell/metadata/marketplace/get_item_condition_policies_spec.rb similarity index 77% rename from spec/operations/commerce/metadata/marketplace/get_item_condition_policies_spec.rb rename to spec/operations/sell/metadata/marketplace/get_item_condition_policies_spec.rb index 89d1f43..7f125cc 100644 --- a/spec/operations/commerce/metadata/marketplace/get_item_condition_policies_spec.rb +++ b/spec/operations/sell/metadata/marketplace/get_item_condition_policies_spec.rb @@ -1,10 +1,9 @@ - -RSpec.describe EbayAPI, ".commerce.metadata.marketplace.get_item_condition_policies" do +RSpec.describe EbayAPI, ".sell.metadata.marketplace.get_item_condition_policies" do let(:client) { described_class.new(**settings) } - let(:scope) { client.commerce.metadata.marketplace(marketplace_id: "EBAY_US") } + let(:scope) { client.sell.metadata.marketplace(marketplace_id: "EBAY_US") } let(:settings) { yaml_fixture_file("settings.valid.yml") } let(:url) do - "https://api.ebay.com/commerce/catalog/v1/marketplace/EBAY_US/get_item_condition_policies" + "https://api.ebay.com/sell/metadata/v1/marketplace/EBAY_US/get_item_condition_policies" end before { stub_request(:get, url).to_return(response) } @@ -12,7 +11,7 @@ context "success" do let(:response) do - open_fixture_file "commerce/metadata/marketplace/get_item_condition_policies/success" + open_fixture_file "sell/metadata/marketplace/get_item_condition_policies/success" end it "sends a request" do