sucker 1.2.0 → 1.3.0.pre

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.
Files changed (41) hide show
  1. data/LICENSE +1 -1
  2. data/README.md +45 -20
  3. data/lib/sucker/parameters.rb +11 -7
  4. data/lib/sucker/parameters.rbc +723 -0
  5. data/lib/sucker/request.rb +52 -154
  6. data/lib/sucker/request.rbc +2719 -0
  7. data/lib/sucker/response.rb +14 -36
  8. data/lib/sucker/response.rbc +1307 -0
  9. data/lib/sucker/version.rb +3 -1
  10. data/lib/sucker/version.rbc +130 -0
  11. data/lib/sucker.rb +4 -2
  12. data/lib/sucker.rbc +286 -0
  13. data/spec/fixtures/cassette_library/0394751221.yml +26 -0
  14. data/spec/fixtures/cassette_library/0415246334.yml +26 -0
  15. data/spec/fixtures/cassette_library/0679753354.yml +26 -0
  16. data/spec/fixtures/cassette_library/0816614024-0007218095.yml +26 -0
  17. data/spec/fixtures/cassette_library/0816614024-0143105825.yml +26 -0
  18. data/spec/fixtures/cassette_library/0816614024.yml +26 -0
  19. data/spec/fixtures/cassette_library/482224816x.yml +26 -0
  20. data/spec/fixtures/cassette_library/816614024.yml +151 -0
  21. data/spec/fixtures/cassette_library/a2h6nh4sqyfz4m.yml +26 -0
  22. data/spec/fixtures/cassette_library/a2jyso6w6kep83.yml +26 -0
  23. data/spec/fixtures/cassette_library/author-lacan-or-deleuze-and-not-fiction.yml +26 -0
  24. data/spec/fixtures/cassette_library/b000aspues.yml +26 -0
  25. data/spec/fixtures/cassette_library/deleuze-binding-kindle.yml +26 -0
  26. data/spec/fixtures/cassette_library/deleuze.yml +26 -0
  27. data/spec/fixtures/cassette_library/george-orwell.yml +26 -0
  28. data/spec/fixtures/cassette_library/spec/sucker/request.yml +4 -4
  29. data/spec/fixtures/cassette_library/spec/sucker/response.yml +3 -3
  30. data/spec/spec_helper.rbc +230 -0
  31. data/spec/sucker/parameters_spec.rbc +1476 -0
  32. data/spec/sucker/request_spec.rb +34 -217
  33. data/spec/sucker/request_spec.rbc +2473 -0
  34. data/spec/sucker/response_spec.rb +46 -95
  35. data/spec/sucker/response_spec.rbc +2854 -0
  36. data/spec/sucker_spec.rbc +287 -0
  37. data/spec/support/amazon_credentials.rbc +154 -0
  38. data/spec/support/asins.rbc +335 -0
  39. data/spec/support/vcr.rbc +356 -0
  40. metadata +72 -96
  41. data/CHANGELOG.md +0 -47
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2010 Paper Cavalier
3
+ Copyright (c) 2011 Paper Cavalier
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,59 +1,84 @@
1
1
  Sucker
2
2
  ======
3
3
 
