handcrafted-ebay_products 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/ebay_products.gemspec +49 -0
- data/lib/ebay_products.rb +22 -5
- data/lib/ebay_products/data.rb +19 -5
- data/spec/ebay_products_spec.rb +18 -9
- metadata +5 -4
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "ebay_products"
|
8
|
-
gem.summary = %Q{
|
8
|
+
gem.summary = %Q{Wrapper for eBay web services}
|
9
9
|
gem.email = "joshua.owens@gmail.com"
|
10
10
|
gem.homepage = "http://github.com/handcrafted/ebay_products"
|
11
11
|
gem.authors = ["Josh Owens"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{ebay_products}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Josh Owens"]
|
9
|
+
s.date = %q{2009-06-26}
|
10
|
+
s.email = %q{joshua.owens@gmail.com}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".document",
|
17
|
+
".gitignore",
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"ebay_products.gemspec",
|
23
|
+
"lib/ebay_products.rb",
|
24
|
+
"lib/ebay_products/data.rb",
|
25
|
+
"spec/ebay_products_spec.rb",
|
26
|
+
"spec/samples/harry_potter.xml",
|
27
|
+
"spec/spec.opts",
|
28
|
+
"spec/spec_helper.rb"
|
29
|
+
]
|
30
|
+
s.homepage = %q{http://github.com/handcrafted/ebay_products}
|
31
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.3.4}
|
34
|
+
s.summary = %q{Wrapper for eBay web services}
|
35
|
+
s.test_files = [
|
36
|
+
"spec/ebay_products_spec.rb",
|
37
|
+
"spec/spec_helper.rb"
|
38
|
+
]
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
45
|
+
else
|
46
|
+
end
|
47
|
+
else
|
48
|
+
end
|
49
|
+
end
|
data/lib/ebay_products.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
gem 'httparty'
|
3
3
|
require 'httparty'
|
4
|
+
require 'activesupport'
|
4
5
|
require File.dirname(__FILE__) + '/ebay_products/data'
|
5
6
|
|
6
7
|
class EbayProducts
|
@@ -9,18 +10,34 @@ class EbayProducts
|
|
9
10
|
base_uri "open.api.ebay.com"
|
10
11
|
default_params :responseencoding => 'XML', :callname => "FindProducts", :version => "619", :siteid => 0, :maxentries => 18
|
11
12
|
|
12
|
-
attr_reader :query, :appid
|
13
|
+
attr_reader :query, :appid, :product_id
|
13
14
|
|
14
|
-
def initialize(
|
15
|
-
@query
|
15
|
+
def initialize(args, appid)
|
16
|
+
@query = args[:keywords]
|
17
|
+
@product_id = args[:product_id]
|
18
|
+
@appid = appid
|
16
19
|
end
|
17
20
|
|
18
21
|
def search
|
19
|
-
@search ||= self.class.get("/shopping", :query =>
|
22
|
+
@search ||= self.class.get("/shopping", :query => options, :format => :xml)["FindProductsResponse"]["Product"]
|
20
23
|
end
|
21
24
|
|
22
25
|
def products
|
23
26
|
@products ||= search.collect {|product| ProductInformation.new(product) }
|
24
27
|
end
|
25
|
-
|
28
|
+
|
29
|
+
def product
|
30
|
+
products.first
|
31
|
+
end
|
32
|
+
|
33
|
+
def options
|
34
|
+
hash = {:appid => @appid}
|
35
|
+
if @product_id
|
36
|
+
hash['ProductID.value'.to_sym] = @product_id
|
37
|
+
hash['ProductID.type'.to_sym] = 'Reference' # assumes product id is of type reference
|
38
|
+
else
|
39
|
+
hash[:QueryKeywords] = @query
|
40
|
+
end
|
41
|
+
hash
|
42
|
+
end
|
26
43
|
end
|
data/lib/ebay_products/data.rb
CHANGED
@@ -3,7 +3,7 @@ class EbayProducts
|
|
3
3
|
attr_reader :data
|
4
4
|
|
5
5
|
def initialize(data)
|
6
|
-
@data = data
|
6
|
+
@data = downcase_keys(data)
|
7
7
|
end
|
8
8
|
|
9
9
|
def method_missing(method, *args)
|
@@ -14,10 +14,24 @@ class EbayProducts
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
private
|
18
|
+
|
19
|
+
def downcase_keys(hash)
|
20
|
+
hash = hash.dup
|
21
|
+
new_hash = {}
|
22
|
+
hash.keys.each do |key|
|
23
|
+
value = hash.delete(key)
|
24
|
+
new_hash[downcase_key(key)] = value
|
25
|
+
new_hash[downcase_key(key)] = downcase_keys(value) if value.is_a?(Hash)
|
26
|
+
new_hash[downcase_key(key)] = value.each{|p| downcase_keys(p) if p.is_a?(Hash)} if value.is_a?(Array)
|
27
|
+
end
|
28
|
+
new_hash
|
29
|
+
end
|
30
|
+
|
31
|
+
def downcase_key(key)
|
32
|
+
key.underscore.titlecase.downcase.gsub(' ', '_')
|
33
|
+
end
|
34
|
+
|
21
35
|
end
|
22
36
|
|
23
37
|
class ProductInformation < Data; end
|
data/spec/ebay_products_spec.rb
CHANGED
@@ -3,29 +3,38 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
3
3
|
describe "EbayProducts" do
|
4
4
|
|
5
5
|
context "Initializing" do
|
6
|
-
|
6
|
+
|
7
7
|
it "should raise an error without a query and appid" do
|
8
8
|
lambda {EbayProducts.new}.should raise_error
|
9
|
-
lambda {EbayProducts.new("query")}.should raise_error
|
9
|
+
lambda {EbayProducts.new({:keywords => "query"})}.should raise_error
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
it "save the query and appid" do
|
13
|
-
ebay = EbayProducts.new("query", "1234")
|
13
|
+
ebay = EbayProducts.new({:keywords => "query"}, "1234")
|
14
14
|
ebay.query.should == "query"
|
15
15
|
ebay.appid.should == "1234"
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
end
|
19
19
|
|
20
20
|
context "Finding" do
|
21
21
|
|
22
22
|
before(:each) do
|
23
|
-
FakeWeb.register_uri(:get, "http://open.api.ebay.com:80/shopping?QueryKeywords=harry%20potter&callname=FindProducts&siteid=0&maxentries=18&appid=123abc&version=619&responseencoding=XML", :
|
23
|
+
FakeWeb.register_uri(:get, "http://open.api.ebay.com:80/shopping?QueryKeywords=harry%20potter&callname=FindProducts&siteid=0&maxentries=18&appid=123abc&version=619&responseencoding=XML", :body => File.read("#{File.dirname(__FILE__)}/samples/harry_potter.xml"))
|
24
|
+
@ebay = EbayProducts.new({:keywords => "harry potter"}, "123abc")
|
24
25
|
end
|
25
|
-
|
26
|
+
|
27
|
+
it "search should return an Array" do
|
28
|
+
@ebay.search.should be_an_instance_of(Array)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "ebay products should not wipe out search results" do
|
32
|
+
product = @ebay.search.first
|
33
|
+
proc { @ebay.products }.should_not change(product, :size)
|
34
|
+
end
|
35
|
+
|
26
36
|
it "should find the products" do
|
27
|
-
|
28
|
-
puts e.products
|
37
|
+
@ebay.products.size.should == 2
|
29
38
|
end
|
30
39
|
|
31
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: handcrafted-ebay_products
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Owens
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-26 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -29,13 +29,14 @@ files:
|
|
29
29
|
- README.rdoc
|
30
30
|
- Rakefile
|
31
31
|
- VERSION
|
32
|
+
- ebay_products.gemspec
|
32
33
|
- lib/ebay_products.rb
|
33
34
|
- lib/ebay_products/data.rb
|
34
35
|
- spec/ebay_products_spec.rb
|
35
36
|
- spec/samples/harry_potter.xml
|
36
37
|
- spec/spec.opts
|
37
38
|
- spec/spec_helper.rb
|
38
|
-
has_rdoc:
|
39
|
+
has_rdoc: false
|
39
40
|
homepage: http://github.com/handcrafted/ebay_products
|
40
41
|
post_install_message:
|
41
42
|
rdoc_options:
|
@@ -60,7 +61,7 @@ rubyforge_project:
|
|
60
61
|
rubygems_version: 1.2.0
|
61
62
|
signing_key:
|
62
63
|
specification_version: 3
|
63
|
-
summary:
|
64
|
+
summary: Wrapper for eBay web services
|
64
65
|
test_files:
|
65
66
|
- spec/ebay_products_spec.rb
|
66
67
|
- spec/spec_helper.rb
|