url2png 0.2.1 → 0.2.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.markdown CHANGED
@@ -6,9 +6,8 @@ A Ruby gem wrapping the url2png.com API.
6
6
  ## Who should use it?
7
7
  Any Ruby on Rails developer who wants/needs to generate screenshots from sites using url2png.com.
8
8
 
9
- ## Usage
10
9
 
11
- ### Installation
10
+ ## Installation
12
11
 
13
12
  gem install url2png
14
13
 
@@ -26,7 +25,7 @@ You must define your public key and shared secret, they are required:
26
25
  You can define the api version if you want to use an different version of the url2png api.
27
26
 
28
27
  Url2png.api_version = "v4"
29
-
28
+ g
30
29
  Available versions:
31
30
 
32
31
  * v4 (default)
@@ -48,11 +47,11 @@ Options are:
48
47
  In Rails you probably want to do configuration in an initializer.
49
48
 
50
49
 
51
- ### Helpers
50
+ ## Usage
52
51
 
53
52
  Generate an image tag:
54
53
 
55
- site_image_tag url, [options]
54
+ url2png_image_tag [options]
56
55
 
57
56
 
58
57
  Options differ by version!
@@ -64,21 +63,25 @@ Options differ by version!
64
63
  Constrain screenshot based on width or height or both.<br>
65
64
  default: no resizing
66
65
 
67
- = site_image_tag 'http://www.zwartopwit.com', :thumbnail_max_width => 500, :thumbnail_max_height => 500
66
+ url2png_image_tag :url => 'http://www.zwartopwit.com',
67
+ :thumbnail_max_width => 500,
68
+ :thumbnail_max_height => 500
68
69
 
69
70
 
70
71
  ##### Viewport
71
72
  Set viewport dimensions, adjust to your hearts content.<br>
72
73
  default: 1480x1037
73
74
 
74
- = site_image_tag 'http://www.zwartopwit.com', :viewport => "1024x900"
75
+ url2png_image_tag :url => 'http://www.zwartopwit.com',
76
+ :viewport => "1024x900"
75
77
 
76
78
 
77
79
  ##### Fullpage
78
80
  Will attempt to capture entire document canvas.<br>
79
81
  default: false
80
82
 
81
- = site_image_tag 'http://www.zwartopwit.com', :fullpage => true
83
+ url2png_image_tag :url => 'http://www.zwartopwit.com',
84
+ :fullpage => true
82
85
 
83
86
 
84
87
  ##### Delay
@@ -89,14 +92,17 @@ max: 5<br>
89
92
 
90
93
  example:
91
94
 
92
- site_image_tag url, :size => '300x200', :delay => 2
95
+ url2png_image_tag :url => "http://www.zwartopwit.com",
96
+ :size => '300x200',
97
+ :delay => 2
93
98
 
94
99
 
95
100
  ##### Force
96
101
  Forces a fresh screenshot with each request, overwriting the previous copy.<br>
97
102
  **You will be charged for every request made using the force option.**
98
103
 
99
- = site_image_tag 'http://www.zwartopwit.com', :force => true
104
+ = url2png_image_tag :url => 'http://www.zwartopwit.com',
105
+ :force => true
100
106
 
101
107
 
102
108
  ### Version 4
@@ -104,11 +110,13 @@ Forces a fresh screenshot with each request, overwriting the previous copy.<br>
104
110
  By default the size is set to 400 x 400 px.
105
111
  To generate an image with a specific size:
106
112
 
107
- site_image_tag url, :size => '300x200'
113
+ url2png_image_tag :url => "http://www.zwartopwit.com",
114
+ :size => '300x200'
108
115
 
109
116
  To only get the image url:
110
117
 
111
- site_image_url url, :size => '300x200'
118
+ site_image_url :url => "http://www.zwartopwit.com",
119
+ :size => '300x200'
112
120
 
113
121
  Options are:
114
122
 
@@ -118,9 +126,11 @@ Thumbnails will be resized to fit within this box.<br>
118
126
  default: 'ORIGINAL'<br>
119
127
  examples:
120
128
 
121
- site_image_tag url, :size => '500x500'
129
+ url2png_image_tag :url => "http://www.zwartopwit.com",
130
+ :size => '500x500'
122
131
 
123
- site_image_tag url, :size => 'ORIGINAL'
132
+ url2png_image_tag :url => "http://www.zwartopwit.com",
133
+ :size => 'ORIGINAL'
124
134
 
