handcrafted-a2ws 0.1.8 → 0.1.9
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/VERSION.yml +1 -1
- data/a2ws.gemspec +1 -1
- data/lib/a2ws/base.rb +2 -2
- data/lib/a2ws/image.rb +2 -1
- data/lib/a2ws/image_search.rb +10 -11
- data/lib/a2ws/item.rb +1 -11
- data/lib/a2ws/item_search.rb +3 -8
- data/lib/a2ws/methodize.rb +6 -0
- metadata +1 -1
data/VERSION.yml
CHANGED
data/a2ws.gemspec
CHANGED
data/lib/a2ws/base.rb
CHANGED
@@ -14,7 +14,7 @@ module A2WS
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
def downcase_keys(hash)
|
17
|
+
def self.downcase_keys(hash)
|
18
18
|
new_hash = {}
|
19
19
|
hash.keys.each do |key|
|
20
20
|
value = hash.delete(key)
|
@@ -25,7 +25,7 @@ module A2WS
|
|
25
25
|
new_hash
|
26
26
|
end
|
27
27
|
|
28
|
-
def downcase_key(key)
|
28
|
+
def self.downcase_key(key)
|
29
29
|
key.titlecase.downcase.gsub(' ', '_')
|
30
30
|
end
|
31
31
|
|
data/lib/a2ws/image.rb
CHANGED
data/lib/a2ws/image_search.rb
CHANGED
@@ -2,18 +2,17 @@ module A2WS
|
|
2
2
|
|
3
3
|
|
4
4
|
class ImageSearch < Base
|
5
|
-
attr_accessor :item_id
|
6
5
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
def self.find(item)
|
7
|
+
items = get('/onca/xml', :query => {:ItemId => item, :Operation => "ItemLookup", :ResponseGroup => "Images"})
|
8
|
+
puts items.inspect
|
9
|
+
if items['ItemLookupResponse']["Items"]["Request"]['IsValid'] == 'True'
|
10
|
+
items["ItemLookupResponse"]["Items"]["Item"].delete("ImageSets")
|
11
|
+
items["ItemLookupResponse"]["Items"]["Item"].delete("ASIN")
|
12
|
+
downcase_keys(items["ItemLookupResponse"]["Items"]["Item"]).collect { |size, data| Image.new(size, data) }
|
13
|
+
else
|
14
|
+
raise items['Request']['Errors']['Error']['Message']
|
15
|
+
end
|
17
16
|
end
|
18
17
|
|
19
18
|
end
|
data/lib/a2ws/item.rb
CHANGED
@@ -2,31 +2,21 @@ module A2WS
|
|
2
2
|
|
3
3
|
|
4
4
|
class Item
|
5
|
-
attr_accessor :data_hash
|
6
5
|
include Methodize
|
7
6
|
|
8
|
-
def initialize(item)
|
9
|
-
@data_hash = item
|
10
|
-
end
|
11
|
-
|
12
7
|
def item_attributes
|
13
8
|
ItemAttributes.new @data_hash["item_attributes"]
|
14
9
|
end
|
15
10
|
|
16
11
|
def images
|
17
|
-
ImageSearch.
|
12
|
+
ImageSearch.find(@data_hash["asin"])
|
18
13
|
end
|
19
14
|
|
20
15
|
end
|
21
16
|
|
22
17
|
class ItemAttributes
|
23
|
-
attr_accessor :data_hash
|
24
18
|
include Methodize
|
25
19
|
|
26
|
-
def initialize(item_attributes)
|
27
|
-
@data_hash = item_attributes
|
28
|
-
end
|
29
|
-
|
30
20
|
end
|
31
21
|
|
32
22
|
|
data/lib/a2ws/item_search.rb
CHANGED
@@ -1,15 +1,10 @@
|
|
1
1
|
module A2WS
|
2
2
|
|
3
3
|
class ItemSearch < Base
|
4
|
-
attr_accessor :search_index
|
5
4
|
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def find(keywords, options = {})
|
11
|
-
options.merge!({:Keywords => keywords, :SearchIndex => @search_index})
|
12
|
-
result = self.class.get('/onca/xml', :query => options)
|
5
|
+
def self.find(keywords, search_index = :All, options = {})
|
6
|
+
options.merge!({:Keywords => keywords, :SearchIndex => search_index})
|
7
|
+
result = get('/onca/xml', :query => options)
|
13
8
|
|
14
9
|
items = result["ItemSearchResponse"]["Items"]
|
15
10
|
if items['Request']['IsValid'] == 'True'
|
data/lib/a2ws/methodize.rb
CHANGED