xtremelabs / xl-passbook-ruby

Apache License 2.0
16 stars 10 forks source link

Easy way to render .pkpass file to disk? #9

Closed aphotofolio closed 11 years ago

aphotofolio commented 11 years ago

Great project, really getting into it.

One question I have is: in my current project, I'd like to email the .pkpass files as attachments. I saw the pkpass renderer so I can always use open-uri to read my own path and File.open + f.write to save it ... I just wondered if there's an easier way than hitting my own URLs.

Thanks.

xtreme-andrei-dinin commented 11 years ago

Thanks!

The easiest thing is to email the link to your server. Email attachments is fine though and is one of the distribution paths that Apple suggests.

What you can do is: Let's say the model you generated is called "Ticket"

ticket = Ticket.update_or_create {:name=>"blah"} pkpass = Passbook::Pkpass.new ticket, serial_number pkpass_io = pkpass.package

at this time "pkpass_io" is the actual pkpass file content. I'm sure you can figure out what to do with it after. the {:name=>"blah"} is just a hash with params you need for your model, so plug in what you need.

Let me know if that helps!

aphotofolio commented 11 years ago

Thanks for the quick reply. My model is called "Coupon" and I'm getting an error when running Passbook::Pkpass.new

Here's my console output (I'm just grabbing the last coupon record):

1.9.3p286 :006 > coupon = Coupon.last
  Coupon Load (0.5ms)  SELECT "coupons".* FROM "coupons" ORDER BY "coupons"."id" DESC LIMIT 1
 => #<Coupon id: 2, serial_number: "d3c3K2FmcVNqeFA1NmhXOVU4a3pML3FRSUJPelNDQnRQelpGRG5...", authentication_token: "cm54NG1sSm5Nb2ZCQ2pSL3NsZml2Y1NXV0xMbjJWMzkzSXI0MFJ...", card_id: nil, created_at: "2013-02-07 06:51:51", updated_at: "2013-02-07 06:51:51"> 
1.9.3p286 :007 > pkpass = Passbook::Pkpass.new coupon, coupon.serial_number
ArgumentError: Could not find configuration for #<Coupon:0x007f8f99976ac8>
    from /Users/erikdungan/.rvm/gems/ruby-1.9.3-p286@sexypass/gems/passbook-ruby-0.1.1/lib/passbook/pkpass.rb:36:in `initialize'
    from (irb):7:in `new'
    from (irb):7
    from /Users/erikdungan/.rvm/gems/ruby-1.9.3-p286@sexypass/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
    from /Users/erikdungan/.rvm/gems/ruby-1.9.3-p286@sexypass/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
    from /Users/erikdungan/.rvm/gems/ruby-1.9.3-p286@sexypass/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

The error is about a configuration file but I'm assuming that is setup properly since I'm able to create coupons/passes.

Thanks again.

xtreme-andrei-dinin commented 11 years ago

Ah, my bad, haven't used it in a while. Try this instead

coupon = Coupon.update_or_create {:name=>"blah"}
pkpass = Passbook::Pkpass.new pass_type_id , serial_number
coupon.update_pass pkpass
pkpass_io = pkpass.package

Make sure to put the right pass_type_id Let me know if that works.

xtreme-andrei-dinin commented 11 years ago

No response for 11 days. Closing the issue.