mobile-pass 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2012 Xtreme Labs
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # Passbook-Ruby
2
+
3
+ [![Build Status](https://secure.travis-ci.org/xtremelabs/xl-passbook-ruby.png)](http://travis-ci.org/xtremelabs/xl-passbook-ruby)
4
+
5
+ [Passbook] is an app distributed on iOS6.
6
+ This is an implementation for management and signing of pkpasses for your Rails application.
7
+ The management of templates and all the other data is done in-memory. This gem does not write to the filesystem. This results in a speed boost.
8
+
9
+ **Quick Start Video:**<br/>
10
+ http://www.youtube.com/watch?v=GeWFk1FvEKc
11
+
12
+ ## Usage
13
+
14
+ ### Install
15
+
16
+ ```
17
+ gem 'passbook-ruby'
18
+ bundle
19
+ ```
20
+ ### P12 certificate
21
+ This the first of 2 certificates you need to sign a pkpass.
22
+ [Apple has a step-by-step] for most of it. You can pick up from step 7.
23
+ Alternatively, you can follow all of my steps:
24
+
25
+ 1. Go to <b>[iOS Provisioning Portal]</b> (you need to login or register)
26
+ * Click on <b>"Pass Type IDs"</b> on the left side menu
27
+ * Click on <b>"New Pass Type ID"</b> and fill in the 2 fields
28
+ * After you come back to the listing of pass type ids, click on <b>"Configure"</b> link next to the one you created
29
+ * Click on <b>Configure</b> button and <b>follow the instructions</b> in the wizard
30
+ * Once you <b>download</b> the pass.cer, double-click to <b>install</b>
31
+ * In the "Keychain Access" tool <b>right-click</b> on Pass Type ID: <you.pass.id> and click <b>"Export "Pass Type .....""</b>
32
+ * Change "File Format" to "Personal Information Exchange(.p12)" and <b>save</b> (preferably to Rails.root/data/certificates/)
33
+ * The password you enter during the saving process will go into the initializer ("Run Generator" step)
34
+
35
+ ### WWDR Certificate
36
+ Second certificate you need to sign a pkpass
37
+
38
+ 1. <b>Download</b> http://developer.apple.com/certificationauthority/AppleWWDRCA.cer
39
+ * Double-click to <b>install</b>
40
+ * In the "Keychain Access" tool <b>right-click</b> on "Apple Worldwide Developer Relations Certification Authority" and click on <b>Export "Apple....</b>
41
+ * Change "File Format" to "Privacy Enhanced Mail (.pem)" and <b>save</b> it (preferably to Rails.root/data/certificates/)
42
+
43
+ ### Run generators
44
+ All the <b>parameters are optional</b>. You can just edit the initializer later
45
+ ```
46
+ rails g passbook:config [wwdr_certificate_path]
47
+ ```
48
+ That creates an initializer and a migration.
49
+ Don't forget to put the WWDR certificate into the path now, if you used the defaults.
50
+
51
+
52
+ After that, let's create a pkpass model (ie. ticket).
53
+ I would strongly advise specifying **model_name**, **pass_type_id** and **tead_id** at this points.
54
+
55
+ ```
56
+ rails g passbook:pkpass [model_name] [pass_type_id] [team_id] [cert_path] [cert_password]
57
+ ```
58
+ This will generate a model, a migration, an initializer, a route and a sample pass (to data/templates/your_pass_type_id). Make sure to add your
59
+ .p12 into the path now if you use the defaults. Also, if you didn't set the password for the cert in the above command, make sure you change the default to
60
+ your password in config/initializers/passbook_#{model_name}.rb.
61
+
62
+
63
+ ```
64
+ rake db:migrate
65
+ rails s
66
+ ```
67
+ and go to \passes\model_name on your iphone (make sure it is in debug mode and allows http connections)
68
+
69
+
70
+
71
+ #### Check out [FAQs] wiki section if you get in trouble
72
+
73
+ ####Thank you for help:
74
+ Dwayne Forde, Cody Veal, Gregory Chow, Vincent Lee, Hussam Sheikh, Tanzeeb Khalili, Vincent Coste
75
+
76
+
77
+ ####Lisence
78
+
79
+ Except as otherwise noted, the Passbook-Ruby gem is licensed under the [Apache License, Version 2.0]
80
+
81
+
82
+ [passbook]: https://developer.apple.com/passbook/
83
+ [iOS Provisioning Portal]: https://developer.apple.com/devcenter/ios/index.action
84
+ [Apple has a step-by-step]: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/PassKit_PG/Chapters/YourFirst.html#//apple_ref/doc/uid/TP40012195-CH2-SW27
85
+ [Pass Design and Creation]: https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/PassKit_PG/Chapters/Creating.html#//apple_ref/doc/uid/TP40012195-CH4-SW1
86
+ [Apple documentation]: https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/PassKit_PG/Chapters/Introduction.html
87
+ [Download a sample]: https://github.com/downloads/xtremelabs/xl-passbook-ruby/pass.com.acme.zip
88
+ [FAQs]: https://github.com/xtremelabs/xl-passbook-ruby/wiki/faqs
89
+ [teamIdentifier]: https://github.com/xtremelabs/xl-passbook-ruby/wiki/faqs
90
+ [Apache License, Version 2.0]: http://www.apache.org/licenses/LICENSE-2.0.html
@@ -0,0 +1,33 @@
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
+ module Passbook
19
+ class LogsController < ApplicationController
20
+
21
+ def log
22
+ # if request && request.body
23
+ # request.body.rewind
24
+ # json_body = JSON.parse(request.body.read)
25
+ # File.open(File.expand_path(Rails.root) + "/log/devices.log", "a") do |f|
26
+ # f.write "[#{Time.now}] #{json_body["description"]}\n"
27
+ # end
28
+ # end
29
+ render :nothing => true, :status => 200
30
+ end
31
+
32
+ end #Class
33
+ end
@@ -0,0 +1,34 @@
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
+ module Passbook
20
+ class PassesController < ApplicationController
21
+ def get_pass
22
+ pass = Passbook.pass_type_id_to_class(params[:pass_type_id]).find_by_serial_number params[:serial_number]
23
+ return render(:json => {}, :status => 401) if pass.blank?
24
+ pass.check_for_updates if pass.respond_to? :check_for_updates
25
+ return render(:json => {}, :status => 304) if !request.headers['if-modified-since'].blank? && pass.updated_at<=Time.zone.parse(request.headers['if-modified-since'])
26
+ get_pkpass pass
27
+ end
28
+
29
+ def get_pkpass pass=nil
30
+ pass ||=Passbook.pass_type_id_to_class(params[:pass_type_id]).update_or_create params
31
+ render :pkpass => pass
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,169 @@
1
+ # Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple")
2
+ # in consideration of your agreement to the following terms, and your use,
3
+ # installation, modification or redistribution of this Apple software
4
+ # constitutes acceptance of these terms. If you do not agree with these
5
+ # terms, please do not use, install, modify or redistribute this Apple
6
+ # software.
7
+ #
8
+ # In consideration of your agreement to abide by the following terms, and
9
+ # subject to these terms, Apple grants you a personal, non - exclusive
10
+ # license, under Apple's copyrights in this original Apple software ( the
11
+ # "Apple Software" ), to use, reproduce, modify and redistribute the Apple
12
+ # Software, with or without modifications, in source and / or binary forms;
13
+ # provided that if you redistribute the Apple Software in its entirety and
14
+ # without modifications, you must retain this notice and the following text
15
+ # and disclaimers in all such redistributions of the Apple Software. Neither
16
+ # the name, trademarks, service marks or logos of Apple Inc. may be used to
17
+ # endorse or promote products derived from the Apple Software without specific
18
+ # prior written permission from Apple. Except as expressly stated in this
19
+ # notice, no other rights or licenses, express or implied, are granted by
20
+ # Apple herein, including but not limited to any patent rights that may be
21
+ # infringed by your derivative works or by other works in which the Apple
22
+ # Software may be incorporated.
23
+ #
24
+ # The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
25
+ # WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
26
+ # WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A
27
+ # PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION
28
+ # ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
29
+ #
30
+ # IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
31
+ # CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33
+ # INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION
34
+ # AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER
35
+ # UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR
36
+ # OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
+ #
38
+ # Copyright ( C ) 2012 Apple Inc. All Rights Reserved.
39
+
40
+
41
+ module Passbook
42
+ class RegistrationsController < ApplicationController
43
+ def create
44
+ puts "Handling registration request..."
45
+ # validate that the request is authorized to deal with the pass referenced
46
+ pass = Passbook.pass_type_id_to_class(params[:pass_type_id]).where(:serial_number => params[:serial_number]).where(:authentication_token => authentication_token).first
47
+ unless pass.blank?
48
+ puts 'Pass and authentication token match.'
49
+
50
+ # Validate that the device has not previously registered
51
+ # Note: this is done with a composite key that is combination of the device_id and the pass serial_number
52
+ uuid = params[:device_id] + "-" + params[:serial_number]
53
+ if Registration.where(:uuid => uuid).count < 1
54
+ # No registration found, lets add the device
55
+ # push_token = params[:push_token]
56
+ Registration.create!(:uuid => uuid,
57
+ :device_id => params[:device_id],
58
+ :pass_type_id => params[:pass_type_id],
59
+ :push_token => push_token,
60
+ :serial_number => params[:serial_number])
61
+
62
+ # spawn an event for registration creation
63
+ pass.register_handler if pass.respond_to? :register_handler
64
+
65
+ # Return a 201 CREATED status
66
+ # status 201
67
+ render :json => {}, :status => 201
68
+ else
69
+ # The device has already registered for updates on this pass
70
+ # Acknowledge the request with a 200 OK response
71
+ # status 200
72
+ render :json => {}, :status => 200
73
+ end
74
+
75
+ else
76
+ # The device did not statisfy the authentication requirements
77
+ # Return a 401 NOT AUTHORIZED response
78
+ # status 401
79
+ render :json => {}, :status => 401
80
+ end
81
+ end
82
+
83
+
84
+ def delete
85
+ puts "Handling unregistration request..."
86
+ puts authentication_token
87
+ if Passbook.pass_type_id_to_class(params[:pass_type_id]).where(:serial_number => params[:serial_number], :authentication_token => authentication_token).first
88
+ puts 'Pass and authentication token match.'
89
+
90
+ # Validate that the device has previously registered
91
+ # Note: this is done with a composite key that is combination of the device_id and the pass serial_number
92
+ uuid = params[:device_id] + "-" + params[:serial_number]
93
+ registration = Registration.find_by_uuid(uuid)
94
+ unless registration.blank?
95
+ Registration.delete registration.id
96
+
97
+ # spawn an event for unregistration event
98
+ pass.unregister_handler if pass.respond_to? :unregister_handler
99
+
100
+ render :json => {}, :status => 200
101
+ else
102
+ puts 'Registration does not exist.'
103
+ render :json => {}, :status => 401
104
+ end
105
+ else
106
+ # Not authorized
107
+ render :json => {}, :status => 401
108
+ end
109
+ end
110
+
111
+ def updatable
112
+ puts "Handling updates request..."
113
+ # Check first that the device has registered with the service
114
+ if Registration.where(:device_id => params[:device_id]).count > 0
115
+
116
+ # The device is registered with the service
117
+
118
+ # Find the registrations for the device
119
+ registered_serial_numbers = Registration.where(:device_id => params[:device_id], :pass_type_id => params[:pass_type_id]).collect{|r| r[:serial_number]}
120
+
121
+ # The passesUpdatedSince param is optional for scoping the update query
122
+ if params[:passesUpdatedSince] && params[:passesUpdatedSince] != ""
123
+ registered_passes = Passbook.pass_type_id_to_class(params[:pass_type_id]).where(:serial_number => registered_serial_numbers).where('updated_at IS NULL OR updated_at >= ?', params[:passesUpdatedSince])
124
+ else
125
+ registered_passes = Passbook.pass_type_id_to_class(params[:pass_type_id]).where(:serial_number => registered_serial_numbers)
126
+ end
127
+
128
+ # Are there passes that this device should recieve updates for?
129
+ if registered_passes.count > 0
130
+ # Found passes that could be updated for this device
131
+ # Build the response object
132
+ update_time = registered_passes.map(&:updated_at).max
133
+ updatable_passes_payload = {:lastUpdated => update_time}
134
+ updatable_passes_payload[:serialNumbers] = registered_passes.collect{|rp| rp[:serial_number]}
135
+
136
+ render :json => updatable_passes_payload.to_json, :status => 200
137
+ else
138
+ render :json => {}, :status=>204
139
+ end
140
+
141
+ else
142
+ # This device is not currently registered with the service
143
+ render :json => {}, :status=> 404
144
+ end
145
+ end
146
+
147
+ private
148
+
149
+ def authentication_token
150
+ if request.env && request.env['HTTP_AUTHORIZATION']
151
+ request.env['HTTP_AUTHORIZATION'].split(" ").last
152
+ end
153
+ end
154
+
155
+
156
+ # Convienience method for parsing the pushToken out of a JSON POST body
157
+ def push_token
158
+ return params[:pushToken] if params.include?(:pushToken)
159
+ if request && request.body
160
+ request.body.rewind
161
+ json_body = JSON.parse(request.body.read)
162
+ if json_body['pushToken']
163
+ json_body['pushToken']
164
+ end
165
+ end
166
+ end
167
+
168
+ end
169
+ end
@@ -0,0 +1,24 @@
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
+ module Passbook
20
+ class Registration < ActiveRecord::Base
21
+ set_table_name "passbook_registrations"
22
+ attr_accessible :device_id, :pass_type_id, :push_token, :serial_number, :uuid
23
+ end
24
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,36 @@
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
+ if Passbook::Config.instance.enable_routes
20
+ Rails.application.routes.draw do
21
+ get "/v1/passes/:pass_type_id/:serial_number" => "Passbook::passes#get_pass", :constraints => { :pass_type_id => /[^\/]+/ }
22
+
23
+ post "/v1/devices/:device_id/registrations/:pass_type_id/:serial_number" => "Passbook::registrations#create", :constraints => { :pass_type_id => /[^\/]+/ }
24
+ delete "/v1/devices/:device_id/registrations/:pass_type_id/:serial_number" => "Passbook::registrations#delete", :constraints => { :pass_type_id => /[^\/]+/ }
25
+ get "/v1/devices/:device_id/registrations/:pass_type_id" =>"Passbook::registrations#updatable", :constraints => { :pass_type_id => /[^\/]+/ }
26
+
27
+ post "/v1/log" => "Passbook::logs#log"
28
+ end
29
+ end
30
+
31
+
32
+
33
+
34
+
35
+
36
+
@@ -0,0 +1,74 @@
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 'fileutils'
20
+ require 'singleton'
21
+
22
+ module Passbook
23
+ class Config
24
+ include Singleton
25
+ attr_accessor :pass_config, :wwdr_intermediate_certificate_path, :wwdr_certificate, :preload_template, :enable_routes
26
+
27
+ def configure
28
+ self.pass_config = Hash.new unless self.pass_config
29
+ yield self
30
+ read_wwdr_certificate
31
+ end
32
+
33
+ def add_pkpass
34
+ self.pass_config = Hash.new unless self.pass_config
35
+ yield self
36
+ self.preload_template ||= ::Rails.env.production? if defined? ::Rails
37
+ read_templates if self.preload_template
38
+ read_p12_certificates
39
+ end
40
+
41
+ def read_templates
42
+ self.pass_config.each do |pass_type_id, config|
43
+ raise(ArgumentError, "Please specify a template_path in your configuration (in initializer)") unless config['template_path']
44
+ config['files']||= load_files config['template_path']
45
+ end
46
+ end
47
+
48
+ def load_files path
49
+ files = {}
50
+ Dir.glob(path+"/**/**").each do |file_path|
51
+ next if File.directory? file_path
52
+ filename = Pathname.new(file_path).relative_path_from(Pathname.new(path))
53
+ file = File.open(file_path, "rb")
54
+ files[filename.to_s] = File.read(file)
55
+ end
56
+ files
57
+ end
58
+
59
+ def read_p12_certificates
60
+ pass_config.each do |pass_type_id, config|
61
+ raise(ArgumentError, "Please specify cert_path (certificate path) in your configuration (in initializer)") unless config['cert_path'] && !config['cert_path'].blank?
62
+ raise(ArgumentError, "Please specify cert_password (certificate password) in your configuration (in initializer)") unless config['cert_password']
63
+ config['p12_certificate'] ||= OpenSSL::PKCS12::new(File.read(config['cert_path']), config['cert_password'])
64
+ end
65
+ end
66
+
67
+ def read_wwdr_certificate
68
+ # raise(ArgumentError, "Please specify the WWDR Intermediate certificate in your initializer") unless self.wwdr_intermediate_certificate_path
69
+ self.wwdr_certificate||= OpenSSL::X509::Certificate.new(File.read(self.wwdr_intermediate_certificate_path))
70
+ end
71
+
72
+ end
73
+ end
74
+