firefly 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -1,3 +1,7 @@
1
+ = 1.1.0 / 2010-10-02
2
+
3
+ * 2010-10-02 - Generate a QR Code image when accessing http://:host/:code.png
4
+
1
5
  = 1.0.0 / 2010-09-19
2
6
 
3
7
  * 2010-09-18 - Added better support for URLs with spaces and other special characters. Closes #19
data/Rakefile CHANGED
@@ -18,6 +18,8 @@ begin
18
18
  gemspec.add_dependency('dm-aggregates', '~> 1.0.2')
19
19
  gemspec.add_dependency('dm-sqlite-adapter', '~> 1.0.2')
20
20
  gemspec.add_dependency('haml', '~> 3.0.18')
21
+ gemspec.add_dependency('barby', '~> 0.4.0')
22
+ gemspec.add_dependency('png', '1.1.0')
21
23
 
22
24
  gemspec.add_development_dependency('rspec', '~> 1.3.0')
23
25
  gemspec.add_development_dependency('rack-test', '~> 0.5.4')
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.1.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{firefly}
8
- s.version = "1.0.1"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ariejan de Vroom"]
12
- s.date = %q{2010-09-19}
12
+ s.date = %q{2010-10-02}
13
13
  s.description = %q{FireFly is a simple URL shortner for personal use. It's powered by Sinatra and can be run with any Rack-capable web server.}
14
14
  s.email = %q{ariejan@ariejan.net}
15
15
  s.extra_rdoc_files = [
@@ -76,6 +76,8 @@ Gem::Specification.new do |s|
76
76
  s.add_runtime_dependency(%q<dm-aggregates>, ["~> 1.0.2"])
77
77
  s.add_runtime_dependency(%q<dm-sqlite-adapter>, ["~> 1.0.2"])
78
78
  s.add_runtime_dependency(%q<haml>, ["~> 3.0.18"])
79
+ s.add_runtime_dependency(%q<barby>, ["~> 0.4.0"])
80
+ s.add_runtime_dependency(%q<png>, ["= 1.1.0"])
79
81
  s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
80
82
  s.add_development_dependency(%q<rack-test>, ["~> 0.5.4"])
81
83
  else
@@ -86,6 +88,8 @@ Gem::Specification.new do |s|
86
88
  s.add_dependency(%q<dm-aggregates>, ["~> 1.0.2"])
87
89
  s.add_dependency(%q<dm-sqlite-adapter>, ["~> 1.0.2"])
88
90
  s.add_dependency(%q<haml>, ["~> 3.0.18"])
91
+ s.add_dependency(%q<barby>, ["~> 0.4.0"])
92
+ s.add_dependency(%q<png>, ["= 1.1.0"])
89
93
  s.add_dependency(%q<rspec>, ["~> 1.3.0"])
90
94
  s.add_dependency(%q<rack-test>, ["~> 0.5.4"])
91
95
  end
@@ -97,6 +101,8 @@ Gem::Specification.new do |s|
97
101
  s.add_dependency(%q<dm-aggregates>, ["~> 1.0.2"])
98
102
  s.add_dependency(%q<dm-sqlite-adapter>, ["~> 1.0.2"])
99
103
  s.add_dependency(%q<haml>, ["~> 3.0.18"])
104
+ s.add_dependency(%q<barby>, ["~> 0.4.0"])
105
+ s.add_dependency(%q<png>, ["= 1.1.0"])
100
106
  s.add_dependency(%q<rspec>, ["~> 1.3.0"])
101
107
  s.add_dependency(%q<rack-test>, ["~> 0.5.4"])
102
108
  end
@@ -7,6 +7,8 @@ require 'dm-core'
7
7
  require 'dm-migrations'
8
8
  require 'dm-transactions'
9
9
  require 'dm-aggregates'
10
+ require 'barby'
11
+ require 'barby/outputter/png_outputter'
10
12
 
11
13
  $:.unshift(File.dirname(__FILE__)) unless
12
14
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
@@ -214,6 +214,23 @@ module Firefly
214
214
  YAML::dump(output)
215
215
  end
216
216
 
217
+ # GET /b3d.png
218
+ #
219
+ # Return a QR code image
220
+ get '/:code.png' do
221
+ @url = Firefly::Url.first(:code => params[:code])
222
+
223
+ if @url.nil?
224
+ status 404
225
+ "Sorry, that code is unknown."
226
+ else
227
+ qr = Barby::QrCode.new(short_url(@url))
228
+ content_type('image/png')
229
+ cache_control :public, :max_age => 2592000 # One month
230
+ body(qr.to_png(:xdim => 15, :margin => 30))
231
+ end
232
+ end
233
+
217
234
  # GET /b3d
218
235
  #
219
236
  # Redirect to the shortened URL
@@ -14,6 +14,27 @@ describe "Firefly" do
14
14
  end
15
15
  end
16
16
 
17
+ describe "QR Codes" do
18
+ before(:each) do
19
+ @url = Firefly::Url.create(:url => 'http://example.com/123', :code => 'alpha')
20
+ end
21
+
22
+ it "should return a 200 status" do
23
+ get '/alpha.png'
24
+ last_response.should be_ok
25
+ end
26
+
27
+ it "should return a PNG image" do
28
+ get '/alpha.png'
29
+ last_response.headers['Content-Type'].should eql('image/png')
30
+ end
31
+
32
+ it "should cache-control to 1 month" do
33
+ get '/alpha.png'
34
+ last_response.headers['Cache-Control'].should eql('public, max-age=2592000')
35
+ end
36
+ end
37
+
17
38
  describe "redirecting" do
18
39
  it "should redirect to the original URL" do
19
40
  fake = Firefly::Url.create(:url => 'http://example.com/123', :code => 'alpha')
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firefly
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 0
9
8
  - 1
10
- version: 1.0.1
9
+ - 0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ariejan de Vroom
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-19 00:00:00 +02:00
18
+ date: 2010-10-02 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -130,9 +130,41 @@ dependencies:
130
130
  type: :runtime
131
131
  version_requirements: *id007
132
132
  - !ruby/object:Gem::Dependency
133
- name: rspec
133
+ name: barby
134
134
  prerelease: false
135
135
  requirement: &id008 !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ~>
139
+ - !ruby/object:Gem::Version
140
+ hash: 15
141
+ segments:
142
+ - 0
143
+ - 4
144
+ - 0
145
+ version: 0.4.0
146
+ type: :runtime
147
+ version_requirements: *id008
148
+ - !ruby/object:Gem::Dependency
149
+ name: png
150
+ prerelease: false
151
+ requirement: &id009 !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - "="
155
+ - !ruby/object:Gem::Version
156
+ hash: 19
157
+ segments:
158
+ - 1
159
+ - 1
160
+ - 0
161
+ version: 1.1.0
162
+ type: :runtime
163
+ version_requirements: *id009
164
+ - !ruby/object:Gem::Dependency
165
+ name: rspec
166
+ prerelease: false
167
+ requirement: &id010 !ruby/object:Gem::Requirement
136
168
  none: false
137
169
  requirements:
138
170
  - - ~>
@@ -144,11 +176,11 @@ dependencies:
144
176
  - 0
145
177
  version: 1.3.0
146
178
  type: :development
147
- version_requirements: *id008
179
+ version_requirements: *id010
148
180
  - !ruby/object:Gem::Dependency
149
181
  name: rack-test
150
182
  prerelease: false
151
- requirement: &id009 !ruby/object:Gem::Requirement
183
+ requirement: &id011 !ruby/object:Gem::Requirement
152
184
  none: false
153
185
  requirements:
154
186
  - - ~>
@@ -160,7 +192,7 @@ dependencies:
160
192
  - 4
161
193
  version: 0.5.4
162
194
  type: :development
163
- version_requirements: *id009
195
+ version_requirements: *id011
164
196
  description: FireFly is a simple URL shortner for personal use. It's powered by Sinatra and can be run with any Rack-capable web server.
165
197
  email: ariejan@ariejan.net
166
198
  executables: []