razsell 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +12 -3
- data/VERSION +1 -1
- data/lib/razsell.rb +5 -1
- data/lib/razsell/constants/product_types.rb +1 -0
- data/lib/razsell/engine.rb +5 -3
- data/lib/razsell/http_service.rb +1 -0
- data/lib/razsell/item.rb +2 -1
- data/lib/razsell/query.rb +30 -15
- data/lib/razsell/results.rb +13 -12
- data/razsell.gemspec +8 -5
- data/test/razsell_test.rb +18 -2
- metadata +53 -22
data/Rakefile
CHANGED
@@ -9,15 +9,16 @@ begin
|
|
9
9
|
require 'jeweler'
|
10
10
|
Jeweler::Tasks.new do |gem|
|
11
11
|
gem.name = "razsell"
|
12
|
-
gem.summary = %Q{A gem for getting info about products on
|
12
|
+
gem.summary = %Q{A gem for getting info about products on Zazzle.com}
|
13
13
|
gem.description = %Q{Queries Zazzle RSS feed for data.}
|
14
14
|
gem.email = "jamal.hansen@gmail.com"
|
15
|
-
gem.homepage = "http://
|
15
|
+
gem.homepage = "http://rubyyot.com/razsell"
|
16
16
|
gem.authors = ["Jamal Hansen"]
|
17
17
|
gem.add_dependency('hpricot', '>= 0.8.1')
|
18
18
|
gem.add_development_dependency('cucumber', '>= 0.3.11')
|
19
19
|
gem.add_development_dependency('mocha')
|
20
20
|
gem.add_development_dependency('shoulda')
|
21
|
+
gem.add_development_dependency('reek')
|
21
22
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
22
23
|
end
|
23
24
|
|
@@ -47,7 +48,7 @@ end
|
|
47
48
|
|
48
49
|
begin
|
49
50
|
require 'cucumber/rake/task'
|
50
|
-
Cucumber::Rake::Task.new(:features)
|
51
|
+
Cucumber::Rake::Task.new(:features)
|
51
52
|
rescue LoadError
|
52
53
|
task :features do
|
53
54
|
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
@@ -80,3 +81,11 @@ namespace :products do
|
|
80
81
|
results.items.sort {|x,y| x.title <=> y.title }.each { |p| puts p.title }
|
81
82
|
end
|
82
83
|
end
|
84
|
+
|
85
|
+
require 'reek/rake/task'
|
86
|
+
|
87
|
+
Reek::Rake::Task.new do |t|
|
88
|
+
t.fail_on_error = false
|
89
|
+
end
|
90
|
+
|
91
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.11
|
data/lib/razsell.rb
CHANGED
@@ -4,7 +4,7 @@ require 'razsell/item'
|
|
4
4
|
require 'razsell/query'
|
5
5
|
|
6
6
|
|
7
|
-
module Razsell
|
7
|
+
module Razsell::Mixin
|
8
8
|
def request query, opts={}
|
9
9
|
engine = Razsell::Engine.new opts
|
10
10
|
engine.request(query)
|
@@ -15,4 +15,8 @@ module Razsell
|
|
15
15
|
query = Razsell::Query.new.for_artist(artist)
|
16
16
|
engine.request(query)
|
17
17
|
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Razsell
|
21
|
+
extend Razsell::Mixin
|
18
22
|
end
|
data/lib/razsell/engine.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'razsell/http_service'
|
2
2
|
|
3
3
|
module Razsell
|
4
|
+
# Use the engine class to make requests and receive results
|
4
5
|
class Engine
|
5
6
|
def initialize opts={}
|
6
|
-
@
|
7
|
+
@opts = opts
|
8
|
+
@http_service = get_http_service
|
7
9
|
end
|
8
10
|
|
9
11
|
def request query
|
@@ -18,8 +20,8 @@ module Razsell
|
|
18
20
|
results
|
19
21
|
end
|
20
22
|
|
21
|
-
def get_http_service
|
22
|
-
opts[:http_service]
|
23
|
+
def get_http_service
|
24
|
+
@opts[:http_service] || Razsell::HttpService.new
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
data/lib/razsell/http_service.rb
CHANGED
data/lib/razsell/item.rb
CHANGED
data/lib/razsell/query.rb
CHANGED
@@ -2,6 +2,28 @@ require 'razsell/constants'
|
|
2
2
|
require 'cgi'
|
3
3
|
|
4
4
|
module Razsell
|
5
|
+
|
6
|
+
# Allows you to specify the result set you would like returned
|
7
|
+
#
|
8
|
+
# === Attributes that you can specify
|
9
|
+
# * keywords
|
10
|
+
# * product_line
|
11
|
+
# * product_type (see Razsell::ProductTypes)
|
12
|
+
# * sort_type (see Razsell::SortMethods)
|
13
|
+
# * sort_period (see Razsell::SortPeriods)
|
14
|
+
# * image_size (see Razsell::ImageSizes)
|
15
|
+
# * image_background_color
|
16
|
+
#
|
17
|
+
# Additionally you can use
|
18
|
+
#
|
19
|
+
# query = Razsell::Query.new.for_artist('some_zazzle_artist')
|
20
|
+
#
|
21
|
+
# to specify the artist. Or if you have a link to a zazzle item you can get the details with:
|
22
|
+
#
|
23
|
+
# query = Razsell::Query.new.for_item_url('http://www.zazzle.com/some-item-354678976578865')
|
24
|
+
#
|
25
|
+
# Once you have built your query, use Razsell#request(query) to get the results.
|
26
|
+
|
5
27
|
class Query
|
6
28
|
include Razsell::SortMethods
|
7
29
|
include Razsell::ImageSizes
|
@@ -34,9 +56,6 @@ module Razsell
|
|
34
56
|
def strip_item_number_from url
|
35
57
|
url.scan(/\d*$/)[0]
|
36
58
|
end
|
37
|
-
#def add_criteria name, value
|
38
|
-
# this.send name, value
|
39
|
-
#end
|
40
59
|
|
41
60
|
def base_url
|
42
61
|
return "http://feed.zazzle.com/#{@artist}/rss" if @artist
|
@@ -44,7 +63,7 @@ module Razsell
|
|
44
63
|
end
|
45
64
|
|
46
65
|
def to_querystring
|
47
|
-
@querystring.to_a.map { |
|
66
|
+
@querystring.to_a.map { |element| build_pair(element) }.sort {|first, second| first <=> second }.delete_if { |pair| pair == "" }.join("&")
|
48
67
|
end
|
49
68
|
|
50
69
|
def to_url
|
@@ -52,27 +71,25 @@ module Razsell
|
|
52
71
|
end
|
53
72
|
|
54
73
|
def advance_page
|
55
|
-
|
74
|
+
cur_page = @querystring[:page]
|
75
|
+
return false if cur_page >= page_limit
|
56
76
|
|
57
|
-
@querystring[:page] =
|
77
|
+
@querystring[:page] = cur_page + 1
|
58
78
|
true
|
59
79
|
end
|
60
80
|
|
61
81
|
private
|
62
82
|
def build_pair pair
|
63
|
-
|
64
|
-
""
|
65
|
-
|
66
|
-
|
67
|
-
def get_querystring_identifier key
|
68
|
-
@keys[key] if @keys[key]
|
83
|
+
key, value = pair
|
84
|
+
return "" unless value
|
85
|
+
|
86
|
+
"#{@keys[key]}=#{format_value(value)}"
|
69
87
|
end
|
70
88
|
|
71
89
|
def format_value value
|
72
90
|
CGI.escape(value.to_s)
|
73
91
|
end
|
74
92
|
|
75
|
-
|
76
93
|
def set_default_page_limit
|
77
94
|
@page_limit = 5
|
78
95
|
end
|
@@ -103,8 +120,6 @@ module Razsell
|
|
103
120
|
end
|
104
121
|
end
|
105
122
|
|
106
|
-
|
107
|
-
|
108
123
|
attr_querystring_read :keywords, :product_line, :product_type,
|
109
124
|
:sort_type, :sort_period, :page, :items_per_page,
|
110
125
|
:feed_type, :image_size, :image_background_color,
|
data/lib/razsell/results.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'hpricot'
|
2
2
|
|
3
3
|
module Razsell
|
4
|
+
|
5
|
+
# This class returns the query results
|
6
|
+
|
4
7
|
class Results
|
5
8
|
attr_accessor :items, :result_count, :items_per_page
|
6
9
|
|
@@ -22,18 +25,16 @@ module Razsell
|
|
22
25
|
end
|
23
26
|
|
24
27
|
def build_hash_from item
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
item_hash[:rating] = item.at("media:rating").inner_html
|
36
|
-
item_hash
|
28
|
+
{ title: strip_cdata(item.at("title").inner_html),
|
29
|
+
guid: item.at("guid").inner_html,
|
30
|
+
pub_date: Time.parse(item.at("pubDate").inner_html),
|
31
|
+
link: item.at("link").inner_html,
|
32
|
+
author: item.at("author").inner_html,
|
33
|
+
description: strip_cdata(item.at("media:description").inner_html),
|
34
|
+
thumbnail_url: item.at("media:thumbnail")['url'],
|
35
|
+
content_url: item.at("media:content")['url'],
|
36
|
+
keywords: split_keywords(item.at("media:keywords").inner_html),
|
37
|
+
rating: item.at("media:rating").inner_html }
|
37
38
|
end
|
38
39
|
|
39
40
|
def split_keywords words
|
data/razsell.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{razsell}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.11"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jamal Hansen"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-03-14}
|
13
13
|
s.description = %q{Queries Zazzle RSS feed for data.}
|
14
14
|
s.email = %q{jamal.hansen@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -54,11 +54,11 @@ Gem::Specification.new do |s|
|
|
54
54
|
"test/results_test.rb",
|
55
55
|
"test/test_helper.rb"
|
56
56
|
]
|
57
|
-
s.homepage = %q{http://
|
57
|
+
s.homepage = %q{http://rubyyot.com/razsell}
|
58
58
|
s.rdoc_options = ["--charset=UTF-8"]
|
59
59
|
s.require_paths = ["lib"]
|
60
|
-
s.rubygems_version = %q{1.3.
|
61
|
-
s.summary = %q{A gem for getting info about products on
|
60
|
+
s.rubygems_version = %q{1.3.6}
|
61
|
+
s.summary = %q{A gem for getting info about products on Zazzle.com}
|
62
62
|
s.test_files = [
|
63
63
|
"test/product_types_test.rb",
|
64
64
|
"test/fixtures.rb",
|
@@ -78,17 +78,20 @@ Gem::Specification.new do |s|
|
|
78
78
|
s.add_development_dependency(%q<cucumber>, [">= 0.3.11"])
|
79
79
|
s.add_development_dependency(%q<mocha>, [">= 0"])
|
80
80
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
81
|
+
s.add_development_dependency(%q<reek>, [">= 0"])
|
81
82
|
else
|
82
83
|
s.add_dependency(%q<hpricot>, [">= 0.8.1"])
|
83
84
|
s.add_dependency(%q<cucumber>, [">= 0.3.11"])
|
84
85
|
s.add_dependency(%q<mocha>, [">= 0"])
|
85
86
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
87
|
+
s.add_dependency(%q<reek>, [">= 0"])
|
86
88
|
end
|
87
89
|
else
|
88
90
|
s.add_dependency(%q<hpricot>, [">= 0.8.1"])
|
89
91
|
s.add_dependency(%q<cucumber>, [">= 0.3.11"])
|
90
92
|
s.add_dependency(%q<mocha>, [">= 0"])
|
91
93
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
94
|
+
s.add_dependency(%q<reek>, [">= 0"])
|
92
95
|
end
|
93
96
|
end
|
94
97
|
|
data/test/razsell_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
4
|
-
include Razsell
|
3
|
+
class RazsellMixinTest < Test::Unit::TestCase
|
4
|
+
include Razsell::Mixin
|
5
5
|
|
6
6
|
context "basic operations" do
|
7
7
|
setup do
|
@@ -17,3 +17,19 @@ class RazsellTest < Test::Unit::TestCase
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
class RazsellNonMixinTest < Test::Unit::TestCase
|
22
|
+
context "basic operations" do
|
23
|
+
setup do
|
24
|
+
@query = Razsell::Query.new
|
25
|
+
end
|
26
|
+
|
27
|
+
should "return results" do
|
28
|
+
http_service = Razsell::HttpService.new
|
29
|
+
http_service.expects(:get).once.returns("")
|
30
|
+
|
31
|
+
result = Razsell.request @query, :http_service => http_service
|
32
|
+
assert_equal Razsell::Results, result.class
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: razsell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 11
|
9
|
+
version: 0.0.11
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Jamal Hansen
|
@@ -9,49 +14,73 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-03-14 00:00:00 -06:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: hpricot
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 8
|
30
|
+
- 1
|
23
31
|
version: 0.8.1
|
24
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: cucumber
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ">="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 3
|
44
|
+
- 11
|
33
45
|
version: 0.3.11
|
34
|
-
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
35
48
|
- !ruby/object:Gem::Dependency
|
36
49
|
name: mocha
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
52
|
requirements:
|
41
53
|
- - ">="
|
42
54
|
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
43
57
|
version: "0"
|
44
|
-
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id003
|
45
60
|
- !ruby/object:Gem::Dependency
|
46
61
|
name: shoulda
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
47
70
|
type: :development
|
48
|
-
|
49
|
-
|
71
|
+
version_requirements: *id004
|
72
|
+
- !ruby/object:Gem::Dependency
|
73
|
+
name: reek
|
74
|
+
prerelease: false
|
75
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
50
76
|
requirements:
|
51
77
|
- - ">="
|
52
78
|
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
53
81
|
version: "0"
|
54
|
-
|
82
|
+
type: :development
|
83
|
+
version_requirements: *id005
|
55
84
|
description: Queries Zazzle RSS feed for data.
|
56
85
|
email: jamal.hansen@gmail.com
|
57
86
|
executables: []
|
@@ -99,7 +128,7 @@ files:
|
|
99
128
|
- test/results_test.rb
|
100
129
|
- test/test_helper.rb
|
101
130
|
has_rdoc: true
|
102
|
-
homepage: http://
|
131
|
+
homepage: http://rubyyot.com/razsell
|
103
132
|
licenses: []
|
104
133
|
|
105
134
|
post_install_message:
|
@@ -111,21 +140,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
140
|
requirements:
|
112
141
|
- - ">="
|
113
142
|
- !ruby/object:Gem::Version
|
143
|
+
segments:
|
144
|
+
- 0
|
114
145
|
version: "0"
|
115
|
-
version:
|
116
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
147
|
requirements:
|
118
148
|
- - ">="
|
119
149
|
- !ruby/object:Gem::Version
|
150
|
+
segments:
|
151
|
+
- 0
|
120
152
|
version: "0"
|
121
|
-
version:
|
122
153
|
requirements: []
|
123
154
|
|
124
155
|
rubyforge_project:
|
125
|
-
rubygems_version: 1.3.
|
156
|
+
rubygems_version: 1.3.6
|
126
157
|
signing_key:
|
127
158
|
specification_version: 3
|
128
|
-
summary: A gem for getting info about products on
|
159
|
+
summary: A gem for getting info about products on Zazzle.com
|
129
160
|
test_files:
|
130
161
|
- test/product_types_test.rb
|
131
162
|
- test/fixtures.rb
|