Skip to content
Open
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
22 changes: 19 additions & 3 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 cerificates 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 cerificates 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 cerificate 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 i-phone via e-mail to view your pass.

Expand Down Expand Up @@ -156,6 +156,22 @@ Sometime you might want to be able to use different certificates for different p
....
```

### Using Different Compressor

Sometime you might want to be able to another compressor from rubyzip.

For the moment, only rubyzip is supported, but feel free to add your own into `lib/passbook/compressors/` and add it to the list of available compressors into `lib/passbook/compressors.rb`

In order to change the default compressor use the configuration like that

```
Passbook.configure do |passbook|
...
passbook.compressor = :rubyzip # or wathever you want and that is implemented
...
end
```

### Push Notifications

If you want to support passbook push notification updates you will need to configure the appropriate bits above.
Expand Down Expand Up @@ -260,7 +276,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
3 changes: 2 additions & 1 deletion lib/passbook.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
require "passbook/version"
require "passbook/pkpass"
require "passbook/signer"
require 'passbook/compressor'
require 'active_support/core_ext/module/attribute_accessors'
require 'passbook/push_notification'
require 'grocer/passbook_notification'
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, :compressor

def self.configure
yield self
Expand Down
35 changes: 35 additions & 0 deletions lib/passbook/compressor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Passbook
module Compressor
extend self

def all_compressors
[:rubyzip]
end

def get name
@compressors = {} unless defined?(@compressors)
@compressors[name] = spawn(name) unless @compressors.include?(name)
@compressors[name]
end

private

##
# Spawn a Lookup of the given name.
#
def spawn name
Passbook::Compressor.const_get(classify_name(name)).new
end

##
# Convert an "underscore" version of a name into a "class" version.
#
def classify_name filename
filename.to_s.split("_").map{ |i| i[0...1].upcase + i[1..-1] }.join
end
end
end

Passbook::Compressor.all_compressors.each do |name|
require "passbook/compressors/#{name}"
end
24 changes: 24 additions & 0 deletions lib/passbook/compressors/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Passbook
module Compressor
class Base

def initialize
end

###
# Human-readable name of the compressors
#
def name
fail
end

###
# Output zip string
#
def outputZip pass, files, manifest, signature
fail
end

end
end
end
43 changes: 43 additions & 0 deletions lib/passbook/compressors/rubyzip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'passbook/compressors/base'
require 'zip'

module Passbook
module Compressor

class Rubyzip < Base

###
# Human-readable name of the compressors
#
def name
"RubyZip"
end

###
# Output zip string
#
def outputZip pass, files, manifest, signature
Zip::OutputStream.write_buffer do |zip|
zip.put_next_entry 'pass.json'
zip.write pass
zip.put_next_entry 'manifest.json'
zip.write manifest
zip.put_next_entry 'signature'
zip.write signature

files.each do |file|
if file.class == Hash
zip.put_next_entry file[:name]
zip.print file[:content]
else
zip.put_next_entry File.basename(file)
zip.print IO.read(file)
end
end
end
end

end

end
end
26 changes: 3 additions & 23 deletions lib/passbook/pkpass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def file(options = {})
def stream
manifest, signature = build

outputZip manifest, signature
compressor = Passbook::Compressor.get Passbook.compressor || :rubyzip

compressor.outputZip @pass, @manifest_files, manifest, signature
end

private
Expand Down Expand Up @@ -94,27 +96,5 @@ def createManifest

return sha1s.to_json
end

def outputZip manifest, signature

Zip::OutputStream.write_buffer do |zip|
zip.put_next_entry 'pass.json'
zip.write @pass
zip.put_next_entry 'manifest.json'
zip.write manifest
zip.put_next_entry 'signature'
zip.write signature

@manifest_files.each do |file|
if file.class == Hash
zip.put_next_entry file[:name]
zip.print file[:content]
else
zip.put_next_entry File.basename(file)
zip.print IO.read(file)
end
end
end
end
end
end