Class: Simplificator::Webthumb::Easythumb

Inherits:
Object
  • Object
show all
Defined in:
lib/rwebthumb/easythumb.rb

Constant Summary collapse

VALID_SIZES =
[:small, :medium, :medium2, :large]

Instance Method Summary collapse

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

Raises:



18
19
20
21
22
23
24
# File 'lib/rwebthumb/easythumb.rb', line 18

def build_url(options = {})
  raise WebthumbException.new(':url is required') if (options[:url] == nil || options[:url] == '')
  options[:size] ||= :medium
  options[:cache] ||= 15
  hash_out = Digest::MD5.hexdigest("#{Time.now.strftime('%Y%m%d')}#{options[:url]}#{@api_key}")
  "#{@api_endpoint}?user=#{@user_id}&cache=#{options[:cache]}&size=#{options[:size]}&url=#{CGI.escape(options[:url])}&hash=#{hash_out}"
end