quick_response 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/lib/quick_response/base.rb +69 -0
- data/lib/quick_response/shorthand.rb +35 -0
- data/lib/quick_response/types/call.rb +5 -0
- data/lib/quick_response/types/email.rb +5 -0
- data/lib/quick_response/types/geo.rb +5 -0
- data/lib/quick_response/types/maps.rb +10 -0
- data/lib/quick_response/types/sms.rb +5 -0
- data/lib/quick_response/types/text.rb +5 -0
- data/lib/quick_response/types/url.rb +5 -0
- data/lib/quick_response/version.rb +3 -0
- data/lib/quick_response.rb +19 -0
- data/quick_response.gemspec +22 -0
- metadata +97 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
module QuickResponse
|
2
|
+
class Base
|
3
|
+
GOOGLE_CHART_API = "http://chart.apis.google.com/chart"
|
4
|
+
DEFAULT_OPTIONS = { :size => 256 }
|
5
|
+
|
6
|
+
attr_reader :content
|
7
|
+
attr_accessor :size
|
8
|
+
|
9
|
+
def initialize(*args)
|
10
|
+
# Extract options
|
11
|
+
options = args.last.is_a?(Hash) ? DEFAULT_OPTIONS.merge(args.pop) : DEFAULT_OPTIONS
|
12
|
+
|
13
|
+
self.content = args
|
14
|
+
self.size = options[:size]
|
15
|
+
end
|
16
|
+
|
17
|
+
def content=(*args)
|
18
|
+
@content = to_format(args)
|
19
|
+
end
|
20
|
+
|
21
|
+
def image_url
|
22
|
+
uri.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
def save(location = "./qr.png")
|
26
|
+
Net::HTTP.start(uri.host) do |http|
|
27
|
+
resp = http.get(image_url)
|
28
|
+
open(location, 'wb') do |file|
|
29
|
+
file.write(resp.body)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def uri
|
37
|
+
@uri ||= URI.parse(GOOGLE_CHART_API)
|
38
|
+
@uri.query = [cht, chs, chl].join("&")
|
39
|
+
@uri
|
40
|
+
end
|
41
|
+
|
42
|
+
def cht
|
43
|
+
param :cht, "qr"
|
44
|
+
end
|
45
|
+
|
46
|
+
def chs
|
47
|
+
param :chs, "?x?".gsub("?", size.to_s)
|
48
|
+
end
|
49
|
+
|
50
|
+
def chl
|
51
|
+
param :chl, CGI.escape(content)
|
52
|
+
end
|
53
|
+
|
54
|
+
def param(key, value)
|
55
|
+
[key.to_s, value].join("=")
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.format(format, options = {})
|
59
|
+
define_method :to_format do |args|
|
60
|
+
args = args.slice(0, options[:limit]) if options[:limit]
|
61
|
+
output = options[:output] || format
|
62
|
+
str = args.join(options[:join])
|
63
|
+
|
64
|
+
str.match(format) ? str : output.gsub("(.*)", str)
|
65
|
+
end
|
66
|
+
private :to_format
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module QuickResponse
|
2
|
+
module Shorthand
|
3
|
+
def new(*args)
|
4
|
+
args.first.is_a?(Symbol) ? send(*args) : text(*args)
|
5
|
+
end
|
6
|
+
|
7
|
+
def text(*args)
|
8
|
+
::QuickResponse::Text.new(*args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def url(*args)
|
12
|
+
::QuickResponse::Url.new(*args)
|
13
|
+
end
|
14
|
+
|
15
|
+
def email(*args)
|
16
|
+
::QuickResponse::Email.new(*args)
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(*args)
|
20
|
+
::QuickResponse::Call.new(*args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def sms(*args)
|
24
|
+
::QuickResponse::Sms.new(*args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def geo(*args)
|
28
|
+
::QuickResponse::Geo.new(*args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def maps(*args)
|
32
|
+
::QuickResponse::Maps.new(*args)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'uri'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module QuickResponse
|
6
|
+
autoload :Base, "quick_response/base"
|
7
|
+
|
8
|
+
autoload :Text, "quick_response/types/text"
|
9
|
+
autoload :Url, "quick_response/types/url"
|
10
|
+
autoload :Email, "quick_response/types/email"
|
11
|
+
autoload :Call, "quick_response/types/call"
|
12
|
+
autoload :Sms, "quick_response/types/sms"
|
13
|
+
autoload :Geo, "quick_response/types/geo"
|
14
|
+
autoload :Maps, "quick_response/types/maps"
|
15
|
+
|
16
|
+
autoload :Shorthand, "quick_response/shorthand"
|
17
|
+
|
18
|
+
extend Shorthand
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/quick_response/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "quick_response"
|
6
|
+
s.version = QuickResponse::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Robin Clart"]
|
9
|
+
s.email = ["robin@charlin.be"]
|
10
|
+
s.homepage = "http://rubygems.org/gems/quick_response"
|
11
|
+
s.summary = "QR code generator"
|
12
|
+
s.description = "A simple gem that output an image url for a given data"
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "quick_response"
|
16
|
+
|
17
|
+
s.add_development_dependency "bundler", ">= 1.0.0.rc.6"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
21
|
+
s.require_path = 'lib'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quick_response
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Robin Clart
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-03-03 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- rc
|
33
|
+
- 6
|
34
|
+
version: 1.0.0.rc.6
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: A simple gem that output an image url for a given data
|
38
|
+
email:
|
39
|
+
- robin@charlin.be
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- .gitignore
|
48
|
+
- Gemfile
|
49
|
+
- Rakefile
|
50
|
+
- lib/quick_response.rb
|
51
|
+
- lib/quick_response/base.rb
|
52
|
+
- lib/quick_response/shorthand.rb
|
53
|
+
- lib/quick_response/types/call.rb
|
54
|
+
- lib/quick_response/types/email.rb
|
55
|
+
- lib/quick_response/types/geo.rb
|
56
|
+
- lib/quick_response/types/maps.rb
|
57
|
+
- lib/quick_response/types/sms.rb
|
58
|
+
- lib/quick_response/types/text.rb
|
59
|
+
- lib/quick_response/types/url.rb
|
60
|
+
- lib/quick_response/version.rb
|
61
|
+
- quick_response.gemspec
|
62
|
+
has_rdoc: true
|
63
|
+
homepage: http://rubygems.org/gems/quick_response
|
64
|
+
licenses: []
|
65
|
+
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
segments:
|
85
|
+
- 1
|
86
|
+
- 3
|
87
|
+
- 6
|
88
|
+
version: 1.3.6
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project: quick_response
|
92
|
+
rubygems_version: 1.3.7
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: QR code generator
|
96
|
+
test_files: []
|
97
|
+
|