diff --git a/app/controllers/passkit/api/v1/registrations_controller.rb b/app/controllers/passkit/api/v1/registrations_controller.rb index 99e82c0..25e7b9d 100644 --- a/app/controllers/passkit/api/v1/registrations_controller.rb +++ b/app/controllers/passkit/api/v1/registrations_controller.rb @@ -73,7 +73,9 @@ def load_device end def register_device - device = Passkit::Device.find_or_create_by!(identifier: params[:device_id]) { |d| d.push_token = push_token } + device = Passkit::Device.find_or_create_by!(identifier: params[:device_id]) + device.update(push_token: push_token, push_service_url: push_service_url) + @pass.registrations.create!(device: device) end @@ -105,6 +107,14 @@ def push_token json_body = JSON.parse(request.body.read) json_body["pushToken"] end + + def push_service_url + return unless request&.body + + request.body.rewind + json_body = JSON.parse(request.body.read) + json_body["pushServiceUrl"] + end end end end diff --git a/config/routes.rb b/config/routes.rb index 79a2040..d47c501 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,7 @@ scope :v1 do resources :devices, only: [] do post "registrations/:pass_type_id/:serial_number" => "api/v1/registrations#create", :as => :register + post "registrations_attido/:pass_type_id/:serial_number" => "api/v1/registrations#create", :as => :register_for_android delete "registrations/:pass_type_id/:serial_number" => "api/v1/registrations#destroy", :as => :unregister get "registrations/:pass_type_id" => "api/v1/registrations#show", :as => :registrations end diff --git a/lib/generators/passkit/install_generator.rb b/lib/generators/passkit/install_generator.rb index fc8bac6..4976a7b 100644 --- a/lib/generators/passkit/install_generator.rb +++ b/lib/generators/passkit/install_generator.rb @@ -19,6 +19,7 @@ def self.next_migration_number(dirname) desc "Copy all files to your application." def generate_files migration_template "create_passkit_tables.rb", "db/migrate/create_passkit_tables.rb" + migration_template "add_push_service_url_to_devices.rb", "db/migrate/add_push_service_url_to_devices.rb" copy_file "passkit.rb", "config/initializers/passkit.rb" end end diff --git a/lib/generators/templates/add_push_service_url_to_devices.rb.tt b/lib/generators/templates/add_push_service_url_to_devices.rb.tt new file mode 100644 index 0000000..e6ee48d --- /dev/null +++ b/lib/generators/templates/add_push_service_url_to_devices.rb.tt @@ -0,0 +1,5 @@ +class AddPushServiceUrlToDevices < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>] + def change + add_column :passkit_devices, :push_service_url, :string + end +end