README.md in push_to_sns-0.2.0 vs README.md in push_to_sns-0.3.0

- old
+ new

@@ -29,11 +29,11 @@ This will generate the file `app/initializers/push_to_sns.rb` with the following content: (if you're not using rails, just paste the code in a place to be executed once on startup) ```ruby PushToSNS.configure do - read_device_id { |device| } + read_device_token { |device| } read_source { |device| } read_endpoint_arn { |device| } read_platform_arn { |device| } read_ios_apns { |device| } @@ -44,11 +44,11 @@ 3. This initializer is only full of some empty methods. Why? Because we don't want to enforce a `Device` model or couple heavily with `ActiveRecord`, you can specify the way you want us to read and store device identifiers and SNS endpoints in your model. We don't want to be an obstacle in your way. But, anyway, we can suggest the following: ```ruby PushToSNS.configure do - read_device_id { |device| device.device_id } + read_device_token { |device| device.device_token } read_source { |device| device.source } read_endpoint_arn { |device| device.endpoint_arn } read_platform_arn { |device| ENV["SNS_#{device.source.upcase}_PLATFORM_ARN"] } read_ios_apns { ENV["APNS"] } @@ -58,23 +58,31 @@ end ``` ### Device Setup -This is up to you in some way. For example, you can have a controller to receive `device_id`s from a mobile device and you want to register the device to be able to receive push notifications. You can do it in this way: +This is up to you in some way. For example, you can have a controller to receive a `device_token` and `device_uuid` from a mobile device and you want to register the device to be able to receive push notifications. You can do it in this way: ```ruby class DevicesController < ApiController def create - device = Device.create(device_params) - PushToSNS.setup_device(device) + device = Device.find_by(device_uuid: device_params[:device_uuid]) + if device.present? + # We first teardown the old endpoint arn. + PushToSNS.teardown_device(device) + device.update(device_params.slice(:device_token)) + else + device = Device.create(device_params) + end + + PushToSNS.setup_device(device) respond_with device end private def device_params - params.require(:device).permit(:device_id, :source) + params.require(:device).permit(:device_token, :device_uuid, :source) end end ``` `PushToSNS.setup_device` will get the device identifier from the object passed and register it on SNS. Then, it will store the endpoint returned using the code specified in `save_endpoint_arn` configuration.