Module: PageGlimpse

Defined in:
lib/page_glimpse.rb,
lib/page_glimpse/api.rb,
lib/page_glimpse/image.rb,
lib/page_glimpse/exceptions.rb,
lib/page_glimpse/json_parser.rb,
lib/page_glimpse/image_parser.rb

Defined Under Namespace

Classes: API, Exception, Image, ImageParser, InvalidDeveloperKeyError, JsonParser

Class Method Summary collapse

Class Method Details

.developer_key=(key) ⇒ Object

Sets the developer key to use with the requests.



13
14
15
# File 'lib/page_glimpse.rb', line 13

def self.developer_key=(key)
  @@developer_key = key
end

.exist?(url, options = {}) ⇒ Boolean

Returns true if the thumbnail exists on Page Glimpse, false otherwise.

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
# File 'lib/page_glimpse.rb', line 20

def self.exist?(url, options = {})
  options[:url] = url
  response = api.exist?(options)
  response.kind_of?(Array) && response.size == 2 && response[1] == API::THUMBNAIL_EXISTS
rescue RestClient::ResourceNotFound
  return false
rescue RestClient::RequestFailed
  handle_failure($!)
end

.get(url, options = {}) ⇒ Object

Returns the binary data for the thumbnail requested.

Valid options:

size

Sets the size of the graphic to get from Page Glimpse.

Available options are:

small

150x108 px

medium

280x202 px

large

430x310 px

nothumb

Indicates if the thumbnails for the domain root should be displayed. If set to “no”, it will display the not found image, otherwise it will display the thumbnails for root domain page. Default value is “yes”.

root

Indicates if the thumbnails for the domain root should be displayed. If set to “no”, it will display the not found image, otherwise it will display the thumbnails for root domain page. Default value is “yes”.



54
55
56
57
58
59
# File 'lib/page_glimpse.rb', line 54

def self.get(url, options = {})
  options[:url] = url
  exist?(url, options) ? api.thumbnail(options) : nil
rescue RestClient::RequestFailed
  handle_failure($!)
end

.queue(url) ⇒ Object

Instructs Page Glimpse to enqueue the thumbnailing of a specific URL.



64
65
66
67
68
69
# File 'lib/page_glimpse.rb', line 64

def self.queue(url)
  response = api.queue(:url => url)
  response.kind_of?(Array) && response.size == 2 && response[1] == API::QUEUE_SUCCESS
rescue RestClient::RequestFailed
  handle_failure($!)
end