Skip to content
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
12 changes: 11 additions & 1 deletion app/controllers/passkit/api/v1/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the previous version, no changes are made to the db a device is found. Now, the device is being updated every time.

Maybe like this to back fill missing push_service_url?

          device = Passkit::Device.find_or_create_by!(identifier: params[:device_id]) do |d| 
          d.push_service_url = push_service_url 
          d.push_token = push_token 
          end
          
          device.update(push_service_url: push_service_url) if device.push_service_url.blank?

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

Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fairly atypical. Can you not acccess it with params["pushServiceUrl"]?

json_body = JSON.parse(request.body.read)
json_body["pushServiceUrl"]
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/generators/passkit/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPushServiceUrlToDevices < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
def change
add_column :passkit_devices, :push_service_url, :string
end
end