sucker 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -63,8 +63,3 @@ Notes
63
63
  * The unit specs should run out of the box after you `bundle install`, but the integration specs require you to create [an amazon.yml file with valid credentials](http://github.com/papercavalier/sucker/blob/master/spec/support/amazon.yml.example) in `spec/support`.
64
64
 
65
65
  * Version 0.6.0 now has Active Support's Nokogiri-based `to_hash` under the hood. After some meddling, it does what it's supposed to do and is blazing fast. Fix up your code accordingly.
66
-
67
- user system total real
68
- Crack 0.830000 0.010000 0.840000 ( 0.871951)
69
- SimpleXml 2.470000 0.050000 2.520000 ( 2.560045)
70
- AS + Nokogiri 0.440000 0.010000 0.450000 ( 0.450201)
@@ -1,6 +1,7 @@
1
+ require "active_support/xml_mini/nokogiri"
1
2
  require "cgi"
2
3
  require "curb"
3
- require "active_support/xml_mini/nokogiri"
4
+ require 'digest/md5'
4
5
  require "sucker/request"
5
6
  require "sucker/response"
6
7
 
@@ -14,12 +14,7 @@ module Sucker
14
14
  def stub(request)
15
15
  request.instance_eval do
16
16
  self.class.send :define_method, :fixture do
17
- filename = parameters.
18
- values.
19
- flatten.
20
- join.
21
- gsub(/(?:[aeiou13579]|[^\w])+/i, '')[0, 251]
22
-
17
+ filename = Digest::MD5.hexdigest(parameters.values.flatten.join)
23
18
  "#{Sucker.fixtures_path}/#{filename}.xml"
24
19
  end
25
20
 
@@ -4,13 +4,13 @@ require "benchmark"
4
4
  require "crack/xml"
5
5
  require "xmlsimple"
6
6
 
7
- @worker = Sucker.new(
7
+ worker = Sucker.new(
8
8
  :locale => "us",
9
9
  :key => amazon["key"],
10
10
  :secret => amazon["secret"])
11
11
 
12
12
  # Prep worker
13
- @worker << {
13
+ worker << {
14
14
  "Operation" => "ItemLookup",
15
15
  "ItemLookup.Shared.IdType" => "ASIN",
16
16
  "ItemLookup.Shared.Condition" => "All",
@@ -18,20 +18,20 @@ require "xmlsimple"
18
18
  "ItemLookup.Shared.ResponseGroup" => "OfferFull" }
19
19
 
20
20
  # Push twenty ASINs to worker
21
- @asins = %w{
21
+ asins = %w{
22
22
  0816614024 0143105825 0485113600 0816616779 0942299078
23
23
  0816614008 144006654X 0486400360 0486417670 087220474X
24
24
  0486454398 0268018359 1604246014 184467598X 0312427182
25
25
  1844674282 0745640974 0745646441 0826489540 1844672972 }
26
- @worker << {
27
- "ItemLookup.1.ItemId" => @asins[0, 10],
28
- "ItemLookup.2.ItemId" => @asins[10, 10] }
26
+ worker << {
27
+ "ItemLookup.1.ItemId" => asins[0, 10],
28
+ "ItemLookup.2.ItemId" => asins[10, 10] }
29
29
 
30
- Sucker.stub(@worker)
30
+ Sucker.stub(worker)
31
31
 
32
- response = @worker.get
32
+ response = worker.get
33
33
 
34
- Benchmark.bm(20) do |x|
34
+ Benchmark.bm(100) do |x|
35
35
  x.report("Crack") { Crack::XML.parse(response.body) }
36
36
  x.report("SimpleXml") { XmlSimple.xml_in(response.body, { "ForceArray" => false }) }
37
37
  x.report("AS + Nokogiri") { response.to_h }
@@ -9,8 +9,9 @@ module Sucker
9
9
  :secret => amazon["secret"])
10
10
 
11
11
  @worker << {
12
- "Operation" => "ItemLookup",
13
- "IdType" => "ASIN" }
12
+ "Operation" => "ItemLookup",
13
+ "IdType" => "ASIN",
14
+ "ResponseGroup" => ["ItemAttributes", "OfferFull"] }
14
15
 
15
16
  Sucker.stub(@worker)
16
17
  end
@@ -42,31 +42,8 @@ module Sucker
42
42
 
43
43
  context "defines:" do
44
44
  context "#fixture" do
45
- it "ignores odd numbers" do
46
- @worker << { "Foo" => "13579" }
47
- @worker.fixture.should_not match /[^\/]*[13579][^\/]*xml$/
48
- end
49
-
50
- it "does not ignore odd numbers" do
51
- @worker << { "Foo" => "24680" }
52
- (0..8).step(2) do |odd_no|
53
- @worker.fixture.should match Regexp.new(odd_no.to_s)
54
- end
55
- end
56
-
57
- it "ignores vowels" do
58
- @worker << { "Foo" => "aeiou" }
59
- @worker.fixture.should_not match /[^\/]*[aeiou][^\/]*xml$/
60
- end
61
-
62
- it "does not ignore consonants" do
63
- @worker << { "Foo" => ("a".."z").to_a.join }
64
- @worker.fixture.should include(("a".."z").to_a.join.gsub(/[aeiou]/, ""))
65
- end
66
-
67
- it "ignores non-alphanumeric characters" do
68
- @worker << { "Foo" => ";+*&!~" }
69
- @worker.fixture.should_not match /[;+*&!~]/
45
+ it "generates a path for the fixture" do
46
+ @worker.fixture.should match /.*\/[0-9a-f]{32}\.xml$/
70
47
  end
71
48
  end
72
49
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sucker
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 0
10
- version: 0.6.0
9
+ - 1
10
+ version: 0.6.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Hakan Ensari
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-08-02 00:00:00 +01:00
19
+ date: 2010-08-03 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency