diff --git a/Gemfile b/Gemfile index 4d57d15..c0bd4dd 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source "http://rubygems.org" gemspec -gem "rails", "3.2.3" +gem 'rails', '4.0.0' group :test do gem 'rake' diff --git a/Gemfile.lock b/Gemfile.lock index 4f1b458..e736b5f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/app/controllers/passbook/passes_controller.rb b/app/controllers/passbook/passes_controller.rb index 79c1d5f..d69051b 100644 --- a/app/controllers/passbook/passes_controller.rb +++ b/app/controllers/passbook/passes_controller.rb @@ -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 diff --git a/app/controllers/passbook/registrations_controller.rb b/app/controllers/passbook/registrations_controller.rb index 2f4c092..df84f6b 100644 --- a/app/controllers/passbook/registrations_controller.rb +++ b/app/controllers/passbook/registrations_controller.rb @@ -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 diff --git a/app/models/passbook/registration.rb b/app/models/passbook/registration.rb index 6e6c03b..899c4c6 100644 --- a/app/models/passbook/registration.rb +++ b/app/models/passbook/registration.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index b8fbc9e..6f37d71 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/lib/passbook/pkpass.rb b/lib/passbook/pkpass.rb index 7b72d52..45768c9 100644 --- a/lib/passbook/pkpass.rb +++ b/lib/passbook/pkpass.rb @@ -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 @@ -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 diff --git a/lib/rails/generators/passbook/pkpass/pkpass_generator.rb b/lib/rails/generators/passbook/pkpass/pkpass_generator.rb index 93ceeec..406c445 100644 --- a/lib/rails/generators/passbook/pkpass/pkpass_generator.rb +++ b/lib/rails/generators/passbook/pkpass/pkpass_generator.rb @@ -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") diff --git a/lib/rails/generators/passbook/pkpass/templates/model.rb b/lib/rails/generators/passbook/pkpass/templates/model.rb index 1ae5b59..d79b701 100644 --- a/lib/rails/generators/passbook/pkpass/templates/model.rb +++ b/lib/rails/generators/passbook/pkpass/templates/model.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bb667bc..9b6f036 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,6 +15,7 @@ require "rails" require "rails/test_help" +require "zip" require_relative '../lib/passbook-ruby' require_relative '../lib/passbook/config' @@ -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 diff --git a/test.zip b/test.zip new file mode 100644 index 0000000..f2d4ef2 Binary files /dev/null and b/test.zip differ