url2png 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +20 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +77 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/lib/url2png/config.rb +45 -0
- data/lib/url2png/dimensions.rb +15 -0
- data/lib/url2png/helpers/common.rb +35 -0
- data/lib/url2png.rb +9 -0
- data/test/helper.rb +18 -0
- data/test/test_url2png.rb +7 -0
- metadata +149 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.2"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
jeweler (1.5.2)
|
6
|
+
bundler (~> 1.0.0)
|
7
|
+
git (>= 1.2.5)
|
8
|
+
rake
|
9
|
+
rake (0.8.7)
|
10
|
+
rcov (0.9.9)
|
11
|
+
shoulda (2.11.3)
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
ruby
|
15
|
+
|
16
|
+
DEPENDENCIES
|
17
|
+
bundler (~> 1.0.0)
|
18
|
+
jeweler (~> 1.5.2)
|
19
|
+
rcov
|
20
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 wout fierens
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# url2png gem
|
2
|
+
|
3
|
+
## What is it?
|
4
|
+
A Ruby gem wrapping the url2png.com API.
|
5
|
+
|
6
|
+
## Who should use it?
|
7
|
+
Any Ruby on Rails developer who wants/needs to generate screenshots from sites using url2png.com.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
### Installation
|
12
|
+
|
13
|
+
gem install url2png
|
14
|
+
|
15
|
+
|
16
|
+
### Configuration
|
17
|
+
|
18
|
+
First define your public key and shared secret:
|
19
|
+
|
20
|
+
Url2png::Config.public_key = 'PXXXXXXXXXXXXX'
|
21
|
+
Url2png::Config.shared_secret = 'SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
|
22
|
+
|
23
|
+
In Rails you probably want to do that in your application file.
|
24
|
+
|
25
|
+
|
26
|
+
### Helpers
|
27
|
+
|
28
|
+
Generate an image tag:
|
29
|
+
|
30
|
+
site_image_tag url, [options]
|
31
|
+
|
32
|
+
Options are the same as the image_tag in Rails.
|
33
|
+
|
34
|
+
By default the size is set to 400 x 400 px.
|
35
|
+
To generate an image with a specific site:
|
36
|
+
|
37
|
+
site_image_tag url, :size => '300x200'
|
38
|
+
|
39
|
+
To only get the image url:
|
40
|
+
|
41
|
+
site_image_url url, :size => '300x200'
|
42
|
+
|
43
|
+
|
44
|
+
## Important
|
45
|
+
|
46
|
+
This gem is written for Rails 3.
|
47
|
+
Rails 2 might work but it's not tested.
|
48
|
+
|
49
|
+
Note that this gem is still under development.
|
50
|
+
|
51
|
+
|
52
|
+
## Contributing to url2png
|
53
|
+
|
54
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
55
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
56
|
+
* Fork the project
|
57
|
+
* Start a feature/bugfix branch
|
58
|
+
* Commit and push until you are happy with your contribution
|
59
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
60
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
61
|
+
|
62
|
+
## Copyright
|
63
|
+
|
64
|
+
Copyright (c) 2011 Wout Fierens. See LICENSE.txt for
|
65
|
+
further details.
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "url2png"
|
16
|
+
gem.homepage = "http://github.com/wout/url2png"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{A ruby gem for the url2png screenshot service API}
|
19
|
+
gem.description = %Q{A ruby gem wrapping the url2png screenshot service API}
|
20
|
+
gem.email = "wout@boysabroad.com"
|
21
|
+
gem.authors = ["wout fierens"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
|
26
|
+
gem.add_development_dependency 'rspec', '> 2.6.0'
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
29
|
+
|
30
|
+
require 'rake/testtask'
|
31
|
+
Rake::TestTask.new(:test) do |test|
|
32
|
+
test.libs << 'lib' << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
|
37
|
+
require 'rcov/rcovtask'
|
38
|
+
Rcov::RcovTask.new do |test|
|
39
|
+
test.libs << 'test'
|
40
|
+
test.pattern = 'test/**/test_*.rb'
|
41
|
+
test.verbose = true
|
42
|
+
end
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "url2png #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Url2png
|
2
|
+
module Config
|
3
|
+
|
4
|
+
def self.api_url
|
5
|
+
Thread.current[:url2png_url] ||= 'http://api.url2png.com'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.api_version
|
9
|
+
Thread.current[:url2png_version] ||= 'v3'
|
10
|
+
end
|
11
|
+
|
12
|
+
# public key setter and getter
|
13
|
+
def self.public_key= key
|
14
|
+
raise 'Url2png error: Invalid public key!' unless key.match(/^P/)
|
15
|
+
|
16
|
+
Thread.current[:url2png_key] ||= key
|
17
|
+
end
|
18
|
+
def self.public_key
|
19
|
+
raise 'Url2png error: No public key defined!' if Thread.current[:url2png_key].nil?
|
20
|
+
|
21
|
+
Thread.current[:url2png_key]
|
22
|
+
end
|
23
|
+
|
24
|
+
# shared secret setter and getter
|
25
|
+
def self.shared_secret= secret
|
26
|
+
raise 'Url2png error: Invalid shared secret!' unless secret.match(/^S/)
|
27
|
+
|
28
|
+
Thread.current[:url2png_secret] ||= secret
|
29
|
+
end
|
30
|
+
def self.shared_secret
|
31
|
+
raise 'Url2png error: No shared secret defined!' if Thread.current[:url2png_secret].nil?
|
32
|
+
|
33
|
+
Thread.current[:url2png_secret]
|
34
|
+
end
|
35
|
+
|
36
|
+
# size
|
37
|
+
def self.default_size= size
|
38
|
+
Thread.current[:url2png_size] ||= size
|
39
|
+
end
|
40
|
+
def self.default_size
|
41
|
+
Thread.current[:url2png_size] ||= '400x400'
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Url2png
|
2
|
+
module Dimensions
|
3
|
+
|
4
|
+
def self.parse options
|
5
|
+
size = options[:size] || Url2png::Config.default_size
|
6
|
+
|
7
|
+
{
|
8
|
+
:size => size,
|
9
|
+
:width => options[:width] || size.split('x')[0],
|
10
|
+
:height => options[:height] || size.split('x')[1]
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Url2png
|
2
|
+
module Helpers
|
3
|
+
module Common
|
4
|
+
|
5
|
+
def site_image_tag url, options = {}
|
6
|
+
dim = Url2png::Dimensions.parse(options)
|
7
|
+
|
8
|
+
# build image tag
|
9
|
+
img = '<img'
|
10
|
+
img << " src='#{ site_image_url(url, options) }'"
|
11
|
+
img << " alt='#{ options[:alt] || url }'"
|
12
|
+
img << " width='#{ dim[:width] }'"
|
13
|
+
img << " height='#{ dim[:height] }'"
|
14
|
+
options.each_pair do |k, v|
|
15
|
+
img << " #{ k }='#{ v }'" unless v.nil? || v == ''
|
16
|
+
end
|
17
|
+
img << ' />'
|
18
|
+
end
|
19
|
+
|
20
|
+
def site_image_url url, options = {}
|
21
|
+
dim = Url2png::Dimensions.parse(options)
|
22
|
+
|
23
|
+
# escape the url
|
24
|
+
safe_url = URI.escape(url)
|
25
|
+
|
26
|
+
# generate token
|
27
|
+
token = Digest::MD5.hexdigest("#{ Url2png::Config.shared_secret }+#{ safe_url }")
|
28
|
+
|
29
|
+
# build image url
|
30
|
+
File.join(Url2png::Config.api_url, Url2png::Config.api_version, Url2png::Config.public_key, token, dim[:size], safe_url)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/url2png.rb
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'url2png'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: url2png
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- wout fierens
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-05-24 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: shoulda
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
prerelease: false
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 1
|
42
|
+
- 0
|
43
|
+
- 0
|
44
|
+
version: 1.0.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: jeweler
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 5
|
58
|
+
- 2
|
59
|
+
version: 1.5.2
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rcov
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
type: :development
|
74
|
+
prerelease: false
|
75
|
+
version_requirements: *id004
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: rspec
|
78
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 2
|
85
|
+
- 6
|
86
|
+
- 0
|
87
|
+
version: 2.6.0
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *id005
|
91
|
+
description: A ruby gem wrapping the url2png screenshot service API
|
92
|
+
email: wout@boysabroad.com
|
93
|
+
executables: []
|
94
|
+
|
95
|
+
extensions: []
|
96
|
+
|
97
|
+
extra_rdoc_files:
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.markdown
|
100
|
+
files:
|
101
|
+
- .document
|
102
|
+
- Gemfile
|
103
|
+
- Gemfile.lock
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.markdown
|
106
|
+
- Rakefile
|
107
|
+
- VERSION
|
108
|
+
- lib/url2png.rb
|
109
|
+
- lib/url2png/config.rb
|
110
|
+
- lib/url2png/dimensions.rb
|
111
|
+
- lib/url2png/helpers/common.rb
|
112
|
+
- test/helper.rb
|
113
|
+
- test/test_url2png.rb
|
114
|
+
has_rdoc: true
|
115
|
+
homepage: http://github.com/wout/url2png
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
hash: 4190063888804664978
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
version: "0"
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
version: "0"
|
140
|
+
requirements: []
|
141
|
+
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 1.3.7
|
144
|
+
signing_key:
|
145
|
+
specification_version: 3
|
146
|
+
summary: A ruby gem for the url2png screenshot service API
|
147
|
+
test_files:
|
148
|
+
- test/helper.rb
|
149
|
+
- test/test_url2png.rb
|