cafepress_api 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cafepress_api/version.rb +1 -1
- data/lib/cafepress_api.rb +13 -7
- metadata +3 -3
data/lib/cafepress_api.rb
CHANGED
@@ -69,7 +69,9 @@ Or better yet, add the mapping yourself in product_genders.rb and submit it back
|
|
69
69
|
|
70
70
|
# The CafePress API (at the time of this code) doesn't correctly return
|
71
71
|
# product images only for the colors which are available for the product.
|
72
|
-
# as such, I am filtering out "invalid" colors from the productUrl(s)
|
72
|
+
# as such, I am filtering out "invalid" colors from the productUrl(s).
|
73
|
+
# Except in the case where the API returns NO colors... then I am accepting
|
74
|
+
# all images with a color id of "0", whatever that means...
|
73
75
|
valid_color_ids = []
|
74
76
|
product.get_elements('color').each do |color|
|
75
77
|
color_id = color.attributes['id']
|
@@ -88,7 +90,7 @@ Or better yet, add the mapping yourself in product_colors.rb and submit it back
|
|
88
90
|
image_urls = []
|
89
91
|
product.get_elements("productImage").each do |product_image|
|
90
92
|
# only parse if it is a product image for an available color
|
91
|
-
if valid_color_ids.include?(product_image.attributes['colorId'])
|
93
|
+
if valid_color_ids.include?(product_image.attributes['colorId']) || valid_color_ids.length == 0
|
92
94
|
if product_image.attributes['productUrl'].include?('_Front')
|
93
95
|
image_urls << {:color_id => product_image.attributes['colorId'], :url => product_image.attributes['productUrl'], :view => FRONT_PRODUCT_VIEW, :size => product_image.attributes['imageSize']}
|
94
96
|
elsif product_image.attributes['productUrl'].include?('_Back')
|
@@ -100,14 +102,18 @@ Or better yet, add the mapping yourself in product_colors.rb and submit it back
|
|
100
102
|
end
|
101
103
|
end
|
102
104
|
|
103
|
-
#
|
104
|
-
|
105
|
-
default_color_id = product.get_elements("color[@default='true']").first.attributes['id']
|
106
|
-
rescue
|
105
|
+
# For some reason, there are some products without colors...
|
106
|
+
if valid_color_ids.length == 0
|
107
107
|
default_color_id = nil
|
108
|
+
else
|
109
|
+
begin
|
110
|
+
default_color_id = product.get_elements("color[@default='true']").first.attributes['id']
|
111
|
+
rescue
|
112
|
+
# Some products HAVE colors, but don't have any set to default=true
|
113
|
+
default_color_id = nil
|
114
|
+
end
|
108
115
|
end
|
109
116
|
|
110
|
-
|
111
117
|
products << {
|
112
118
|
:name => product.attributes['name'],
|
113
119
|
:default_caption => product.attributes['defaultCaption'],
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cafepress_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Benjamin Lee Smith
|