amazon-hacks 0.1.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +8 -1
- data/README.txt +5 -7
- data/lib/amazon-hacks.rb +32 -11
- data/test/test_amazon-hacks.rb +2 -1
- metadata +3 -3
data/History.txt
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
==
|
1
|
+
== 0.5.0 / 2007-01-02
|
2
|
+
|
3
|
+
* More bugs fixed
|
4
|
+
* Major error where chaining transforms didn't work (wrong join char)
|
5
|
+
* Some minor formatting fixes in docs
|
6
|
+
* Changed all bang methods to return self
|
7
|
+
|
8
|
+
== 0.3.0 / 2006-12-04
|
2
9
|
|
3
10
|
* Initial Release
|
4
11
|
* Some URL hacks
|
data/README.txt
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
AmazonHacks
|
2
|
-
by Jacob Harris
|
3
|
-
harrisj@schizopolis.net
|
4
|
-
http://www.nimblecode.com/
|
5
|
-
|
6
|
-
NYC.rb
|
7
|
-
http://www.nycruby.org/
|
2
|
+
by Jacob Harris
|
3
|
+
harrisj@schizopolis.net
|
4
|
+
Blog: http://www.nimblecode.com/
|
5
|
+
NYC.rb: http://www.nycruby.org/
|
8
6
|
|
9
7
|
== DESCRIPTION:
|
10
8
|
|
@@ -14,7 +12,7 @@ and Images. This is mainly useful if you find yourself creating a site where you
|
|
14
12
|
might link to Amazon product pages and display images for them. Examples of this
|
15
13
|
might include:
|
16
14
|
|
17
|
-
* Social consumption sites like http://www.allconsuming.net/
|
15
|
+
* Social consumption sites like {All Consuming}[http://www.allconsuming.net/]
|
18
16
|
* Blogs or tumbleblogs with book/music/etc. reviews
|
19
17
|
* Normalizing Amazon links or create associate IDs
|
20
18
|
|
data/lib/amazon-hacks.rb
CHANGED
@@ -3,7 +3,7 @@ require 'uri'
|
|
3
3
|
require 'color'
|
4
4
|
|
5
5
|
class AmazonHacks
|
6
|
-
VERSION = '0.
|
6
|
+
VERSION = '0.5.0'
|
7
7
|
end
|
8
8
|
|
9
9
|
module Amazon
|
@@ -27,7 +27,7 @@ module Amazon
|
|
27
27
|
##
|
28
28
|
# The countries module is a convenience mixin to retrieve the correct
|
29
29
|
# server, etc. for an Image or Link. This module requires the class to
|
30
|
-
# include a
|
30
|
+
# include a @country instance variable.
|
31
31
|
module Countries
|
32
32
|
|
33
33
|
##
|
@@ -155,20 +155,29 @@ module Amazon
|
|
155
155
|
c[0] unless c.nil? #.country unless c.nil?
|
156
156
|
end
|
157
157
|
|
158
|
+
##
|
159
|
+
# Returns a normalized URL for the product with an Amazon Associate ID
|
160
|
+
# appended to it.
|
158
161
|
def associate_url(assoc_id)
|
159
162
|
normalize + "/#{assoc_id}"
|
160
163
|
end
|
161
164
|
|
165
|
+
##
|
166
|
+
# Like #normalize, but changes the internal url
|
162
167
|
def normalize!
|
163
168
|
u = normalize
|
164
169
|
@url = URI.parse(u)
|
165
170
|
self
|
166
171
|
end
|
167
172
|
|
173
|
+
##
|
174
|
+
# Returns the saved URL
|
168
175
|
def url
|
169
176
|
@url.to_s
|
170
177
|
end
|
171
178
|
|
179
|
+
##
|
180
|
+
# The to_s method returns the internal URL.
|
172
181
|
alias :to_s :url
|
173
182
|
end
|
174
183
|
end
|
@@ -250,16 +259,18 @@ module Amazon
|
|
250
259
|
# if you can handle some variation.
|
251
260
|
def set_size!(size)
|
252
261
|
@transforms << SIZES[size]
|
262
|
+
self
|
253
263
|
end
|
254
264
|
|
255
265
|
##
|
256
|
-
# Add a simple shadow to the left or right; takes arguments
|
257
|
-
#
|
266
|
+
# Add a simple shadow to the left or right; takes arguments :left or
|
267
|
+
# :right.
|
258
268
|
def add_shadow! (side)
|
259
269
|
case
|
260
270
|
when side == :left then @transforms << "PB"
|
261
271
|
when side == :right then @transforms << "PC"
|
262
272
|
end
|
273
|
+
self
|
263
274
|
end
|
264
275
|
|
265
276
|
##
|
@@ -273,6 +284,7 @@ module Amazon
|
|
273
284
|
# blur the sharpness of the shadow's edge
|
274
285
|
def add_custom_shadow! (size, xoff, yoff, fuzz)
|
275
286
|
@transforms << "PA#{size},#{xoff},#{yoff},#{fuzz}"
|
287
|
+
self
|
276
288
|
end
|
277
289
|
|
278
290
|
##
|
@@ -286,6 +298,7 @@ module Amazon
|
|
286
298
|
cmd = "BO#{width},"
|
287
299
|
cmd << [color.r, color.g, color.b].map {|c| (c*255).to_i }.join(",")
|
288
300
|
@transforms << cmd
|
301
|
+
self
|
289
302
|
end
|
290
303
|
|
291
304
|
##
|
@@ -300,6 +313,7 @@ module Amazon
|
|
300
313
|
# so you should consider using a size adjustment after rotation."
|
301
314
|
def tilt! (degrees)
|
302
315
|
@transforms << "PT#{degrees}"
|
316
|
+
self
|
303
317
|
end
|
304
318
|
|
305
319
|
##
|
@@ -307,6 +321,7 @@ module Amazon
|
|
307
321
|
# essential thing to know is the higher the value, the blurrier it gets.
|
308
322
|
def blur! (radius)
|
309
323
|
@transforms << "BL#{radius}"
|
324
|
+
self
|
310
325
|
end
|
311
326
|
|
312
327
|
##
|
@@ -314,6 +329,7 @@ module Amazon
|
|
314
329
|
# affect color and increase noise significantly.
|
315
330
|
def sharpen! (percent)
|
316
331
|
@transforms << "SH#{percent}"
|
332
|
+
self
|
317
333
|
end
|
318
334
|
|
319
335
|
##
|
@@ -328,6 +344,7 @@ module Amazon
|
|
328
344
|
# proportionally scaled.
|
329
345
|
def scale!(type, size)
|
330
346
|
@transforms << "#{SCALE_TYPES[type]}#{size}"
|
347
|
+
self
|
331
348
|
end
|
332
349
|
|
333
350
|
##
|
@@ -342,6 +359,7 @@ module Amazon
|
|
342
359
|
# * +height+ - height of crop square
|
343
360
|
def crop! (xoff, yoff, width, height)
|
344
361
|
@transforms << "CR#{xoff},#{yoff},#{width},#{height}"
|
362
|
+
self
|
345
363
|
end
|
346
364
|
|
347
365
|
##
|
@@ -355,14 +373,14 @@ module Amazon
|
|
355
373
|
# * +width+ - width of the text box
|
356
374
|
# * +height+ - height of the text box in pixels
|
357
375
|
# * +font+ - four options are allowed:
|
358
|
-
# *
|
359
|
-
# *
|
360
|
-
# *
|
361
|
-
# *
|
362
|
-
# *
|
376
|
+
# * :times - Times Roman
|
377
|
+
# * :arial - Arial
|
378
|
+
# * :arialbi - Arial Bold Italic
|
379
|
+
# * :verdanab - Verdana Bold
|
380
|
+
# * :advc128d - barcode font
|
363
381
|
# * +size+ - font size (points?)
|
364
382
|
# * +color+ - a color specified in HTML style (eg, "#CCEECC")
|
365
|
-
# * +align+ - may be
|
383
|
+
# * +align+ - may be :left or :center only, defaults to :left
|
366
384
|
def add_text! (text, xoff, yoff, width, height, font, size, html_color, align=:left)
|
367
385
|
color = Color::RGB.from_html(html_color)
|
368
386
|
cmd = (align == :center) ? "ZC" : "ZA"
|
@@ -370,6 +388,7 @@ module Amazon
|
|
370
388
|
[color.r, color.g, color.b].map {|c| (c*255).to_i }
|
371
389
|
cmd << parts.join(",")
|
372
390
|
@transforms << cmd
|
391
|
+
self
|
373
392
|
end
|
374
393
|
|
375
394
|
##
|
@@ -384,6 +403,7 @@ module Amazon
|
|
384
403
|
# * +intensity+ - I really don't know what this means, but more is bigger
|
385
404
|
def highlight!(xoff, yoff, width, height, intensity)
|
386
405
|
@transforms << "HL#{xoff},#{yoff},#{width},#{height},#{intensity}"
|
406
|
+
self
|
387
407
|
end
|
388
408
|
|
389
409
|
##
|
@@ -392,6 +412,7 @@ module Amazon
|
|
392
412
|
# the transforms and revert to the original image, this command does that.
|
393
413
|
def reset_transforms!
|
394
414
|
@transforms = []
|
415
|
+
self
|
395
416
|
end
|
396
417
|
|
397
418
|
##
|
@@ -400,7 +421,7 @@ module Amazon
|
|
400
421
|
url = "http://#{country_imghost}/images/P/#{asin}"
|
401
422
|
url << "." << country_imgcode << "."
|
402
423
|
|
403
|
-
url << "_" << @transforms.join("
|
424
|
+
url << "_" << @transforms.join("_") << "_" << ".jpg"
|
404
425
|
end
|
405
426
|
|
406
427
|
##
|
data/test/test_amazon-hacks.rb
CHANGED
@@ -152,7 +152,8 @@ module TestAmazon
|
|
152
152
|
def test_chain_transforms
|
153
153
|
@img.set_size! :small
|
154
154
|
@img.blur! 87
|
155
|
-
|
155
|
+
@img.tilt! 23
|
156
|
+
assert_equal("#{URL_PREFIX}_SCTZZZZZZZ_BL87_PT23_.jpg", @img.url)
|
156
157
|
end
|
157
158
|
end
|
158
159
|
end
|
metadata
CHANGED
@@ -3,15 +3,15 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: amazon-hacks
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date:
|
6
|
+
version: 0.5.0
|
7
|
+
date: 2007-01-02 00:00:00 -05:00
|
8
8
|
summary: A collection of useful snippets against the Amazon website
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: harrisj@schizopolis.net
|
12
12
|
homepage: http://www.nimblecode.com/code/AmazonHacks
|
13
13
|
rubyforge_project: amazon-hacks
|
14
|
-
description: "
|
14
|
+
description: "Mainly the product of messing around, this gem comprises Ruby code for a few useful \"Amazon Hacks\" -- common techniques for manipulating Amazon product URLs and Images. This is mainly useful if you find yourself creating a site where you might link to Amazon product pages and display images for them. Examples of this might include: * Social consumption sites like {All Consuming}[http://www.allconsuming.net/] * Blogs or tumbleblogs with book/music/etc. reviews * Normalizing Amazon links or create associate IDs This GEM is NOT related to using the Amazon Web Services and there is already an excellent gem for that if you need more heavy-duty use of the Amazon website (this gem does not even communicate with Amazon at all). Also, note this gem is meant in the spirit of fun hackery. You can use it to create interesting images from Amazon on demand, but if you are going to use it on a serious website, please consider caching and attributing that image to Amazon (I also have no idea what the official legal policy for using Amazon's book images is). And of course, do not even consider using this for fraud. It is possible to generate \"20% off\" or \"Look Inside!\" badges on Amazon images, but this gem does not support that since I can not think of any reason why outside sites would use that. == FEATURES/PROBLEMS:"
|
15
15
|
autorequire:
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|