url2png 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,13 +1,9 @@
1
1
  source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
2
 
6
3
  # Add dependencies to develop your gem here.
7
4
  # Include everything needed to run rake, tests, features, etc.
8
5
  group :development do
9
- gem "rspec", "~> 2.6.0"
10
- gem "bundler", "~> 1.1.3"
6
+ gem "rspec", "~> 2.11.0"
11
7
  gem "jeweler", "~> 1.8.3"
12
8
  gem "rcov", ">= 0"
13
- end
9
+ end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- diff-lcs (1.1.2)
4
+ diff-lcs (1.1.3)
5
5
  git (1.2.5)
6
6
  jeweler (1.8.3)
7
7
  bundler (~> 1.0)
@@ -9,20 +9,19 @@ GEM
9
9
  rake
10
10
  rake (0.9.2.2)
11
11
  rcov (0.9.9)
12
- rspec (2.6.0)
13
- rspec-core (~> 2.6.0)
14
- rspec-expectations (~> 2.6.0)
15
- rspec-mocks (~> 2.6.0)
16
- rspec-core (2.6.3)
17
- rspec-expectations (2.6.0)
18
- diff-lcs (~> 1.1.2)
19
- rspec-mocks (2.6.0)
12
+ rspec (2.11.0)
13
+ rspec-core (~> 2.11.0)
14
+ rspec-expectations (~> 2.11.0)
15
+ rspec-mocks (~> 2.11.0)
16
+ rspec-core (2.11.1)
17
+ rspec-expectations (2.11.3)
18
+ diff-lcs (~> 1.1.3)
19
+ rspec-mocks (2.11.3)
20
20
 
21
21
  PLATFORMS
22
22
  ruby
23
23
 
24
24
  DEPENDENCIES
25
- bundler (~> 1.1.3)
26
25
  jeweler (~> 1.8.3)
27
26
  rcov
