Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Then go to a directory that you want to generate your pass under and use the "pk
pk generate your_pass_name
```

This will generate a directory called your_pass_name. Edit your pass.json file in the your_pass_directory to have a valid team identifier and passTypeIdentifier and create your certificates if you haven't yet. [See this article for information on how to do this.](http://www.raywenderlich.com/20734/beginning-passbook-part-1#more-20734)
This will generate a directory called your_pass_name. Edit your pass.json file in the your_pass_directory to have a valid team identifier and passTypeIdentifier and create your certificates if you haven't yet. [See this article for information on how to do this.](http://www.raywenderlich.com/20734/beginning-passbook-part-1#more-20734)

Assuming that you have put your certificate files etc. in your working directory.

Expand All @@ -40,7 +40,7 @@ If you are not building your passes on a mac or just prefer to use the pass cert

```
pk build passbook_gem_name -w ./wwdc.pem -c ./your_pass_name_certificate.pem -k your_pass_name_key.pem -p '12345'
```
```

Now you can drag the file over to a simulator or send it to your iPhone via e-mail to view your pass.

Expand Down Expand Up @@ -79,6 +79,7 @@ If You are doing push notifications then you will need to add some extra configu
Passbook.configure do |passbook|
.....other settings.....
passbook.notification_gateway = 'gateway.push.apple.com'
passbook.notification_passphrase = 'my_hard_password' (optional)
passbook.notification_cert = 'lib/assets/my_notification_cert.pem'
end
```
Expand Down Expand Up @@ -232,7 +233,7 @@ module Passbook
# you will want to return
my_pass = PkPass.new 'your pass json'
# you will want to return the string from the stream of your PkPass object.
mypass.stream.string
{:status => 200, :latest_pass => mypass.stream.string, :last_modified => '1442120893'}
end

# This is called whenever there is something from the update process that is a warning
Expand All @@ -247,10 +248,10 @@ end

```

To send a push notification for a updated pass simply call Passbook::PassbookPushNotification.send_notifications_for_promotion with the push token for the pass you are updating
To send a push notification for a updated pass simply call Passbook::PushNotification.send_notification with the push token for the device you are updating

```
Passbook::PassbookPushNotification.send_notifications_for_promotion the_pass_push_token
Passbook::PushNotification.send_notification the_device_push_token

```

