Class: Simplificator::Webthumb::Easythumb
- Inherits:
-
Object
- Object
- Simplificator::Webthumb::Easythumb
- Defined in:
- lib/rwebthumb/easythumb.rb
Constant Summary collapse
- VALID_SIZES =
[:small, :medium, :medium2, :large]
Instance Method Summary collapse
-
#build_url(options = {}) ⇒ Object
Build an Easythumb URL options are url: the url to take a snapshot from.
-
#initialize(api_key, user_id, api_endpoint = 'http://webthumb.bluga.net/easythumb.php') ⇒ Easythumb
constructor
A new instance of Easythumb.
Constructor Details
#initialize(api_key, user_id, api_endpoint = 'http://webthumb.bluga.net/easythumb.php') ⇒ Easythumb
Returns a new instance of Easythumb.
7 8 9 10 11 |
# File 'lib/rwebthumb/easythumb.rb', line 7 def initialize(api_key, user_id, api_endpoint = 'http://webthumb.bluga.net/easythumb.php') @api_key = api_key @user_id = user_id @api_endpoint = api_endpoint end |
Instance Method Details
#build_url(options = {}) ⇒ Object
Build an Easythumb URL options are
url: the url to take a snapshot from. required.
size: the size of the thumbnail to take (VALID_SIZES). Defaults to :medium
cache: the maximum allowed age in the cache (1-30). Defaults to 15
18 19 20 21 22 23 24 |
# File 'lib/rwebthumb/easythumb.rb', line 18 def build_url( = {}) raise WebthumbException.new(':url is required') if ([:url] == nil || [:url] == '') [:size] ||= :medium [:cache] ||= 15 hash_out = Digest::MD5.hexdigest("#{Time.now.strftime('%Y%m%d')}#{[:url]}#{@api_key}") "#{@api_endpoint}?user=#{@user_id}&cache=#{[:cache]}&size=#{[:size]}&url=#{CGI.escape([:url])}&hash=#{hash_out}" end |