sucker 1.2.0 → 1.3.0.pre

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,160 +1,111 @@
1
1
  # encoding: utf-8
2
- require "spec_helper"
2
+
3
+ require 'spec_helper'
3
4
 
4
5
  module Sucker
5
6
  describe Response do
6
- use_vcr_cassette "spec/sucker/response", :record => :new_episodes
7
+ use_vcr_cassette 'spec/sucker/response', :record => :new_episodes
7
8
 
8
- let(:asins) { ["0816614024", "0143105825"] }
9
+ let(:asins) { ['0816614024', '0143105825'] }
9
10
 
10
11
  let(:response) do
11
12
  worker = Sucker.new(
12
- :locale => "us",
13
- :key => amazon["key"],
14
- :secret => amazon["secret"])
13
+ :locale => :us,
14
+ :key => amazon['key'],
15
+ :secret => amazon['secret'])
15
16
  worker << {
16
- "Operation" => "ItemLookup",
17
- "IdType" => "ASIN",
18
- "ItemId" => asins }
17
+ 'Operation' => 'ItemLookup',
18
+ 'IdType' => 'ASIN',
19
+ 'ItemId' => asins }
19
20
  worker.get
20
21
  end
21
22
 
22
- describe ".new" do
23
- it "initializes the response body" do
23
+ describe '.new' do
24
+ it 'initializes the response body' do
24
25
  response.body.should be_an_instance_of String
25
26
  end
26
27
 
27
- it "initializes the response code" do
28
- response.code.should == 200
29
- end
30
-
31
- it "initializes the response time" do
32
- response.time.should be_an_instance_of Float
33
- end
34
-
35
- it "initializes the request URI" do
36
- response.uri.should be_an_instance_of String
28
+ it 'initializes the response code' do
29
+ response.code.should == '200'
37
30
  end
38
31
  end
39
32
 
40
- describe "#each" do
41
- context "when a block is given" do
42
- it "yields each match to a block" do
43
- has_yielded = false
44
-
45
- response.each("ItemAttributes") do |item|
46
- has_yielded = true
47
- item.should be_an_instance_of Hash
48
- end
49
-
50
- has_yielded.should be_true
51
- end
52
- end
53
-
54
- context "when no block is given" do
55
- it "raises error" do
56
- expect do
57
- response.each("ItemAttributes")
58
- end.to raise_error(LocalJumpError)
59
- end
60
- end
61
- end
62
-
63
- context "when response contains errors" do
33
+ context 'when response contains errors' do
64
34
  before do
65
35
  response.body = "<?xml version=\"1.0\" ?><ItemLookupResponse xmlns=\"http://webservices.amazon.com/AWSECommerceService/2010-09-01\"><Errors><Error>foo</Error><Error>bar</Error></Errors>"
66
36
  end
67
37
 
68
- describe "#errors" do
69
- it "returns an array of errors" do
38
+ describe '#errors' do
39
+ it 'returns an array of errors' do
70
40
  response.errors.count.should eql 2
71
41
  end
72
42
  end
73
43
 
74
- describe "#has_errors?" do
75
- it "returns true if the response has errors" do
44
+ describe '#has_errors?' do
45
+ it 'returns true if the response has errors' do
76
46
  response.should have_errors
77
47
  end
78
48
  end
79
49
  end
80
50
 
81
- describe "#find" do
82
- context "when there are matches" do
83
-
84
- it "returns an array of matching nodes" do
85
- response.find("ASIN").should eql asins
51
+ describe '#find' do
52
+ context 'when there are matches' do
53
+ it 'returns an array of matching nodes' do
54
+ response.find('ASIN').should eql asins
86
55
  end
87
56
  end
88
57
 
89
- context "when there are no matches" do
90
- it "returns an empty array" do
91
- node = response.find("Foo")
58
+ context 'when there are no matches' do
59
+ it 'returns an empty array' do
60
+ node = response.find('Foo')
92
61
  node.should eql []
93
62
  end
94
63
  end
95
64
  end
96
65
 
97
- describe "#map" do
98
- context "when a block is given" do
99
- it "yields each match to a block and maps returned values" do
100
- titles = response.map("ItemAttributes") { |item| item["Title"] }
101
-
102
- titles.count.should eql 2
103
- end
104
- end
105
-
106
- context "when no block is given" do
107
- it "raises error" do
108
- expect do
109
- response.map("ItemAttributes")
110
- end.to raise_error(LocalJumpError)
111
- end
112
- end
113
- end
114
-
115
- describe "#to_hash" do
116
- it "returns a hash" do
66
+ describe '#to_hash' do
67
+ it 'returns a hash' do
117
68
  response.to_hash.should be_an_instance_of Hash
118
69
  end
119
70
 
120
- it "converts a content hash to string" do
121
- response.body = "<book><title>A Thousand Plateaus</title></book>"
122
- response.to_hash["book"]["title"].should be_an_instance_of String
71
+ it 'converts a content hash to string' do
72
+ response.body = '<book><title>A Thousand Plateaus</title></book>'
73
+ response.to_hash['book']['title'].should be_an_instance_of String
123
74
  end
124
75
 
125
- it "renders French" do
76
+ it 'renders French' do
126
77
  response.body = "<Title>L'archéologie du savoir</Title>"
127
- response.to_hash["Title"].should eql "L'archéologie du savoir"
78
+ response.to_hash['Title'].should eql "L'archéologie du savoir"
128
79
  end
129
80
 
130
- it "renders German" do
131
- response.body = "<Title>Kafka: Für eine kleine Literatur</Title>"
132
- response.to_hash["Title"].should eql "Kafka: Für eine kleine Literatur"
81
+ it 'renders German' do
82
+ response.body = '<Title>Kafka: Für eine kleine Literatur</Title>'
83
+ response.to_hash['Title'].should eql 'Kafka: Für eine kleine Literatur'
133
84
  end
134
85
 
135
- it "renders Japanese" do
136
- response.body = "<Title>スティーブ・ジョブズ 驚異のプレゼン―人々を惹きつける18の法則</Title>"
137
- response.to_hash["Title"].should eql "スティーブ・ジョブズ 驚異のプレゼン―人々を惹きつける18の法則"
86
+ it 'renders Japanese' do
87
+ response.body = '<Title>スティーブ・ジョブズ 驚異のプレゼン―人々を惹きつける18の法則</Title>'
88
+ response.to_hash['Title'].should eql 'スティーブ・ジョブズ 驚異のプレゼン―人々を惹きつける18の法則'
138
89
  end
139
90
  end
140
91
 
141
- describe "#valid?" do
142
- context "when HTTP status is OK" do
143
- it "returns true" do
92
+ describe '#valid?' do
93
+ context 'when HTTP status is OK' do
94
+ it 'returns true' do
144
95
  response.should be_valid
145
96
  end
146
97
  end
147
98
 
148
- context "when HTTP status is not OK" do
149
- it "returns false" do
99
+ context 'when HTTP status is not OK' do
100
+ it 'returns false' do
150
101
  response.code = 403
151
102
  response.should_not be_valid
152
103
  end
153
104
  end
154
105
  end
155
106
 
156
- describe "#xml" do
157
- it "returns a Nokogiri document" do
107
+ describe '#xml' do
108
+ it 'returns a Nokogiri document' do
158
109
  response.xml.should be_an_instance_of Nokogiri::XML::Document
159
110
  end
160
111
  end