class Passifier::Pass

Attributes

archive[R]
asset_files[R]
manifest[R]
serial_number[R]
signature[R]
spec[R]

Public Class Methods

create_archive(path, serial_number, spec_hash, assets, signing, options = {}) click to toggle source

Create a Pass and corresponding Archive file @param [String] path The desired path of the Archive @param [String] serial_number An ID for this pass, used as the serial number in pass.json @param [Hash] spec_hash The pass's spec (pass.json) @param [Hash] assets The pass's assets (can be local files or remote urls)

ex. { "background.png" => "https://www.google.com/images/srpr/logo3w.png", 
    "thumbnail.png" => "~/thumb.png" }

@param [Signing] signing A valid signing @return [Archive] The complete stored archive

# 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
new(serial_number, spec_hash, assets, signing, options = {}) click to toggle source

@param [String] serial_number An ID for this pass, used as the serial number in pass.json @param [Hash] spec_hash The pass's spec (pass.json) @param [Hash] assets The pass's assets (can be local files or remote urls)

ex. { "background.png" => "https://www.google.com/images/srpr/logo3w.png", 
    "thumbnail.png" => "~/thumb.png" }

@param [Signing] signing A valid signing

# 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
to_apple_datetime(time_with_zone) click to toggle source

Convert a Time object to Apple's preferred String time format @param [Time, Date, DateTime] The time object to convert to a String @return [String] The converted time object in Apple's preferred format

# 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

Public Instance Methods

create_archive(path, options = {}) click to toggle source

Create the Archive file for this Pass @param [String] path The desired path of the Archive @return [Archive] The complete stored archive

# 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
Also aliased as: generate, save
files_for_archive() click to toggle source

File objects that should be included in the archive @return [Array<Spec, Manifest, ManifestSignature, StaticFile, UrlSource>] File objects that will appear in

this pass' archive
# File lib/passifier/pass.rb, line 31
def files_for_archive
  [@spec, @manifest, @signature, @asset_files].flatten.compact
end
generate(path, options = {})
Alias for: create_archive
save(path, options = {})
Alias for: create_archive

Protected Instance Methods

to_asset_files(assets) click to toggle source

Convert a list of assets sources to file objects @param [Hash] assets A Hash of filenames and corresponding file paths or urls @return [Array<StaticFile, UrlSource>] The resulting StaticFile and/or UrlSource objects

# File lib/passifier/pass.rb, line 72
def to_asset_files(assets)
  assets.map do |filename, source| 
    klass = (source =~ /https?:\/\/[\S]+/) ? UrlSource : StaticFile
    klass.new(filename, source)
  end.flatten.compact
end