125
135
  ##### Thumbnail (alias for :size)
126
136
 
@@ -131,7 +141,9 @@ min: '200x200'<br>
131
141
  max: '4000x4000'<br>
132
142
  example:
133
143
 
134
- site_image_tag url, :size => '300x200', :browser_size => '1024x2500'
144
+ url2png_image_tag :url => "http://www.zwartopwit.com",
145
+ :size => '300x200',
146
+ :browser_size => '1024x2500'
135
147
 
136
148
  ##### Delay
137
149
  Extra delay (in seconds) forced between page load and screenshot.<br>
@@ -140,7 +152,9 @@ min: 1<br>
140
152
  max: 5<br>
141
153
  example:
142
154
 
143
- site_image_tag url, :size => '300x200', :delay => 2
155
+ url2png_image_tag :url => "http://www.zwartopwit.com",
156
+ :size => '300x200',
157
+ :delay => 2
144
158
 
145
159
  ##### Fullscreen
146
160
  When true, Will attempt to capture entire document canvas.<br>
@@ -149,7 +163,9 @@ default: false<br>
149
163
 
150
164
  example:
151
165
 
152
- site_image_tag url, :size => '300x200', :fullscreen => true
166
+ url2png_image_tag :url => "http://www.zwartopwit.com",
167
+ :size => '300x200',
168
+ :fullscreen => true
153
169
 
154
170
 
155
171
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -3,17 +3,19 @@ module Url2png
3
3
  module Common
4
4
  extend self
5
5
 
6
+ # ------------------
6
7
  # complete image tag
7
- def site_image_tag url, options = {}
8
+
9
+ def url2png_image_tag options = {}
8
10
  # parse size
9
11
  dim = Url2png::Dimensions.parse(options)
10
-
11
- # ensure image alt
12
- alt = options.key?(:alt) ? options.delete(:alt) : url
12
+
13
+ # ensure image alt
14
+ alt = options.key?(:alt) ? options.delete(:alt) : options[:url]
13
15
 
14
16
  # build image tag
15
17
  img = '<img'
16
- img << " src='#{ site_image_url(url, options) }'"
18
+ img << " src='#{ site_image_url(options) }'"
17
19
  img << " alt='#{ alt }'"
18
20
  img << " width='#{ dim[:width] }'" if options[:size]
19
21
  img << " height='#{ dim[:height] }'" if options[:size]
@@ -24,8 +26,22 @@ module Url2png
24
26
  img.html_safe
25
27
  end
26
28
 
29
+
30
+ def check_options options, options_available
31
+ # filter out unavailable options
32
+ options = options.select do |key, value|
33
+ if options_available.include? key
34
+ true
35
+ else
36
+ # size is a special option, only usable in the gem
37
+ warn "\"#{key}\" is not a valid option" unless key == :size
38
+ end
39
+ end
40
+ end
41
+
42
+ # --------------------------
27
43
  # only the url for the image
28
- def site_image_url url, options = {}
44
+ def site_image_url options = {}
29
45
  # parse size
30
46
  dim = Url2png::Dimensions.parse(options)
31
47
 
@@ -66,20 +82,14 @@ module Url2png
66
82
  when 'v6'
67
83
  ######
68
84
  # v6 #
85
+ # http://beta.url2png.com/v6/<APIKEY>/<TOKEN>/png/?url=google.com
69
86
  ######
70
87
 
71
- # http://beta.url2png.com/v6/<APIKEY>/<TOKEN>/png/?url=google.com
72
-
73
- query = {
74
- :url => url,
75
- :force => options[:force], # [false,always,timestamp] Default: false
76
- :fullpage => options[:fullpage], # [true,false] Default: false
77
- :thumbnail_max_width => options[:thumbnail_max_width], # scaled img width px; Default no-scaling
78
- :thumbnail_max_height => options[:thumbnail_max_height],
79
- :viewport => options[:viewport], # Max 5000x5000; Default 1280x1024
80
- }
88
+ # check for unavailable options
89
+ options_available = [:url, :force, :fullpage, :thumbnail_max_width, :thumbnail_max_height, :viewport]
90
+ options = check_options(options, options_available)
81
91
 
82
- query_string = query.
92
+ query_string = options.
83
93
  sort_by {|s| s[0].to_s }. # sort query by keys for uniformity
84
94
  select {|s| s[1] }. # skip empty options
