From f3bf9f539b51d1830f9a0bc5e49d7f01b7dd5790 Mon Sep 17 00:00:00 2001 From: Kaan Baris BAYRAK Date: Fri, 22 Oct 2021 16:35:05 +0200 Subject: [PATCH] Mobile push notification and Oauth flow --- .../HopperAPIAuthWithCodeRequest.kt | 22 ++++++++++++++++ ...erAPIUpdateGetMobileNotificationRequest.kt | 14 +++++++++++ ...rAPIUpdateGetMobileNotificationResponse.kt | 8 ++++++ .../HopperAPIUpdatePushNotificationRequest.kt | 23 +++++++++++++++++ .../android/sdk/CryptohopperAuth.kt | 10 ++++++++ .../android/sdk/CryptohopperUser.kt | 25 +++++++++++++++++++ .../User/Enums/PushNotificationPermissions.kt | 1 + 7 files changed, 103 insertions(+) create mode 100644 sdk/src/main/java/cryptohopper/android/sdk/API/Authentication/AuthWithCode/HopperAPIAuthWithCodeRequest.kt create mode 100644 sdk/src/main/java/cryptohopper/android/sdk/API/User/General/GetMobileNotifications/HopperAPIUpdateGetMobileNotificationRequest.kt create mode 100644 sdk/src/main/java/cryptohopper/android/sdk/API/User/General/GetMobileNotifications/HopperAPIUpdateGetMobileNotificationResponse.kt create mode 100644 sdk/src/main/java/cryptohopper/android/sdk/API/User/General/UpdateMobilePushNotification/HopperAPIUpdatePushNotificationRequest.kt diff --git a/sdk/src/main/java/cryptohopper/android/sdk/API/Authentication/AuthWithCode/HopperAPIAuthWithCodeRequest.kt b/sdk/src/main/java/cryptohopper/android/sdk/API/Authentication/AuthWithCode/HopperAPIAuthWithCodeRequest.kt new file mode 100644 index 0000000..07fb714 --- /dev/null +++ b/sdk/src/main/java/cryptohopper/android/sdk/API/Authentication/AuthWithCode/HopperAPIAuthWithCodeRequest.kt @@ -0,0 +1,22 @@ +package cryptohopper.android.sdk.API.Authentication.AuthWithCode + +import HopperAPIAuthenticationResponse +import HopperAPIRequest +import cryptohopper.android.sdk.API.Hopper.General.CreateHopper.HopperAPICreateHopperResponse +import cryptohopper.android.sdk.SharedModels.ConfigModels.HopperAPIHttpMethod + +class HopperAPIAuthWithCodeRequest: HopperAPIRequest { + + constructor(code: String, userAgent: String) { + this.httpMethod = HopperAPIHttpMethod.POST + this.needsAuthentication = false + this.setIsAuthenticationRequest(true) + this.changeUrlPath("/oauth2/token") + addBodyItem( "grant_type", "authorization_code") + addBodyItem( "client_id", HopperAPIConfigurationManager.shared.config.clientId!!) + addBodyItem( "code", code) + addBodyItem( "scope", "read,user,notifications,trade,manage") + addHeader("User-Agent",userAgent) + } + +} \ No newline at end of file diff --git a/sdk/src/main/java/cryptohopper/android/sdk/API/User/General/GetMobileNotifications/HopperAPIUpdateGetMobileNotificationRequest.kt b/sdk/src/main/java/cryptohopper/android/sdk/API/User/General/GetMobileNotifications/HopperAPIUpdateGetMobileNotificationRequest.kt new file mode 100644 index 0000000..6de8ce8 --- /dev/null +++ b/sdk/src/main/java/cryptohopper/android/sdk/API/User/General/GetMobileNotifications/HopperAPIUpdateGetMobileNotificationRequest.kt @@ -0,0 +1,14 @@ +package cryptohopper.android.sdk.API.User.General.GetMobileNotifications + +import HopperAPIRequest +import cryptohopper.android.sdk.SharedModels.ConfigModels.HopperAPIHttpMethod + +class HopperAPIUpdateGetMobileNotificationRequest: HopperAPIRequest { + + constructor(data : String) { + this.httpMethod = HopperAPIHttpMethod.GET + this.needsAuthentication = true + this.changeUrlPath("/user/mobilepushnotifications") + } + +} \ No newline at end of file diff --git a/sdk/src/main/java/cryptohopper/android/sdk/API/User/General/GetMobileNotifications/HopperAPIUpdateGetMobileNotificationResponse.kt b/sdk/src/main/java/cryptohopper/android/sdk/API/User/General/GetMobileNotifications/HopperAPIUpdateGetMobileNotificationResponse.kt new file mode 100644 index 0000000..5eef939 --- /dev/null +++ b/sdk/src/main/java/cryptohopper/android/sdk/API/User/General/GetMobileNotifications/HopperAPIUpdateGetMobileNotificationResponse.kt @@ -0,0 +1,8 @@ +package cryptohopper.android.sdk.API.User.General.GetMobileNotifications + +import com.google.gson.annotations.SerializedName + +data class HopperAPIUpdateGetMobileNotificationResponse ( + @SerializedName("data") val notifications: Map? +) + diff --git a/sdk/src/main/java/cryptohopper/android/sdk/API/User/General/UpdateMobilePushNotification/HopperAPIUpdatePushNotificationRequest.kt b/sdk/src/main/java/cryptohopper/android/sdk/API/User/General/UpdateMobilePushNotification/HopperAPIUpdatePushNotificationRequest.kt new file mode 100644 index 0000000..a47937d --- /dev/null +++ b/sdk/src/main/java/cryptohopper/android/sdk/API/User/General/UpdateMobilePushNotification/HopperAPIUpdatePushNotificationRequest.kt @@ -0,0 +1,23 @@ +package cryptohopper.android.sdk.API.User.General.UpdateMobilePushNotification + +import HopperAPIRequest +import HopperCommonMessageResponse +import cryptohopper.android.sdk.SharedModels.ConfigModels.HopperAPIHttpMethod + +internal class HopperAPIUpdatePushNotificationRequest: HopperAPIRequest { + + constructor( + permissions : Map + ) { + this.httpMethod = HopperAPIHttpMethod.POST + this.needsAuthentication = true + this.changeUrlPath("/user/mobilepushnotifications") + + var arr = mutableMapOf() + for ((k, v) in permissions) { + arr[k] = v + } + addBodyItem("settings",arr) + } + +} \ No newline at end of file diff --git a/sdk/src/main/java/cryptohopper/android/sdk/CryptohopperAuth.kt b/sdk/src/main/java/cryptohopper/android/sdk/CryptohopperAuth.kt index bd6a0dd..fb41e9e 100644 --- a/sdk/src/main/java/cryptohopper/android/sdk/CryptohopperAuth.kt +++ b/sdk/src/main/java/cryptohopper/android/sdk/CryptohopperAuth.kt @@ -4,6 +4,7 @@ import HopperAPIAuthenticationRequest import HopperAPIAuthenticationResponse import HopperError import android.content.Context +import cryptohopper.android.sdk.API.Authentication.AuthWithCode.HopperAPIAuthWithCodeRequest import cryptohopper.android.sdk.SharedModels.ConfigModels.HopperAPIEnvironment import cryptohopper.android.sdk.SharedModels.ConfigModels.HopperAPIError @@ -20,6 +21,15 @@ class CryptohopperAuth { }) } + fun loginWithCode(code: String,userAgent : String,callback: (String?,HopperAPIError?) -> Unit) { + HopperAPIAuthWithCodeRequest(code,userAgent).request({ response -> + HopperAPISessionManager.shared.handleAuthResponse(response) + callback("Successfully Logged In",null) + },{error -> + callback(null,error) + }) + } + fun logout() { HopperAPISessionManager.shared.removeSession() } diff --git a/sdk/src/main/java/cryptohopper/android/sdk/CryptohopperUser.kt b/sdk/src/main/java/cryptohopper/android/sdk/CryptohopperUser.kt index 743698b..644e48d 100644 --- a/sdk/src/main/java/cryptohopper/android/sdk/CryptohopperUser.kt +++ b/sdk/src/main/java/cryptohopper/android/sdk/CryptohopperUser.kt @@ -1,4 +1,7 @@ +import cryptohopper.android.sdk.API.User.General.GetMobileNotifications.HopperAPIUpdateGetMobileNotificationRequest +import cryptohopper.android.sdk.API.User.General.GetMobileNotifications.HopperAPIUpdateGetMobileNotificationResponse import cryptohopper.android.sdk.API.User.General.RegisterUser.HopperAPIRegisterUserResponse +import cryptohopper.android.sdk.API.User.General.UpdateMobilePushNotification.HopperAPIUpdatePushNotificationRequest import cryptohopper.android.sdk.SharedModels.ConfigModels.HopperAPIError class CryptohopperUser { @@ -58,6 +61,28 @@ class CryptohopperUser { } + /// Get Mobile Notification + /// + fun getMobilePushNotificationPrefs(callback: (Map?, HopperAPIError?) -> Unit) { + HopperAPIUpdateGetMobileNotificationRequest("").request({ data -> + callback(data.notifications,null) + } ,{ error -> + callback(null,error) + }) + } + + + /// Update Mobile Notification + /// + fun updateMobilePushNotificationPrefs(permissions : Map, callback: (String?, HopperAPIError?) -> Unit) { + HopperAPIUpdatePushNotificationRequest(permissions).request({ data -> + callback(data.data,null) + } ,{ error -> + callback(null,error) + }) + } + + /// Get User Email /// fun getUserEmail(callback: (String?, HopperAPIError?) -> Unit) { diff --git a/sdk/src/main/java/cryptohopper/android/sdk/SharedModels/User/Enums/PushNotificationPermissions.kt b/sdk/src/main/java/cryptohopper/android/sdk/SharedModels/User/Enums/PushNotificationPermissions.kt index d17d323..a861a8e 100644 --- a/sdk/src/main/java/cryptohopper/android/sdk/SharedModels/User/Enums/PushNotificationPermissions.kt +++ b/sdk/src/main/java/cryptohopper/android/sdk/SharedModels/User/Enums/PushNotificationPermissions.kt @@ -12,6 +12,7 @@ enum class PushNotificationPermissions(val rawValue: String) { @SerializedName("on_first_start") ON_FIRST_START("on_first_start"), @SerializedName("on_trigger") ON_TRIGGER("on_trigger"), @SerializedName("on_panic_start") ON_PANIC_START("on_panic_start"), + @SerializedName("on_panic_end") ON_PANIC_END("on_panic_end"), @SerializedName("order_placed") ORDER_PLACED("order_placed"), @SerializedName("trade_completed") TRADE_COMPLETED("trade_completed"), @SerializedName("order_cancelled") ORDER_CANCELLED("order_cancelled")