barcodeservice 1.0.0

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/.gems ADDED
@@ -0,0 +1,2 @@
1
+ gbarcode
2
+
data/README.markdown ADDED
@@ -0,0 +1,24 @@
1
+ # Barcode Service
2
+
3
+ This is a simple Sinatra server that turns simple web requests into formatted barcode images.
4
+
5
+
6
+ ## Instant installation and deploy
7
+
8
+ * Clone this: `git clone git://github.com/JackDanger/barcodeservice.git`
9
+ * Signup for an account at Heroku ([better details here](http://github.com/sinatra/heroku-sinatra-app))
10
+ * push it to Heroku.com: `git push heroku master`
11
+
12
+
13
+ ## HowTo
14
+
15
+ You can embed barcodes into your web pages simply by using an <img> tag
16
+
17
+ <img src="http://my-barcode-server.heroku.com/999999999999999.png?type=ISBN" />
18
+ <img src="http://my-barcode-server.heroku.com/ABCDEF1232333.png?type=code93" />
19
+ <img src="http://my-barcode-server.heroku.com/ABC123.png?type=code93&width=50&height=30&x=4&y=200&scale=2" />
20
+
21
+
22
+ Patches welcome, forks celebrated.
23
+
24
+ Copyright (c) 2010 [Jack Danger Canty](http://jåck.com). Released under the MIT License.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ gem.name = "barcodeservice"
5
+ gem.summary = %Q{lightwight barcode image server running on Heroku.com}
6
+ gem.description = %Q{Run your own barcode image generator for free on Heroku.com}
7
+ gem.email = "gitcommit@6brand.com"
8
+ gem.homepage = "http://github.com/JackDanger/barcodeservice"
9
+ gem.authors = ["Jack Danger Canty"]
10
+ gem.add_development_dependency "shoulda", ">= 0"
11
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
12
+ end
13
+ Jeweler::GemcutterTasks.new
14
+ rescue LoadError
15
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
16
+ end
17
+
18
+
19
+
20
+ task :default => :test
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << '.'
25
+ test.pattern = 'test.rb'
26
+ test.verbose = true
27
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/config.ru ADDED
@@ -0,0 +1,6 @@
1
+ require 'lib/barcode_service_server'
2
+
3
+ ## There is no need to set directories here anymore;
4
+ ## Just run the application
5
+
6
+ run Sinatra::Application
@@ -0,0 +1,99 @@
1
+ ## Resources
2
+ require 'rubygems'
3
+ gem 'sinatra', '~> 1.0.0'
4
+ require 'sinatra'
5
+ gem 'gbarcode'
6
+ require 'gbarcode'
7
+
8
+
9
+
10
+ ## Application
11
+
12
+
13
+ get '/:code.:extension' do
14
+ # begin
15
+ options = request.env['rack.request.query_hash']
16
+ options = default_options.merge(options)
17
+
18
+ content_type "image/#{params[:extension]}"
19
+
20
+ Converter.encode params[:code], params[:extension], options
21
+ # rescue => error
22
+ # puts error.inspect
23
+ # status 400
24
+ # end
25
+ end
26
+
27
+ get '/' do
28
+ %Q{
29
+ <body style='line-height: 1.8em; font-family: Archer, Museo, Helvetica, Georgia; font-size 25px; text-align: center; padding-top: 20%;'>
30
+ Get a barcode image by crafting a url at this domain.
31
+ <pre style='font-family: Iconsolata, monospace;background-color:#EEE'><img src="http://#{request.host}/12345632323.jpg?type=isbn</pre>
32
+ <br />
33
+ Also, try <a href='http://github.com/JackDanger/barcodeservice'>the official Ruby client</a>
34
+ </body
35
+ }
36
+ end
37
+
38
+ ## HELPERS
39
+
40
+ def default_options
41
+ {
42
+ :type => '93',
43
+ :output => 'png',
44
+ :width => 100,
45
+ :height => 50,
46
+ :x => 0,
47
+ :y => 0,
48
+ :margin => 0,
49
+ :scale => 0
50
+ }
51
+ end
52
+
53
+ TYPES = {
54
+ 'ean' => 'BARCODE_EAN',
55
+ 'upc' => 'BARCODE_UPC',
56
+ 'isbn' => 'BARCODE_ISBN',
57
+ '128b' => 'BARCODE_128B',
58
+ '128C' => 'BARCODE_128C',
59
+ '128' => 'BARCODE_128',
60
+ '128raw' => 'BARCODE_128RAW',
61
+ '39' => 'BARCODE_39',
62
+ 'I25' => 'BARCODE_I25',
63
+ 'cbr' => 'BARCODE_CBR',
64
+ 'msi' => 'BARCODE_MSI',
65
+ 'pls' => 'BARCODE_PLS',
66
+ '93' => 'BARCODE_93'
67
+ }
68
+
69
+ module Converter
70
+ include Gbarcode
71
+ extend Gbarcode
72
+ def self.encode(code, format, options)
73
+ require 'stringio'
74
+
75
+ barcode = barcode_create(code)
76
+ barcode_encode barcode, BARCODE_NO_CHECKSUM | const_get(TYPES[options[:type]])
77
+ file = Tempfile.new('barcode')
78
+ File.open(file.path, 'w') do |f|
79
+ barcode_print(barcode, f, BARCODE_OUT_EPS)
80
+ end
81
+
82
+ output = case format
83
+ when 'eps'
84
+ file.read
85
+ when "png"
86
+ %x{convert eps:#{file.path} png:-}
87
+ when "jpg", "jpeg"
88
+ %x{convert eps:#{file.path} jpg:-}
89
+ when "gif"
90
+ %x{convert eps:#{file.path} gif:-}
91
+ end
92
+
93
+ file.unlink
94
+
95
+ output
96
+ end
97
+ end
98
+
99
+
@@ -0,0 +1 @@
1
+ require 'barcode_service'
data/test.rb ADDED
@@ -0,0 +1,64 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+ require 'shoulda'
6
+ require 'rack/test'
7
+ require 'lib/barcode_service'
8
+
9
+ class BarcodeServiceTest < Test::Unit::TestCase
10
+ include Rack::Test::Methods
11
+
12
+ def app
13
+ Sinatra::Application
14
+ end
15
+
16
+ context "on GET to /" do
17
+ setup {
18
+ get '/'
19
+ }
20
+ should "return ok" do
21
+ assert last_response.ok?
22
+ end
23
+ should "have some kind of welcome" do
24
+ assert last_response.body =~ /<img/
25
+ end
26
+ end
27
+
28
+ {:eps => /%!PS-Adobe-2.0 EPSF-1.2/,
29
+ :gif => /^GIF89/,
30
+ :png => /^.?PNG/,
31
+ :jpeg => //
32
+ }.each do |format, fileheader|
33
+ context "on GET with code and #{format} type" do
34
+ setup {
35
+ get "/1234322.#{format}"
36
+ }
37
+ should "return ok" do
38
+ assert last_response.ok?
39
+ end
40
+ should "return #{format} content-type" do
41
+ assert_equal "image/#{format}", last_response.headers['Content-Type']
42
+ end
43
+ should "return the #{format} document" do
44
+ body = last_response.body
45
+ body.force_encoding('binary') if body.respond_to?(:force_encoding)
46
+ assert body =~ fileheader
47
+ end
48
+ end
49
+ end
50
+
51
+ TYPES.each do |type|
52
+ context "on GET with code and #{type} barcode" do
53
+ setup {
54
+ get "/1234322.png?type=#{type}"
55
+ }
56
+ should "return ok" do
57
+ assert last_response.ok?
58
+ end
59
+ should "return png content-type" do
60
+ assert_equal "image/png", last_response.headers['Content-Type']
61
+ end
62
+ end
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: barcodeservice
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Jack Danger Canty
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-02 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: Run your own barcode image generator for free on Heroku.com
36
+ email: gitcommit@6brand.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.markdown
43
+ files:
44
+ - .gems
45
+ - README.markdown
46
+ - Rakefile
47
+ - VERSION
48
+ - config.ru
49
+ - lib/barcode_service.rb
50
+ - lib/barcodeservice.rb
51
+ - test.rb
52
+ has_rdoc: true
53
+ homepage: http://github.com/JackDanger/barcodeservice
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --charset=UTF-8
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.7
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: lightwight barcode image server running on Heroku.com
86
+ test_files: []
87
+