sucker 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +56 -13
- data/lib/sucker.rbc +41 -25
- data/lib/sucker/parameters.rbc +81 -157
- data/lib/sucker/request.rb +4 -39
- data/lib/sucker/request.rbc +1014 -853
- data/lib/sucker/response.rbc +495 -377
- data/lib/sucker/version.rb +1 -1
- data/lib/sucker/version.rbc +9 -9
- data/spec/spec_helper.rbc +5 -5
- data/spec/sucker/parameters_spec.rbc +39 -38
- data/spec/sucker/request_spec.rbc +468 -86
- data/spec/sucker/response_spec.rbc +365 -1142
- data/spec/sucker_spec.rbc +9 -9
- data/spec/support/amazon_credentials.rbc +5 -5
- data/spec/support/asins.rbc +9 -9
- data/spec/support/vcr.rbc +7 -7
- metadata +2 -5
- data/lib/sucker/hash.rbc +0 -914
- data/spec/sucker/hash_spec.rbc +0 -861
data/README.md
CHANGED
@@ -10,47 +10,90 @@ Sucker is fast and supports __the entire Amazon API__.
|
|
10
10
|
Usage
|
11
11
|
-----
|
12
12
|
|
13
|
+
Read the [API](http://aws.amazon.com/archives/Product%20Advertising%20API). Jump to the __Operations__ section if in a hurry.
|
14
|
+
|
13
15
|
Set up.
|
14
16
|
|
15
|
-
worker = Sucker.new
|
17
|
+
worker = Sucker.new \
|
16
18
|
:locale => :us,
|
17
|
-
:key =>
|
18
|
-
:secret =>
|
19
|
+
:key => api_key,
|
20
|
+
:secret => api_secret
|
19
21
|
|
20
22
|
Build a request.
|
21
23
|
|
22
24
|
worker << {
|
23
25
|
'Operation' => 'ItemLookup',
|
24
26
|
'IdType' => 'ASIN',
|
25
|
-
'ItemId' =>
|
27
|
+
'ItemId' => 10.asins,
|
26
28
|
'ResponseGroup' => 'ItemAttributes' }
|
27
29
|
|
28
30
|
Get a response.
|
29
31
|
|
30
32
|
response = worker.get
|
31
33
|
|
32
|
-
|
34
|
+
Fulfill a business value.
|
33
35
|
|
34
|
-
|
36
|
+
if response.valid?
|
37
|
+
response.each('Item') do |item|
|
38
|
+
consume item
|
39
|
+
end
|
40
|
+
end
|
35
41
|
|
36
42
|
Repeat ad infinitum.
|
37
43
|
|
44
|
+
The following are all valid ways to query a response:
|
45
|
+
|
46
|
+
items = response.find('Item')
|
47
|
+
items = response['Item']
|
48
|
+
items = response.map('Item') { |item| ... }
|
49
|
+
response.each('Item') { |item| ... }
|
50
|
+
|
51
|
+
To dig further into the response object:
|
52
|
+
|
53
|
+
p response.valid?,
|
54
|
+
response.body,
|
55
|
+
response.code,
|
56
|
+
response.errors,
|
57
|
+
response.has_errors?,
|
58
|
+
response.to_hash,
|
59
|
+
response.xml
|
60
|
+
|
38
61
|
Read further [here](http://rdoc.info/github/papercavalier/sucker/master/frames) and [here](http://relishapp.com/papercavalier/sucker).
|
39
62
|
|
40
|
-
|
41
|
-
|
63
|
+
API Usage
|
64
|
+
---------
|
65
|
+
|
66
|
+
I have a growing cottage industry of gems we use to manage our
|
67
|
+
consumption of the Amazon API.
|
68
|
+
|
69
|
+
* [Multiplex](http://github.com/papercavalier/multiplex) binds a request
|
70
|
+
to a specified local IP.
|
71
|
+
* [Throttler](http://github.com/papercavalier/throttler) throttles
|
72
|
+
requests to a venue to one per second per IP.
|
42
73
|
|
43
|
-
Amazon limits calls to a venue to one per second per IP address.
|
44
74
|
|
45
|
-
|
75
|
+
A hypothetical setup:
|
46
76
|
|
47
|
-
|
77
|
+
require 'multiplex'
|
78
|
+
require 'throttler'
|
79
|
+
|
80
|
+
ips.each do |ip|
|
48
81
|
Thread.new do
|
49
|
-
|
50
|
-
|
82
|
+
scope = "#{ip}-#{locale}"
|
83
|
+
Throttler.throttle(scope) do
|
84
|
+
Net::HTTP.bind ip do
|
85
|
+
# Set up worker
|
86
|
+
response = worker.get
|
87
|
+
# Consume response
|
88
|
+
end
|
89
|
+
end
|
51
90
|
end
|
52
91
|
end
|
53
92
|
|
93
|
+
We prefer to use [Resque](http://github.com/defunkt/resque) to manage
|
94
|
+
multiple requests. Generally, four or five workers per venue per IP
|
95
|
+
should provide optimum throughput.
|
96
|
+
|
54
97
|
Stubbing in Tests
|
55
98
|
-----------------
|
56
99
|
|
data/lib/sucker.rbc
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
!RBIX
|
2
|
-
|
2
|
+
0
|
3
3
|
x
|
4
4
|
M
|
5
5
|
1
|
@@ -9,7 +9,7 @@ x
|
|
9
9
|
10
|
10
10
|
__script__
|
11
11
|
i
|
12
|
-
|
12
|
+
55
|
13
13
|
5
|
14
14
|
7
|
15
15
|
0
|
@@ -28,30 +28,39 @@ i
|
|
28
28
|
1
|
29
29
|
1
|
30
30
|
15
|
31
|
-
|
31
|
+
5
|
32
32
|
7
|
33
33
|
3
|
34
|
-
|
34
|
+
64
|
35
|
+
47
|
35
36
|
49
|
37
|
+
1
|
38
|
+
1
|
39
|
+
15
|
40
|
+
99
|
41
|
+
7
|
36
42
|
4
|
43
|
+
65
|
44
|
+
49
|
45
|
+
5
|
37
46
|
2
|
38
47
|
13
|
39
48
|
99
|
40
49
|
12
|
41
50
|
7
|
42
|
-
|
51
|
+
6
|
43
52
|
12
|
44
53
|
7
|
45
|
-
|
54
|
+
7
|
46
55
|
12
|
47
56
|
65
|
48
57
|
12
|
49
58
|
49
|
50
|
-
|
59
|
+
8
|
51
60
|
4
|
52
61
|
15
|
53
62
|
49
|
54
|
-
|
63
|
+
6
|
55
64
|
0
|
56
65
|
15
|
57
66
|
2
|
@@ -66,14 +75,17 @@ I
|
|
66
75
|
0
|
67
76
|
n
|
68
77
|
p
|
69
|
-
|
78
|
+
9
|
70
79
|
s
|
71
|
-
|
72
|
-
sucker/
|
80
|
+
17
|
81
|
+
sucker/parameters
|
73
82
|
x
|
74
83
|
7
|
75
84
|
require
|
76
85
|
s
|
86
|
+
14
|
87
|
+
sucker/request
|
88
|
+
s
|
77
89
|
15
|
78
90
|
sucker/response
|
79
91
|
x
|
@@ -208,16 +220,16 @@ p
|
|
208
220
|
I
|
209
221
|
-1
|
210
222
|
I
|
211
|
-
|
223
|
+
13
|
212
224
|
I
|
213
225
|
e
|
214
226
|
I
|
215
|
-
|
227
|
+
14
|
216
228
|
I
|
217
229
|
2b
|
218
230
|
x
|
219
|
-
|
220
|
-
/Users/
|
231
|
+
44
|
232
|
+
/Users/hakanensari/code/sucker/lib/sucker.rb
|
221
233
|
p
|
222
234
|
1
|
223
235
|
x
|
@@ -231,35 +243,39 @@ p
|
|
231
243
|
I
|
232
244
|
2
|
233
245
|
I
|
234
|
-
|
246
|
+
13
|
235
247
|
I
|
236
248
|
d
|
237
249
|
x
|
238
|
-
|
239
|
-
/Users/
|
250
|
+
44
|
251
|
+
/Users/hakanensari/code/sucker/lib/sucker.rb
|
240
252
|
p
|
241
253
|
0
|
242
254
|
x
|
243
255
|
13
|
244
256
|
attach_method
|
245
257
|
p
|
246
|
-
|
258
|
+
9
|
247
259
|
I
|
248
260
|
0
|
249
261
|
I
|
250
|
-
|
262
|
+
3
|
251
263
|
I
|
252
264
|
9
|
253
265
|
I
|
254
|
-
|
266
|
+
4
|
255
267
|
I
|
256
268
|
12
|
257
269
|
I
|
258
|
-
|
270
|
+
5
|
271
|
+
I
|
272
|
+
1b
|
259
273
|
I
|
260
|
-
|
274
|
+
a
|
275
|
+
I
|
276
|
+
37
|
261
277
|
x
|
262
|
-
|
263
|
-
/Users/
|
278
|
+
44
|
279
|
+
/Users/hakanensari/code/sucker/lib/sucker.rb
|
264
280
|
p
|
265
281
|
0
|
data/lib/sucker/parameters.rbc
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
!RBIX
|
2
|
-
|
2
|
+
0
|
3
3
|
x
|
4
4
|
M
|
5
5
|
1
|
@@ -9,31 +9,40 @@ x
|
|
9
9
|
10
|
10
10
|
__script__
|
11
11
|
i
|
12
|
-
|
13
|
-
|
12
|
+
37
|
13
|
+
5
|
14
14
|
7
|
15
15
|
0
|
16
|
-
|
16
|
+
64
|
17
|
+
47
|
17
18
|
49
|
18
19
|
1
|
20
|
+
1
|
21
|
+
15
|
22
|
+
99
|
23
|
+
7
|
24
|
+
2
|
25
|
+
65
|
26
|
+
49
|
27
|
+
3
|
19
28
|
2
|
20
29
|
13
|
21
30
|
99
|
22
31
|
12
|
23
32
|
7
|
24
|
-
|
33
|
+
4
|
25
34
|
12
|
26
35
|
7
|
27
|
-
|
36
|
+
5
|
28
37
|
12
|
29
38
|
65
|
30
39
|
12
|
31
40
|
49
|
32
|
-
|
41
|
+
6
|
33
42
|
4
|
34
43
|
15
|
35
44
|
49
|
36
|
-
|
45
|
+
4
|
37
46
|
0
|
38
47
|
15
|
39
48
|
2
|
@@ -48,7 +57,13 @@ I
|
|
48
57
|
0
|
49
58
|
n
|
50
59
|
p
|
51
|
-
|
60
|
+
7
|
61
|
+
s
|
62
|
+
24
|
63
|
+
active_support/inflector
|
64
|
+
x
|
65
|
+
7
|
66
|
+
require
|
52
67
|
x
|
53
68
|
6
|
54
69
|
Sucker
|
@@ -72,30 +87,30 @@ i
|
|
72
87
|
99
|
73
88
|
7
|
74
89
|
0
|
75
|
-
|
76
|
-
43
|
90
|
+
45
|
77
91
|
1
|
92
|
+
2
|
78
93
|
65
|
79
94
|
49
|
80
|
-
|
95
|
+
3
|
81
96
|
3
|
82
97
|
13
|
83
98
|
99
|
84
99
|
12
|
85
100
|
7
|
86
|
-
|
101
|
+
4
|
87
102
|
12
|
88
103
|
7
|
89
|
-
|
104
|
+
5
|
90
105
|
12
|
91
106
|
65
|
92
107
|
12
|
93
108
|
49
|
94
|
-
|
109
|
+
6
|
95
110
|
4
|
96
111
|
15
|
97
112
|
49
|
98
|
-
|
113
|
+
4
|
99
114
|
0
|
100
115
|
11
|
101
116
|
I
|
@@ -108,13 +123,14 @@ I
|
|
108
123
|
0
|
109
124
|
n
|
110
125
|
p
|
111
|
-
|
126
|
+
7
|
112
127
|
x
|
113
128
|
10
|
114
129
|
Parameters
|
115
130
|
x
|
116
131
|
4
|
117
132
|
Hash
|
133
|
+
n
|
118
134
|
x
|
119
135
|
10
|
120
136
|
open_class
|
@@ -308,24 +324,24 @@ p
|
|
308
324
|
I
|
309
325
|
-1
|
310
326
|
I
|
311
|
-
|
327
|
+
b
|
312
328
|
I
|
313
329
|
0
|
314
330
|
I
|
315
|
-
|
331
|
+
c
|
316
332
|
I
|
317
333
|
b
|
318
334
|
I
|
319
|
-
|
335
|
+
d
|
320
336
|
I
|
321
337
|
16
|
322
338
|
I
|
323
|
-
|
339
|
+
e
|
324
340
|
I
|
325
341
|
21
|
326
342
|
x
|
327
|
-
|
328
|
-
/Users/
|
343
|
+
55
|
344
|
+
/Users/hakanensari/code/sucker/lib/sucker/parameters.rb
|
329
345
|
p
|
330
346
|
0
|
331
347
|
x
|
@@ -391,7 +407,7 @@ x
|
|
391
407
|
9
|
392
408
|
normalize
|
393
409
|
i
|
394
|
-
|
410
|
+
75
|
395
411
|
58
|
396
412
|
37
|
397
413
|
19
|
@@ -451,19 +467,8 @@ i
|
|
451
467
|
49
|
452
468
|
5
|
453
469
|
0
|
454
|
-
7
|
455
|
-
6
|
456
|
-
64
|
457
470
|
49
|
458
|
-
|
459
|
-
1
|
460
|
-
56
|
461
|
-
8
|
462
|
-
50
|
463
|
-
9
|
464
|
-
0
|
465
|
-
49
|
466
|
-
4
|
471
|
+
6
|
467
472
|
0
|
468
473
|
20
|
469
474
|
3
|
@@ -471,7 +476,7 @@ i
|
|
471
476
|
18
|
472
477
|
3
|
473
478
|
49
|
474
|
-
|
479
|
+
7
|
475
480
|
2
|
476
481
|
15
|
477
482
|
15
|
@@ -488,7 +493,7 @@ I
|
|
488
493
|
2
|
489
494
|
n
|
490
495
|
p
|
491
|
-
|
496
|
+
8
|
492
497
|
x
|
493
498
|
5
|
494
499
|
Array
|
@@ -505,94 +510,9 @@ join
|
|
505
510
|
x
|
506
511
|
4
|
507
512
|
to_s
|
508
|
-
s
|
509
|
-
1
|
510
|
-
_
|
511
513
|
x
|
512
|
-
5
|
513
|
-
split
|
514
|
-
M
|
515
|
-
1
|
516
|
-
p
|
517
|
-
2
|
518
|
-
x
|
519
|
-
9
|
520
|
-
for_block
|
521
|
-
t
|
522
|
-
n
|
523
|
-
x
|
524
|
-
9
|
525
|
-
normalize
|
526
|
-
i
|
527
|
-
29
|
528
|
-
57
|
529
|
-
19
|
530
|
-
0
|
531
|
-
15
|
532
|
-
20
|
533
|
-
0
|
534
|
-
78
|
535
|
-
79
|
536
|
-
20
|
537
|
-
0
|
538
|
-
78
|
539
|
-
79
|
540
|
-
49
|
541
|
-
0
|
542
|
-
2
|
543
|
-
49
|
544
|
-
1
|
545
|
-
0
|
546
|
-
13
|
547
|
-
18
|
548
|
-
4
|
549
|
-
49
|
550
|
-
2
|
551
|
-
3
|
552
|
-
15
|
553
|
-
15
|
554
|
-
20
|
555
|
-
0
|
556
|
-
11
|
557
|
-
I
|
558
514
|
8
|
559
|
-
|
560
|
-
1
|
561
|
-
I
|
562
|
-
1
|
563
|
-
I
|
564
|
-
1
|
565
|
-
n
|
566
|
-
p
|
567
|
-
3
|
568
|
-
x
|
569
|
-
2
|
570
|
-
[]
|
571
|
-
x
|
572
|
-
6
|
573
|
-
upcase
|
574
|
-
x
|
575
|
-
3
|
576
|
-
[]=
|
577
|
-
p
|
578
|
-
3
|
579
|
-
I
|
580
|
-
0
|
581
|
-
I
|
582
|
-
11
|
583
|
-
I
|
584
|
-
1d
|
585
|
-
x
|
586
|
-
47
|
587
|
-
/Users/snl/code/sucker/lib/sucker/parameters.rb
|
588
|
-
p
|
589
|
-
1
|
590
|
-
x
|
591
|
-
1
|
592
|
-
w
|
593
|
-
x
|
594
|
-
3
|
595
|
-
map
|
515
|
+
camelize
|
596
516
|
x
|
597
517
|
3
|
598
518
|
[]=
|
@@ -601,28 +521,28 @@ p
|
|
601
521
|
I
|
602
522
|
0
|
603
523
|
I
|
604
|
-
|
524
|
+
12
|
605
525
|
I
|
606
526
|
a
|
607
527
|
I
|
608
|
-
|
528
|
+
13
|
609
529
|
I
|
610
530
|
18
|
611
531
|
I
|
612
|
-
|
532
|
+
14
|
613
533
|
I
|
614
534
|
34
|
615
535
|
I
|
616
|
-
|
536
|
+
15
|
617
537
|
I
|
618
|
-
|
538
|
+
48
|
619
539
|
I
|
620
|
-
|
540
|
+
16
|
621
541
|
I
|
622
|
-
|
542
|
+
4b
|
623
543
|
x
|
624
|
-
|
625
|
-
/Users/
|
544
|
+
55
|
545
|
+
/Users/hakanensari/code/sucker/lib/sucker/parameters.rb
|
626
546
|
p
|
627
547
|
4
|
628
548
|
x
|
@@ -645,16 +565,16 @@ p
|
|
645
565
|
I
|
646
566
|
-1
|
647
567
|
I
|
648
|
-
|
568
|
+
11
|
649
569
|
I
|
650
570
|
0
|
651
571
|
I
|
652
|
-
|
572
|
+
12
|
653
573
|
I
|
654
574
|
f
|
655
575
|
x
|
656
|
-
|
657
|
-
/Users/
|
576
|
+
55
|
577
|
+
/Users/hakanensari/code/sucker/lib/sucker/parameters.rb
|
658
578
|
p
|
659
579
|
0
|
660
580
|
x
|
@@ -720,16 +640,16 @@ p
|
|
720
640
|
I
|
721
641
|
-1
|
722
642
|
I
|
723
|
-
|
643
|
+
1c
|
724
644
|
I
|
725
645
|
0
|
726
646
|
I
|
727
|
-
|
647
|
+
1d
|
728
648
|
I
|
729
649
|
10
|
730
650
|
x
|
731
|
-
|
732
|
-
/Users/
|
651
|
+
55
|
652
|
+
/Users/hakanensari/code/sucker/lib/sucker/parameters.rb
|
733
653
|
p
|
734
654
|
0
|
735
655
|
p
|
@@ -737,32 +657,32 @@ p
|
|
737
657
|
I
|
738
658
|
2
|
739
659
|
I
|
740
|
-
|
660
|
+
8
|
741
661
|
I
|
742
662
|
c
|
743
663
|
I
|
744
|
-
|
664
|
+
9
|
745
665
|
I
|
746
666
|
16
|
747
667
|
I
|
748
|
-
|
668
|
+
b
|
749
669
|
I
|
750
670
|
24
|
751
671
|
I
|
752
|
-
|
672
|
+
11
|
753
673
|
I
|
754
674
|
32
|
755
675
|
I
|
756
|
-
|
676
|
+
1a
|
757
677
|
I
|
758
678
|
36
|
759
679
|
I
|
760
|
-
|
680
|
+
1c
|
761
681
|
I
|
762
682
|
44
|
763
683
|
x
|
764
|
-
|
765
|
-
/Users/
|
684
|
+
55
|
685
|
+
/Users/hakanensari/code/sucker/lib/sucker/parameters.rb
|
766
686
|
p
|
767
687
|
0
|
768
688
|
x
|
@@ -773,27 +693,31 @@ p
|
|
773
693
|
I
|
774
694
|
2
|
775
695
|
I
|
776
|
-
|
696
|
+
7
|
777
697
|
I
|
778
698
|
1f
|
779
699
|
x
|
780
|
-
|
781
|
-
/Users/
|
700
|
+
55
|
701
|
+
/Users/hakanensari/code/sucker/lib/sucker/parameters.rb
|
782
702
|
p
|
783
703
|
0
|
784
704
|
x
|
785
705
|
13
|
786
706
|
attach_method
|
787
707
|
p
|
788
|
-
|
708
|
+
5
|
789
709
|
I
|
790
710
|
0
|
791
711
|
I
|
792
|
-
|
712
|
+
3
|
793
713
|
I
|
794
|
-
|
714
|
+
9
|
715
|
+
I
|
716
|
+
5
|
717
|
+
I
|
718
|
+
25
|
795
719
|
x
|
796
|
-
|
797
|
-
/Users/
|
720
|
+
55
|
721
|
+
/Users/hakanensari/code/sucker/lib/sucker/parameters.rb
|
798
722
|
p
|
799
723
|
0
|