goqr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - rbx-19mode
5
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in goqr.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2012 Patricio Mac Adden <patriciomacadden@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # goqr [![Build Status](https://travis-ci.org/patriciomacadden/goqr.png)](https://travis-ci.org/patriciomacadden/goqr) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/patriciomacadden/goqr)
2
+
3
+ ### QR codes for ruby/rails using goqr.me API
4
+
5
+ ![patriciomacadden/goqr](http://api.qrserver.com/v1/create-qr-code/?data=https%3A%2F%2Fgithub.com%2Fpatriciomacadden%2Fgoqr&size=256x256)
6
+
7
+ ## Installation
8
+
9
+ Add it to your Gemfile and run the `bundle` command:
10
+
11
+ ```ruby
12
+ gem 'goqr'
13
+ ```
14
+
15
+ ## Getting started
16
+
17
+ In rails, you can generate a QR code just using the `goqr` helper method:
18
+
19
+ ```ruby
20
+ <%= image_tag goqr(data: 'Hi! goqr is awesome!', size: '128x128') %>
21
+ ```
22
+
23
+ ## Available options
24
+
25
+ All available options are the specified by [goqr API documentation](http://qrserver.com/api/documentation/create-qr-code/).
26
+
27
+ ## Gotchas
28
+
29
+ * If you want to generate a QR code just for text or urls, use the data
30
+ parameter normally:
31
+
32
+ ```ruby
33
+ <%= image_tag goqr(data: 'Just text') %>
34
+
35
+ <%= image_tag goqr(data: 'http://patriciomacadden.com.ar') %>
36
+ ```
37
+
38
+ * If you want to generate a QR code for phone numbers, just prepend `TEL:` in
39
+ the data parameter:
40
+
41
+ ```ruby
42
+ <%= image_tag goqr(data: 'TEL:+542211234567') %>
43
+ ```
44
+
45
+ * If you want to generate a QR code for SMSs, just prepend `SMSTO:` in the data
46
+ parameter, separating the phone number and the text by a `:`:
47
+
48
+ ```ruby
49
+ <%= image_tag goqr(data: 'SMSTO:+542211234567:Hi!') %>
50
+ ```
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it
55
+ 2. Create a branch (`git checkout -b my_awesome_branch`)
56
+ 3. Commit your changes (`git commit -am "Added some magic"`)
57
+ 4. Push to the branch (`git push origin my_awesome_branch`)
58
+ 5. Send pull request
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:spec) do |t|
5
+ t.libs << 'spec'
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+
9
+ desc 'Run specs'
10
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'goqr/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'goqr'
7
+ s.version = Goqr::VERSION
8
+ s.authors = ['Patricio Mac Adden']
9
+ s.email = ['patriciomacadden@gmail.com']
10
+ s.homepage = 'https://github.com/patriciomacadden/simple_gravatar'
11
+ s.summary = %q{QR codes for ruby/rails using goqr.me API}
12
+ s.description = %q{QR codes for ruby/rails using goqr.me API}
13
+
14
+ s.rubyforge_project = 'goqr'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ['lib']
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ s.add_dependency 'railties'
25
+ s.add_dependency 'activesupport'
26
+ end
@@ -0,0 +1,32 @@
1
+ require 'goqr/version'
2
+
3
+ module Goqr
4
+ DEFAULT_OPTIONS = {
5
+ bgcolor: 'f-f-f',
6
+ :'charset-source' => 'UTF-8',
7
+ :'charset-target' => 'UTF-8',
8
+ color: '0-0-0',
9
+ data: nil,
10
+ ecc: 'L',
11
+ format: 'png',
12
+ margin: 1,
13
+ size: '10x10',
14
+ qzone: 0
15
+ }
16
+
17
+ def goqr(options = {})
18
+ options = options.reverse_merge(DEFAULT_OPTIONS)
19
+ options[:data] = CGI.escape(options[:data])
20
+ params = options.collect { |k, v| "#{k}=#{v}" }.join('&')
21
+
22
+ "#{goqr_api_url}?#{params}"
23
+ end
24
+
25
+ private
26
+
27
+ def goqr_api_url
28
+ 'http://api.qrserver.com/v1/create-qr-code'
29
+ end
30
+ end
31
+
32
+ ActionView::Base.send(:include, Goqr) if defined? ActionView::Base
@@ -0,0 +1,3 @@
1
+ module Goqr
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+
3
+ require 'active_support/all'
4
+ require 'cgi'
5
+ require 'minitest/autorun'
6
+
7
+ require 'goqr'
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ include Goqr
4
+
5
+ describe Goqr do
6
+ describe Goqr::VERSION do
7
+ it 'should be defined' do
8
+ Goqr::VERSION.wont_be_nil
9
+ end
10
+ end
11
+
12
+ describe :goqr do
13
+ describe 'when overriding bgcolor parameter' do
14
+ it 'should be replaced' do
15
+ url = Goqr.goqr data: 'testing', bgcolor: '5-5-5'
16
+ url.must_match 'bgcolor=5-5-5'
17
+ end
18
+ end
19
+
20
+ describe 'when overriding charset-source parameter' do
21
+ it 'should be replaced' do
22
+ url = Goqr.goqr data: 'testing', :'charset-source' => 'ISO-8859-1'
23
+ url.must_match 'charset-source=ISO-8859-1'
24
+ end
25
+ end
26
+
27
+ describe 'when overriding charset-target parameter' do
28
+ it 'should be replaced' do
29
+ url = Goqr.goqr data: 'testing', :'charset-target' => 'ISO-8859-1'
30
+ url.must_match 'charset-target=ISO-8859-1'
31
+ end
32
+ end
33
+
34
+ describe 'when overriding color parameter' do
35
+ it 'should be replaced' do
36
+ url = Goqr.goqr data: 'testing', color: '5-5-5'
37
+ url.must_match 'color=5-5-5'
38
+ end
39
+ end
40
+
41
+ describe 'when overriding data parameter' do
42
+ it 'should be replaced' do
43
+ url = Goqr.goqr data: 'testing'
44
+ url.must_match 'data=testing'
45
+ end
46
+
47
+ it 'should be encoded' do
48
+ url = Goqr.goqr data: 'testing goqr'
49
+ url.must_match 'data=testing+goqr'
50
+ end
51
+ end
52
+
53
+ describe 'when overriding ecc parameter' do
54
+ it 'should be replaced' do
55
+ url = Goqr.goqr data: 'testing', ecc: 'M'
56
+ url.must_match 'ecc=M'
57
+ end
58
+ end
59
+
60
+ describe 'when overriding format parameter' do
61
+ it 'should be replaced' do
62
+ url = Goqr.goqr data: 'testing', format: 'gif'
63
+ url.must_match 'format=gif'
64
+ end
65
+ end
66
+
67
+ describe 'when overriding margin parameter' do
68
+ it 'should be replaced' do
69
+ url = Goqr.goqr data: 'testing', margin: 2
70
+ url.must_match 'margin=2'
71
+ end
72
+ end
73
+
74
+ describe 'when overriding size parameter' do
75
+ it 'should be replaced' do
76
+ url = Goqr.goqr data: 'testing', size: '50x50'
77
+ url.must_match 'size=50x50'
78
+ end
79
+ end
80
+
81
+ describe 'when overriding qzone parameter' do
82
+ it 'should be replaced' do
83
+ url = Goqr.goqr data: 'testing', qzone: 1
84
+ url.must_match 'qzone=1'
85
+ end
86
+ end
87
+ end
88
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: goqr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Patricio Mac Adden
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: &70341733019020 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70341733019020
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &70341733033060 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70341733033060
36
+ description: QR codes for ruby/rails using goqr.me API
37
+ email:
38
+ - patriciomacadden@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - .travis.yml
45
+ - Gemfile
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - goqr.gemspec
50
+ - lib/goqr.rb
51
+ - lib/goqr/version.rb
52
+ - spec/spec_helper.rb
53
+ - spec/unit/goqr_spec.rb
54
+ homepage: https://github.com/patriciomacadden/simple_gravatar
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project: goqr
74
+ rubygems_version: 1.8.17
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: QR codes for ruby/rails using goqr.me API
78
+ test_files:
79
+ - spec/spec_helper.rb
80
+ - spec/unit/goqr_spec.rb