Class: Passbook::PKPass
- Inherits:
-
Object
- Object
- Passbook::PKPass
- Defined in:
- lib/passbook/pkpass.rb
Constant Summary collapse
- TYPES =
%w(boarding-pass coupon event-ticket store-card generic)
Instance Attribute Summary collapse
-
#manifest_files ⇒ Object
Returns the value of attribute manifest_files.
-
#pass ⇒ Object
Returns the value of attribute pass.
-
#signer ⇒ Object
Returns the value of attribute signer.
Instance Method Summary collapse
-
#add_file(file) ⇒ Object
Adds a single file to the pass.
-
#add_files(files_array) ⇒ Object
Adds multiple files to the pass.
-
#build ⇒ Object
Builds the pass.
-
#file(options = {}) ⇒ Object
Return a Tempfile containing our ZipStream.
-
#initialize(pass, init_signer = nil) ⇒ PKPass
constructor
Initializes a new Passbook::PKPass object.
-
#list_files ⇒ Object
List of files in the pass.
-
#stream ⇒ Object
Return a ZipOutputStream.
Constructor Details
#initialize(pass, init_signer = nil) ⇒ PKPass
Initializes a new Passbook::PKPass object
15 16 17 18 19 |
# File 'lib/passbook/pkpass.rb', line 15 def initialize(pass, init_signer = nil) @pass = pass @manifest_files = [] @signer = init_signer || Passbook::Signer.new end |
Instance Attribute Details
#manifest_files ⇒ Object
Returns the value of attribute manifest_files.
8 9 10 |
# File 'lib/passbook/pkpass.rb', line 8 def manifest_files @manifest_files end |
#pass ⇒ Object
Returns the value of attribute pass.
8 9 10 |
# File 'lib/passbook/pkpass.rb', line 8 def pass @pass end |
#signer ⇒ Object
Returns the value of attribute signer.
8 9 10 |
# File 'lib/passbook/pkpass.rb', line 8 def signer @signer end |
Instance Method Details
#add_file(file) ⇒ Object
Adds a single file to the pass
22 23 24 |
# File 'lib/passbook/pkpass.rb', line 22 def add_file(file) @manifest_files << file end |
#add_files(files_array) ⇒ Object
Adds multiple files to the pass
27 28 29 |
# File 'lib/passbook/pkpass.rb', line 27 def add_files(files_array) @manifest_files += files_array end |
#build ⇒ Object
Builds the pass. Creates the manifest, checks for necessary files and fields Returns an array with the manifest and the pass’ cryptographic signature Don’t call this unless you have a specific need. Use #file or #stream instead
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/passbook/pkpass.rb', line 65 def build manifest = create_manifest # Check pass for necessary files and fields check_pass manifest # Create pass signature signature = @signer.sign manifest [manifest, signature] end |
#file(options = {}) ⇒ Object
Return a Tempfile containing our ZipStream
45 46 47 48 49 50 51 52 |
# File 'lib/passbook/pkpass.rb', line 45 def file( = {}) [:file_name] ||= 'pass.pkpass' [:directory] ||= Dir.tmpdir desired_path = File.join([:directory], [:file_name]) File.binwrite(desired_path, self.stream.string) File.new(desired_path) end |
#list_files ⇒ Object
List of files in the pass
32 33 34 |
# File 'lib/passbook/pkpass.rb', line 32 def list_files @manifest_files end |
#stream ⇒ Object
Return a ZipOutputStream
55 56 57 58 59 |
# File 'lib/passbook/pkpass.rb', line 55 def stream manifest, signature = build output_zip manifest, signature end |