Class: Ebay::Browse

Inherits:
Object
  • Object
show all
Includes:
Requestable
Defined in:
lib/ebay/browse.rb

Overview

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.

Instance Attribute Summary collapse

Attributes included from Requestable

#endpoint, #headers, #http

Instance Method Summary collapse

Methods included from Requestable

#market_id=, #persistent, #sandbox, #use, #via

Constructor Details

#initialize(access_token:, campaign_id:, reference_id: nil, country: nil, zip: nil, market_id: 'EBAY_US') ⇒ Browse

Returns a Browse API request instance

Parameters:

  • access_token (String)
  • campaign_id (String)
  • reference_id (String) (defaults to: nil)
  • country (String) (defaults to: nil)
  • zip (String) (defaults to: nil)
  • market_id (String) (defaults to: 'EBAY_US')


50
51
52
53
54
55
56
57
# File 'lib/ebay/browse.rb', line 50

def initialize(access_token:, campaign_id:, reference_id: nil, country: nil, zip: nil, market_id: 'EBAY_US')
  @campaign_id = campaign_id
  @reference_id = reference_id
  @country = country
  @zip = zip
  @access_token = access_token
  @market_id = market_id
end

Instance Attribute Details

#access_tokenString (readonly)

Returns:

  • (String)


25
26
27
# File 'lib/ebay/browse.rb', line 25

def access_token
  @access_token
end

#campaign_idString (readonly)

Returns:

  • (String)


28
29
30
# File 'lib/ebay/browse.rb', line 28

def campaign_id
  @campaign_id
end

#countryString? (readonly)

Returns:

  • (String, nil)


34
35
36
# File 'lib/ebay/browse.rb', line 34

def country
  @country
end

#market_idString? (readonly)

Returns:

  • (String, nil)


40
41
42
# File 'lib/ebay/browse.rb', line 40

def market_id
  @market_id
end

#reference_idString? (readonly)

Returns:

  • (String, nil)


31
32
33
# File 'lib/ebay/browse.rb', line 31

def reference_id
  @reference_id
end

#zipString? (readonly)

Returns:

  • (String, nil)


37
38
39
# File 'lib/ebay/browse.rb', line 37

def zip
  @zip
end

Instance Method Details

#add_itemObject



131
132
133
# File 'lib/ebay/browse.rb', line 131

def add_item
  raise 'not implemented'
end

#check_compatibility(item_id, marketplace_id, compatibility_properties) ⇒ HTTP::Response

Retrieves the details of the individual items in an item group

Parameters:

  • item_id (String)
  • marketplace_id (String)

Returns:

  • (HTTP::Response)


122
123
124
125
126
127
128
129
# File 'lib/ebay/browse.rb', line 122

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')
  body = JSON.dump('compatibilityProperties' => compatibility_properties)

  http.headers(headers).post(url, body: body)
end

#get_item(item_id, params = {}) ⇒ HTTP::Response

Retrieves the details of a specific item

Parameters:

  • item_id (String)
  • params (Hash) (defaults to: {})

Returns:

  • (HTTP::Response)


87
88
89
90
91
92
# File 'lib/ebay/browse.rb', line 87

def get_item(item_id, params = {})
  url = build_url('item', item_id)
  params = params.merge(item_id: item_id)

  http.headers(build_headers).get(url, params: params)
end

#get_item_by_legacy_id(legacy_item_id, params = {}) ⇒ HTTP::Response

Retrieves the details of a specific item using its legacy item ID

Parameters:

  • legacy_item_id (String)
  • params (Hash) (defaults to: {})

Returns:

  • (HTTP::Response)


99
100
101
102
103
104
# File 'lib/ebay/browse.rb', line 99

def get_item_by_legacy_id(legacy_item_id, params = {})
  url = build_url('item', 'get_item_by_legacy_id')
  params = params.merge(legacy_item_id: legacy_item_id)

  http.headers(build_headers).get(url, params: params)
end

#get_items_by_item_group(item_group_id) ⇒ HTTP::Response

Retrieves the details of the individual items in an item group

Parameters:

  • item_group_id (String)

Returns:

  • (HTTP::Response)


110
111
112
113
114
115
# File 'lib/ebay/browse.rb', line 110

def get_items_by_item_group(item_group_id)
  url = build_url('item', 'get_items_by_item_group')
  params = { item_group_id: item_group_id }

  http.headers(build_headers).get(url, params: params)
end

#get_shopping_cartObject



135
136
137
# File 'lib/ebay/browse.rb', line 135

def get_shopping_cart
  raise 'not implemented'
end

#remove_itemObject



139
140
141
# File 'lib/ebay/browse.rb', line 139

def remove_item
  raise 'not implemented'
end

#search(params = {}) ⇒ HTTP::Response

Searches for eBay items by various query parameters and retrieves summaries of the item

Parameters:

  • params (Hash) (defaults to: {})

Returns:

  • (HTTP::Response)


63
64
65
66
# File 'lib/ebay/browse.rb', line 63

def search(params = {})
  url = build_url('item_summary', 'search')
  http.headers(build_headers).get(url, params: params)
end

#search_by_image(image, params = {}) ⇒ HTTP::Response

Searches for eBay items based on a image and retrieves their summaries

Parameters:

  • image (File)
  • params (Hash) (defaults to: {})

Returns:

  • (HTTP::Response)


73
74
75
76
77
78
79
80
# File 'lib/ebay/browse.rb', line 73

def search_by_image(image, params = {})
  url = build_url('item_summary', 'search_by_image')
  headers = build_headers.update('CONTENT-TYPE' => 'application/json')
  encoded_string = Base64.encode64(image.read)
  body = JSON.dump(image: encoded_string)

  http.headers(headers).post(url, params: params, body: body)
end

#update_quantityObject



143
144
145
# File 'lib/ebay/browse.rb', line 143

def update_quantity
  raise 'not implemented'
end