diff --git a/lib/ebay_api.rb b/lib/ebay_api.rb index 26afe31..89d361d 100644 --- a/lib/ebay_api.rb +++ b/lib/ebay_api.rb @@ -98,6 +98,6 @@ class << self code = data.dig("errors", 0, "errorId") message = data.dig("errors", 0, "longMessage") || data.dig("errors", 0, "message") - raise InternalServerError.new(code: code), message + raise InternalServerError.new(code: code, data: data), message end end diff --git a/lib/ebay_api/middlewares/log_request.rb b/lib/ebay_api/middlewares/log_request.rb index 8c7654c..63fcd62 100644 --- a/lib/ebay_api/middlewares/log_request.rb +++ b/lib/ebay_api/middlewares/log_request.rb @@ -19,7 +19,31 @@ def log_info(key, data = nil) logger.info "[EbayAPI] | #{format('%9s', key)} | #{data}" end + APIS = %w(PUT DELETE POST) + def log_api_request_log(env) + return unless APIS.include?(env["REQUEST_METHOD"]) + + Thread.current[:request_callname] = env["REQUEST_METHOD"] + Thread.current[:request_url] = env["PATH_INFO"] + Thread.current[:request_body] = env["rack.input"] + Thread.current[:request_restful] = true + rescue StandardError + nil + end + + def log_api_response_log(output) + return unless Thread.current[:request_callname] + + status, headers, body = output + Thread.current[:response_headers] = headers + Thread.current[:response_body] = body + Thread.current[:response_code] = status + rescue StandardError + nil + end + def log_request(env) + log_api_request_log(env) return unless logger log_info "REQUEST:" log_info "Url", env["PATH_INFO"] @@ -29,6 +53,7 @@ def log_request(env) end def log_response(output) + log_api_response_log(output) return unless logger status, headers, body = output log_info "RESPONSE:" @@ -37,4 +62,6 @@ def log_response(output) log_info "Body", body end end + + end diff --git a/lib/ebay_api/operations.rb b/lib/ebay_api/operations.rb index ed2095a..9e5afdf 100644 --- a/lib/ebay_api/operations.rb +++ b/lib/ebay_api/operations.rb @@ -1,3 +1,4 @@ require_relative "operations/sell" require_relative "operations/developer" require_relative "operations/commerce" +require_relative "operations/ebaymagapi" diff --git a/lib/ebay_api/operations/commerce.rb b/lib/ebay_api/operations/commerce.rb index cd80922..205eb00 100644 --- a/lib/ebay_api/operations/commerce.rb +++ b/lib/ebay_api/operations/commerce.rb @@ -9,5 +9,7 @@ class EbayAPI require_relative "commerce/notification" require_relative "commerce/taxonomy" + require_relative "commerce/translation" + require_relative "commerce/media" end end diff --git a/lib/ebay_api/operations/commerce/media.rb b/lib/ebay_api/operations/commerce/media.rb new file mode 100644 index 0000000..407d8f4 --- /dev/null +++ b/lib/ebay_api/operations/commerce/media.rb @@ -0,0 +1,14 @@ +class EbayAPI + scope :commerce do + # + # eBay Commerce Media API Overview + # + # @see https://developer.ebay.com/api-docs/commerce/media/overview.html + # + scope :media do + path { "media/v1_beta" } + + require_relative "media/document" + end + end +end diff --git a/lib/ebay_api/operations/commerce/media/document.rb b/lib/ebay_api/operations/commerce/media/document.rb new file mode 100644 index 0000000..897b637 --- /dev/null +++ b/lib/ebay_api/operations/commerce/media/document.rb @@ -0,0 +1,16 @@ +class EbayAPI + scope :commerce do + # + # eBay Commerce Media API about document + # + scope :media do + scope :document do + path { "document" } + + require_relative "document/get" + require_relative "document/create" + require_relative "document/upload" + end + end + end +end diff --git a/lib/ebay_api/operations/commerce/media/document/create.rb b/lib/ebay_api/operations/commerce/media/document/create.rb new file mode 100644 index 0000000..2010753 --- /dev/null +++ b/lib/ebay_api/operations/commerce/media/document/create.rb @@ -0,0 +1,18 @@ +class EbayAPI + scope :commerce do + scope :media do + scope :document do + # + # https://developer.ebay.com/api-docs/commerce/media/resources/document/methods/createDocument + # + operation :create do + option :data, proc(&:to_h) + + path { "/" } + http_method :post + body { data } + end + end + end + end +end diff --git a/lib/ebay_api/operations/commerce/media/document/get.rb b/lib/ebay_api/operations/commerce/media/document/get.rb new file mode 100644 index 0000000..ccd6d06 --- /dev/null +++ b/lib/ebay_api/operations/commerce/media/document/get.rb @@ -0,0 +1,17 @@ +class EbayAPI + scope :commerce do + scope :media do + scope :document do + # + # https://developer.ebay.com/api-docs/commerce/media/resources/document/methods/getDocument + # + 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/commerce/media/document/upload.rb b/lib/ebay_api/operations/commerce/media/document/upload.rb new file mode 100644 index 0000000..ff7a862 --- /dev/null +++ b/lib/ebay_api/operations/commerce/media/document/upload.rb @@ -0,0 +1,19 @@ +class EbayAPI + scope :commerce do + scope :media do + scope :document do + # + # https://developer.ebay.com/api-docs/commerce/media/resources/document/methods/uploadDocument + # + operation :upload do + option :id + option :data + + path { "#{id}/upload" } + http_method :post + body { data } + end + end + 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 index 82afabc..a669125 100644 --- a/lib/ebay_api/operations/commerce/taxonomy/category_tree.rb +++ b/lib/ebay_api/operations/commerce/taxonomy/category_tree.rb @@ -15,6 +15,7 @@ class EbayAPI require_relative "category_tree/get_category_suggestions" require_relative "category_tree/get_item_aspects_for_category" require_relative "category_tree/fetch_item_aspects" + require_relative "category_tree/get_compatibility_properties" end end end diff --git a/lib/ebay_api/operations/commerce/taxonomy/category_tree/get_compatibility_properties.rb b/lib/ebay_api/operations/commerce/taxonomy/category_tree/get_compatibility_properties.rb new file mode 100644 index 0000000..7676577 --- /dev/null +++ b/lib/ebay_api/operations/commerce/taxonomy/category_tree/get_compatibility_properties.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/getCompatibilityProperties + operation :get_compatibility_properties do + option :category_id, proc(&:to_s) + + path { "get_compatibility_properties" } + 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_compatibility_property_values.rb b/lib/ebay_api/operations/commerce/taxonomy/category_tree/get_compatibility_property_values.rb new file mode 100644 index 0000000..b909b4b --- /dev/null +++ b/lib/ebay_api/operations/commerce/taxonomy/category_tree/get_compatibility_property_values.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/getCompatibilityPropertyValues + operation :get_compatibility_property_values do + option :category_id, proc(&:to_s) + + path { "get_compatibility_property_values" } + query { { category_id: category_id } } + http_method :get + end + end + end + end +end diff --git a/lib/ebay_api/operations/commerce/translation.rb b/lib/ebay_api/operations/commerce/translation.rb new file mode 100644 index 0000000..ddec0a1 --- /dev/null +++ b/lib/ebay_api/operations/commerce/translation.rb @@ -0,0 +1,14 @@ +class EbayAPI + scope :commerce do + # + # eBay Commerce Translation API + # + # @see https://developer.ebay.com/api-docs/commerce/translation/overview.html + # + scope :translation do + path { "translation/v1_beta" } + + require_relative "translation/translate" + end + end +end diff --git a/lib/ebay_api/operations/commerce/translation/translate.rb b/lib/ebay_api/operations/commerce/translation/translate.rb new file mode 100644 index 0000000..373da71 --- /dev/null +++ b/lib/ebay_api/operations/commerce/translation/translate.rb @@ -0,0 +1,13 @@ +class EbayAPI + scope :commerce do + scope :translation do + operation :translate do + option :data, proc(&:to_h) # TODO: add model to validate input + + path { "/translate" } + http_method :post + body { data } + end + end + end +end diff --git a/lib/ebay_api/operations/ebaymagapi.rb b/lib/ebay_api/operations/ebaymagapi.rb new file mode 100644 index 0000000..15b3142 --- /dev/null +++ b/lib/ebay_api/operations/ebaymagapi.rb @@ -0,0 +1,12 @@ +class EbayAPI + # + # eBay Commerce APIs + # + # @see https://developer.ebay.com/api-docs/commerce/static/commerce-landing.html + # + scope :ebaymagapi do + path "ebaymagapi" + + require_relative "ebaymagapi/v1" + end +end diff --git a/lib/ebay_api/operations/ebaymagapi/operations/poll_message.rb b/lib/ebay_api/operations/ebaymagapi/operations/poll_message.rb new file mode 100644 index 0000000..4c5fe8b --- /dev/null +++ b/lib/ebay_api/operations/ebaymagapi/operations/poll_message.rb @@ -0,0 +1,13 @@ +class EbayAPI + scope :ebaymagapi do + scope :v1 do + operation :poll_message do + option :data, proc(&:to_h) + + path { "/poll_message" } + http_method :post + body { data } + end + end + end +end diff --git a/lib/ebay_api/operations/ebaymagapi/operations/send_batch_message.rb b/lib/ebay_api/operations/ebaymagapi/operations/send_batch_message.rb new file mode 100644 index 0000000..f97bae5 --- /dev/null +++ b/lib/ebay_api/operations/ebaymagapi/operations/send_batch_message.rb @@ -0,0 +1,17 @@ +class EbayAPI + scope :ebaymagapi do + scope :v1 do + operation :send_batch_message do + option :data do |value| + value.is_a?(Array) ? value : value.to_h + end + + path { "/send_batch_message" } + http_method :post + body { data } + end + end + end +end + + diff --git a/lib/ebay_api/operations/ebaymagapi/operations/send_message.rb b/lib/ebay_api/operations/ebaymagapi/operations/send_message.rb new file mode 100644 index 0000000..c3d6fe5 --- /dev/null +++ b/lib/ebay_api/operations/ebaymagapi/operations/send_message.rb @@ -0,0 +1,13 @@ +class EbayAPI + scope :ebaymagapi do + scope :v1 do + operation :send_message do + option :data, proc(&:to_h) + + path { "/send_message" } + http_method :post + body { data } + end + end + end +end diff --git a/lib/ebay_api/operations/ebaymagapi/v1.rb b/lib/ebay_api/operations/ebaymagapi/v1.rb new file mode 100644 index 0000000..74d52bd --- /dev/null +++ b/lib/ebay_api/operations/ebaymagapi/v1.rb @@ -0,0 +1,16 @@ +class EbayAPI + scope :ebaymagapi do + # + # eBayMsa + # + # @see + # + scope :v1 do + path { "v1" } + + require_relative "operations/send_message" + require_relative "operations/poll_message" + require_relative "operations/send_batch_message" + end + end +end diff --git a/lib/ebay_api/operations/sell.rb b/lib/ebay_api/operations/sell.rb index b4a68bf..b3434c1 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/analytics" end end diff --git a/lib/ebay_api/operations/sell/account.rb b/lib/ebay_api/operations/sell/account.rb index 10e2596..ee2200f 100644 --- a/lib/ebay_api/operations/sell/account.rb +++ b/lib/ebay_api/operations/sell/account.rb @@ -12,6 +12,7 @@ class EbayAPI require_relative "account/return_policy" require_relative "account/payment_policy" require_relative "account/payments_program" + require_relative "account/subscription" end end end diff --git a/lib/ebay_api/operations/sell/account/program.rb b/lib/ebay_api/operations/sell/account/program.rb index 0e523b2..06a9d1d 100644 --- a/lib/ebay_api/operations/sell/account/program.rb +++ b/lib/ebay_api/operations/sell/account/program.rb @@ -1,4 +1,5 @@ require_relative "program/opt_in" +require_relative "program/get" class EbayAPI scope :sell do diff --git a/lib/ebay_api/operations/sell/account/subscription.rb b/lib/ebay_api/operations/sell/account/subscription.rb new file mode 100644 index 0000000..5249123 --- /dev/null +++ b/lib/ebay_api/operations/sell/account/subscription.rb @@ -0,0 +1,11 @@ +require_relative "subscription/get" + +class EbayAPI + scope :sell do + scope :account do + scope :subscription do + path { "subscription" } + end + end + end +end diff --git a/lib/ebay_api/operations/sell/account/subscription/get.rb b/lib/ebay_api/operations/sell/account/subscription/get.rb new file mode 100644 index 0000000..f58c89c --- /dev/null +++ b/lib/ebay_api/operations/sell/account/subscription/get.rb @@ -0,0 +1,17 @@ +class EbayAPI + scope :sell do + scope :account do + scope :subscription do + # @see https://developer.ebay.com/api-docs/sell/account/resources/subscription/methods/getSubscription + operation :get do + option :limit, proc(&:to_s), optional: true + option :continuation_token, proc(&:to_s), optional: true + + path { "/" } + query { { limit: limit, continuation_token: continuation_token }.compact } + http_method :get + end + end + end + end +end diff --git a/lib/ebay_api/operations/sell/analytics.rb b/lib/ebay_api/operations/sell/analytics.rb new file mode 100644 index 0000000..5451ef0 --- /dev/null +++ b/lib/ebay_api/operations/sell/analytics.rb @@ -0,0 +1,13 @@ +# +# findSellerStandardsProfiles +# https://developer.ebay.com/api-docs/sell/analytics/resources/seller_standards_profile/methods/findSellerStandardsProfiles +# +class EbayAPI + scope :sell do + scope :analytics do + path { "analytics/v#{EbayAPI::SELL_INVENTORY_VERSION[/^\d+/]}" } + + require_relative "analytics/seller_standards_profile" + end + end +end diff --git a/lib/ebay_api/operations/sell/analytics/seller_standards_profile.rb b/lib/ebay_api/operations/sell/analytics/seller_standards_profile.rb new file mode 100644 index 0000000..82f577e --- /dev/null +++ b/lib/ebay_api/operations/sell/analytics/seller_standards_profile.rb @@ -0,0 +1,16 @@ +# +# findSellerStandardsProfiles +# +class EbayAPI + scope :sell do + scope :analytics do + scope :seller_standards_profile do + path "seller_standards_profile" + + operation :get do + http_method :get + end + end + end + end +end diff --git a/spec/fixtures/sell/account/subscription/get/bad_request b/spec/fixtures/sell/account/subscription/get/bad_request new file mode 100644 index 0000000..79b9c09 --- /dev/null +++ b/spec/fixtures/sell/account/subscription/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/subscription/get/server_error b/spec/fixtures/sell/account/subscription/get/server_error new file mode 100644 index 0000000..9420ebf --- /dev/null +++ b/spec/fixtures/sell/account/subscription/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/subscription/get/success b/spec/fixtures/sell/account/subscription/get/success new file mode 100644 index 0000000..c7168c2 --- /dev/null +++ b/spec/fixtures/sell/account/subscription/get/success @@ -0,0 +1,5 @@ +HTTP/1.1 200 OK +Content-Length: 232 +Content-Type: application/json + +{"total":1,"subscriptions":[{"marketplaceId":"EBAY_US","subscriptionId":"4********1","subscriptionLevel":"Featured","subscriptionType":"STORE_PLAN","term":{"value":12,"unit":"MONTH"},"limit":10,"continuation_token":"some_token"}]} diff --git a/spec/fixtures/sell/account/subscription/get/success.yml b/spec/fixtures/sell/account/subscription/get/success.yml new file mode 100644 index 0000000..2dffff0 --- /dev/null +++ b/spec/fixtures/sell/account/subscription/get/success.yml @@ -0,0 +1,12 @@ +--- +total: 1 +subscriptions: + - marketplaceId: EBAY_US + subscriptionId: 4********1 + subscriptionLevel: Featured + subscriptionType: STORE_PLAN + term: + value: 12 + unit: MONTH + limit: 10 + continuation_token: some_token diff --git a/spec/operations/sell/account/subscription/get_spec.rb b/spec/operations/sell/account/subscription/get_spec.rb new file mode 100644 index 0000000..d419482 --- /dev/null +++ b/spec/operations/sell/account/subscription/get_spec.rb @@ -0,0 +1,56 @@ +RSpec.describe EbayAPI, ".sell.account.subscription.get" do + let(:client) { described_class.new(settings) } + let(:scope) { client.sell.account(version: version).subscription } + let(:settings) { yaml_fixture_file(settings_file) } + let(:version) { "1.2.0" } + let(:settings_file) { "settings.valid.yml" } + let(:url) do + "https://api.ebay.com/sell/account/v1/subscription/" \ + "?limit=10&continuation_token=some_token" + end + + before { stub_request(:get, url).to_return(response) } + subject { scope.get limit: 10, continuation_token: "some_token" } + + context "success" do + let(:response) do + open_fixture_file "sell/account/subscription/get/success" + end + + let(:policy) do + yaml_fixture_file \ + "sell/account/subscription/get/success.yml" + end + + it "returns just parsed JSON with data about subscription" do + expect(subject).to eq(policy) + end + end + + context "bad request" do + let(:response) do + open_fixture_file "sell/account/subscription/get/bad_request" + end + + it "raises an exception" do + expect { subject }.to raise_error EbayAPI::Error + end + + it "carries error message" do + subject + rescue => err + expect(err.code).to eq 1002 + expect(err.data).not_to be_empty + end + end + + context "server error" do + let(:response) do + open_fixture_file "sell/account/subscription/get/server_error" + end + + it "raises an exception" do + expect { subject }.to raise_error EbayAPI::Error + end + end +end