Class: Passbook::PKPass

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

Constant Summary collapse

TYPES =
['boarding-pass', 'coupon', 'event-ticket', 'store-card', 'generic']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pass, init_signer = nil) ⇒ PKPass

Returns a new instance of PKPass.



12
13
14
15
16
# File 'lib/passbook/pkpass.rb', line 12

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

#addFile(file) ⇒ Object



18
19
20
# File 'lib/passbook/pkpass.rb', line 18

def addFile(file)
  @manifest_files << file
end

#addFiles(files) ⇒ Object



22
23
24
# File 'lib/passbook/pkpass.rb', line 22

def addFiles(files)
  @manifest_files += files
end

#buildObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/passbook/pkpass.rb', line 31

def build
  manifest = createManifest

  # Check pass for necessary files and fields
  checkPass manifest

  # Create pass signature
  signature = @signer.sign manifest

  [manifest, signature]
end

#createObject

Backward compatibility



44
45
46
# File 'lib/passbook/pkpass.rb', line 44

def create
  self.file.path
end

#file(options = {}) ⇒ Object

Return a Tempfile containing our ZipStream



49
50
51
52
53
54
55
56
57
58
# File 'lib/passbook/pkpass.rb', line 49

def file(options = {})
  options[:file_name] ||= 'pass.pkpass'

  temp_file = Tempfile.new(options[:file_name])
  temp_file.binmode
  temp_file.write self.stream.string
  temp_file.close

  temp_file
end

#json=(json) ⇒ Object

for backwards compatibility



27
28
29
# File 'lib/passbook/pkpass.rb', line 27

def json=(json)
  @pass = json
end

#streamObject

Return a ZipOutputStream



61
62
63
64
65
# File 'lib/passbook/pkpass.rb', line 61

def stream
  manifest, signature = build

  outputZip manifest, signature
end