nbibler-page_glimpse 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +38 -3
- data/Rakefile +2 -1
- data/VERSION.yml +1 -1
- data/lib/page_glimpse/api.rb +5 -2
- data/lib/page_glimpse/exceptions.rb +5 -1
- data/lib/page_glimpse/image.rb +5 -0
- data/lib/page_glimpse/image_parser.rb +1 -1
- data/lib/page_glimpse/json_parser.rb +1 -1
- data/lib/page_glimpse.rb +9 -9
- data/page_glimpse.gemspec +2 -1
- data/test/integrations/page_glimpse_test.rb +3 -3
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
=
|
1
|
+
= Page Glimpse
|
2
2
|
|
3
3
|
{PageGlimpse.com}[http://www.pageglimpse.com] is a SaaS provider which has a
|
4
4
|
REST API for downloading website thumbnails by URI. This library wraps that
|
@@ -6,7 +6,42 @@ interface to provide a Ruby-like means of interacting with it.
|
|
6
6
|
|
7
7
|
<b>Note:</b> The author of this gem is entirely unaffiliated with the PageGlimpse.com web service.
|
8
8
|
|
9
|
+
== Getting Started
|
10
|
+
|
11
|
+
The following example shows how to use the PageGlimpse API:
|
12
|
+
|
13
|
+
gem 'page_glimpse'
|
14
|
+
require 'page_glimpse'
|
15
|
+
|
16
|
+
PageGlimpse.developer_key = 'abc123def456ghi789jkl123mno456pq'
|
17
|
+
|
18
|
+
if PageGlimpse.exist?('http://www.github.com')
|
19
|
+
image = PageGlimpse.get('http://www.github.com')
|
20
|
+
puts "Image type: #{image.content_type}" # => "image/jpeg"
|
21
|
+
puts "Image size: #{image.content_length}" # => 2572
|
22
|
+
puts "Image filename: #{image.filename}" # => nil or a name
|
23
|
+
|
24
|
+
# Save the transmitted binary (image.content) as a local file
|
25
|
+
File.open('github.jpg', File::CREAT|File::WRONLY|File::TRUNC) do |file|
|
26
|
+
file.write image.content
|
27
|
+
end
|
28
|
+
else
|
29
|
+
PageGlimpse.queue('http://www.github.com')
|
30
|
+
# and then try back later ...
|
31
|
+
end
|
32
|
+
|
33
|
+
== Contributing
|
34
|
+
|
35
|
+
To contribute to this library, fork it on
|
36
|
+
{GitHub}[http://www.github.com/nbibler/page_glimpse] and follow the
|
37
|
+
{contribution guide}[https://rails.lighthouseapp.com/projects/8994/sending-patches]
|
38
|
+
provided for the Ruby on Rails project.
|
39
|
+
|
9
40
|
== Copyright
|
10
41
|
|
11
|
-
|
12
|
-
|
42
|
+
PageGlimpse.com is owned and operated by {RADSense Software}[http://www.radsense.com/],
|
43
|
+
Copyright (c) 2006 - 2009. Any and all questions about the Page Glimpse
|
44
|
+
service should be directed toward <tt>support [at] PageGlimpse.com</tt>.
|
45
|
+
|
46
|
+
Copyright (c) 2009 {Nathaniel E. Bibler}[http://www.nathanielbibler.com].
|
47
|
+
Released under the MIT License. See the LICENSE file for more details.
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ begin
|
|
9
9
|
gem.email = "gem@nathanielbibler.com"
|
10
10
|
gem.homepage = "http://github.com/nbibler/page_glimpse"
|
11
11
|
gem.authors = ["Nathaniel Bibler"]
|
12
|
-
|
12
|
+
gem.rubyforge_project = 'page-glimpse'
|
13
13
|
|
14
14
|
gem.add_dependency('relax', '~> 0.1.1')
|
15
15
|
gem.add_dependency('json', '~> 1.1.6')
|
@@ -58,6 +58,7 @@ Rake::RDocTask.new do |rdoc|
|
|
58
58
|
rdoc.rdoc_dir = 'rdoc'
|
59
59
|
rdoc.title = "page_glimpse #{version}"
|
60
60
|
rdoc.rdoc_files.include('README*')
|
61
|
+
rdoc.rdoc_files.include('LICENSE*')
|
61
62
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
62
63
|
end
|
63
64
|
|
data/VERSION.yml
CHANGED
data/lib/page_glimpse/api.rb
CHANGED
@@ -4,7 +4,10 @@ require 'page_glimpse/json_parser'
|
|
4
4
|
|
5
5
|
module PageGlimpse
|
6
6
|
|
7
|
-
class API < Relax::Service
|
7
|
+
class API < Relax::Service #:nodoc:
|
8
|
+
|
9
|
+
THUMBNAIL_EXISTS = 'yes'
|
10
|
+
QUEUE_SUCCESS = 'success'
|
8
11
|
|
9
12
|
defaults do
|
10
13
|
parameter :devkey, :required => true
|
@@ -27,7 +30,7 @@ module PageGlimpse
|
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
30
|
-
action :
|
33
|
+
action :exist?, :url => '/thumbnails/exists' do
|
31
34
|
parameter :size
|
32
35
|
|
33
36
|
parser JsonParser do
|
@@ -1,7 +1,11 @@
|
|
1
1
|
module PageGlimpse
|
2
2
|
|
3
|
+
##
|
4
|
+
# Catch-all exception for anything raised by the PageGlimpse library.
|
5
|
+
#
|
3
6
|
class Exception < RuntimeError; end
|
4
7
|
|
5
|
-
class InvalidDeveloperKeyError < Exception
|
8
|
+
class InvalidDeveloperKeyError < Exception #:nodoc:
|
9
|
+
end
|
6
10
|
|
7
11
|
end
|
data/lib/page_glimpse/image.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
module PageGlimpse
|
2
2
|
|
3
|
+
##
|
4
|
+
# An instance of this class is returned with a successful <tt>PageGlimpse.get</tt>
|
5
|
+
# request. This object wraps the information returned by Page Glimpse about
|
6
|
+
# the thumbnail requested.
|
7
|
+
#
|
3
8
|
class Image
|
4
9
|
attr_accessor :content_type,
|
5
10
|
:content_length,
|
data/lib/page_glimpse.rb
CHANGED
@@ -7,9 +7,6 @@ require 'page_glimpse/api'
|
|
7
7
|
|
8
8
|
module PageGlimpse
|
9
9
|
|
10
|
-
THUMBNAIL_EXISTS = 'yes'
|
11
|
-
QUEUE_SUCCESS = 'success'
|
12
|
-
|
13
10
|
##
|
14
11
|
# Sets the developer key to use with the requests.
|
15
12
|
#
|
@@ -18,12 +15,12 @@ module PageGlimpse
|
|
18
15
|
end
|
19
16
|
|
20
17
|
##
|
21
|
-
# Returns +true+ if the thumbnail exists on
|
18
|
+
# Returns +true+ if the thumbnail exists on Page Glimpse, +false+ otherwise.
|
22
19
|
#
|
23
|
-
def self.
|
20
|
+
def self.exist?(url, options = {})
|
24
21
|
options[:url] = url
|
25
|
-
response = api.
|
26
|
-
response.kind_of?(Array) && response.size == 2 && response[1] == THUMBNAIL_EXISTS
|
22
|
+
response = api.exist?(options)
|
23
|
+
response.kind_of?(Array) && response.size == 2 && response[1] == API::THUMBNAIL_EXISTS
|
27
24
|
rescue RestClient::ResourceNotFound
|
28
25
|
return false
|
29
26
|
rescue RestClient::RequestFailed
|
@@ -35,14 +32,17 @@ module PageGlimpse
|
|
35
32
|
#
|
36
33
|
def self.get(url, options = {})
|
37
34
|
options[:url] = url
|
38
|
-
|
35
|
+
exist?(url, options) ? api.thumbnail(options) : nil
|
39
36
|
rescue RestClient::RequestFailed
|
40
37
|
handle_failure($!)
|
41
38
|
end
|
42
39
|
|
40
|
+
##
|
41
|
+
# Instructs Page Glimpse to enqueue the thumbnailing of a specific URL.
|
42
|
+
#
|
43
43
|
def self.queue(url)
|
44
44
|
response = api.queue(:url => url)
|
45
|
-
response.kind_of?(Array) && response.size == 2 && response[1] == QUEUE_SUCCESS
|
45
|
+
response.kind_of?(Array) && response.size == 2 && response[1] == API::QUEUE_SUCCESS
|
46
46
|
rescue RestClient::RequestFailed
|
47
47
|
handle_failure($!)
|
48
48
|
end
|
data/page_glimpse.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{page_glimpse}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Nathaniel Bibler"]
|
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
|
|
36
36
|
s.homepage = %q{http://github.com/nbibler/page_glimpse}
|
37
37
|
s.rdoc_options = ["--charset=UTF-8"]
|
38
38
|
s.require_paths = ["lib"]
|
39
|
+
s.rubyforge_project = %q{page-glimpse}
|
39
40
|
s.rubygems_version = %q{1.3.2}
|
40
41
|
s.summary = %q{A Ruby library for the PageGlimpse.com service}
|
41
42
|
s.test_files = [
|
@@ -4,14 +4,14 @@ class PageGlimpseTest < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
context 'PageGlimpse' do
|
6
6
|
|
7
|
-
context '
|
7
|
+
context 'exist?' do
|
8
8
|
|
9
9
|
should 'be true for thumbnails which exist' do
|
10
|
-
assert PageGlimpse.
|
10
|
+
assert PageGlimpse.exist?('http://goodurl.local/', :size => 'large')
|
11
11
|
end
|
12
12
|
|
13
13
|
should 'be false for thumbnails which do not exist' do
|
14
|
-
assert !PageGlimpse.
|
14
|
+
assert !PageGlimpse.exist?('http://badurl.local/', :size => 'large')
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nbibler-page_glimpse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathaniel Bibler
|
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
111
|
version:
|
112
112
|
requirements: []
|
113
113
|
|
114
|
-
rubyforge_project:
|
114
|
+
rubyforge_project: page-glimpse
|
115
115
|
rubygems_version: 1.2.0
|
116
116
|
signing_key:
|
117
117
|
specification_version: 3
|