Class: Passifier::Pass

Inherits:
Object
  • Object
show all
Defined in:
lib/passifier/pass.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(serial_number, spec_hash, assets, signing, options = {}) ⇒ Pass

Returns a new instance of Pass.

Parameters:

  • serial_number (String)

    An ID for this pass, used as the serial number in pass.json

  • spec_hash (Hash)

    The pass’s spec (pass.json)

  • assets (Hash)

    The pass’s assets (can be local files or remote urls) ex. { “background.png” => “”,

    "thumbnail.png" => "~/thumb.png" }
    
  • signing (Signing)

    A valid signing



20
21
22
23
24
25
26
# File 'lib/passifier/pass.rb', line 20

def initialize(serial_number, spec_hash, assets, signing, options = {})
  @signing = signing
  @spec = Spec.new(serial_number, spec_hash)
  @asset_files = to_asset_files(assets)
  @manifest = Manifest.new(@asset_files, signing)
  @signature = ManifestSignature.new(@manifest, signing)
end

Instance Attribute Details

#archiveObject (readonly)

Returns the value of attribute archive.



7
8
9
# File 'lib/passifier/pass.rb', line 7

def archive
  @archive
end

#asset_filesObject (readonly)

Returns the value of attribute asset_files.



7
8
9
# File 'lib/passifier/pass.rb', line 7

def asset_files
  @asset_files
end

#manifestObject (readonly)

Returns the value of attribute manifest.



7
8
9
# File 'lib/passifier/pass.rb', line 7

def manifest
  @manifest
end

#serial_numberObject (readonly)

Returns the value of attribute serial_number.



7
8
9
# File 'lib/passifier/pass.rb', line 7

def serial_number
  @serial_number
end

#signatureObject (readonly)

Returns the value of attribute signature.



7
8
9
# File 'lib/passifier/pass.rb', line 7

def signature
  @signature
end

#specObject (readonly)

Returns the value of attribute spec.



7
8
9
# File 'lib/passifier/pass.rb', line 7

def spec
  @spec
end

Class Method Details

.create_archive(path, serial_number, spec_hash, assets, signing, options = {}) ⇒ Archive

Create a Pass and corresponding Archive file

Parameters:

  • path (String)

    The desired path of the Archive

  • serial_number (String)

    An ID for this pass, used as the serial number in pass.json

  • spec_hash (Hash)

    The pass’s spec (pass.json)

  • assets (Hash)

    The pass’s assets (can be local files or remote urls) ex. { “background.png” => “”,

    "thumbnail.png" => "~/thumb.png" }
    
  • signing (Signing)

    A valid signing

Returns:

  • (Archive)

    The complete stored archive



62
63
64
65
# File 'lib/passifier/pass.rb', line 62

def self.create_archive(path, serial_number, spec_hash, assets, signing, options = {})
  pass = new(serial_number, spec_hash, assets, signing, options)
  pass.create_archive(path, options)
end

.to_apple_datetime(time_with_zone) ⇒ String

Convert a Time object to Apple’s preferred String time format

Parameters:

  • The (Time, Date, DateTime)

    time object to convert to a String

Returns:

  • (String)

    The converted time object in Apple’s preferred format



49
50
51
# File 'lib/passifier/pass.rb', line 49

def self.to_apple_datetime(time_with_zone)
  time_with_zone.strftime("%Y-%m-%dT%H:%M%:z")
end

Instance Method Details

#create_archive(path, options = {}) ⇒ Archive

Create the Archive file for this Pass

Parameters:

  • path (String)

    The desired path of the Archive

Returns:

  • (Archive)

    The complete stored archive



38
39
40
41
42
# File 'lib/passifier/pass.rb', line 38

def create_archive(path, options = {})
  @archive = Archive.new(path, @spec.serial_number, files_for_archive)
  @archive.store(options)
  @archive
end

#files_for_archiveArray<Spec, Manifest, ManifestSignature, StaticFile, UrlSource>

File objects that should be included in the archive

Returns:



31
32
33
# File 'lib/passifier/pass.rb', line 31

def files_for_archive
  [@spec, @manifest, @signature, @asset_files].flatten.compact
end

#generateArchive

Create the Archive file for this Pass

Parameters:

  • path (String)

    The desired path of the Archive

Returns:

  • (Archive)

    The complete stored archive



43
44
45
46
47
# File 'lib/passifier/pass.rb', line 43

def create_archive(path, options = {})
  @archive = Archive.new(path, @spec.serial_number, files_for_archive)
  @archive.store(options)
  @archive
end

#saveArchive

Create the Archive file for this Pass

Parameters:

  • path (String)

    The desired path of the Archive

Returns:

  • (Archive)

    The complete stored archive



44
45
46
47
48
# File 'lib/passifier/pass.rb', line 44

def create_archive(path, options = {})
  @archive = Archive.new(path, @spec.serial_number, files_for_archive)
  @archive.store(options)
  @archive
end