4
- Sucker is a [cURL-](http://github.com/taf2/curb) and [Nokogiri-](http://github.com/rails/rails/blob/master/activesupport/lib/active_support/xml_mini/nokogiri.rb)driven Ruby wrapper to the [Amazon Product Advertising API](https://affiliate-program.amazon.co.uk/gp/advertising/api/detail/main.html).
4
+ Sucker is a [Nokogiri-](http://github.com/rails/rails/blob/master/activesupport/lib/active_support/xml_mini/nokogiri.rb)based Ruby wrapper to the [Amazon Product Advertising API](https://affiliate-program.amazon.co.uk/gp/advertising/api/detail/main.html).
5
5
 
6
6
  It's fast and supports __the entire API__.
7
7
 
8
8
  ![Electrolux](https://github.com/papercavalier/sucker/raw/master/electrolux.jpg)
9
9
 
10
+
11
+ 1.3.0.pre
12
+ ---------
13
+ This release has major changes under the hood.
14
+
15
+ I replaced curb with Net::HTTP to make the library JRuby compatible and edited out some nonessential code. Check [here](http://rdoc.info/github/papercavalier/sucker/master/frames) to see what's left.
16
+
10
17
  Usage
11
18
  -----
12
19
 
13
- Where's your worker?
20
+ Set up.
14
21
 
15
22
  worker = Sucker.new(
16
23
  :locale => :us,
17
- :key => "API KEY",
18
- :secret => "API SECRET")
24
+ :key => 'API KEY',
25
+ :secret => 'API SECRET')
19
26
 
20
- Build a query.
27
+ Build a request.
21
28
 
22
29
  worker << {
23
- "Operation" => "ItemLookup",
24
- "IdType" => "ASIN",
25
- "ItemId" => some_asins,
26
- "ResponseGroup" => "ItemAttributes" }
30
+ "Operation" => 'ItemLookup',
31
+ "IdType" => 'ASIN',
32
+ "ItemId" => '0816614024',
33
+ "ResponseGroup" => 'ItemAttributes' }
27
34
 
28
35
  Get a response.
29
36
 
30
37
  response = worker.get
31
38
 
32
- Parse.
39
+ Consume.
33
40
 
34
- books = response.map("Item") do |item|
35
- # parse
36
- end
41
+ items = response.find('Item') if response.valid?
37
42
 
38
43
  Repeat ad infinitum.
39
44
 
40
- [Check the features](http://relishapp.com/papercavalier/sucker) for more detailed examples.
45
+ [Check the features](http://relishapp.com/papercavalier/sucker).
46
+
47
+ [Read the API.](https://affiliate-program.amazon.co.uk/gp/advertising/api/detail/main.html)
48
+
49
+
50
+ Multiple local IPs
51
+ ------------------
41
52
 
42
- Read the source code and dive into the [Amazon API docs](https://affiliate-program.amazon.co.uk/gp/advertising/api/detail/main.html).
53
+ Amazon limits calls to a venue to one per second per IP. If you have
54
+ multiple interfaces set up and want to use all to query Amazon, just do:
55
+
56
+ worker.local_ip = '75.80.85.90'
57
+ worker.get # This request will route through the above IP
58
+
59
+ More concise syntax
60
+ -------------------
61
+
62
+ If you are on Ruby 1.9, try:
63
+
64
+ worker << {
65
+ operation: 'ItemLookup',
66
+ id_type: 'ASIN',
67
+ item_id: '0816614024' }
43
68
 
44
69
  Stubbing
45
70
  --------
46
71
 
47
- Use [VCR](http://github.com/myronmarston/vcr) to stub your requests.
72
+ Use [VCR](http://github.com/myronmarston/vcr).
48
73
 
49
- [This is how my VCR setup looks like](http://github.com/papercavalier/sucker/blob/master/spec/support/vcr.rb).
74
+ Check out [this](http://github.com/papercavalier/sucker/blob/master/spec/support/vcr.rb) and [this](https://github.com/papercavalier/sucker/blob/master/features/step_definitions/sucker_steps.rb).
50
75
 
51
76
  Compatibility
52
77
  -------------
53
78
 
54
- Specs pass against Ruby 1.8.7 and Ruby 1.9.2. Sucker has cURL under the hood, so no JRuby.
79
+ Specs pass against Ruby 1.8.7, Ruby 1.9.2, JRuby 1.5.6, and Rubinius 1.2.1.
55
80
 
56
- Afterword
57
- ---------
81
+ Morale of the story
82
+ -------------------
58
83
 
59
84
  Don't overabstract a spaghetti API.
@@ -1,21 +1,25 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'active_support/inflector'
2
4
 
3
- module Sucker
4
- class Parameters < Hash
5
+ module Sucker #:nodoc:
6
+
7
+ class Parameters < Hash #:nodoc:
5
8
  API_VERSION = '2010-11-01'
6
9
  SERVICE = 'AWSECommerceService'
7
10
 
8
- def initialize #:nodoc
11
+ def initialize
9
12
  self.store 'Service', SERVICE
10
13
  self.store 'Version', API_VERSION
11
14
  self.store 'Timestamp', timestamp
12
15
  end
13
16
 
14
17
  def normalize
15
- inject({}) do |h, kv|
16
- k, v = kv
17
- h[k.to_s.camelize] = v.is_a?(Array) ? v.join(',') : v.to_s
18
- h
18
+ inject({}) do |hash, key_value|
19
+ key, value = key_value
20
+ value = value.is_a?(Array) ? value.join(',') : value.to_s
21
+ hash[key.to_s.camelize] = value
22
+ hash
19
23
  end
20
24
  end
21
25