Expand All @@ -260,7 +261,7 @@ Apple will send out a notification to your phone (usually within 15 minutes or l

To launch tests :
```
bundle exec rake spec
bundle exec rake spec
```

## Contributing
Expand Down
2 changes: 1 addition & 1 deletion lib/passbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require 'rack/passbook_rack'

module Passbook
mattr_accessor :p12_certificate, :p12_password, :wwdc_cert, :p12_key, :notification_cert, :notification_gateway
mattr_accessor :p12_certificate, :p12_password, :wwdc_cert, :p12_key, :notification_cert, :notification_gateway, :notification_passphrase

def self.configure
yield self
Expand Down
2 changes: 1 addition & 1 deletion lib/passbook/push_notification.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Passbook
class PushNotification
def self.send_notification(device_token)
pusher = Grocer.pusher({:certificate => Passbook.notification_cert, :gateway => Passbook.notification_gateway})
pusher = Grocer.pusher({:certificate => Passbook.notification_cert, :passphrase => Passbook.notification_passphrase || "", :gateway => Passbook.notification_gateway})
notification = Grocer::PassbookNotification.new(:device_token => device_token)

pusher.push notification
Expand Down
16 changes: 8 additions & 8 deletions lib/rack/passbook_rack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def call(env)
when 'device_register_delete'
if env['REQUEST_METHOD'] == 'POST'
[Passbook::PassbookNotification.
register_pass(method_and_params[:params].merge! JSON.parse(env['rack.input'].read 1000))[:status],
register_pass(method_and_params[:params].merge! JSON.parse(env['rack.input'].read 1000))[:status],
{}, ['']]
elsif env['REQUEST_METHOD'] == 'DELETE'
[Passbook::PassbookNotification.unregister_pass(method_and_params[:params])[:status], {}, {}]
Expand All @@ -25,12 +25,12 @@ def call(env)
[response ? 200 : 204, {}, [response.to_json]]
when 'latest_pass'
response = Passbook::PassbookNotification.latest_pass(method_and_params[:params])
if response
[200, {'Content-Type' => 'application/vnd.apple.pkpass',
'Content-Disposition' => 'attachment',
'filename' => "#{method_and_params[:params]['serialNumber']}.pkpass"}, [response]]
if response[:status] == 200
[200, {'Content-Type' => 'application/vnd.apple.pkpass',
'Content-Disposition' => 'attachment',
'filename' => "#{method_and_params[:params]['serialNumber']}.pkpass","last-modified" => response[:last_modified]}, [response[:latest_pass]]]
else
[204, {}, {}]
[response[:status], {}, {}]
end
when 'log'
Passbook::PassbookNotification.passbook_log JSON.parse(env['rack.input'].read 10000)
Expand Down Expand Up @@ -69,10 +69,10 @@ def find_method(path)
end
end

return nil
return nil
end

private
private

def method_and_params_hash(method, path)
parsed_path = path.split '/'
Expand Down
7 changes: 4 additions & 3 deletions spec/lib/passbook/push_notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@

context 'send notification' do
let(:grocer_pusher) {double 'Grocer'}
let(:notification) {double 'Grocer::Notification'}
let(:notification_settings) {{:certificate => './notification_cert.pem', :gateway => 'honeybadger.apple.com'}}
let(:notification) {double 'Grocer::Notification'}
let(:notification_settings) {{:certificate => './notification_cert.pem', :gateway => 'honeybadger.apple.com', :passphrase => 'ah@rdvintAge'}}

before :each do
Passbook.should_receive(:notification_cert).and_return './notification_cert.pem'
Grocer::PassbookNotification.should_receive(:new).with(:device_token => 'my token').and_return notification
Grocer::PassbookNotification.should_receive(:new).with(:device_token => 'my token').and_return notification
grocer_pusher.should_receive(:push).with(notification).and_return 55
Grocer.should_receive(:pusher).with(notification_settings).and_return grocer_pusher
Passbook.should_receive(:notification_gateway).and_return 'honeybadger.apple.com'
Passbook.should_receive(:notification_passphrase).and_return 'ah@rdvintAge'
end

subject {Passbook::PushNotification.send_notification('my token')}
Expand Down
16 changes: 8 additions & 8 deletions spec/lib/rack/passbook_rack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
its([:params]) {should eq(register_delete_params) }
end

it_behaves_like 'a method that can handle non passbook urls'
it_behaves_like 'a method that can handle non passbook urls'

end

Expand Down Expand Up @@ -144,7 +144,7 @@

context 'get latest pass' do
context 'valid pass' do
let(:raw_pass) {'some url encoded text'}
let(:raw_pass) {{:status => 200, :latest_pass => 'some url encoded text', :last_modified => '1442401010'}}

before do
Passbook::PassbookNotification.should_receive(:latest_pass).with(latest_pass_params).
Expand All @@ -154,15 +154,15 @@

subject {last_response}
its(:status) {should eq 200}
its(:header) {should eq({'Content-Type' => 'application/vnd.apple.pkpass',
'Content-Disposition' => 'attachment', 'filename' => '27-1.pkpass', 'Content-Length' => '21'})}
its(:body) {should eq raw_pass}
its(:header) {should eq({'Content-Type' => 'application/vnd.apple.pkpass',
'Content-Disposition' => 'attachment', 'filename' => '27-1.pkpass', 'last-modified' => '1442401010', 'Content-Length' => '21'})}
its(:body) {should eq raw_pass[:latest_pass]}
end

context 'no pass' do
before do
Passbook::PassbookNotification.should_receive(:latest_pass).with(latest_pass_params).
and_return(nil)
and_return({:status => 204, :latest_pass => nil})
get latest_pass_path
end

Expand Down Expand Up @@ -213,7 +213,7 @@
subject {last_response}
its(:status) {should eq 200}
its(:body) {should eq 'test app'}
end
end
end

end
Expand All @@ -224,7 +224,7 @@
def app
test_app = lambda do |env|
[200, {}, 'test app']
end
end

Rack::PassbookRack.new test_app
end
Expand Down