Class: Passbook::PKPass

Inherits:
Object
  • Object
show all
Defined in:
lib/passbook/pkpass.rb

Constant Summary collapse

TYPES =
%w(boarding-pass coupon event-ticket store-card generic)

Instance Attribute Summary collapse

Instance Method Summary collapse

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_filesObject

Returns the value of attribute manifest_files.



8
9
10
# File 'lib/passbook/pkpass.rb', line 8

def manifest_files
  @manifest_files
end

#passObject

Returns the value of attribute pass.



8
9
10
# File 'lib/passbook/pkpass.rb', line 8

def pass
  @pass
end

#signerObject

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

#buildObject

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(options = {})
  options[:file_name] ||= 'pass.pkpass'
  options[:directory] ||= Dir.tmpdir
  desired_path = File.join(options[:directory], options[:file_name])

  File.binwrite(desired_path, self.stream.string)
  File.new(desired_path)
end

#list_filesObject

List of files in the pass



32
33
34
# File 'lib/passbook/pkpass.rb', line 32

def list_files
  @manifest_files
end

#streamObject

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