url2png 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -10,4 +10,4 @@ group :development do
10
10
  gem "bundler", "~> 1.0.0"
11
11
  gem "jeweler", "~> 1.5.2"
12
12
  gem "rcov", ">= 0"
13
- end
13
+ end
data/README.markdown CHANGED
@@ -20,7 +20,17 @@ First define your public key and shared secret:
20
20
  Url2png::Config.public_key = 'PXXXXXXXXXXXXX'
21
21
  Url2png::Config.shared_secret = 'SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
22
22
 
23
- In Rails you probably want to do that in your application.rb file.
23
+ If you are generating local urls in development you can use a placeholder or dummy image.
24
+ This is done by setting the mode:
25
+
26
+ Url2png::Config.mode = :placehold if Rails.env.development?
27
+
28
+ Options are:
29
+ - :production (default; will use the url2png api to generate images)
30
+ - :placehold (will generate images at http://placehold.it)
31
+ - :dummy (will give a grey base64 data image)
32
+
33
+ In Rails you probably want to do configuration in an initializer.
24
34
 
25
35
 
26
36
  ### Helpers
data/Rakefile CHANGED
@@ -17,8 +17,8 @@ Jeweler::Tasks.new do |gem|
17
17
  gem.license = "MIT"
18
18
  gem.summary = %Q{A ruby gem wrapping the url2png.com screenshot service API}
19
19
  gem.description = %Q{Generate screenshots from websites almost instantly at any preferred size using ruby and the url2png.com API}
20
- gem.email = "wout@boysabroad.com"
21
- gem.authors = ["wout fierens"]
20
+ gem.email = "wout@impinc.co.uk"
21
+ gem.authors = ["wout fierens", "fuzzyalej", "ceritium"]
22
22
  # Include your dependencies below. Runtime dependencies are required when using your gem,
23
23
  # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
24
  # gem.add_runtime_dependency 'jabber4r', '> 0.1'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
@@ -1,45 +1,59 @@
1
1
  module Url2png
2
+
2
3
  module Config
3
4
 
5
+ # modes
6
+ MODES = %w{production placehold dummy}
7
+
8
+ def self.mode= mode
9
+ raise "Url2png error: Invalid mode, only #{ MODES.join(', ') } are allowed" unless MODES.include?(mode.to_s)
10
+ @url2png_mode ||= mode.to_s
11
+ end
12
+
13
+ def self.mode
14
+ @url2png_mode ||= 'production'
15
+ end
16
+
17
+ # api settings
4
18
  def self.api_url protocol
5
- Thread.current[:url2png_url] ||= "#{ protocol }api.url2png.com"
19
+ @url2png_url ||= "#{ protocol }api.url2png.com"
6
20
  end
7
21
 
8
22
  def self.api_version
9
- Thread.current[:url2png_version] ||= 'v3'
23
+ @url2png_version ||= 'v3'
10
24
  end
11
25
 
12
26
  # public key setter and getter
13
27
  def self.public_key= key
14
28
  raise 'Url2png error: Invalid public key!' unless key.match(/^P/)
15
-
16
- Thread.current[:url2png_key] ||= key
29
+ @url2png_key ||= key
17
30
  end
18
- def self.public_key
19
- raise 'Url2png error: No public key defined!' if Thread.current[:url2png_key].nil?
20
31
 
21
- Thread.current[:url2png_key]
32
+ def self.public_key
33
+ raise 'Url2png error: No public key defined!' if @url2png_key.nil?
34
+ @url2png_key
22
35
  end
23
36
 
24
37
  # shared secret setter and getter
25
38
  def self.shared_secret= secret
26
39
  raise 'Url2png error: Invalid shared secret!' unless secret.match(/^S/)
27
-
28
- Thread.current[:url2png_secret] ||= secret
40
+ @url2png_secret ||= secret
29
41
  end
30
- def self.shared_secret
31
- raise 'Url2png error: No shared secret defined!' if Thread.current[:url2png_secret].nil?
32
42
 
33
- Thread.current[:url2png_secret]
43
+ def self.shared_secret
44
+ raise 'Url2png error: No shared secret defined!' if @url2png_secret.nil?
45
+ @url2png_secret
34
46
  end
35
47
 
36
48
  # size
37
49
  def self.default_size= size
38
- Thread.current[:url2png_size] ||= size
50
+ @url2png_size ||= size
39
51
  end
52
+
40
53
  def self.default_size
41
- Thread.current[:url2png_size] ||= '400x400'
54
+ @url2png_size ||= '400x400'
42
55
  end
43
56
 
44
57
  end
58
+
45
59
  end
@@ -1,7 +1,7 @@
1
1
  module Url2png
2
2
  module Helpers
3
3
  module Common
4
-
4
+
5
5
  def site_image_tag url, options = {}
6
6
  dim = Url2png::Dimensions.parse(options)
7
7
 
@@ -15,23 +15,57 @@ module Url2png
15
15
  img << " #{ k }='#{ v }'" unless v.nil? || v == ''
16
16
  end
17
17
  img << ' />'
18
+ img.html_safe
18
19
  end
19
-
20
+
20
21
  def site_image_url url, options = {}
21
- options[:protocol] ||= 'http://'
22
-
23
22
  dim = Url2png::Dimensions.parse(options)
24
-
25
- # escape the url
26
- safe_url = URI.escape(url)
27
-
28
- # generate token
29
- token = Digest::MD5.hexdigest("#{ Url2png::Config.shared_secret }+#{ safe_url }")
30
-
31
- # build image url
32
- File.join(Url2png::Config.api_url(options[:protocol]), Url2png::Config.api_version, Url2png::Config.public_key, token, dim[:size], safe_url)
23
+
24
+ case Url2png::Config.mode
25
+ when 'dummy'
26
+ 'data:image/png;base64,
27
+ iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAADHmlDQ1BJQ0MgUHJvZmlsZQAAeAGF
28
+ VN9r01AU/tplnbDhizpnEQk+aJFuZFN0Q5y2a1e6zVrqNrchSJumbVyaxiTtfrAH2YtvOsV38Qc+
29
+ +QcM2YNve5INxhRh+KyIIkz2IrOemzRNJ1MDufe73/nuOSfn5F6g+XFa0xQvDxRVU0/FwvzE5BTf
30
+ 8gFeHEMr/GhNi4YWSiZHQA/Tsnnvs/MOHsZsdO5v36v+Y9WalQwR8BwgvpQ1xCLhWaBpXNR0E+DW
31
+ ie+dMTXCzUxzWKcECR9nOG9jgeGMjSOWZjQ1QJoJwgfFQjpLuEA4mGng8w3YzoEU5CcmqZIuizyr
32
+ RVIv5WRFsgz28B9zg/JfsKiU6Zut5xCNbZoZTtF8it4fOX1wjOYA1cE/Xxi9QbidcFg246M1fkLN
33
+ JK4RJr3n7nRpmO1lmpdZKRIlHCS8YlSuM2xp5gsDiZrm0+30UJKwnzS/NDNZ8+PtUJUE6zHF9fZL
34
+ RvS6vdfbkZMH4zU+pynWf0D+vff1corleZLw67QejdX0W5I6Vtv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c2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgrlPw1BAAAAFElEQVQIHWM8
49
+ fPjwfwYgYAIRIAAAMrgDTJyW2igAAAAASUVORK5CYII='.gsub(/\n/,'')
50
+
51
+ when 'placehold'
52
+ "http://placehold.it/#{ dim[:size] }"
53
+
54
+ else
55
+ options[:protocol] ||= 'http://'
56
+
57
+ # escape the url
58
+ safe_url = URI.escape(url)
59
+
60
+ # generate token
61
+ token = Digest::MD5.hexdigest("#{ Url2png::Config.shared_secret }+#{ safe_url }")
62
+
63
+ # build image url
64
+ File.join(Url2png::Config.api_url(options[:protocol]), Url2png::Config.api_version, Url2png::Config.public_key, token, dim[:size], safe_url)
65
+ end
66
+
33
67
  end
34
-
68
+
35
69
  end
36
70
  end
37
71
  end
data/url2png.gemspec CHANGED
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{url2png}
8
- s.version = "0.0.6"
7
+ s.name = "url2png"
8
+ s.version = "0.0.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["wout fierens"]
12
- s.date = %q{2011-06-23}
13
- s.description = %q{Generate screenshots from websites almost instantly at any preferred size using ruby and the url2png.com API}
14
- s.email = %q{wout@boysabroad.com}
11
+ s.authors = ["wout fierens", "fuzzyalej", "ceritium"]
12
+ s.date = "2011-12-01"
13
+ s.description = "Generate screenshots from websites almost instantly at any preferred size using ruby and the url2png.com API"
14
+ s.email = "wout@impinc.co.uk"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.markdown"
@@ -35,11 +35,11 @@ Gem::Specification.new do |s|
35
35
  "spec/url2png_spec.rb",
36
36
  "url2png.gemspec"
37
37
  ]
