Created
June 24, 2016 10:14
-
-
Save raviwu/cc97fc5c822daf6f39161f8484a89c95 to your computer and use it in GitHub Desktop.
API endpoints setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In your api call endpoint for update_push_subscription | |
# I use Grape, but the logic is similar in RailsAPI | |
resource :update_push_subscription do | |
desc "Update the user mobil push notification registration on Amazon SNS" | |
params do | |
requires :push_platform, type: String, desc: "Push Service Platform", values: %w(apns gcm) | |
requires :device_token, type: String, desc: "Device Token for Mobile Push Notification" | |
end | |
post do | |
# you'll need to do some pre processing to get the valid @user before getting into here | |
authenticate! | |
existed_amazon_sns_infos = AmazonSnsInfo.where(device_token: params[:device_token], platform: params[:push_platform]) | |
existed_amazon_sns_infos.destroy_all | |
amazon_sns_info = AmazonSnsInfo.create(user: @user, device_token: params[:device_token], platform: params[:push_platform]) | |
error!("Update Amazon SNS Subscription Failed", 403) unless amazon_sns_info.update_topic_subscription | |
# delete parse installation with provided device_token | |
ParseInstallationWrapper.check_and_unregister(device_token: amazon_sns_info.device_token, email: @user.email) | |
present :amazon_sns_info, amazon_sns_info.reload, with: API::V2::Entities::EntityAmazonSnsInfo | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In your api call endpoint for logout | |
# I use Grape, but the logic is similar in RailsAPI | |
resource :logout do | |
desc "Logout user and unsubscribe the push notification" | |
params do | |
requires :push_platform, type: String, desc: "Push Service Platform", values: %w(apns gcm) | |
requires :device_token, type: String, desc: "Device Token for Mobile Push Notification" | |
end | |
post do | |
# you'll need to do some pre processing to get the valid @user before getting into here | |
authenticate! | |
amazon_sns_info = AmazonSnsInfo.where(user: @user, device_token: params[:device_token], platform: params[:push_platform]).last | |
if amazon_sns_info.present? | |
error!("Update Amazon SNS Subscription Failed", 403) unless amazon_sns_info.unsubscribe_topic_subscriptions | |
present :amazon_sns_info, amazon_sns_info.reload, with: API::V2::Entities::EntityAmazonSnsInfo | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment