Module: Passbook

Defined in:
lib/passbook-ruby.rb,
lib/passbook/config.rb,
lib/passbook/engine.rb,
lib/passbook/pkpass.rb,
app/models/passbook/registration.rb,
app/controllers/passbook/logs_controller.rb,
app/controllers/passbook/passes_controller.rb,
app/controllers/passbook/registrations_controller.rb,
lib/rails/generators/passbook/config/config_generator.rb,
lib/rails/generators/passbook/pkpass/pkpass_generator.rb

Defined Under Namespace

Modules: Generators Classes: Config, Engine, LogsController, PassesController, Pkpass, Registration, RegistrationsController

Class Method Summary collapse

Class Method Details

.class_name_to_pass_type_id(class_name) ⇒ Object



33
34
35
36
37
# File 'lib/passbook-ruby.rb', line 33

def self.class_name_to_pass_type_id class_name
  Passbook::Config.instance.pass_config.each do |pass_type_id, config|
    return pass_type_id if config['class']==class_name
  end
end

.pass_type_id_to_class(pass_type_id) ⇒ Object



28
29
30
# File 'lib/passbook-ruby.rb', line 28

def self.pass_type_id_to_class pass_type_id
  Passbook::Config.instance.pass_config[pass_type_id]['class'].constantize
end

.register_pkpassObject

Registers a custom renderer for .pkpass files (executed at load time)

example:

render :pkpass ticket

(where ‘ticket` is an instance of a model that is configured with passbook-ruby gem)



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/passbook-ruby.rb', line 46

def self.register_pkpass
  Mime::Type.register 'application/vnd.apple.pkpass', :pkpass

  ActionController::Renderers.add :pkpass do |obj, options|
    pkpass = Passbook::Pkpass.new Passbook.class_name_to_pass_type_id(obj.class.to_s), obj.serial_number
    obj.update_pass pkpass if obj.respond_to? :update_pass
    pkpass_io = pkpass.package
    response.headers["last-modified"] = obj.updated_at.strftime("%Y-%m-%d %H:%M:%S")
    send_data(pkpass_io.sysread, :type => 'application/vnd.apple.pkpass', :disposition=>'inline', :filename=>"#{obj.serial_number}.pkpass")
  end
end