38
- s.homepage = %q{http://github.com/wout/url2png-gem}
38
+ s.homepage = "http://github.com/wout/url2png-gem"
39
39
  s.licenses = ["MIT"]
40
40
  s.require_paths = ["lib"]
41
- s.rubygems_version = %q{1.3.7}
42
- s.summary = %q{A ruby gem wrapping the url2png.com screenshot service API}
41
+ s.rubygems_version = "1.8.11"
42
+ s.summary = "A ruby gem wrapping the url2png.com screenshot service API"
43
43
  s.test_files = [
44
44
  "spec/helpers/common_rspec.rb",
45
45
  "spec/spec_helper.rb",
@@ -47,7 +47,6 @@ Gem::Specification.new do |s|
47
47
  ]
48
48
 
49
49
  if s.respond_to? :specification_version then
50
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
50
  s.specification_version = 3
52
51
 
53
52
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
metadata CHANGED
@@ -1,105 +1,82 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: url2png
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 6
9
- version: 0.0.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - wout fierens
9
+ - fuzzyalej
10
+ - ceritium
13
11
  autorequire:
14
12
  bindir: bin
15
13
  cert_chain: []
16
-
17
- date: 2011-06-23 00:00:00 +01:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
14
+ date: 2011-12-01 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
21
17
  name: rspec
22
- requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirement: &2157323520 !ruby/object:Gem::Requirement
23
19
  none: false
24
- requirements:
20
+ requirements:
25
21
  - - ~>
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 2
29
- - 6
30
- - 0
22
+ - !ruby/object:Gem::Version
31
23
  version: 2.6.0
32
24
  type: :development
33
25
  prerelease: false
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
26
+ version_requirements: *2157323520
27
+ - !ruby/object:Gem::Dependency
36
28
  name: bundler
37
- requirement: &id002 !ruby/object:Gem::Requirement
29
+ requirement: &2157321920 !ruby/object:Gem::Requirement
38
30
  none: false
39
- requirements:
31
+ requirements:
40
32
  - - ~>
41
- - !ruby/object:Gem::Version
42
- segments:
43
- - 1
44
- - 0
45
- - 0
33
+ - !ruby/object:Gem::Version
46
34
  version: 1.0.0
47
35
  type: :development
48
36
  prerelease: false
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
37
+ version_requirements: *2157321920
38
+ - !ruby/object:Gem::Dependency
51
39
  name: jeweler
52
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ requirement: &2157320760 !ruby/object:Gem::Requirement
53
41
  none: false
54
- requirements:
42
+ requirements:
55
43
  - - ~>
56
- - !ruby/object:Gem::Version
57
- segments:
58
- - 1
59
- - 5
60
- - 2
44
+ - !ruby/object:Gem::Version
61
45
  version: 1.5.2
62
46
  type: :development
63
47
  prerelease: false
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
48
+ version_requirements: *2157320760
49
+ - !ruby/object:Gem::Dependency
66
50
  name: rcov
67
- requirement: &id004 !ruby/object:Gem::Requirement
51
+ requirement: &2157319780 !ruby/object:Gem::Requirement
68
52
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- segments:
73
- - 0
74
- version: "0"
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
75
57
  type: :development
76
58
  prerelease: false
77
- version_requirements: *id004
78
- - !ruby/object:Gem::Dependency
59
+ version_requirements: *2157319780
60
+ - !ruby/object:Gem::Dependency
79
61
  name: rspec
80
- requirement: &id005 !ruby/object:Gem::Requirement
62
+ requirement: &2157318140 !ruby/object:Gem::Requirement
81
63
  none: false
82
- requirements:
83
- - - ">"
84
- - !ruby/object:Gem::Version
85
- segments:
86
- - 2
87
- - 6
88
- - 0
64
+ requirements:
65
+ - - ! '>'
66
+ - !ruby/object:Gem::Version
89
67
  version: 2.6.0
90
68
  type: :development
91
69
  prerelease: false
92
- version_requirements: *id005
93
- description: Generate screenshots from websites almost instantly at any preferred size using ruby and the url2png.com API
94
- email: wout@boysabroad.com
70
+ version_requirements: *2157318140
71
+ description: Generate screenshots from websites almost instantly at any preferred
72
+ size using ruby and the url2png.com API
73
+ email: wout@impinc.co.uk
95
74
  executables: []
96
-
97
75
  extensions: []
98
-
99
- extra_rdoc_files:
76
+ extra_rdoc_files:
100
77
  - LICENSE.txt
101
78
  - README.markdown
102
- files:
79
+ files:
103
80
  - .document
104
81
  - .rspec
105
82
  - Gemfile
@@ -117,40 +94,35 @@ files:
117
94
  - spec/spec_helper.rb
118
95
  - spec/url2png_spec.rb
119
96
  - url2png.gemspec
120
- has_rdoc: true
121
97
  homepage: http://github.com/wout/url2png-gem
122
- licenses:
98
+ licenses:
123
99
  - MIT
124
100
  post_install_message:
125
101
  rdoc_options: []
126
-
127
- require_paths:
102
+ require_paths:
128
103
  - lib
129
- required_ruby_version: !ruby/object:Gem::Requirement
104
+ required_ruby_version: !ruby/object:Gem::Requirement
130
105
  none: false
131
- requirements:
132
- - - ">="
133
- - !ruby/object:Gem::Version
134
- hash: -4384475011927731947
135
- segments:
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ segments:
136
111
  - 0
137
- version: "0"
138
- required_rubygems_version: !ruby/object:Gem::Requirement
112
+ hash: -2618384894962089538
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
114
  none: false
140
- requirements:
141
- - - ">="
142
- - !ruby/object:Gem::Version
143
- segments:
144
- - 0
145
- version: "0"
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
146
119
  requirements: []
147
-
148
120
  rubyforge_project:
149
- rubygems_version: 1.3.7
121
+ rubygems_version: 1.8.11
150
122
  signing_key:
151
123
  specification_version: 3
152
124
  summary: A ruby gem wrapping the url2png.com screenshot service API
153
- test_files:
125
+ test_files:
154
126
  - spec/helpers/common_rspec.rb
155
127
  - spec/spec_helper.rb
156
128
  - spec/url2png_spec.rb