passbook-ruby 0.0.5

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.
@@ -0,0 +1,27 @@
1
+
2
+ # Copyright 2012 Xtreme Labs
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
17
+
18
+
19
+ Passbook::Config.instance.add_pkpass do |passbook|
20
+ passbook.pass_config["<%= pass_type_id %>"]={
21
+ "cert_path"=>"<%= cert_path.blank? ? "#{Rails.root}/data/certificates/#{pass_type_id}.p12" : cert_path %>",
22
+ "cert_password"=>"<%= cert_password %>",
23
+ "template_path"=>"<%= "#{Rails.root}/data/templates/#{pass_type_id}" %>",
24
+ "class"=>"<%= class_name %>"
25
+ }
26
+
27
+ end
@@ -0,0 +1,29 @@
1
+
2
+ # Copyright 2012 Xtreme Labs
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
17
+
18
+
19
+ class Create<%= class_name.pluralize %> < ActiveRecord::Migration
20
+ def change
21
+ create_table :<%= plural_name %> do |t|
22
+ t.string :serial_number
23
+ t.string :authentication_token
24
+ t.string :card_id
25
+
26
+ t.timestamps
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,54 @@
1
+
2
+ # Copyright 2012 Xtreme Labs
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
17
+
18
+
19
+ class <%= class_name %> < ActiveRecord::Base
20
+ attr_protected :serial_number, :authentication_token
21
+ attr_accessible :card_id
22
+ before_create :set_pass_fields
23
+
24
+ def set_pass_fields
25
+ self.authentication_token = Base64.urlsafe_encode64(SecureRandom.base64(36))
26
+ self.serial_number||= Base64.urlsafe_encode64(SecureRandom.base64(36))
27
+ end
28
+
29
+ def self.update_or_create params
30
+ <%= plural_name.singularize %>_pass = find_by_card_id params[:card_id]
31
+ <%= plural_name.singularize %>_pass ||=new
32
+ params.slice(*attr_accessible[:default].map(&:to_sym)).each do |attr, val|
33
+ <%= plural_name.singularize %>_pass.send :"#{attr}=", val
34
+ end
35
+ <%= plural_name.singularize %>_pass.save!
36
+ <%= plural_name.singularize %>_pass
37
+ end
38
+
39
+ def check_for_updates
40
+
41
+ end
42
+
43
+ def update_pass pkpass
44
+ update_json pkpass.json
45
+ end
46
+
47
+ def update_json pass_json
48
+ pass_json['authenticationToken'] = authentication_token
49
+ pass_json['serialNumber'] = serial_number
50
+ #don't forget to change the URL to whatever address your server is at
51
+ pass_json['webServiceURL'] = "http://192.168.x.x:3000"
52
+ #add more customization to your passbook's JSON right here
53
+ end
54
+ end
@@ -0,0 +1,38 @@
1
+ {
2
+ "formatVersion" : 1,
3
+ "passTypeIdentifier" : "<%= pass_type_id %>",
4
+ "serialNumber" : "12345",
5
+ "teamIdentifier" : "<%= team_id %>",
6
+ "webServiceURL" : "http://192.168.91.151:3000",
7
+ "authenticationToken" : "",
8
+ "barcode" : {
9
+ "message" : "34534636",
10
+ "format" : "PKBarcodeFormatPDF417",
11
+ "messageEncoding" : "iso-8859-1"
12
+ },
13
+ "organizationName" : "ACME Inc.",
14
+ "description" : "",
15
+ "logoText" : "ACME",
16
+ "foregroundColor" : "rgb(22, 55, 110)",
17
+ "backgroundColor" : "rgb(50, 91, 185)",
18
+ "coupon" : {
19
+ "headerFields" : [
20
+ {
21
+ "label" : "TEST",
22
+ "key" : "test",
23
+ "value" : "#1",
24
+ "changeMessage" : "Test number changed to %@."
25
+ }
26
+ ],
27
+ "primaryFields" : [
28
+ {
29
+ "key" : "passbook",
30
+ "label" : "",
31
+ "value" : "<%= class_name %>"
32
+ }
33
+ ],
34
+ "secondaryFields" : [],
35
+ "auxiliaryFields" : [],
36
+ "backFields" : []
37
+ }
38
+ }
@@ -0,0 +1,45 @@
1
+
2
+ # Copyright 2012 Xtreme Labs
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
17
+
18
+
19
+ require 'spec_helper'
20
+
21
+ describe Passbook::Config do
22
+ it "should throw ArgumentError because wwdr_intermediate_certificate_path is missing" do
23
+ expect {Passbook::Config.instance.configure {}}.to raise_error(ArgumentError)
24
+ end
25
+
26
+ it "should throw ArgumentError because cert_path is missing" do
27
+ expect{ Passbook::Config.instance.add_pkpass do |passbook|
28
+ passbook.wwdr_intermediate_certificate_path = "test"
29
+ passbook.wwdr_certificate = OpenSSL::X509::Certificate.new
30
+ passbook.pass_config["pass.com.acme"] = {"template_path"=>"tmp"}
31
+ end}.to raise_error(ArgumentError)
32
+ end
33
+
34
+ it "should throw ArgumentError because cert_password is missing" do
35
+ expect{ Passbook::Config.instance.add_pkpass do |passbook|
36
+ passbook.wwdr_intermediate_certificate_path = "test"
37
+ passbook.wwdr_certificate = OpenSSL::X509::Certificate.new
38
+ passbook.pass_config["pass.com.acme"] = {
39
+ "cert_path"=>"tmp"
40
+ }
41
+ end}.to raise_error(ArgumentError)
42
+ end
43
+
44
+ end
45
+
@@ -0,0 +1,26 @@
1
+ {
2
+ "formatVersion" : 1,
3
+ "passTypeIdentifier" : "pass.com.acme",
4
+ "serialNumber" : "werwer",
5
+ "teamIdentifier" : "sdfsdfsdf",
6
+ "webServiceURL" : "https://acme.com/passes/",
7
+ "authenticationToken" : "werwfdsfd",
8
+ "barcode" : {
9
+ "message" : "",
10
+ "format" : "PKBarcodeFormatPDF417",
11
+ "messageEncoding" : "iso-8859-1"
12
+ },
13
+ "organizationName" : "Acme",
14
+ "description" : "test",
15
+ "logoText" : "test",
16
+ "foregroundColor" : "rgb(0, 0, 0)",
17
+ "backgroundColor" : "rgb(0, 0, 0)",
18
+ "boardingPass" : {
19
+ "transitType" : "PKTransitTypeAir",
20
+ "headerFields" : [],
21
+ "primaryFields" : [],
22
+ "secondaryFields" : [],
23
+ "auxiliaryFields" : [],
24
+ "backFields" : []
25
+ }
26
+ }
@@ -0,0 +1,117 @@
1
+
2
+ # Copyright 2012 Xtreme Labs
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
17
+
18
+
19
+ require 'spec_helper'
20
+ require 'json'
21
+
22
+
23
+ RSpec.configure do |c|
24
+ c.include Helpers
25
+ end
26
+
27
+ describe Passbook::Pkpass do
28
+ before :all do
29
+ Passbook::Config.instance.configure do |passbook|
30
+ passbook.wwdr_certificate = OpenSSL::X509::Certificate.new
31
+ end
32
+
33
+ Passbook::Config.instance.add_pkpass do |passbook|
34
+ template_path = "#{Dir.pwd}/spec/data/templates"
35
+ cert_path = "#{Dir.pwd}/spec/data/certificates"
36
+ passbook.pass_config["pass.com.acme"]={
37
+ "cert_path"=>"#{cert_path}/pass.com.acme.p12",
38
+ "cert_password"=>"test",
39
+ "template_path"=>"#{template_path}/pass.com.acme",
40
+ "p12_certificate"=>create_p12
41
+ }
42
+ passbook.wwdr_intermediate_certificate_path = "#{Dir.pwd}/spec/data/certificates/wwdr.pem"
43
+ end
44
+ end
45
+
46
+ before :each do
47
+ @pass = Passbook::Pkpass.new("pass.com.acme", "test")
48
+ end
49
+
50
+
51
+ it "should throw ArgumentError because there is no config for 'test'" do
52
+ expect {Passbook::Pkpass.new("test", "test")}.to raise_error(ArgumentError, /configuration for test/)
53
+ end
54
+
55
+ it "should make an instance of Pkpass" do
56
+ expect {Passbook::Pkpass.new("pass.com.acme", "test")}.to_not raise_error
57
+ end
58
+
59
+ it "should have the added file in zip file" do
60
+ @pass.add_file "andrei.png", "haha"
61
+ pkpass_io = @pass.package
62
+ check_file_in_zip(pkpass_io, "andrei.png").should be_true
63
+ end
64
+
65
+ it "should have the added file in zip file(in a folder)" do
66
+ @pass.add_file "fr.lproj/andrei.png", "haha"
67
+ pkpass_io = @pass.package
68
+ check_file_in_zip(pkpass_io, "fr.lproj/andrei.png").should be_true
69
+ end
70
+
71
+ it "should add an entry in the right pass.strings file" do
72
+ @pass.add_translation_string "yes", "qui", "fr"
73
+ pass_strings = file_from_zip(@pass.package, "fr.lproj/pass.strings")
74
+ pass_strings.should_not be_nil
75
+ pass_strings.should match /\"yes\" = \"qui\";/
76
+ end
77
+
78
+ it "should only append to strings file" do
79
+ @pass.add_file "fr.lproj/pass.strings", "\"not\" = \"not\";"
80
+ @pass.add_translation_string "yes", "qui", "fr"
81
+ pass_strings = file_from_zip(@pass.package, "fr.lproj/pass.strings")
82
+ pass_strings.should_not be_nil
83
+ pass_strings.should match /\"not\" = \"not\";/
84
+ pass_strings.should match /\"yes\" = \"qui\";/
85
+ end
86
+
87
+ it "should include all the files from template_path" do
88
+ pkpass_io = @pass.package
89
+ Dir.glob(@pass.config["template_path"]+"/**/**").each do |file|
90
+ next if File.directory? file
91
+ filename = Pathname.new(file).relative_path_from(Pathname.new(@pass.config['template_path']))
92
+ check_file_in_zip(pkpass_io, filename.to_s).should be_true
93
+ end
94
+ end
95
+
96
+ it "should include manifest.json" do
97
+ check_file_in_zip(@pass.package, "manifest.json").should be_true
98
+ end
99
+
100
+ it "should have all the files in manifest.json and none more" do
101
+ files_json = JSON.parse(file_from_zip(@pass.package, "manifest.json"))
102
+ Dir.glob(@pass.config["template_path"]+"/**/**").each do |file|
103
+ next if File.directory? file
104
+ filename = Pathname.new(file).relative_path_from(Pathname.new(@pass.config['template_path'])).to_s
105
+ if files_json.include? filename
106
+ files_json.delete filename
107
+ else
108
+ fail
109
+ end
110
+ end
111
+ files_json.should be_empty
112
+ end
113
+
114
+ it "should have a signature" do
115
+ check_file_in_zip(@pass.package, "signature").should be_true
116
+ end
117
+ end
@@ -0,0 +1,82 @@
1
+
2
+ # Copyright 2012 Xtreme Labs
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require "rails"
17
+ require "rails/test_help"
18
+
19
+ require_relative '../lib/passbook-ruby'
20
+ require_relative '../lib/passbook/config'
21
+ require_relative '../lib/passbook/pkpass'
22
+
23
+
24
+ module Helpers
25
+
26
+ def zip_io zip_file_io
27
+ File.open("test.zip", 'w') do |file|
28
+ zip_file_io.rewind
29
+ file.write zip_file_io.sysread.force_encoding("UTF-8")
30
+ end
31
+ Zip::ZipInputStream::open("test.zip")
32
+ end
33
+
34
+ def file_from_zip zip_file_io, filename
35
+ io = zip_io zip_file_io
36
+ while (entry = io.get_next_entry) do
37
+ return io.read if entry.name == filename
38
+ end
39
+ nil
40
+ end
41
+
42
+ def check_file_in_zip zip_file_io, filename
43
+ io = zip_io zip_file_io
44
+ while (entry = io.get_next_entry) do
45
+ return true if entry.name == filename
46
+ end
47
+ false
48
+
49
+ # def zip_file_io.path
50
+ # 'bypass_rubyzip_issue'
51
+ # end
52
+ # puts "We got #{zip_file_io.size}"
53
+
54
+ # Zip::ZipInputStream::open_buffer(zip_file_io) do |io|
55
+ # entry = io.get_next_entry
56
+ # # while (entry = io.get_next_entry) do
57
+ # # puts "entry: #{entry.name}"
58
+ # # end
59
+ # end
60
+ end
61
+
62
+ def create_p12
63
+ root_key = OpenSSL::PKey::RSA.new 2048 # the CA's public/private key
64
+ root_ca = OpenSSL::X509::Certificate.new
65
+ root_ca.version = 2 # cf. RFC 5280 - to make it a "v3" certificate
66
+ root_ca.serial = 1
67
+ root_ca.subject = OpenSSL::X509::Name.parse "/DC=org/DC=ruby-lang/CN=Ruby CA"
68
+ root_ca.issuer = root_ca.subject # root CA's are "self-signed"
69
+ root_ca.public_key = root_key.public_key
70
+ root_ca.not_before = Time.now
71
+ root_ca.not_after = root_ca.not_before + 2 * 365 * 24 * 60 * 60 # 2 years validity
72
+ ef = OpenSSL::X509::ExtensionFactory.new
73
+ ef.subject_certificate = root_ca
74
+ ef.issuer_certificate = root_ca
75
+ root_ca.add_extension(ef.create_extension("basicConstraints","CA:TRUE",true))
76
+ root_ca.add_extension(ef.create_extension("keyUsage","keyCertSign, cRLSign", true))
77
+ root_ca.add_extension(ef.create_extension("subjectKeyIdentifier","hash",false))
78
+ root_ca.add_extension(ef.create_extension("authorityKeyIdentifier","keyid:always",false))
79
+ root_ca.sign(root_key, OpenSSL::Digest::SHA256.new)
80
+ OpenSSL::PKCS12.create("test", "test", root_key, root_ca)
81
+ end
82
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: passbook-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrei Dinin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &70284296286940 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70284296286940
25
+ - !ruby/object:Gem::Dependency
26
+ name: rubyzip
27
+ requirement: &70284296285700 !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: *70284296285700
36
+ - !ruby/object:Gem::Dependency
37
+ name: json
38
+ requirement: &70284296284320 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70284296284320
47
+ - !ruby/object:Gem::Dependency
48
+ name: activesupport
49
+ requirement: &70284296282360 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70284296282360
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &70284296281680 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>'
64
+ - !ruby/object:Gem::Version
65
+ version: '2.0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70284296281680
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: &70284296258280 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70284296258280
80
+ description: Passbook pkpass creation and management for Ruby projects
81
+ email: andrei.dinin@xtremelabs.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - app/controllers/passbook/logs_controller.rb
87
+ - app/controllers/passbook/passes_controller.rb
88
+ - app/controllers/passbook/registrations_controller.rb
89
+ - app/models/passbook/registration.rb
90
+ - config/routes.rb
91
+ - lib/passbook/config.rb
92
+ - lib/passbook/engine.rb
93
+ - lib/passbook/pkpass.rb
94
+ - lib/passbook-ruby.rb
95
+ - lib/rails/generators/passbook/config/config_generator.rb
96
+ - lib/rails/generators/passbook/config/templates/initializer.rb
97
+ - lib/rails/generators/passbook/config/templates/migration.rb
98
+ - lib/rails/generators/passbook/pkpass/pkpass_generator.rb
99
+ - lib/rails/generators/passbook/pkpass/templates/icon.png
100
+ - lib/rails/generators/passbook/pkpass/templates/icon@2x.png
101
+ - lib/rails/generators/passbook/pkpass/templates/initializer.rb
102
+ - lib/rails/generators/passbook/pkpass/templates/migration.rb
103
+ - lib/rails/generators/passbook/pkpass/templates/model.rb
104
+ - lib/rails/generators/passbook/pkpass/templates/pass.json
105
+ - spec/config_spec.rb
106
+ - spec/data/templates/pass.com.acme/pass.json
107
+ - spec/pkpass_spec.rb
108
+ - spec/spec_helper.rb
109
+ - README.md
110
+ - LICENSE
111
+ homepage: https://github.com/xtremelabs/xl-passbook-ruby/
112
+ licenses: []
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: 1.9.0
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project: passbook-ruby
131
+ rubygems_version: 1.8.10
132
+ signing_key:
133
+ specification_version: 3
134
+ summary: Passbook pkpass creation and management for Ruby projects
135
+ test_files: []