28
- rspec (~> 2.6.0)
27
+ rspec (~> 2.11.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.5
@@ -2,18 +2,18 @@ module Url2png
2
2
  module Helpers
3
3
  module Common
4
4
  extend self
5
-
5
+
6
6
  # ------------------
7
7
  # complete image tag
8
-
9
-
8
+
9
+
10
10
  def url2png_image_tag url, options = {}
11
11
  # parse size
12
12
  dim = Url2png::Dimensions.parse(options)
13
-
13
+
14
14
  # ensure image alt
15
15
  alt = options.key?(:alt) ? options.delete(:alt) : url
16
-
16
+
17
17
  # build image tag
18
18
  img = '<img'
19
19
  img << " src='#{ url2png_image_url(url, options) }'"
@@ -24,16 +24,16 @@ module Url2png
24
24
  img << " #{ k }=#{ v }" unless v.nil? || v == ''
25
25
  end
26
26
  img << ' />'
27
- img.html_safe
27
+ img.respond_to?(:html_safe) ? img.html_safe : img # Utilize ActiveSupport if loaded
28
28
  end
29
-
30
-
29
+
30
+
31
31
  # --------------------------
32
32
  # only the url for the image
33
33
  def url2png_image_url url, options = {}
34
34
  # parse size
35
35
  dim = Url2png::Dimensions.parse(options)
36
-
36
+
37
37
  case Url2png.mode
38
38
  when 'dummy'
39
39
  'data:image/png;base64,
@@ -60,11 +60,11 @@ module Url2png
60
60
  ICAgICAgICAgICAgPHJkZjpCYWcvPgogICAgICAgICA8L2RjOnN1YmplY3Q+CiAgICAgIDwvcmRm
61
61
  OkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgrlPw1BAAAAFElEQVQIHWM8
62
62
  fPjwfwYgYAIRIAAAMrgDTJyW2igAAAAASUVORK5CYII='.gsub(/\n/,'')
63
-
63
+
64
64
  when 'placehold'
65
65
  "http://placehold.it/#{ dim[:size] }"
66
-
67
- else
66
+
67
+ else
68
68
  # build parameters portion of URL
69
69
  case Url2png.api_version
70
70
  when 'v6'
@@ -72,11 +72,11 @@ module Url2png
72
72
  # v6 #
73
73
  # http://api.url2png.com/v6/<APIKEY>/<TOKEN>/png/?url=google.com
74
74
  ######
75
-
75
+
76
76
  # check for unavailable options
77
77
  options_alias = [:max_width, :max_height]
78
- options_available = [:delay, :force, :fullpage, :thumbnail_max_width, :thumbnail_max_height, :viewport]
79
-
78
+ options_available = [:delay, :force, :fullpage, :thumbnail_max_width, :thumbnail_max_height, :viewport, :format]
79
+
80
80
  # assign alias to valid option
81
81
  options_alias.each do |key|
82
82
  if options.key?(key)
@@ -93,17 +93,13 @@ module Url2png
93
93
  end
94
94
  end
95
95
  end
96
-
97
- # options_alias.each do |key|
98
- # if options.include?(key) then options.delete(key) end
99
- # end
100
-
101
-
96
+
102
97
  options = check_options(options, options_available)
103
-
98
+
104
99
  # add url to options query
105
100
  options[:url] = url
106
-
101
+
102
+
107
103
  query_string = options.
108
104
  sort_by {|s| s[0].to_s }. # sort query by keys for uniformity
109
105
  select {|s| s[1] }. # skip empty options
@@ -112,38 +108,40 @@ module Url2png
112
108
 
113
109
  # generate token
114
110
  token = Url2png.token query_string
115
-
116
-
117
- "http://api.url2png.com/v6/#{Url2png.api_key}/#{token}/png/?#{query_string}"
118
-
111
+
112
+ # set the format of the asset requested
113
+ format = options[:format] || "png"
114
+
115
+ "http://api.url2png.com/v6/#{Url2png.api_key}/#{token}/#{format}/?#{query_string}"
116
+
119
117
  when 'v4'
120
118
  ######
121
119
  # v4 #
122
120
  # http://beta.url2png.com/v4/<APIKEY>/<TOKEN>/<VIEWPORT>-<THUMBNAIL>-<FULL>/<TARGET>
123
121
  ######
124
-
122
+
125
123
  # check for unavailable options
126
124
  options_available = [:size, :thumbnail, :browser_size, :delay, :fullscreen]
127
125
  options = check_options(options, options_available)
128
-
126
+
129
127
  # escape the url
130
128
  safe_url= CGI::escape(url)
131
-
129
+
132
130
  # generate token
133
131
  token = Url2png.token safe_url
134
-
132
+
135
133
  # build options portion of URL
136
134
  url_options = []
137
-
135
+
138
136
  # set thumbnail
139
137
  options[:thumbnail] ||= options[:size]
140
-
138
+
141
139
  url_options << "t#{ options[:thumbnail] }"
142
140
  url_options << "s#{ options[:browser_size] }" if options[:browser_size]
143
141
  url_options << "d#{ options[:delay] }" if options[:delay]
144
142
  url_options << "FULL" if options[:fullscreen]
145
143
  url_options_string = url_options.join('-')
146
-
144
+
147
145
  # build image url
148
146
  File.join(
149
147
  "http://beta.url2png.com",
@@ -153,33 +151,33 @@ module Url2png
153
151
  url_options_string,
154
152
  safe_url
155
153
  )
156
-
154
+
157
155
  when 'v3'
158
156
  ######
159
157
  # v3 #
160
158
  ######
161
-
159
+
162
160
  # http://api.url2png.com/v3/api_key/security_hash/bounds/url
163
-
161
+
164
162
  options_available = [:fullscreen, :size]
165
163
  options = check_options(options, options_available)
166
-
164
+
167
165
  # escape the url
168
166
  safe_url= CGI::escape(url)
169
-
167
+
170
168
  # generate token
171
169
  token = Url2png.token safe_url
172
-
170
+
173
171
  # custom size or default_size
174
172
  size = options[:size] || Url2png.default_size
175
-
173
+
176
174
  # build options portion of URL
177
175
  if options[:fullscreen]
178
176
  bounds = "FULL"
179
177
  else
180
178
  bounds = size
181
179
  end
182
-
180
+
183
181
  # build image url
184
182
  File.join(
185
183
  "http://api.url2png.com",
@@ -190,12 +188,12 @@ module Url2png
190
188
  safe_url
191
189
  )
192
190
  end
193
-
191
+
194
192
  end
195
193
  end
196
-
194
+
197
195
  def check_options options, options_available
198
-
196
+
199
197
  # filter out unavailable options
200
198
  options = options.select do |key, value|
201
199
  if options_available.include? key
@@ -204,20 +202,20 @@ module Url2png
204
202
  # size is a special option, only usable in the gem
205
203
  homepage = "https://github.com/robinhoudmeyers/url2png-gem"
206
204
  raise "#{options} \n \"#{key}\" is not a valid option \nCheck the gem homepage for information about options: #{homepage}" unless key == :size
207
-
205
+
208
206
  end
209
207
  end
210
208
  end
211
-
209
+
212
210
  # -----
213
211
  # Alias
214
212
  def site_image_tag url, options = {}
215
213
  url2png_image_tag(url, options)
216
214
  end
217
-
215
+
218
216
  def site_image_url url, options = {}
219
217
  url2png_image_url(url, options)
220
218
  end
221
219
  end
222
220
  end
223
- end
221
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Url2png do
4
+ include Url2png::Helpers::Common
5
+
6
+ before(:all) do
7
+ Url2png.config({
8
+ :api_key => "P4DBEC0200EE98",
9
+ :private_key => "S169B0E051EAC6794B3EC9F385866187R"
10
+ })
11
+ end
12
+
13
+ describe "site_image_tag" do
14
+ it "should return the url of the http://pasparout.com image" do
15
+ site_image_tag('http://pasparout.com').should_not be_nil
16
+ end
17
+ end
18
+
19
+ describe "site_image_url" do
20
+ it "should encode the thumbnail max width when provided" do
21
+ site_image_url('http://www.nytimes.com/', :thumbnail_max_width => '200').should =~ %r{thumbnail_max_width=200}
22
+ end
23
+
24
+ it "should encode the thumbnail max height when provided" do
25
+ site_image_url('http://www.nytimes.com/', :thumbnail_max_height => '400').should =~ %r{thumbnail_max_height=400}
26
+ end
27
+
28
+ it "should encode the viewport size when provided" do
29
+ site_image_url('http://www.nytimes.com/', :viewport => '200x300').should =~ %r{viewport=200x300}
30
+ end
31
+
32
+ it "should encode the delay when provided" do
33
+ site_image_url('http://www.nytimes.com/', :delay => 3).should =~ %r{delay=3}
34
+ end
35
+
36
+ it "should encode the fullpage flag when provided" do
37
+ site_image_url('http://www.nytimes.com/', :fullpage => true).should =~ %r{fullpage=true}
38
+ end
39
+
40
+ it "should concatenate options by using ampersands" do
41
+ site_image_url('http://www.nytimes.com/', :delay => 3, :fullpage => true).should =~ %r{delay=3&fullpage=true}
42
+ end
43
+
44
+ it "should request the png format by default" do
45
+ site_image_url('http://www.nytimes.com/').should =~ %r{png}
46
+ end
47
+
48
+ it "should request the json format" do
49
+ site_image_url('http://www.nytimes.com/', :format => :json).should =~ %r{json}
50
+ end
51
+
52
+ it "should request the png format" do
53
+ site_image_url('http://www.nytimes.com/', :format => :png).should =~ %r{png}
54
+ end
55
+ end
56
+ end
data/spec/spec_helper.rb CHANGED
@@ -8,5 +8,7 @@ require 'url2png'
8
8
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
9
 
10
10
  RSpec.configure do |config|
11
-
12
- end
11
+ config.filter_run :focused => true
12
+ config.run_all_when_everything_filtered = true
13
+ config.alias_example_to :fit, :focused => true
14
+ end
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.3.4"
8
+ s.version = "0.3.5"
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-10-08"
12
+ s.date = "2012-11-16"
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 = [
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
31
31
  "lib/url2png/dimensions.rb",
32
32
  "lib/url2png/helpers/common.rb",
33
33
  "lib/url2png/rails.rb",
34
- "spec/helpers/common_rspec.rb",
34
+ "spec/helpers/common_spec.rb",
35
35
  "spec/spec_helper.rb",
36
36
  "spec/url2png_spec.rb",
37
37
  "url2png.gemspec"
@@ -46,21 +46,18 @@ Gem::Specification.new do |s|
46
46
  s.specification_version = 3
47
47
 
48
48
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
- s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
50
- s.add_development_dependency(%q<bundler>, ["~> 1.1.3"])
49
+ s.add_development_dependency(%q<rspec>, ["~> 2.11.0"])
51
50
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
52
51
  s.add_development_dependency(%q<rcov>, [">= 0"])
53
52
  s.add_development_dependency(%q<rspec>, ["> 2.6.0"])
54
53
  else
55
- s.add_dependency(%q<rspec>, ["~> 2.6.0"])
56
- s.add_dependency(%q<bundler>, ["~> 1.1.3"])
54
+ s.add_dependency(%q<rspec>, ["~> 2.11.0"])
57
55
  s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
58
56
  s.add_dependency(%q<rcov>, [">= 0"])
59
57
  s.add_dependency(%q<rspec>, ["> 2.6.0"])
60
58
  end
61
59
  else
62
- s.add_dependency(%q<rspec>, ["~> 2.6.0"])
63
- s.add_dependency(%q<bundler>, ["~> 1.1.3"])
60
+ s.add_dependency(%q<rspec>, ["~> 2.11.0"])
64
61
  s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
65
62
  s.add_dependency(%q<rcov>, [">= 0"])
66
63
  s.add_dependency(%q<rspec>, ["> 2.6.0"])
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.3.4
4
+ version: 0.3.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2012-10-08 00:00:00.000000000 Z
16
+ date: 2012-11-16 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: rspec
@@ -22,23 +22,7 @@ dependencies:
22
22
  requirements:
23
23
  - - ~>
24
24
  - !ruby/object:Gem::Version
25
- version: 2.6.0
26
- type: :development
27
- prerelease: false
28
- version_requirements: !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: 2.6.0
34
- - !ruby/object:Gem::Dependency
35
- name: bundler
36
- requirement: !ruby/object:Gem::Requirement
37
- none: false
38
- requirements:
39
- - - ~>
40
- - !ruby/object:Gem::Version
41
- version: 1.1.3
25
+ version: 2.11.0
42
26
  type: :development
43
27
  prerelease: false
44
28
  version_requirements: !ruby/object:Gem::Requirement
@@ -46,7 +30,7 @@ dependencies:
46
30
  requirements:
47
31
  - - ~>
48
32
  - !ruby/object:Gem::Version
49
- version: 1.1.3
33
+ version: 2.11.0
50
34
  - !ruby/object:Gem::Dependency
51
35
  name: jeweler
52
36
  requirement: !ruby/object:Gem::Requirement
@@ -118,7 +102,7 @@ files:
118
102
  - lib/url2png/dimensions.rb
119
103
  - lib/url2png/helpers/common.rb
120
104
  - lib/url2png/rails.rb
121
- - spec/helpers/common_rspec.rb
105
+ - spec/helpers/common_spec.rb
122
106
  - spec/spec_helper.rb
123
107
  - spec/url2png_spec.rb
124
108
  - url2png.gemspec
@@ -137,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
121
  version: '0'
138
122
  segments:
139
123
  - 0
140
- hash: -2433164738939015678
124
+ hash: -2645353561694603571
141
125
  required_rubygems_version: !ruby/object:Gem::Requirement
142
126
  none: false
143
127
  requirements:
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
- require 'url2png/helpers/common'
3
-
4
- describe Url2png do
5
- include Url2png::Helpers::Common
6
- before(:all) do
7
- Url2png::Config.public_key = "P4DBEC0200EE98"
8
- Url2png::Config.shared_secret = "S169B0E051EAC6794B3EC9F385866187R"
9
- end
10
-
11
- describe "site_image_tag" do
12
- it "should return the url of the http://pasparout.com image" do
13
- site_image_tag('http://pasparout.com').should_not be_nil
14
- end
15
- end
16
-
17
- describe "site_image_url" do
18
- it "should encode the thumbnail size when provided" do
19
- site_image_url('http://www.nytimes.com/', :thumbnail => '200x300').should =~ %r{t200x300}
20
- end
21
-
22
- it "should encode the initial browser size when provided" do
23
- site_image_url('http://www.nytimes.com/', :browser_size => '200x300').should =~ %r{s200x300}
24
- end
25
-
26
- it "should encode the delay when provided" do
27
- site_image_url('http://www.nytimes.com/', :delay => 3).should =~ %r{d3}
28
- end
29
-
30
- it "should encode the fullscreen capture flag when provided" do
31
- site_image_url('http://www.nytimes.com/', :fullscreen => true).should =~ %r{FULL}
32
- end
33
-
34
- it "should concatenate options by using hyphens" do
35
- site_image_url('http://www.nytimes.com/', :delay => 3, :fullscreen => true).should =~ %r{d3-FULL}
36
- end
37
- end
38
- end