cafepress_api 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,5 +15,5 @@
15
15
  # along with CafePressAPI. If not, see <http://www.gnu.org/licenses/>.
16
16
 
17
17
  module CafePressAPI
18
- VERSION = "0.1.3"
18
+ VERSION = "0.1.4"
19
19
  end
data/lib/cafepress_api.rb CHANGED
@@ -66,16 +66,24 @@ Or better yet, add the mapping yourself in product_genders.rb and submit it back
66
66
  %})
67
67
  end
68
68
  end
69
-
69
+
70
+ # The CafePress API (at the time of this code) doesn't correctly return
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)
73
+ valid_color_ids = product.get_elements('color').map{|color| color.attributes['id']}
74
+
70
75
  image_urls = []
71
76
  product.get_elements("productImage").each do |product_image|
72
- if product_image.attributes['productUrl'].include?('_Front')
73
- image_urls << {:color_id => product_image.attributes['colorId'], :url => product_image.attributes['productUrl'], :view => FRONT_PRODUCT_VIEW, :size => product_image.attributes['imageSize']}
74
- elsif product_image.attributes['productUrl'].include?('_Back')
75
- image_urls << {:color_id => product_image.attributes['colorId'], :url => product_image.attributes['productUrl'], :view => BACK_PRODUCT_VIEW, :size => product_image.attributes['imageSize']}
76
- else
77
- warn("\nWARNING: the image url #{product_image.attributes['productUrl']} does not appear to be a front or back image, assuming it is a front image.")
78
- image_urls << {:color_id => product_image.attributes['colorId'], :url => product_image.attributes['productUrl'], :view => FRONT_PRODUCT_VIEW, :size => product_image.attributes['imageSize']}
77
+ # only parse if it is a product image for an available color
78
+ if valid_color_ids.include?(product_image.attributes['colorId'])
79
+ if product_image.attributes['productUrl'].include?('_Front')
80
+ image_urls << {:color_id => product_image.attributes['colorId'], :url => product_image.attributes['productUrl'], :view => FRONT_PRODUCT_VIEW, :size => product_image.attributes['imageSize']}
81
+ elsif product_image.attributes['productUrl'].include?('_Back')
82
+ image_urls << {:color_id => product_image.attributes['colorId'], :url => product_image.attributes['productUrl'], :view => BACK_PRODUCT_VIEW, :size => product_image.attributes['imageSize']}
83
+ else
84
+ warn("\nWARNING: the image url #{product_image.attributes['productUrl']} does not appear to be a front or back image, assuming it is a front image.")
85
+ image_urls << {:color_id => product_image.attributes['colorId'], :url => product_image.attributes['productUrl'], :view => FRONT_PRODUCT_VIEW, :size => product_image.attributes['imageSize']}
86
+ end
79
87
  end
80
88
  end
81
89
 
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: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Benjamin Lee Smith
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-04 00:00:00 -07:00
18
+ date: 2011-03-05 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21