lib/ebay/browse.rb in ebay-ruby-0.3.3 vs lib/ebay/browse.rb in ebay-ruby-0.3.4

- old
+ new

@@ -3,15 +3,19 @@ require 'base64' require 'ebay/config' require 'ebay/requestable' +# Ruby wrapper to the eBay APIs module Ebay - # Using the Browse API, you can create a rich selection of items for your - # buyers to browse with keyword and category searches. It also provides the - # ability to eBay members to add items and change the quantity of an item in - # their eBay shopping cart as well as view the contents of their eBay cart. + # Returns a {Ebay::Browse#initialize Browse API} instance + def self.browse(**params) + Browse.new(**params) + end + + # The Browse API allows your buyers to search eBay items by keyword and category. It also allows them to view and add + # items to their eBay shopping cart. # # @see https://developer.ebay.com/api-docs/buy/browse/overview.html class Browse include Requestable @@ -37,21 +41,19 @@ # Returns a Browse API request instance # # @param [String] campaign_id # @param [String] reference_id # @param [String] access_token - def initialize(campaign_id:, reference_id: nil, country: nil, zip: nil, - access_token: nil) + def initialize(campaign_id:, reference_id: nil, country: nil, zip: nil, access_token: nil) @campaign_id = campaign_id @reference_id = reference_id @country = country @zip = zip @access_token = access_token end - # Searches for eBay items by various query parameters and retrieves - # summaries of the item + # Searches for eBay items by various query parameters and retrieves summaries of the item # # @param [Hash] params # @return [HTTP::Response] def search(params = {}) url = build_url('item_summary', 'search') @@ -113,12 +115,11 @@ # @param [String] marketplace_id # @return [HTTP::Response] def check_compatibility(item_id, marketplace_id, compatibility_properties) url = build_url('item', item_id, 'check_compatibility') headers = build_headers - headers.update('X-EBAY-C-MARKETPLACE-ID' => marketplace_id, - 'CONTENT-TYPE' => 'application/json') + headers.update('X-EBAY-C-MARKETPLACE-ID' => marketplace_id, 'CONTENT-TYPE' => 'application/json') body = JSON.dump('compatibilityProperties' => compatibility_properties) http.headers(headers).post(url, body: body) end @@ -150,17 +151,14 @@ end def build_ebay_enduser_context { 'affiliateCampaignId' => campaign_id, 'affiliateReferenceId' => reference_id, - 'contextualLocation' => build_contextual_location } - .compact.map { |kv| kv.join('=') }.join(',') + 'contextualLocation' => build_contextual_location }.compact.map { |kv| kv.join('=') }.join(',') end def build_contextual_location - string = { 'country' => country, 'zip' => zip } - .compact.map { |kv| kv.join('=') }.join(',') - + string = { 'country' => country, 'zip' => zip }.compact.map { |kv| kv.join('=') }.join(',') CGI.escape(string) if string end end end