Skip to content

Commit

Permalink
Mobile push notification and Oauth flow
Browse files Browse the repository at this point in the history
  • Loading branch information
barbayrak committed Oct 22, 2021
1 parent 01c150b commit f3bf9f5
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<HopperAPIAuthenticationResponse> {

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)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cryptohopper.android.sdk.API.User.General.GetMobileNotifications

import HopperAPIRequest
import cryptohopper.android.sdk.SharedModels.ConfigModels.HopperAPIHttpMethod

class HopperAPIUpdateGetMobileNotificationRequest: HopperAPIRequest<HopperAPIUpdateGetMobileNotificationResponse> {

constructor(data : String) {
this.httpMethod = HopperAPIHttpMethod.GET
this.needsAuthentication = true
this.changeUrlPath("/user/mobilepushnotifications")
}

}
Original file line number Diff line number Diff line change
@@ -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<String,String>?
)

Original file line number Diff line number Diff line change
@@ -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<HopperCommonMessageResponse> {

constructor(
permissions : Map<String,String>
) {
this.httpMethod = HopperAPIHttpMethod.POST
this.needsAuthentication = true
this.changeUrlPath("/user/mobilepushnotifications")

var arr = mutableMapOf<String,Any>()
for ((k, v) in permissions) {
arr[k] = v
}
addBodyItem("settings",arr)
}

}
10 changes: 10 additions & 0 deletions sdk/src/main/java/cryptohopper/android/sdk/CryptohopperAuth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -20,6 +21,15 @@ class CryptohopperAuth {
})
}

fun loginWithCode(code: String,userAgent : String,callback: (String?,HopperAPIError?) -> Unit) {
HopperAPIAuthWithCodeRequest(code,userAgent).request<HopperAPIAuthenticationResponse>({ response ->
HopperAPISessionManager.shared.handleAuthResponse(response)
callback("Successfully Logged In",null)
},{error ->
callback(null,error)
})
}

fun logout() {
HopperAPISessionManager.shared.removeSession()
}
Expand Down
25 changes: 25 additions & 0 deletions sdk/src/main/java/cryptohopper/android/sdk/CryptohopperUser.kt
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -58,6 +61,28 @@ class CryptohopperUser {
}


/// Get Mobile Notification
///
fun getMobilePushNotificationPrefs(callback: (Map<String,String>?, HopperAPIError?) -> Unit) {
HopperAPIUpdateGetMobileNotificationRequest("").request<HopperAPIUpdateGetMobileNotificationResponse>({ data ->
callback(data.notifications,null)
} ,{ error ->
callback(null,error)
})
}


/// Update Mobile Notification
///
fun updateMobilePushNotificationPrefs(permissions : Map<String,String>, callback: (String?, HopperAPIError?) -> Unit) {
HopperAPIUpdatePushNotificationRequest(permissions).request<HopperCommonMessageResponse>({ data ->
callback(data.data,null)
} ,{ error ->
callback(null,error)
})
}


/// Get User Email
///
fun getUserEmail(callback: (String?, HopperAPIError?) -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit f3bf9f5

Please sign in to comment.