85
95
  map {|s| s.map {|v| CGI::escape(v.to_s) }.join('=') }. # escape keys & vals
@@ -90,16 +100,21 @@ module Url2png
90
100
 
91
101
 
92
102
  "http://beta.url2png.com/v6/#{Url2png.api_key}/#{token}/png/?#{query_string}"
93
-
103
+
104
+
105
+
94
106
  when 'v4'
95
107
  ######
96
108
  # v4 #
109
+ # http://beta.url2png.com/v4/<APIKEY>/<TOKEN>/<VIEWPORT>-<THUMBNAIL>-<FULL>/<TARGET>
97
110
  ######
98
111
 
99
- # http://beta.url2png.com/v4/<APIKEY>/<TOKEN>/<VIEWPORT>-<THUMBNAIL>-<FULL>/<TARGET>
112
+ # check for unavailable options
113
+ options_available = [:url, :size, :thumbnail, :browser_size, :delay, :fullscreen]
114
+ options = check_options(options, options_available)
100
115
 
101
116
  # escape the url
102
- safe_url= CGI::escape(url)
117
+ safe_url= CGI::escape(options[:url])
103
118
 
104
119
  # generate token
105
120
  token = Digest::MD5.hexdigest("#{ Url2png.private_key }+#{ safe_url }")
data/url2png.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "url2png"
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["robinhoudmeyers", "wout fierens", "fuzzyalej", "ceritium", "lukemelia"]
12
- s.date = "2012-06-13"
12
+ s.date = "2012-06-15"
13
13
  s.description = "Generate screenshots from websites almost instantly at any preferred size using ruby and the url2png.com API"
14
14
  s.email = "houdmeyers@gmail.com"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: url2png
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,11 +13,11 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2012-06-13 00:00:00.000000000 Z
16
+ date: 2012-06-15 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: rspec
20
- requirement: &70331926041900 !ruby/object:Gem::Requirement
20
+ requirement: &70170384723740 !ruby/object:Gem::Requirement
21
21
  none: false
22
22
  requirements:
23
23
  - - ~>
@@ -25,10 +25,10 @@ dependencies:
25
25
  version: 2.6.0
26
26
  type: :development
27
27
  prerelease: false
28
- version_requirements: *70331926041900
28
+ version_requirements: *70170384723740
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: bundler
31
- requirement: &70331926041380 !ruby/object:Gem::Requirement
31
+ requirement: &70170384723260 !ruby/object:Gem::Requirement
32
32
  none: false
33
33
  requirements:
34
34
  - - ~>
@@ -36,10 +36,10 @@ dependencies:
36
36
  version: 1.1.3
37
37
  type: :development
38
38
  prerelease: false
39
- version_requirements: *70331926041380
39
+ version_requirements: *70170384723260
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: jeweler
42
- requirement: &70331926040900 !ruby/object:Gem::Requirement
42
+ requirement: &70170384722780 !ruby/object:Gem::Requirement
43
43
  none: false
44
44
  requirements:
45
45
  - - ~>
@@ -47,10 +47,10 @@ dependencies:
47
47
  version: 1.8.3
48
48
  type: :development
49
49
  prerelease: false
50
- version_requirements: *70331926040900
50
+ version_requirements: *70170384722780
51
51
  - !ruby/object:Gem::Dependency
52
52
  name: rcov
53
- requirement: &70331926040420 !ruby/object:Gem::Requirement
53
+ requirement: &70170384722260 !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements:
56
56
  - - ! '>='
@@ -58,10 +58,10 @@ dependencies:
58
58
  version: '0'
59
59
  type: :development
60
60
  prerelease: false
61
- version_requirements: *70331926040420
61
+ version_requirements: *70170384722260
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: rspec
64
- requirement: &70331926039940 !ruby/object:Gem::Requirement
64
+ requirement: &70170384721780 !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
67
  - - ! '>'
@@ -69,7 +69,7 @@ dependencies:
69
69
  version: 2.6.0
70
70
  type: :development
71
71
  prerelease: false
72
- version_requirements: *70331926039940
72
+ version_requirements: *70170384721780
73
73
  description: Generate screenshots from websites almost instantly at any preferred
74
74
  size using ruby and the url2png.com API
75
75
  email: houdmeyers@gmail.com
@@ -112,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  segments:
114
114
  - 0
115
- hash: 3943409547938200852
115
+ hash: 1190505122960655189
116
116
  required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements: