Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails4 changes #15

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source "http://rubygems.org"

gemspec
gem "rails", "3.2.3"
gem 'rails', '4.0.0'

group :test do
gem 'rake'
Expand Down
144 changes: 70 additions & 74 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,98 +10,94 @@ PATH
GEM
remote: http://rubygems.org/
specs:
actionmailer (3.2.3)
actionpack (= 3.2.3)
mail (~> 2.4.4)
actionpack (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
builder (~> 3.0.0)
actionmailer (4.0.0)
actionpack (= 4.0.0)
mail (~> 2.5.3)
actionpack (4.0.0)
activesupport (= 4.0.0)
builder (~> 3.1.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
rack (~> 1.4.0)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
activemodel (3.2.3)
activesupport (= 3.2.3)
builder (~> 3.0.0)
activerecord (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
activesupport (3.2.3)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.4)
diff-lcs (1.1.3)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
activemodel (4.0.0)
activesupport (= 4.0.0)
builder (~> 3.1.0)
activerecord (4.0.0)
activemodel (= 4.0.0)
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.0)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.0)
i18n (~> 0.6, >= 0.6.4)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
arel (4.0.0)
atomic (1.1.14)
builder (3.1.4)
diff-lcs (1.2.4)
erubis (2.7.0)
hike (1.2.1)
i18n (0.6.1)
journey (1.0.4)
json (1.7.5)
mail (2.4.4)
i18n (>= 0.4.0)
hike (1.2.3)
i18n (0.6.5)
json (1.8.0)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.19)
multi_json (1.3.6)
mime-types (1.25)
minitest (4.7.5)
multi_json (1.8.1)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
rack-ssl (1.3.2)
rack
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
rails (3.2.3)
actionmailer (= 3.2.3)
actionpack (= 3.2.3)
activerecord (= 3.2.3)
activeresource (= 3.2.3)
activesupport (= 3.2.3)
bundler (~> 1.0)
railties (= 3.2.3)
railties (3.2.3)
actionpack (= 3.2.3)
activesupport (= 3.2.3)
rack-ssl (~> 1.3.2)
rails (4.0.0)
actionmailer (= 4.0.0)
actionpack (= 4.0.0)
activerecord (= 4.0.0)
activesupport (= 4.0.0)
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.0)
sprockets-rails (~> 2.0.0)
railties (4.0.0)
actionpack (= 4.0.0)
activesupport (= 4.0.0)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
rspec (2.11.0)
rspec-core (~> 2.11.0)
rspec-expectations (~> 2.11.0)
rspec-mocks (~> 2.11.0)
rspec-core (2.11.1)
rspec-expectations (2.11.3)
diff-lcs (~> 1.1.3)
rspec-mocks (2.11.3)
rubyzip (0.9.9)
sprockets (2.1.3)
thor (>= 0.18.1, < 2.0)
rake (10.1.0)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.5)
rspec-expectations (2.14.3)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.3)
rubyzip (1.0.0)
sprockets (2.10.0)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.11)
sprockets-rails (2.0.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)
thor (0.18.1)
thread_safe (0.1.3)
atomic
tilt (1.4.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.34)
tzinfo (0.3.37)

PLATFORMS
ruby

DEPENDENCIES
passbook-ruby!
rails (= 3.2.3)
rails (= 4.0.0)
rake
rspec (> 2.0)
4 changes: 2 additions & 2 deletions app/controllers/passbook/passes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def get_pass
pass = Passbook.pass_type_id_to_class(params[:pass_type_id]).find_by_serial_number params[:serial_number]
return render(:json => {}, :status => 401) if pass.blank?
pass.check_for_updates if pass.respond_to? :check_for_updates
return render(:json => {}, :status => 304) if !request.headers['if-modified-since'].blank? && pass.updated_at<=Time.zone.parse(request.headers['if-modified-since'])
return render(:json => {}, :status => 304) if !request.headers['if-modified-since'].blank? && pass.updated_at.to_i<=Time.zone.parse(request.headers['if-modified-since']).to_i
get_pkpass pass
end

def get_pkpass pass=nil
pass ||=Passbook.pass_type_id_to_class(params[:pass_type_id]).update_or_create params
render :pkpass => pass
render pkpass: pass
end
end
end
2 changes: 2 additions & 0 deletions app/controllers/passbook/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

module Passbook
class RegistrationsController < ApplicationController
skip_before_filter :verify_authenticity_token, :only => [:create, :delete]

def create
puts "Handling registration request..."
# validate that the request is authorized to deal with the pass referenced
Expand Down
3 changes: 1 addition & 2 deletions app/models/passbook/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module Passbook
#
# @private
class Registration < ActiveRecord::Base
set_table_name "passbook_registrations"
attr_accessible :device_id, :pass_type_id, :push_token, :serial_number, :uuid
self.table_name = "passbook_registrations"
end
end
10 changes: 5 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

if Passbook::Config.instance.enable_routes
Rails.application.routes.draw do
get "/v1/passes/:pass_type_id/:serial_number" => "Passbook::passes#get_pass", :constraints => { :pass_type_id => /[^\/]+/ }
get "/v1/passes/:pass_type_id/:serial_number" => "passbook/passes#get_pass", :constraints => { :pass_type_id => /[^\/]+/ }

post "/v1/devices/:device_id/registrations/:pass_type_id/:serial_number" => "Passbook::registrations#create", :constraints => { :pass_type_id => /[^\/]+/ }
delete "/v1/devices/:device_id/registrations/:pass_type_id/:serial_number" => "Passbook::registrations#delete", :constraints => { :pass_type_id => /[^\/]+/ }
get "/v1/devices/:device_id/registrations/:pass_type_id" =>"Passbook::registrations#updatable", :constraints => { :pass_type_id => /[^\/]+/ }
post "/v1/devices/:device_id/registrations/:pass_type_id/:serial_number" => "passbook/registrations#create", :constraints => { :pass_type_id => /[^\/]+/ }
delete "/v1/devices/:device_id/registrations/:pass_type_id/:serial_number" => "passbook/registrations#delete", :constraints => { :pass_type_id => /[^\/]+/ }
get "/v1/devices/:device_id/registrations/:pass_type_id" =>"passbook/registrations#updatable", :constraints => { :pass_type_id => /[^\/]+/ }

post "/v1/log" => "Passbook::logs#log"
post "/v1/log" => "passbook/logs#log"
end
end

Expand Down
5 changes: 2 additions & 3 deletions lib/passbook/pkpass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
require 'digest/sha1'
require 'json'
require 'openssl'
require 'zip/zip'
require 'zip/zipfilesystem'
require 'zip'

module Passbook
# Pkpass is the class responsible for managing the contect of a pkpass and also signing the package
Expand Down Expand Up @@ -112,7 +111,7 @@ def sign_manifest

# @private
def compress_pass_file
stringio = Zip::ZipOutputStream::write_buffer do |z|
stringio = Zip::OutputStream::write_buffer do |z|
self.files.each do |filename, content|
z.put_next_entry filename
z.print content
Expand Down
2 changes: 1 addition & 1 deletion lib/rails/generators/passbook/pkpass/pkpass_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PkpassGenerator < Rails::Generators::NamedBase
def create_initializer_file
template 'initializer.rb', File.join('config', 'initializers', "passbook_#{plural_name.singularize}.rb")
template 'model.rb', File.join('app', 'models', "#{plural_name.singularize}.rb")
route "get '/v1/passes/#{plural_name.singularize}' => 'Passbook::Passes#get_pkpass', :defaults => { :pass_type_id => '#{pass_type_id}' }"
route "get '/v1/passes/#{plural_name.singularize}' => 'passbook/passes#get_pkpass', :defaults => { :pass_type_id => '#{pass_type_id}' }"
template 'migration.rb', File.join('db', 'migrate', "#{Time.now.strftime("%Y%m%d%H%M%S")}_create_#{plural_name}.rb")
template 'pass.json', File.join('data', 'templates', pass_type_id, "pass.json")
template 'icon.png', File.join('data', 'templates', pass_type_id, "icon.png")
Expand Down
15 changes: 10 additions & 5 deletions lib/rails/generators/passbook/pkpass/templates/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@


class <%= class_name %> < ActiveRecord::Base
attr_protected :serial_number, :authentication_token
attr_accessible :card_id
before_create :set_pass_fields

def set_pass_fields
Expand All @@ -29,9 +27,10 @@ def set_pass_fields
def self.update_or_create params
<%= plural_name.singularize %>_pass = find_by_card_id params[:card_id]
<%= plural_name.singularize %>_pass ||=new
params.slice(*attr_accessible[:default].map(&:to_sym)).each do |attr, val|
<%= plural_name.singularize %>_pass.send :"#{attr}=", val
end
# TODO: convert this to Rails 4 compatible style
# params.slice(*attr_accessible[:default].map(&:to_sym)).each do |attr, val|
# <%= plural_name.singularize %>_pass.send :"#{attr}=", val
# end
<%= plural_name.singularize %>_pass.save!
<%= plural_name.singularize %>_pass
end
Expand All @@ -51,4 +50,10 @@ def update_json pass_json
pass_json['webServiceURL'] = "http://192.168.x.x:3000"
#add more customization to your passbook's JSON right here
end

private

def <%= plural_name.singularize %>_params
params.permit(:card_id)
end
end
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

require "rails"
require "rails/test_help"
require "zip"

require_relative '../lib/passbook-ruby'
require_relative '../lib/passbook/config'
Expand All @@ -28,7 +29,7 @@ def zip_io zip_file_io
zip_file_io.rewind
file.write zip_file_io.sysread.force_encoding("UTF-8")
end
Zip::ZipInputStream::open("test.zip")
Zip::InputStream::open("test.zip")
end

def file_from_zip zip_file_io, filename
Expand Down
Binary file added test.zip
Binary file not shown.