sucker 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +6 -2
- data/lib/sucker.rb +3 -9
- data/lib/sucker/request.rb +12 -2
- data/lib/sucker/response.rb +5 -0
- data/lib/sucker/stub.rb +1 -0
- data/lib/sucker/version.rb +4 -0
- data/spec/fixtures/asins.txt +1000 -0
- data/spec/integration/item_search_spec.rb +35 -0
- data/spec/support/amazon.yml.example +2 -0
- data/spec/support/asins.rb +3 -0
- data/spec/unit/sucker/response_spec.rb +11 -0
- metadata +114 -22
- data/lib/sucker/active_support/core_ext/object/blank.rb +0 -77
- data/lib/sucker/active_support/xml_mini/nokogiri.rb +0 -77
@@ -0,0 +1,35 @@
|
|
1
|
+
# http://github.com/papercavalier/sucker/issues#issue/2
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
module Sucker
|
6
|
+
describe "Item Search" do
|
7
|
+
before do
|
8
|
+
@worker = Sucker.new(
|
9
|
+
:locale => "us",
|
10
|
+
:key => amazon["key"],
|
11
|
+
:secret => amazon["secret"])
|
12
|
+
|
13
|
+
@worker << {
|
14
|
+
"Operation" => "ItemSearch",
|
15
|
+
"SearchIndex" => "Books",
|
16
|
+
"Author" => "Orwell" }
|
17
|
+
|
18
|
+
#Sucker.stub(@worker)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "works for Orwell" do
|
22
|
+
@worker.get.should be_valid
|
23
|
+
end
|
24
|
+
|
25
|
+
it "works for George Orwell, too" do
|
26
|
+
@worker << {
|
27
|
+
"Operation" => "ItemSearch",
|
28
|
+
"SearchIndex" => "Books",
|
29
|
+
"Author" => "George Orwell" }
|
30
|
+
response = @worker.get
|
31
|
+
response.should be_valid
|
32
|
+
response.node("TotalPages").first.should be_an_instance_of String
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -74,5 +74,16 @@ module Sucker
|
|
74
74
|
@response.to_hash["Title"].should eql "スティーブ・ジョブズ 驚異のプレゼン―人々を惹きつける18の法則"
|
75
75
|
end
|
76
76
|
end
|
77
|
+
|
78
|
+
context "#valid?" do
|
79
|
+
it "returns true if the HTTP status is OK" do
|
80
|
+
@response.should be_valid
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns false if the HTTP status is not OK" do
|
84
|
+
@response.code = 403
|
85
|
+
@response.should_not be_valid
|
86
|
+
end
|
87
|
+
end
|
77
88
|
end
|
78
89
|
end
|
metadata
CHANGED
@@ -5,22 +5,37 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 2
|
9
|
+
version: 0.9.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Hakan Ensari
|
13
|
-
- Piotr
|
13
|
+
- "Piotr \xC5\x81aszewski"
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-06 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: activesupport
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 3
|
31
|
+
- 2
|
32
|
+
version: 2.3.2
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: nokogiri
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
24
39
|
none: false
|
25
40
|
requirements:
|
26
41
|
- - ~>
|
@@ -32,10 +47,10 @@ dependencies:
|
|
32
47
|
version: 1.4.0
|
33
48
|
type: :runtime
|
34
49
|
prerelease: false
|
35
|
-
version_requirements: *
|
50
|
+
version_requirements: *id002
|
36
51
|
- !ruby/object:Gem::Dependency
|
37
52
|
name: curb
|
38
|
-
requirement: &
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
54
|
none: false
|
40
55
|
requirements:
|
41
56
|
- - ~>
|
@@ -47,35 +62,106 @@ dependencies:
|
|
47
62
|
version: 0.7.0
|
48
63
|
type: :runtime
|
49
64
|
prerelease: false
|
50
|
-
version_requirements: *
|
51
|
-
|
52
|
-
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: rake
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: *id004
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: rdiscount
|
81
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *id005
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: rspec
|
94
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - "="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
segments:
|
100
|
+
- 2
|
101
|
+
- 0
|
102
|
+
- 0
|
103
|
+
- rc
|
104
|
+
version: 2.0.0.rc
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: *id006
|
108
|
+
- !ruby/object:Gem::Dependency
|
109
|
+
name: throttler
|
110
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
version: "0"
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: *id007
|
121
|
+
- !ruby/object:Gem::Dependency
|
122
|
+
name: sdoc-helpers
|
123
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
segments:
|
129
|
+
- 0
|
130
|
+
version: "0"
|
131
|
+
type: :development
|
132
|
+
prerelease: false
|
133
|
+
version_requirements: *id008
|
134
|
+
description: A Ruby wrapper to the Amazon Product Advertising API
|
135
|
+
email:
|
136
|
+
- code@papercavalier.com
|
53
137
|
executables: []
|
54
138
|
|
55
139
|
extensions: []
|
56
140
|
|
57
|
-
extra_rdoc_files:
|
58
|
-
|
59
|
-
- README.markdown
|
141
|
+
extra_rdoc_files: []
|
142
|
+
|
60
143
|
files:
|
61
|
-
- LICENSE
|
62
|
-
- README.markdown
|
63
|
-
- lib/sucker.rb
|
64
|
-
- lib/sucker/active_support/core_ext/object/blank.rb
|
65
|
-
- lib/sucker/active_support/xml_mini/nokogiri.rb
|
66
144
|
- lib/sucker/request.rb
|
67
145
|
- lib/sucker/response.rb
|
68
146
|
- lib/sucker/stub.rb
|
147
|
+
- lib/sucker/version.rb
|
148
|
+
- lib/sucker.rb
|
149
|
+
- LICENSE
|
150
|
+
- README.markdown
|
151
|
+
- spec/fixtures/asins.txt
|
69
152
|
- spec/integration/errors_spec.rb
|
70
153
|
- spec/integration/france_spec.rb
|
71
154
|
- spec/integration/images_spec.rb
|
72
155
|
- spec/integration/item_lookup_spec.rb
|
156
|
+
- spec/integration/item_search_spec.rb
|
73
157
|
- spec/integration/japan_spec.rb
|
74
158
|
- spec/integration/related_items_spec.rb
|
75
159
|
- spec/integration/seller_listing_search_spec.rb
|
76
160
|
- spec/integration/twenty_items_in_one_request_spec.rb
|
77
161
|
- spec/spec_helper.rb
|
162
|
+
- spec/support/amazon.yml.example
|
78
163
|
- spec/support/amazon_credentials.rb
|
164
|
+
- spec/support/asins.rb
|
79
165
|
- spec/support/sucker.rb
|
80
166
|
- spec/unit/sucker/request_spec.rb
|
81
167
|
- spec/unit/sucker/response_spec.rb
|
@@ -95,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
181
|
requirements:
|
96
182
|
- - ">="
|
97
183
|
- !ruby/object:Gem::Version
|
98
|
-
hash:
|
184
|
+
hash: -55576138892431507
|
99
185
|
segments:
|
100
186
|
- 0
|
101
187
|
version: "0"
|
@@ -105,26 +191,32 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
191
|
- - ">="
|
106
192
|
- !ruby/object:Gem::Version
|
107
193
|
segments:
|
108
|
-
-
|
109
|
-
|
194
|
+
- 1
|
195
|
+
- 3
|
196
|
+
- 7
|
197
|
+
version: 1.3.7
|
110
198
|
requirements: []
|
111
199
|
|
112
200
|
rubyforge_project:
|
113
201
|
rubygems_version: 1.3.7
|
114
202
|
signing_key:
|
115
203
|
specification_version: 3
|
116
|
-
summary: A
|
204
|
+
summary: A Ruby wrapper to the Amazon Product Advertising API
|
117
205
|
test_files:
|
206
|
+
- spec/fixtures/asins.txt
|
118
207
|
- spec/integration/errors_spec.rb
|
119
208
|
- spec/integration/france_spec.rb
|
120
209
|
- spec/integration/images_spec.rb
|
121
210
|
- spec/integration/item_lookup_spec.rb
|
211
|
+
- spec/integration/item_search_spec.rb
|
122
212
|
- spec/integration/japan_spec.rb
|
123
213
|
- spec/integration/related_items_spec.rb
|
124
214
|
- spec/integration/seller_listing_search_spec.rb
|
125
215
|
- spec/integration/twenty_items_in_one_request_spec.rb
|
126
216
|
- spec/spec_helper.rb
|
217
|
+
- spec/support/amazon.yml.example
|
127
218
|
- spec/support/amazon_credentials.rb
|
219
|
+
- spec/support/asins.rb
|
128
220
|
- spec/support/sucker.rb
|
129
221
|
- spec/unit/sucker/request_spec.rb
|
130
222
|
- spec/unit/sucker/response_spec.rb
|
@@ -1,77 +0,0 @@
|
|
1
|
-
# http://github.com/rails/rails/blob/v3.0.0/activesupport/core_ext/object/blank.rb
|
2
|
-
class Object
|
3
|
-
# An object is blank if it's false, empty, or a whitespace string.
|
4
|
-
# For example, "", " ", +nil+, [], and {} are blank.
|
5
|
-
#
|
6
|
-
# This simplifies:
|
7
|
-
#
|
8
|
-
# if !address.nil? && !address.empty?
|
9
|
-
#
|
10
|
-
# ...to:
|
11
|
-
#
|
12
|
-
# if !address.blank?
|
13
|
-
def blank?
|
14
|
-
respond_to?(:empty?) ? empty? : !self
|
15
|
-
end
|
16
|
-
|
17
|
-
# An object is present if it's not blank.
|
18
|
-
def present?
|
19
|
-
!blank?
|
20
|
-
end
|
21
|
-
|
22
|
-
# Returns object if it's #present? otherwise returns nil.
|
23
|
-
# object.presence is equivalent to object.present? ? object : nil.
|
24
|
-
#
|
25
|
-
# This is handy for any representation of objects where blank is the same
|
26
|
-
# as not present at all. For example, this simplifies a common check for
|
27
|
-
# HTTP POST/query parameters:
|
28
|
-
#
|
29
|
-
# state = params[:state] if params[:state].present?
|
30
|
-
# country = params[:country] if params[:country].present?
|
31
|
-
# region = state || country || 'US'
|
32
|
-
#
|
33
|
-
# ...becomes:
|
34
|
-
#
|
35
|
-
# region = params[:state].presence || params[:country].presence || 'US'
|
36
|
-
def presence
|
37
|
-
self if present?
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
class NilClass #:nodoc:
|
42
|
-
def blank?
|
43
|
-
true
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class FalseClass #:nodoc:
|
48
|
-
def blank?
|
49
|
-
true
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
class TrueClass #:nodoc:
|
54
|
-
def blank?
|
55
|
-
false
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
class Array #:nodoc:
|
60
|
-
alias_method :blank?, :empty?
|
61
|
-
end
|
62
|
-
|
63
|
-
class Hash #:nodoc:
|
64
|
-
alias_method :blank?, :empty?
|
65
|
-
end
|
66
|
-
|
67
|
-
class String #:nodoc:
|
68
|
-
def blank?
|
69
|
-
self !~ /\S/
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
class Numeric #:nodoc:
|
74
|
-
def blank?
|
75
|
-
false
|
76
|
-
end
|
77
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
# http://github.com/rails/rails/blob/v3.0.0/activesupport/lib/active_support/xml_mini/nokogiri.rb
|
2
|
-
module Sucker
|
3
|
-
module ActiveSupport
|
4
|
-
module XmlMini_Nokogiri #:nodoc:
|
5
|
-
extend self
|
6
|
-
|
7
|
-
# Parse an XML Document string or IO into a simple hash using libxml / nokogiri.
|
8
|
-
# data::
|
9
|
-
# XML Document string or IO to parse
|
10
|
-
def parse(data)
|
11
|
-
if !data.respond_to?(:read)
|
12
|
-
data = StringIO.new(data || '')
|
13
|
-
end
|
14
|
-
|
15
|
-
char = data.getc
|
16
|
-
if char.nil?
|
17
|
-
{}
|
18
|
-
else
|
19
|
-
data.ungetc(char)
|
20
|
-
doc = Nokogiri::XML(data)
|
21
|
-
raise doc.errors.first if doc.errors.length > 0
|
22
|
-
doc.to_hash
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
module Conversions #:nodoc:
|
27
|
-
module Document #:nodoc:
|
28
|
-
def to_hash
|
29
|
-
root.to_hash
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
module Node #:nodoc:
|
34
|
-
CONTENT_ROOT = '__content__'.freeze
|
35
|
-
|
36
|
-
# Convert XML document to hash
|
37
|
-
#
|
38
|
-
# hash::
|
39
|
-
# Hash to merge the converted element into.
|
40
|
-
def to_hash(hash={})
|
41
|
-
node_hash = {}
|
42
|
-
|
43
|
-
# Insert node hash into parent hash correctly.
|
44
|
-
case hash[name]
|
45
|
-
when Array then hash[name] << node_hash
|
46
|
-
when Hash then hash[name] = [hash[name], node_hash]
|
47
|
-
when nil then hash[name] = node_hash
|
48
|
-
end
|
49
|
-
|
50
|
-
# Handle child elements
|
51
|
-
children.each do |c|
|
52
|
-
if c.element?
|
53
|
-
c.to_hash(node_hash)
|
54
|
-
elsif c.text? || c.cdata?
|
55
|
-
node_hash[CONTENT_ROOT] ||= ''
|
56
|
-
node_hash[CONTENT_ROOT] << c.content
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# Remove content node if it is blank and there are child tags
|
61
|
-
if node_hash.length > 1 && node_hash[CONTENT_ROOT].blank?
|
62
|
-
node_hash.delete(CONTENT_ROOT)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Handle attributes
|
66
|
-
attribute_nodes.each { |a| node_hash[a.node_name] = a.value }
|
67
|
-
|
68
|
-
hash
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
Nokogiri::XML::Document.send(:include, Conversions::Document)
|
74
|
-
Nokogiri::XML::Node.send(:include, Conversions::Node)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|