rebay 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2010 Chuck Collins
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+ rebay
2
+ ========
3
+ Rebay is a very simple wrapper for the ebay finding and shopping APIs. Please see the ebay documentation for the proper input arguments and expected output.
4
+
5
+ [Ebay Shopping Api Documentation](http://developer.ebay.com/products/shopping/)
6
+
7
+ [Ebay Finding Api Documentation](http://developer.ebay.com/products/finding/)
8
+
9
+ Configuration
10
+ -------------
11
+ Create and require a config.rb, or if using rails create an initializer (rebay.rb perhaps), and place the following code into it:
12
+
13
+ Rebay::Api.configure do |rebay|
14
+ rebay.app_id = 'YOUR APPLICATION ID HERE'
15
+ end
16
+
17
+
18
+ Use
19
+ ---
20
+ If you have questions about optional/required parameters, please check the ebay api docs. The source of this api wrapper also includes links to specific api call documentation. Basically, pass whatever options into the rebay api call and they will be passed through into the actual api call. When getting your return response, the json from ebay is transformed just a bit. You can still expect the same keys to come through in the hash, they just aren't annoyingly wrapped in an array... everywhere.
21
+
22
+
23
+ Example
24
+ -------
25
+ To get search keyword recommendations for *acordian*:
26
+
27
+ finder = Rebay::Finding.new
28
+ response = finder.get_search_keywords_recommendation({:keywords => 'acordian'})
29
+
30
+ Ebay will return an array filled result something like this:
31
+
32
+ {"getSearchKeywordsRecommendationResponse": [{"ack": ["Success"],"version": ["1.5.0"],"timestamp": ["2010-08-13T21:11:02.539Z"],"keywords": ["accordion"]}]}
33
+
34
+ For my own sanity, I transform this response into a more standard ruby hash and in the case of the finding api responses, I removed the XXXResponse key and use the resulting hash as the response (to be inline with the shopping api responses).
35
+
36
+ {"ack" => "Success", "version" => "1.5.0", "timestamp" => "2010-08-13T21:11:02.539Z", "keywords" => "accordion"}
37
+
38
+ You can check for success or failure of the request:
39
+ response.success?
40
+ response.failure?
41
+
42
+ MIT License
43
+ -----------
44
+ Copyright (c) 2010 Chuck Collins
45
+
46
+ Permission is hereby granted, free of charge, to any person obtaining a copy
47
+ of this software and associated documentation files (the "Software"), to deal
48
+ in the Software without restriction, including without limitation the rights
49
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
50
+ copies of the Software, and to permit persons to whom the Software is
51
+ furnished to do so, subject to the following conditions:
52
+
53
+ The above copyright notice and this permission notice shall be included in
54
+ all copies or substantial portions of the Software.
55
+
56
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
57
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
58
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
59
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
60
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
61
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
62
+ THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ require "rake"
2
+
3
+ begin
4
+ require "jeweler"
5
+ Jeweler::Tasks.new do |gem|
6
+ gem.name = "rebay"
7
+ gem.summary = "Client for the RESTful JSON ebay finding and shopping api"
8
+ gem.email = "chuck.collins@gmail.com"
9
+ gem.homepage = "http://github.com/ccollins/rebay"
10
+ gem.authors = ["Chuck Collins"]
11
+ gem.files = Dir["*", "{lib}/**/*"]
12
+ gem.add_dependency("json")
13
+ end
14
+
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.2
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), "lib", "rebay")
@@ -0,0 +1,8 @@
1
+ require 'rebay/api'
2
+ require 'rebay/finding'
3
+ require 'rebay/shopping'
4
+ require 'rebay/response'
5
+
6
+ module Rebay
7
+ require 'rebay/railtie' if defined?(Rails) && Rails::VERSION::MAJOR == 3
8
+ end
@@ -0,0 +1,36 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ module Rebay
6
+ class Api
7
+ EBAY_US = 0
8
+
9
+ def self.app_id= app_id
10
+ @@app_id = app_id
11
+ end
12
+
13
+ def self.app_id
14
+ @@app_id
15
+ end
16
+
17
+ def self.configure
18
+ yield self if block_given?
19
+ end
20
+
21
+ protected
22
+ def get_json_response(url)
23
+ Rebay::Response.new(JSON.parse(Net::HTTP.get_response(URI.parse(url)).body))
24
+ end
25
+
26
+ def build_rest_payload(params)
27
+ payload = ''
28
+ unless params.nil?
29
+ params.keys.each do |key|
30
+ payload += URI.escape "&#{key}=#{params[key]}"
31
+ end
32
+ end
33
+ return payload
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,75 @@
1
+ module Rebay
2
+ class Finding < Rebay::Api
3
+ BASE_URL = 'http://svcs.ebay.com/services/search/FindingService/v1'
4
+ VERSION = '1.0.0'
5
+
6
+ #http://developer.ebay.com/DevZone/finding/CallRef/findItemsAdvanced.html
7
+ def find_items_advanced(params)
8
+ raise ArgumentError unless params[:keywords] or params[:categoryId]
9
+ response = get_json_response(build_request_url('findItemsAdvanced', params))
10
+ response.trim(:findItemsAdvancedResponse)
11
+ return response
12
+ end
13
+
14
+ #http://developer.ebay.com/DevZone/finding/CallRef/findItemsByCategory.html
15
+ def find_items_by_category(params)
16
+ raise ArgumentError unless params[:categoryId]
17
+ response = get_json_response(build_request_url('findItemsByCategory', params))
18
+ response.trim(:findItemsByCategoryResponse)
19
+ return response
20
+ end
21
+
22
+ #http://developer.ebay.com/DevZone/finding/CallRef/findItemsByKeywords.html
23
+ def find_items_by_keywords(params)
24
+ raise ArgumentError unless params[:keywords]
25
+ response = get_json_response(build_request_url('findItemsByKeywords', params))
26
+ response.trim(:findItemsByKeywordsResponse)
27
+ return response
28
+ end
29
+
30
+ #http://developer.ebay.com/DevZone/finding/CallRef/findItemsByProduct.html
31
+ def find_items_by_product(params)
32
+ raise ArgumentError unless params[:productId]
33
+ params['productId.@type'] = 'ReferenceID'
34
+ response = get_json_response(build_request_url('findItemsByProduct', params))
35
+ response.trim(:findItemsByProductResponse)
36
+ return response
37
+ end
38
+
39
+ #http://developer.ebay.com/DevZone/finding/CallRef/findItemsIneBayStores.html
40
+ def find_items_in_ebay_stores(params)
41
+ raise ArgumentError unless params[:keywords] or params[:storeName]
42
+ response = get_json_response(build_request_url('findItemsIneBayStores', params))
43
+ response.trim(:findItemsIneBayStoresResponse)
44
+ return response
45
+ end
46
+
47
+ #http://developer.ebay.com/DevZone/finding/CallRef/getHistograms.html
48
+ def get_histograms(params)
49
+ raise ArgumentError unless params[:categoryId]
50
+ response = get_json_response(build_request_url('getHistograms', params))
51
+ response.trim(:getHistorgramsResponse)
52
+ return response
53
+ end
54
+
55
+ #http://developer.ebay.com/DevZone/finding/CallRef/getSearchKeywordsRecommendation.html
56
+ def get_search_keywords_recommendation(params)
57
+ raise ArgumentError unless params[:keywords]
58
+ response = get_json_response(build_request_url('getSearchKeywordsRecommendation', params))
59
+ response.trim(:getSearchKeywordsRecommendationResponse)
60
+ return response
61
+ end
62
+
63
+ #http://developer.ebay.com/DevZone/finding/CallRef/getVersion.html
64
+ def get_version
65
+ response = get_json_response(build_request_url('getVersion'))
66
+ end
67
+
68
+ private
69
+ def build_request_url(service, params=nil)
70
+ url = "#{BASE_URL}?OPERATION-NAME=#{service}&SERVICE-VERSION=#{VERSION}&SECURITY-APPNAME=#{Rebay::Api.app_id}&RESPONSE-DATA-FORMAT=JSON&REST-PAYLOAD"
71
+ url += build_rest_payload(params)
72
+ return url
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,8 @@
1
+ require 'rebay'
2
+ require 'rails'
3
+
4
+ module Rebay
5
+ class Railtie < Rails::Railtie
6
+ railtie_name :rebay
7
+ end
8
+ end
@@ -0,0 +1,38 @@
1
+ module Rebay
2
+ class Response
3
+ attr_accessor :response
4
+
5
+ def initialize(json_response)
6
+ @response = transform_json_response(json_response)
7
+ end
8
+
9
+ def success?
10
+ return @response["Ack"] == 'Success'
11
+ end
12
+
13
+ def failure?
14
+ return @response["Ack"] == 'Failure'
15
+ end
16
+
17
+ def trim(key)
18
+ if @response.has_key?(key)
19
+ @response = @response[key]
20
+ end
21
+ end
22
+
23
+ protected
24
+ def transform_json_response(response)
25
+ if response.class == Hash
26
+ r = Hash.new
27
+ response.keys.each do |k|
28
+ r[k] = transform_json_response(response[k])
29
+ end
30
+ return r
31
+ elsif response.class == Array and response.size == 1
32
+ return transform_json_response(response[0])
33
+ else
34
+ return response
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,83 @@
1
+ module Rebay
2
+ class Shopping < Rebay::Api
3
+ BASE_URL = 'http://open.api.ebay.com/shopping'
4
+ VERSION = '677'
5
+
6
+ #http://developer.ebay.com/DevZone/shopping/docs/CallRef/FindProducts.html
7
+ def find_products(params)
8
+ raise ArgumentError unless params[:categoryId] or params[:productId] or params[:queryKeywords]
9
+ get_json_response(build_request_url('FindProducts', params))
10
+ end
11
+
12
+ #http://developer.ebay.com/DevZone/shopping/docs/CallRef/FindHalfProducts.html
13
+ def find_half_products(params)
14
+ raise ArgumentError unless params[:productId] or params[:queryKeywords]
15
+ get_json_response(build_request_url('FindHalfProducts', params))
16
+ end
17
+
18
+ #http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetSingleItem.html
19
+ def get_single_item(params)
20
+ raise ArgumentError unless params[:itemId]
21
+ get_json_response(build_request_url('GetSingleItem', params))
22
+ end
23
+
24
+ #http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetItemStatus.html
25
+ def get_item_status(params)
26
+ raise ArgumentError unless params[:itemId]
27
+ get_json_response(build_request_url('GetItemStatus', params))
28
+ end
29
+
30
+ #http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetShippingCosts.html
31
+ def get_shipping_costs(params)
32
+ raise ArgumentError unless params[:itemId]
33
+ get_json_response(build_request_url('GetShippingCosts', params))
34
+ end
35
+
36
+ #http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetMultipleItems.html
37
+ def get_multiple_items(params)
38
+ raise ArgumentError unless params[:itemId]
39
+ get_json_response(build_request_url('GetMultipleItems', params))
40
+ end
41
+
42
+ #http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetUserProfile.html
43
+ def get_user_profile(params)
44
+ raise ArgumentError unless params[:userId]
45
+ get_json_response(build_request_url('GetUserProfile', params))
46
+ end
47
+
48
+ #http://developer.ebay.com/DevZone/shopping/docs/CallRef/FindPopularSearches.html
49
+ def find_popular_searches(params)
50
+ raise ArgumentError unless params[:categoryId]
51
+ get_json_response(build_request_url('FindPopularSearches', params))
52
+ end
53
+
54
+ #http://developer.ebay.com/DevZone/shopping/docs/CallRef/FindPopularItems.html
55
+ def find_popular_items(params={})
56
+ raise ArgumentError unless params[:categoryId] or params[:queryKeywords]
57
+ get_json_response(build_request_url('FindPopularItems', params))
58
+ end
59
+
60
+ #http://developer.ebay.com/DevZone/shopping/docs/CallRef/FindReviewsandGuides.html
61
+ def find_reviews_and_guides(params={})
62
+ get_json_response(build_request_url('FindReviewsAndGuides', params))
63
+ end
64
+
65
+ #http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetCategoryInfo.html
66
+ def get_category_info(params)
67
+ raise ArgumentError unless params[:categoryId]
68
+ get_json_response(build_request_url('GetCategoryInfo', params))
69
+ end
70
+
71
+ def get_category_info_with_children(params)
72
+ params[:IncludeSelector] = 'ChildCategories'
73
+ get_category_info(params)
74
+ end
75
+
76
+ private
77
+ def build_request_url(service, params=nil)
78
+ url = "#{BASE_URL}?callname=#{service}&appid=#{Rebay::Api.app_id}&version=#{VERSION}&responseencoding=JSON&siteid=#{Rebay::Api::EBAY_US}"
79
+ url += build_rest_payload(params)
80
+ return url
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,58 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rebay}
8
+ s.version = "1.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Chuck Collins"]
12
+ s.date = %q{2010-09-15}
13
+ s.email = %q{chuck.collins@gmail.com}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "LICENSE",
20
+ "README.md",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "init.rb",
24
+ "lib/rebay.rb",
25
+ "lib/rebay/api.rb",
26
+ "lib/rebay/finding.rb",
27
+ "lib/rebay/railtie.rb",
28
+ "lib/rebay/response.rb",
29
+ "lib/rebay/shopping.rb",
30
+ "rebay.gemspec"
31
+ ]
32
+ s.homepage = %q{http://github.com/ccollins/rebay}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.7}
36
+ s.summary = %q{Client for the RESTful JSON ebay finding and shopping api}
37
+ s.test_files = [
38
+ "spec/api_spec.rb",
39
+ "spec/finding_spec.rb",
40
+ "spec/response_spec.rb",
41
+ "spec/shopping_spec.rb",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<json>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<json>, [">= 0"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<json>, [">= 0"])
56
+ end
57
+ end
58
+
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ module Rebay
4
+ describe Api do
5
+ it "should respond to configure" do
6
+ Rebay::Api.should respond_to(:configure)
7
+ end
8
+
9
+ it "should allow setting of app_id" do
10
+ Rebay::Api.should respond_to(:app_id=)
11
+ end
12
+
13
+ it "should allow getting of app_id" do
14
+ Rebay::Api.should respond_to(:app_id)
15
+ end
16
+
17
+ it "should return app id after configureation" do
18
+ app_id = Rebay::Api.app_id
19
+ Rebay::Api.configure do |rebay|
20
+ rebay.app_id = 'test'
21
+ end
22
+ Rebay::Api.app_id.should == 'test'
23
+ Rebay::Api.configure do |rebay|
24
+ rebay.app_id = app_id
25
+ end
26
+ end
27
+
28
+ context "when calling build_rest_payload" do
29
+ before(:each) do
30
+ @api = Rebay::Api.new
31
+ end
32
+
33
+ it "should build rest payload from hash" do
34
+ payload = @api.send(:build_rest_payload, {:test=>'blah', :test2=>'blah', :test3=>'blah'})
35
+ payload.should include("&test=blah")
36
+ payload.should include("&test2=blah")
37
+ payload.should include("&test3=blah")
38
+ end
39
+
40
+ it "should escape html chars" do
41
+ payload = @api.send(:build_rest_payload, {:test=>'blah', :test2=>'blah', :test3=>'blah blah'})
42
+ payload.should include("&test=blah")
43
+ payload.should include("&test2=blah")
44
+ payload.should include("&test3=blah%20blah")
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,164 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ module Rebay
4
+ describe Finding do
5
+ before(:each) do
6
+ @finder = Finding.new
7
+ @finder.stub!(:get_json_response).and_return(Rebay::Response.new({"Ack" => 'Success'}))
8
+ end
9
+
10
+ it "should specify base url" do
11
+ Finding::BASE_URL.should_not be_nil
12
+ end
13
+
14
+ it "should specify version" do
15
+ Finding::VERSION.should_not be_nil
16
+ end
17
+
18
+ context "after creation" do
19
+ it "should provide find_items_advanced" do
20
+ @finder.should respond_to(:find_items_advanced)
21
+ end
22
+
23
+ it "should provide find_items_by_category" do
24
+ @finder.should respond_to(:find_items_by_category)
25
+ end
26
+
27
+ it "should provide find_items_by_product" do
28
+ @finder.should respond_to(:find_items_by_product)
29
+ end
30
+
31
+ it "should provide find_items_in_ebay_stores" do
32
+ @finder.should respond_to(:find_items_in_ebay_stores)
33
+ end
34
+
35
+ it "should provide get_histograms" do
36
+ @finder.should respond_to(:get_histograms)
37
+ end
38
+
39
+ it "should provide get_search_keywords_recommendation" do
40
+ @finder.should respond_to(:get_search_keywords_recommendation)
41
+ end
42
+
43
+ it "should provide get_version" do
44
+ @finder.should respond_to(:get_version)
45
+ end
46
+ end
47
+
48
+ context "when calling find_items_advanced" do
49
+ it "should fail without args" do
50
+ lambda { @finder.find_items_advanced }.should raise_error(ArgumentError)
51
+ end
52
+
53
+ it "should return a hash response with categoryId as parameter" do
54
+ @finder.find_items_advanced({:categoryId => 1}).class.should eq(Rebay::Response)
55
+ end
56
+
57
+ it "should return a hash response with keywords as parameter" do
58
+ @finder.find_items_advanced({:keywords => 'feist'}).class.should eq(Rebay::Response)
59
+ end
60
+
61
+ it "should succeed" do
62
+ @finder.find_items_advanced({:keywords => 'feist'}).success?.should be_true
63
+ end
64
+ end
65
+
66
+ context "when calling find_items_by_category" do
67
+ it "should fail without args" do
68
+ lambda { @finder.get_search_keywords_recommendation }.should raise_error(ArgumentError)
69
+ end
70
+
71
+ it "should return a hash response" do
72
+ @finder.find_items_by_category({:categoryId => 1}).class.should eq(Rebay::Response)
73
+ end
74
+
75
+ it "should succeed" do
76
+ @finder.find_items_by_category({:categoryId => 1}).success?.should be_true
77
+ end
78
+ end
79
+
80
+ context "when calling find_items_by_product" do
81
+ it "should fail without args" do
82
+ lambda { @finder.find_items_by_product }.should raise_error(ArgumentError)
83
+ end
84
+
85
+ it "should return a hash response" do
86
+ @finder.find_items_by_product({:productId => 53039031}).class.should eq(Rebay::Response)
87
+ end
88
+
89
+ it "should succeed" do
90
+ @finder.find_items_by_product({:productId => 53039031}).success?.should be_true
91
+ end
92
+ end
93
+
94
+ context "when calling find_items_by_keywords" do
95
+ it "should fail without args" do
96
+ lambda { @finder.find_items_by_keywords }.should raise_error(ArgumentError)
97
+ end
98
+
99
+ it "should return a hash response" do
100
+ @finder.find_items_by_keywords({:keywords => 'feist'}).class.should eq(Rebay::Response)
101
+ end
102
+
103
+ it "should succeed" do
104
+ @finder.find_items_by_keywords({:keywords => 'feist'}).success?.should be_true
105
+ end
106
+ end
107
+
108
+ context "when calling find_items_in_ebay_stores" do
109
+ it "should fail without args" do
110
+ lambda { @finder.find_items_in_ebay_stores }.should raise_error(ArgumentError)
111
+ end
112
+
113
+ it "should return a hash response with storeName as parameter" do
114
+ @finder.find_items_in_ebay_stores({:storeName => 'Laura_Chen\'s_Small_Store'}).class.should eq(Rebay::Response)
115
+ end
116
+
117
+ it "should return a hash response with keywords as parameter" do
118
+ @finder.find_items_in_ebay_stores({:keywords => 'feist'}).class.should eq(Rebay::Response)
119
+ end
120
+
121
+ it "should succeed" do
122
+ @finder.find_items_in_ebay_stores({:keywords => 'feist'}).success?.should be_true
123
+ end
124
+ end
125
+
126
+ context "when calling get_histograms" do
127
+ it "should fail without args" do
128
+ lambda { @finder.get_histograms }.should raise_error(ArgumentError)
129
+ end
130
+
131
+ it "should return a hash response" do
132
+ @finder.get_histograms({:categoryId => 1}).class.should eq(Rebay::Response)
133
+ end
134
+
135
+ it "should succeed" do
136
+ @finder.get_histograms({:categoryId => 1}).success?.should be_true
137
+ end
138
+ end
139
+
140
+ context "when calling get_search_keywords_recommendation" do
141
+ it "should fail without args" do
142
+ lambda { @finder.get_search_keywords_recommendation }.should raise_error(ArgumentError)
143
+ end
144
+
145
+ it "should return a hash response" do
146
+ @finder.get_search_keywords_recommendation({:keywords => 'feist'}).class.should eq(Rebay::Response)
147
+ end
148
+
149
+ it "should succeed" do
150
+ @finder.get_search_keywords_recommendation({:keywords => 'feist'}).success?.should be_true
151
+ end
152
+ end
153
+
154
+ context "when calling get_version" do
155
+ it "should return a hash response" do
156
+ @finder.get_version.class.should eq(Rebay::Response)
157
+ end
158
+
159
+ it "should succeed" do
160
+ @finder.get_version.success?.should be_true
161
+ end
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + "/spec_helper"
2
+
3
+ module Rebay
4
+ describe Response do
5
+ context "on creation" do
6
+ it "should transform the happy json" do
7
+ json_happy = JSON.parse(File.read(File.dirname(__FILE__) + "/json_responses/finding/get_search_keywords_recommendation_happy.json"))
8
+ response = Response.new(json_happy)
9
+ response.response.should eq({"getSearchKeywordsRecommendationResponse" => {"ack" => "Success", "version" => "1.5.0",
10
+ "timestamp" => "2010-08-13T21:11:02.539Z", "keywords" => "accordion"}})
11
+ end
12
+
13
+ it "should transform the sad json" do
14
+ json_sad = JSON.parse(File.read(File.dirname(__FILE__) + "/json_responses/finding/get_search_keywords_recommendation_sad.json"))
15
+ response = Response.new(json_sad)
16
+ response.response.should eq({"getSearchKeywordsRecommendationResponse" =>
17
+ {"ack" => "Warning",
18
+ "errorMessage" => {"error" => {"errorId" => "59", "domain" => "Marketplace", "severity" => "Warning",
19
+ "category" => "Request", "message" => "No recommendation was identified for the submitted keywords.",
20
+ "subdomain" => "Search"}},
21
+ "version" => "1.5.0",
22
+ "timestamp" => "2010-08-13T21:08:30.081Z",
23
+ "keywords" => ""}})
24
+ end
25
+ end
26
+
27
+ it "should return success" do
28
+ response = Response.new({"Ack" => "Success"})
29
+ response.success?.should be_true
30
+ response.failure?.should be_false
31
+ end
32
+
33
+ it "should return failure" do
34
+ response = Response.new({"Ack" => "Failure"})
35
+ response.failure?.should be_true
36
+ response.success?.should be_false
37
+ end
38
+
39
+ it "should trim response" do
40
+ response = Response.new({"Ack" => "Failure", "test" => "test"})
41
+ response.trim("test")
42
+ response.response.should eq("test")
43
+ end
44
+
45
+ it "should not trim response" do
46
+ response = Response.new({"Ack" => "Failure", "test" => "test"})
47
+ response.trim(:nothing)
48
+ response.response.should eq({"Ack" => "Failure", "test" => "test"})
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,214 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ module Rebay
4
+ describe Shopping do
5
+ before(:each) do
6
+ @shopper = Shopping.new
7
+ @shopper.stub!(:get_json_response).and_return(Rebay::Response.new({"Ack" => "Success"}))
8
+ end
9
+
10
+ it "should specify base url" do
11
+ Shopping::BASE_URL.should_not be_nil
12
+ end
13
+
14
+ it "should specify version" do
15
+ Shopping::VERSION.should_not be_nil
16
+ end
17
+
18
+ context "after creation" do
19
+ it "should provide get_category_info" do
20
+ @shopper.should respond_to(:get_category_info)
21
+ end
22
+
23
+ it "should provide get_category_info_with_children" do
24
+ @shopper.should respond_to(:get_category_info_with_children)
25
+ end
26
+
27
+ it "should provide find_products" do
28
+ @shopper.should respond_to(:find_products)
29
+ end
30
+
31
+ it "should provide find_half_products" do
32
+ @shopper.should respond_to(:find_half_products)
33
+ end
34
+
35
+ it "should provide get_single_item" do
36
+ @shopper.should respond_to(:get_single_item)
37
+ end
38
+
39
+ it "should provide get_item_status" do
40
+ @shopper.should respond_to(:get_item_status)
41
+ end
42
+
43
+ it "should provide get_shipping_costs" do
44
+ @shopper.should respond_to(:get_shipping_costs)
45
+ end
46
+
47
+ it "should provide get_multiple_items" do
48
+ @shopper.should respond_to(:get_multiple_items)
49
+ end
50
+
51
+ it "should provide get_user_profile" do
52
+ @shopper.should respond_to(:get_user_profile)
53
+ end
54
+
55
+ it "should provide find_popular_searches" do
56
+ @shopper.should respond_to(:find_popular_searches)
57
+ end
58
+
59
+ it "should provide find_popular_items" do
60
+ @shopper.should respond_to(:find_popular_items)
61
+ end
62
+
63
+ it "should provide find_reviews_and_guides" do
64
+ @shopper.should respond_to(:find_reviews_and_guides)
65
+ end
66
+ end
67
+
68
+ context "when calling get_category_info" do
69
+ it "should fail without args" do
70
+ lambda { @shopper.get_category_info }.should raise_error(ArgumentError)
71
+ end
72
+
73
+ it "should return a hash response" do
74
+ @shopper.get_category_info({:categoryId => 29223}).class.should eq(Rebay::Response)
75
+ end
76
+
77
+ it "should succeed" do
78
+ @shopper.get_category_info({:categoryId => 29223}).success?.should be_true
79
+ end
80
+ end
81
+
82
+ context "when calling find_products" do
83
+ it "should fail without args" do
84
+ lambda { @shopper.find_products }.should raise_error(ArgumentError)
85
+ end
86
+
87
+ it "should return a hash response" do
88
+ @shopper.find_products({:queryKeywords => 'harry potter'}).class.should eq(Rebay::Response)
89
+ end
90
+
91
+ it "should succeed" do
92
+ @shopper.find_products({:queryKeywords => 'harry potter'}).success?.should be_true
93
+ end
94
+ end
95
+
96
+ context "when calling find_half_products" do
97
+ it "should fail without args" do
98
+ lambda { @shopper.find_half_products }.should raise_error(ArgumentError)
99
+ end
100
+
101
+ it "should return a hash response" do
102
+ @shopper.find_half_products({:queryKeywords => 'harry potter'}).class.should eq(Rebay::Response)
103
+ end
104
+
105
+ it "should succeed" do
106
+ @shopper.find_half_products({:queryKeywords => 'harry potter'}).success?.should be_true
107
+ end
108
+ end
109
+
110
+ context "when calling get_single_item" do
111
+ it "should fail without args" do
112
+ lambda { @shopper.get_single_item }.should raise_error(ArgumentError)
113
+ end
114
+
115
+ it "should return a hash response" do
116
+ @shopper.get_single_item({:itemId => 230139965209}).class.should eq(Rebay::Response)
117
+ end
118
+
119
+ it "should succeed" do
120
+ @shopper.get_single_item({:itemId => 230139965209}).success?.should be_true
121
+ end
122
+ end
123
+
124
+ context "when calling get_item_status" do
125
+ it "should fail without args" do
126
+ lambda { @shopper.get_item_status }.should raise_error(ArgumentError)
127
+ end
128
+
129
+ it "should return a hash response" do
130
+ @shopper.get_item_status({:itemId => 230139965209}).class.should eq(Rebay::Response)
131
+ end
132
+
133
+ it "should succeed" do
134
+ @shopper.get_item_status({:itemId => 230139965209}).success?.should be_true
135
+ end
136
+ end
137
+
138
+ context "when calling get_shipping_costs" do
139
+ it "should fail without args" do
140
+ lambda { @shopper.get_shipping_costs }.should raise_error(ArgumentError)
141
+ end
142
+
143
+ it "should return a hash response" do
144
+ @shopper.get_shipping_costs({:itemId => 230139965209}).class.should eq(Rebay::Response)
145
+ end
146
+
147
+ it "should succeed" do
148
+ @shopper.get_shipping_costs({:itemId => 230139965209}).success?.should be_true
149
+ end
150
+ end
151
+
152
+ context "when calling get_multiple_items" do
153
+ it "should fail without args" do
154
+ lambda { @shopper.get_multiple_items }.should raise_error(ArgumentError)
155
+ end
156
+
157
+ it "should return a hash response" do
158
+ @shopper.get_multiple_items({:itemId => 230139965209}).class.should eq(Rebay::Response)
159
+ end
160
+
161
+ it "should succeed" do
162
+ @shopper.get_multiple_items({:itemId => 230139965209}).success?.should be_true
163
+ end
164
+ end
165
+
166
+ context "when calling get_user_profile" do
167
+ it "should fail without args" do
168
+ lambda { @shopper.get_user_profile }.should raise_error(ArgumentError)
169
+ end
170
+
171
+ it "should return a hash response" do
172
+ @shopper.get_user_profile({:userId => 1}).class.should eq(Rebay::Response)
173
+ end
174
+
175
+ it "should succeed" do
176
+ @shopper.get_user_profile({:userId => 1}).success?.should be_true
177
+ end
178
+ end
179
+
180
+ context "when calling find_popular_searches" do
181
+ it "should fail without args" do
182
+ lambda { @shopper.find_popular_searches }.should raise_error(ArgumentError)
183
+ end
184
+
185
+ it "should return a hash response" do
186
+ @shopper.find_popular_searches({:categoryId => 1}).class.should eq(Rebay::Response)
187
+ end
188
+
189
+ it "should succeed" do
190
+ @shopper.find_popular_searches({:categoryId => 1}).success?.should be_true
191
+ end
192
+ end
193
+
194
+ context "when calling find_popular_items" do
195
+ it "should return a hash response" do
196
+ @shopper.find_popular_items({:categoryId => 1}).class.should eq(Rebay::Response)
197
+ end
198
+
199
+ it "should succeed" do
200
+ @shopper.find_popular_items({:categoryId => 1}).success?.should be_true
201
+ end
202
+ end
203
+
204
+ context "when calling find_reviews_and_guides" do
205
+ it "should return a hash response" do
206
+ @shopper.find_reviews_and_guides.class.should eq(Rebay::Response)
207
+ end
208
+
209
+ it "should succeed" do
210
+ @shopper.find_reviews_and_guides.success?.should be_true
211
+ end
212
+ end
213
+ end
214
+ end
@@ -0,0 +1,10 @@
1
+ require 'rspec'
2
+ RSpec.configure do |config|
3
+ config.mock_with :rspec
4
+ end
5
+
6
+ require File.join(File.dirname(__FILE__), "..", "lib", "rebay")
7
+
8
+ Rebay::Api.configure do |rebay|
9
+ rebay.app_id = 'test'
10
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rebay
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 2
10
+ version: 1.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Chuck Collins
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-15 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: json
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description:
36
+ email: chuck.collins@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.md
44
+ files:
45
+ - LICENSE
46
+ - README.md
47
+ - Rakefile
48
+ - VERSION
49
+ - init.rb
50
+ - lib/rebay.rb
51
+ - lib/rebay/api.rb
52
+ - lib/rebay/finding.rb
53
+ - lib/rebay/railtie.rb
54
+ - lib/rebay/response.rb
55
+ - lib/rebay/shopping.rb
56
+ - rebay.gemspec
57
+ - spec/api_spec.rb
58
+ - spec/finding_spec.rb
59
+ - spec/response_spec.rb
60
+ - spec/shopping_spec.rb
61
+ - spec/spec_helper.rb
62
+ has_rdoc: true
63
+ homepage: http://github.com/ccollins/rebay
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --charset=UTF-8
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.7
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Client for the RESTful JSON ebay finding and shopping api
96
+ test_files:
97
+ - spec/api_spec.rb
98
+ - spec/finding_spec.rb
99
+ - spec/response_spec.rb
100
+ - spec/shopping_spec.rb
101
+ - spec/spec_helper.rb