From 30b0f4aa2e89b1f78f4f0c101a3734ce458ec669 Mon Sep 17 00:00:00 2001 From: Mandy Jor Date: Mon, 21 Apr 2025 19:20:15 -0500 Subject: [PATCH 01/12] new endpoint --- .../passkit/api/v1/registrations_controller.rb | 12 ++++++++++++ config/routes.rb | 1 + 2 files changed, 13 insertions(+) diff --git a/app/controllers/passkit/api/v1/registrations_controller.rb b/app/controllers/passkit/api/v1/registrations_controller.rb index 99e82c0..3470ba3 100644 --- a/app/controllers/passkit/api/v1/registrations_controller.rb +++ b/app/controllers/passkit/api/v1/registrations_controller.rb @@ -14,6 +14,18 @@ class RegistrationsController < ActionController::API # @return If the request is not authorized, returns HTTP status 401. # @return Otherwise, returns the appropriate standard HTTP status. def create + puts 'create-------------------------' + if @pass.devices.find_by(identifier: params[:device_id]) + render json: {}, status: :ok + return + end + + register_device + render json: {}, status: :created + end + + def create_walletpass_for_android + puts 'create_walletpass_for_android-------------------------' if @pass.devices.find_by(identifier: params[:device_id]) render json: {}, status: :ok return diff --git a/config/routes.rb b/config/routes.rb index 79a2040..f1d4a9d 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 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 From c48b59bf504b44806b4a2b5e76280b053d0b7256 Mon Sep 17 00:00:00 2001 From: Mandy Jor Date: Tue, 22 Apr 2025 01:24:33 -0500 Subject: [PATCH 02/12] add route --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index f1d4a9d..43e024e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +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 + post "registrations_attido/:pass_type_id/:serial_number" => "api/v1/registrations#create_walletpass_for_android", :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 From 737e740036ed0306c2ac24d2cfa4c49c59efac23 Mon Sep 17 00:00:00 2001 From: Mandy Jor Date: Tue, 22 Apr 2025 01:36:48 -0500 Subject: [PATCH 03/12] do pre load --- app/controllers/passkit/api/v1/registrations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/passkit/api/v1/registrations_controller.rb b/app/controllers/passkit/api/v1/registrations_controller.rb index 3470ba3..592d6c3 100644 --- a/app/controllers/passkit/api/v1/registrations_controller.rb +++ b/app/controllers/passkit/api/v1/registrations_controller.rb @@ -6,7 +6,7 @@ module V1 # @see Apple: https://developer.apple.com/library/archive/documentation/PassKit/Reference/PassKit_WebService/WebService.html # @see Android: https://walletpasses.io/developer/ class RegistrationsController < ActionController::API - before_action :load_pass, only: %i[create destroy] + before_action :load_pass, only: %i[create create_walletpass_for_android destroy] before_action :load_device, only: %i[show] # @return If the serial number is already registered for this device, returns HTTP status 200. From 1e7d70ddd763166b299959ea5dda393b2c6a17d7 Mon Sep 17 00:00:00 2001 From: Mandy Jor Date: Tue, 22 Apr 2025 01:53:32 -0500 Subject: [PATCH 04/12] adding push url column --- lib/generators/passkit/install_generator.rb | 1 + .../templates/add_push_service_url_to_devices.rb.tt | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 lib/generators/templates/add_push_service_url_to_devices.rb.tt 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..a235d88 --- /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 From de5e80e057c35dd7b405fb26a6eef830607e47ce Mon Sep 17 00:00:00 2001 From: Mandy Jor Date: Tue, 22 Apr 2025 01:58:48 -0500 Subject: [PATCH 05/12] fix migraton naming --- lib/generators/templates/add_push_service_url_to_devices.rb.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index a235d88..5cdf12e 100644 --- a/lib/generators/templates/add_push_service_url_to_devices.rb.tt +++ b/lib/generators/templates/add_push_service_url_to_devices.rb.tt @@ -1,4 +1,4 @@ -class AddPushServiceURLtoDevices < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>] +class AddPushServiceURLToDevices < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>] def change add_column :passkit_devices, :push_service_url, :string end From 0cc46ee0a28a9e866eeb5491f9bc27c0df9a0160 Mon Sep 17 00:00:00 2001 From: Mandy Jor Date: Tue, 22 Apr 2025 02:00:54 -0500 Subject: [PATCH 06/12] fix migraton naming --- lib/generators/templates/add_push_service_url_to_devices.rb.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 5cdf12e..e6ee48d 100644 --- a/lib/generators/templates/add_push_service_url_to_devices.rb.tt +++ b/lib/generators/templates/add_push_service_url_to_devices.rb.tt @@ -1,4 +1,4 @@ -class AddPushServiceURLToDevices < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>] +class AddPushServiceUrlToDevices < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>] def change add_column :passkit_devices, :push_service_url, :string end From be22182716db29438df8f7ed1c06ebab87ba9c85 Mon Sep 17 00:00:00 2001 From: Mandy Jor Date: Tue, 22 Apr 2025 02:07:46 -0500 Subject: [PATCH 07/12] store push service url --- .../passkit/api/v1/registrations_controller.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/passkit/api/v1/registrations_controller.rb b/app/controllers/passkit/api/v1/registrations_controller.rb index 592d6c3..a9ed8b7 100644 --- a/app/controllers/passkit/api/v1/registrations_controller.rb +++ b/app/controllers/passkit/api/v1/registrations_controller.rb @@ -85,7 +85,10 @@ 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]) { |d| + d.push_token = push_token + d.push_service_url = push_service_url + } @pass.registrations.create!(device: device) end @@ -117,6 +120,17 @@ 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) + puts '--------------json_body',json_body + puts '--------------push_service_url',json_body["pushServiceUrl"] + + json_body["pushServiceUrl"] + end end end end From c6f6e71f97fa87e01f3dc6711344efa84174126e Mon Sep 17 00:00:00 2001 From: Mandy Jor Date: Tue, 22 Apr 2025 02:14:29 -0500 Subject: [PATCH 08/12] logging --- app/controllers/passkit/api/v1/registrations_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/controllers/passkit/api/v1/registrations_controller.rb b/app/controllers/passkit/api/v1/registrations_controller.rb index a9ed8b7..f2ba479 100644 --- a/app/controllers/passkit/api/v1/registrations_controller.rb +++ b/app/controllers/passkit/api/v1/registrations_controller.rb @@ -85,6 +85,11 @@ def load_device end def register_device + puts 'register_device-------------------------' + puts '--------------push_token',push_token + puts '--------------push_service_url',push_service_url + puts '--------------params',params.inspect + device = Passkit::Device.find_or_create_by!(identifier: params[:device_id]) { |d| d.push_token = push_token d.push_service_url = push_service_url From 8f98813f9342c495445b0db328e07c34f2e45094 Mon Sep 17 00:00:00 2001 From: Mandy Jor Date: Tue, 22 Apr 2025 02:29:56 -0500 Subject: [PATCH 09/12] store push service url --- .../passkit/api/v1/registrations_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/passkit/api/v1/registrations_controller.rb b/app/controllers/passkit/api/v1/registrations_controller.rb index f2ba479..3857538 100644 --- a/app/controllers/passkit/api/v1/registrations_controller.rb +++ b/app/controllers/passkit/api/v1/registrations_controller.rb @@ -90,10 +90,10 @@ def register_device puts '--------------push_service_url',push_service_url puts '--------------params',params.inspect - device = Passkit::Device.find_or_create_by!(identifier: params[:device_id]) { |d| - d.push_token = push_token - d.push_service_url = push_service_url - } + device = Passkit::Device.find_or_create_by!(identifier: params[:device_id]).update(push_token: push_token, push_service_url: push_service_url) + device.update(push_token: push_token, push_service_url: push_service_url) + puts '--------------device',device.inspect + @pass.registrations.create!(device: device) end From e9a017a08604bc8a315ad6c0d9d082e8773b337e Mon Sep 17 00:00:00 2001 From: Mandy Jor Date: Tue, 22 Apr 2025 02:35:08 -0500 Subject: [PATCH 10/12] store push service url --- app/controllers/passkit/api/v1/registrations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/passkit/api/v1/registrations_controller.rb b/app/controllers/passkit/api/v1/registrations_controller.rb index 3857538..f4213f9 100644 --- a/app/controllers/passkit/api/v1/registrations_controller.rb +++ b/app/controllers/passkit/api/v1/registrations_controller.rb @@ -90,7 +90,7 @@ def register_device puts '--------------push_service_url',push_service_url puts '--------------params',params.inspect - device = Passkit::Device.find_or_create_by!(identifier: params[:device_id]).update(push_token: push_token, push_service_url: push_service_url) + device = Passkit::Device.find_or_create_by!(identifier: params[:device_id]) device.update(push_token: push_token, push_service_url: push_service_url) puts '--------------device',device.inspect From 5e0e9b4d45d24dfde2ea59d56873ecc638c1f05d Mon Sep 17 00:00:00 2001 From: Mandy Jor Date: Tue, 22 Apr 2025 15:33:30 -0500 Subject: [PATCH 11/12] use same create method --- app/controllers/passkit/api/v1/registrations_controller.rb | 2 -- config/routes.rb | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/passkit/api/v1/registrations_controller.rb b/app/controllers/passkit/api/v1/registrations_controller.rb index f4213f9..c4d1106 100644 --- a/app/controllers/passkit/api/v1/registrations_controller.rb +++ b/app/controllers/passkit/api/v1/registrations_controller.rb @@ -14,7 +14,6 @@ class RegistrationsController < ActionController::API # @return If the request is not authorized, returns HTTP status 401. # @return Otherwise, returns the appropriate standard HTTP status. def create - puts 'create-------------------------' if @pass.devices.find_by(identifier: params[:device_id]) render json: {}, status: :ok return @@ -25,7 +24,6 @@ def create end def create_walletpass_for_android - puts 'create_walletpass_for_android-------------------------' if @pass.devices.find_by(identifier: params[:device_id]) render json: {}, status: :ok return diff --git a/config/routes.rb b/config/routes.rb index 43e024e..d47c501 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +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_walletpass_for_android", :as => :register_for_android + 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 From 812d3836d226cd3f92090d45e55a0a6a09689c17 Mon Sep 17 00:00:00 2001 From: Mandy Jor Date: Tue, 22 Apr 2025 16:00:35 -0500 Subject: [PATCH 12/12] remove unneeded code --- .../api/v1/registrations_controller.rb | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/app/controllers/passkit/api/v1/registrations_controller.rb b/app/controllers/passkit/api/v1/registrations_controller.rb index c4d1106..25e7b9d 100644 --- a/app/controllers/passkit/api/v1/registrations_controller.rb +++ b/app/controllers/passkit/api/v1/registrations_controller.rb @@ -6,7 +6,7 @@ module V1 # @see Apple: https://developer.apple.com/library/archive/documentation/PassKit/Reference/PassKit_WebService/WebService.html # @see Android: https://walletpasses.io/developer/ class RegistrationsController < ActionController::API - before_action :load_pass, only: %i[create create_walletpass_for_android destroy] + before_action :load_pass, only: %i[create destroy] before_action :load_device, only: %i[show] # @return If the serial number is already registered for this device, returns HTTP status 200. @@ -23,16 +23,6 @@ def create render json: {}, status: :created end - def create_walletpass_for_android - if @pass.devices.find_by(identifier: params[:device_id]) - render json: {}, status: :ok - return - end - - register_device - render json: {}, status: :created - end - # @return If there are matching passes, returns HTTP status 200 # with a JSON dictionary with the following keys and values: # lastUpdated (string): The current modification tag. @@ -83,14 +73,8 @@ def load_device end def register_device - puts 'register_device-------------------------' - puts '--------------push_token',push_token - puts '--------------push_service_url',push_service_url - puts '--------------params',params.inspect - device = Passkit::Device.find_or_create_by!(identifier: params[:device_id]) device.update(push_token: push_token, push_service_url: push_service_url) - puts '--------------device',device.inspect @pass.registrations.create!(device: device) end @@ -129,9 +113,6 @@ def push_service_url request.body.rewind json_body = JSON.parse(request.body.read) - puts '--------------json_body',json_body - puts '--------------push_service_url',json_body["pushServiceUrl"] - json_body["pushServiceUrl"] end end