-
Notifications
You must be signed in to change notification settings - Fork 56
/
shopping.rb
132 lines (117 loc) · 5.23 KB
/
shopping.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
module Rebay
class Shopping < Rebay::Api
def self.base_url_prefix
"http://open.api"
end
def self.base_url_suffix
"ebay.com/shopping"
end
VERSION = '793'
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/FindProducts.html
def find_products(params)
raise ArgumentError unless params[:categoryId] or params["ProductID.Value"] or params[:productId] or params[:queryKeywords]
response = get_json_response(build_request_url('FindProducts', params))
if response.response.has_key?('Product')
response.results = response.response['Product']
end
return response
end
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/FindHalfProducts.html
def find_half_products(params)
raise ArgumentError unless params["ProductID.Value"] or params[:productId] or params[:queryKeywords]
response = get_json_response(build_request_url('FindHalfProducts', params))
if response.response.has_key?('Products') && response.response['Products'].has_key?('Product')
response.results = response.response['Products']['Product']
end
return response
end
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetSingleItem.html
def get_single_item(params)
raise ArgumentError unless params[:itemId]
response = get_json_response(build_request_url('GetSingleItem', params))
if response.response.has_key?('Item')
response.results = response.response['Item']
end
return response
end
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetItemStatus.html
def get_item_status(params)
raise ArgumentError unless params[:itemId]
response = get_json_response(build_request_url('GetItemStatus', params))
if response.response.has_key?('Item')
response.results = response.response['Item']
end
return response
end
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetShippingCosts.html
def get_shipping_costs(params)
raise ArgumentError unless params[:itemId]
response = get_json_response(build_request_url('GetShippingCosts', params))
return response
end
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetMultipleItems.html
def get_multiple_items(params)
raise ArgumentError unless params[:itemId]
response = get_json_response(build_request_url('GetMultipleItems', params))
if response.response.has_key?('Item')
response.results = response.response['Item']
end
return response
end
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetUserProfile.html
def get_user_profile(params)
raise ArgumentError unless params[:userId]
response = get_json_response(build_request_url('GetUserProfile', params))
if response.response.has_key?('User')
response.results = response.response['User']
end
return response
end
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/FindPopularSearches.html
def find_popular_searches(params)
raise ArgumentError unless params[:categoryId]
response = get_json_response(build_request_url('FindPopularSearches', params))
if response.response.has_key?('PopularSearchResult')
response.results = response.response['PopularSearchResult']
end
return response
end
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/FindPopularItems.html
def find_popular_items(params={})
raise ArgumentError unless params[:categoryId] or params[:queryKeywords]
response = get_json_response(build_request_url('FindPopularItems', params))
if response.response.has_key?('ItemArray') && response.response['ItemArray'].has_key?('Item')
response.results = response.response['ItemArray']['Item']
end
return response
end
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/FindReviewsandGuides.html
def find_reviews_and_guides(params={})
response = get_json_response(build_request_url('FindReviewsAndGuides', params))
if response.response.has_key?('BuyingGuideDetails') && response.response['BuyingGuideDetails'].has_key?('BuyingGuide')
response.results = response.response['BuyingGuideDetails']['BuyingGuide']
end
return response
end
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetCategoryInfo.html
def get_category_info(params)
raise ArgumentError unless params[:categoryId]
response = get_json_response(build_request_url('GetCategoryInfo', params))
if response.response.has_key?('CategoryArray') && response.response['CategoryArray'].has_key?('Category')
response.results = response.response['CategoryArray']['Category']
end
return response
end
def get_category_info_with_children(params)
params[:IncludeSelector] = 'ChildCategories'
response = get_category_info(params)
return response
end
private
def build_request_url(service, params=nil)
url = "#{self.class.base_url}?callname=#{service}&appid=#{Rebay::Api.app_id}&version=#{VERSION}&responseencoding=JSON&siteid=#{Rebay::Api::EBAY_US}"
url += build_rest_payload(params)
return url
end
end
end