Permalink
Browse files

cleaning up unneeded structure

  • Loading branch information...
1 parent 71e51b1 commit b63246855af6cbde025aa7cbf327e87e82532450 @JackDanger JackDanger committed Oct 2, 2010
Showing with 99 additions and 131 deletions.
  1. +98 −2 lib/barcode_service.rb
  2. +0 −29 lib/barcode_service_client.rb
  3. +0 −99 lib/barcode_service_server.rb
  4. +1 −1 test.rb
View
@@ -1,3 +1,99 @@
-module BarcodeService
+## Resources
+require 'rubygems'
+gem 'sinatra', '~> 1.0.0'
+require 'sinatra'
+gem 'gbarcode'
+require 'gbarcode'
+
+
+
+## Application
+
+
+get '/:code.:extension' do
+ # begin
+ options = request.env['rack.request.query_hash']
+ options = default_options.merge(options)
+
+ content_type "image/#{params[:extension]}"
+
+ Converter.encode params[:code], params[:extension], options
+ # rescue => error
+ # puts error.inspect
+ # status 400
+ # end
end
-require 'barcode_service_client'
+
+get '/' do
+ %Q{
+ <body style='line-height: 1.8em; font-family: Archer, Museo, Helvetica, Georgia; font-size 25px; text-align: center; padding-top: 20%;'>
+ Get a barcode image by crafting a url at this domain.
+ <pre style='font-family: Iconsolata, monospace;background-color:#EEE'><img src="http://#{request.host}/12345632323.jpg?type=isbn</pre>
+ <br />
+ Also, try <a href='http://github.com/JackDanger/barcodeservice'>the official Ruby client</a>
+ </body
+}
+end
+
+## HELPERS
+
+def default_options
+ {
+ :type => '93',
+ :output => 'png',
+ :width => 100,
+ :height => 50,
+ :x => 0,
+ :y => 0,
+ :margin => 0,
+ :scale => 0
+ }
+end
+
+TYPES = {
+ 'ean' => 'BARCODE_EAN',
+ 'upc' => 'BARCODE_UPC',
+ 'isbn' => 'BARCODE_ISBN',
+ '128b' => 'BARCODE_128B',
+ '128C' => 'BARCODE_128C',
+ '128' => 'BARCODE_128',
+ '128raw' => 'BARCODE_128RAW',
+ '39' => 'BARCODE_39',
+ 'I25' => 'BARCODE_I25',
+ 'cbr' => 'BARCODE_CBR',
+ 'msi' => 'BARCODE_MSI',
+ 'pls' => 'BARCODE_PLS',
+ '93' => 'BARCODE_93'
+}
+
+module Converter
+ include Gbarcode
+ extend Gbarcode
+ def self.encode(code, format, options)
+ require 'stringio'
+
+ barcode = barcode_create(code)
+ barcode_encode barcode, BARCODE_NO_CHECKSUM | const_get(TYPES[options[:type]])
+ file = Tempfile.new('barcode')
+ File.open(file.path, 'w') do |f|
+ barcode_print(barcode, f, BARCODE_OUT_EPS)
+ end
+
+ output = case format
+ when 'eps'
+ file.read
+ when "png"
+ %x{convert eps:#{file.path} png:-}
+ when "jpg", "jpeg"
+ %x{convert eps:#{file.path} jpg:-}
+ when "gif"
+ %x{convert eps:#{file.path} gif:-}
+ end
+
+ file.unlink
+
+ output
+ end
+end
+
+
@@ -1,29 +0,0 @@
-#
-# HowTo:
-#
-# client = BarcodeService::Client.new 'http://my-barcodeservice-app.com'
-# pdf_content = client.render '<html></html>'
-#
-module BarcodeService
- class Client
- # @server: "http://myserver.com"
- def initialize(server)
- require 'net/http'
- @server = URI.parse server
- end
-
- def render code
- start do |http|
- http.get("/?code=#{code}").read_body
- end
- end
-
- protected
-
- def start
- Net::HTTP.start @server.host, @server.port do |http|
- yield http
- end
- end
- end
-end
@@ -1,99 +0,0 @@
-## Resources
-require 'rubygems'
-gem 'sinatra', '~> 1.0.0'
-require 'sinatra'
-gem 'gbarcode'
-require 'gbarcode'
-
-
-
-## Application
-
-
-get '/:code.:extension' do
- # begin
- options = request.env['rack.request.query_hash']
- options = default_options.merge(options)
-
- content_type "image/#{params[:extension]}"
-
- Converter.encode params[:code], params[:extension], options
- # rescue => error
- # puts error.inspect
- # status 400
- # end
-end
-
-get '/' do
- %Q{
- <body style='line-height: 1.8em; font-family: Archer, Museo, Helvetica, Georgia; font-size 25px; text-align: center; padding-top: 20%;'>
- Get a barcode image by crafting a url at this domain.
- <pre style='font-family: Iconsolata, monospace;background-color:#EEE'><img src="http://#{request.host}/12345632323.jpg?type=isbn</pre>
- <br />
- Also, try <a href='http://github.com/JackDanger/barcodeservice'>the official Ruby client</a>
- </body
-}
-end
-
-## HELPERS
-
-def default_options
- {
- :type => '93',
- :output => 'png',
- :width => 100,
- :height => 50,
- :x => 0,
- :y => 0,
- :margin => 0,
- :scale => 0
- }
-end
-
-TYPES = {
- 'ean' => 'BARCODE_EAN',
- 'upc' => 'BARCODE_UPC',
- 'isbn' => 'BARCODE_ISBN',
- '128b' => 'BARCODE_128B',
- '128C' => 'BARCODE_128C',
- '128' => 'BARCODE_128',
- '128raw' => 'BARCODE_128RAW',
- '39' => 'BARCODE_39',
- 'I25' => 'BARCODE_I25',
- 'cbr' => 'BARCODE_CBR',
- 'msi' => 'BARCODE_MSI',
- 'pls' => 'BARCODE_PLS',
- '93' => 'BARCODE_93'
-}
-
-module Converter
- include Gbarcode
- extend Gbarcode
- def self.encode(code, format, options)
- require 'stringio'
-
- barcode = barcode_create(code)
- barcode_encode barcode, BARCODE_NO_CHECKSUM | const_get(TYPES[options[:type]])
- file = Tempfile.new('barcode')
- File.open(file.path, 'w') do |f|
- barcode_print(barcode, f, BARCODE_OUT_EPS)
- end
-
- output = case format
- when 'eps'
- file.read
- when "png"
- %x{convert eps:#{file.path} png:-}
- when "jpg", "jpeg"
- %x{convert eps:#{file.path} jpg:-}
- when "gif"
- %x{convert eps:#{file.path} gif:-}
- end
-
- file.unlink
-
- output
- end
-end
-
-
View
@@ -4,7 +4,7 @@
require 'test/unit'
require 'shoulda'
require 'rack/test'
-require 'lib/barcode_service_server'
+require 'lib/barcode_service'
class BarcodeServiceTest < Test::Unit::TestCase
include Rack::Test::Methods

0 comments on commit b632468

Please sign in to comment.