atpay_ruby 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16c8bf8c8ecb3f3257db50655417cfdc49391a93
4
- data.tar.gz: ca3b3ba2368ecd8bd103eee30f119736ecad28da
3
+ metadata.gz: c80a4321370c8a361724914a5abe9e298a182332
4
+ data.tar.gz: 2365ba4fa43a147fbdca7bcb9d38219b388be574
5
5
  SHA512:
6
- metadata.gz: b4a822b4306f3029790cf321a04899450977f50d38305cca4d3d43e34432e1b963aa41670fcd1e9914f89afaa5d81cc818e257aaf3447600a9678ff863eb6c9c
7
- data.tar.gz: 9a9585cc0d3c05ba2f7470c8661518815b8dcc9a738d92d94efcc8763cc769b8f2a9fa036b33eb29f478bf9eeee26a819e355ea8b83a7e57b2cb708a8fc930c3
6
+ metadata.gz: c203ffa39e4a0247b466ae4a03c5f7af54108b197ee15e8d396bcfe285e73068bdbb72381a71b4f9dddbc7574f8da4f1b3dd31f9bef0159ff2af262b9cef1566
7
+ data.tar.gz: f24c18d7bb17a44fc6fd8bbdb1f670db9b8f7c2294b9e24d1d3e049ac6ce858d3f27e2bbaeead546fba3d10be1bba65f872640efb9a71d95f123e9364a3f2b72
data/README.md CHANGED
@@ -263,6 +263,24 @@ email(button, recipient_address)
263
263
 
264
264
  Default options are [AtPay::Button::OPTIONS](lib/atpay/button.rb).
265
265
 
266
+ ## QR Code Generation
267
+
268
+ NOTE: These functions require independent installation of the `qrencoder` and
269
+ `rasem` gems.
270
+
271
+ As an alternative to the standard Button presentation, a QR code can trigger an
272
+ outgoing email on a Customer's device. To create a QR code, first create
273
+ a button, and then use `AtPay::Button::QRCode`:
274
+
275
+ ```ruby
276
+ token = AtPay::Token::Bulk.new(session, 20.00)
277
+ button = AtPay::Button.new(token.to_s, 20.00, 'My Company').render
278
+ qr = AtPay::Button::QRCode.new(button)
279
+
280
+ File.write("code.png", qr.png) # Export PNG
281
+ File.write("code.svg", qr.svg) # Export SVG
282
+ ```
283
+
266
284
  ## Command Line Usage
267
285
 
268
286
  The `atpay` utility generates **Invoice Tokens**, **Bulk Tokens**, and **Email Buttons**
data/atpay_ruby.gemspec CHANGED
@@ -2,7 +2,7 @@ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'atpay_ruby'
5
- s.version = '0.0.9'
5
+ s.version = '0.0.10'
6
6
  s.summary = 'Ruby bindings for the @Pay API'
7
7
  s.description = ""
8
8
  s.authors = ['James Kassemi', 'Isaiah Baca']
@@ -0,0 +1,30 @@
1
+ # Note: You'll need qrencoder (https://rubygems.org/gems/qrencoder)
2
+ # and rasem (https://rubygems.org/gems/rasem) for this functionality.
3
+
4
+ require 'qrencoder'
5
+ require 'rasem'
6
+ require 'cgi'
7
+
8
+ class AtPay::Button::QRCode
9
+ attr_reader :qr
10
+
11
+ def initialize(button)
12
+ content = CGI.unescape(button.default_mailto)
13
+ @qr = QREncoder.encode(content, correction: :low)
14
+ end
15
+
16
+ def png(pixels_per_module=6)
17
+ @qr.png(pixels_per_module: pixels_per_module).to_blob
18
+ end
19
+
20
+ def svg
21
+ points = @qr.points
22
+ scale = 10
23
+
24
+ Rasem::SVGImage.new(@qr.width * scale, @qr.height * scale) do
25
+ points.each do |point|
26
+ rectangle point[0] * scale, point[1] * scale, scale, scale
27
+ end
28
+ end.output
29
+ end
30
+ end
@@ -0,0 +1,28 @@
1
+ begin
2
+ require 'qrencoder'
3
+ require 'rasem'
4
+ rescue LoadError
5
+ puts %(WARN: Skipping AtPay::Button::QRCode specs - requires 'qrencoder' and 'rasem')
6
+ else
7
+ require 'spec_helper'
8
+ require 'atpay/button'
9
+ require 'atpay/button/qr_code'
10
+
11
+ describe AtPay::Button::QRCode do
12
+ subject { described_class.new(button) }
13
+ let(:button) { instance_double('AtPay::Button', :default_mailto => button_content) }
14
+ let(:button_content) { 'abcd' }
15
+
16
+ it 'produces a valid png' do
17
+ png = subject.png
18
+ File.write('tmp.png', png)
19
+ expect(`sips -g all tmp.png`).to match(/pixelWidth:/)
20
+ end
21
+
22
+ it 'produces svg data' do
23
+ svg = subject.svg
24
+ expect(svg).to match(%r{<svg\s})
25
+ expect(svg).to match(%r{</svg>})
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atpay_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Kassemi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-12 00:00:00.000000000 Z
12
+ date: 2014-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rbnacl-libsodium
@@ -146,6 +146,7 @@ files:
146
146
  - bin/atpay
147
147
  - lib/atpay.rb
148
148
  - lib/atpay/button.rb
149
+ - lib/atpay/button/qr_code.rb
149
150
  - lib/atpay/card.rb
150
151
  - lib/atpay/email_address.rb
151
152
  - lib/atpay/error.rb
@@ -157,6 +158,7 @@ files:
157
158
  - lib/atpay/token/encoder.rb
158
159
  - lib/atpay/token/invoice.rb
159
160
  - lib/atpay/token/registration.rb
161
+ - spec/button/qr_code_spec.rb
160
162
  - spec/button_spec.rb
161
163
  - spec/hook_spec.rb
162
164
  - spec/spec_helper.rb
@@ -190,6 +192,7 @@ signing_key:
190
192
  specification_version: 4
191
193
  summary: Ruby bindings for the @Pay API
192
194
  test_files:
195
+ - spec/button/qr_code_spec.rb
193
196
  - spec/button_spec.rb
194
197
  - spec/hook_spec.rb
195
198
  - spec/spec_helper.rb