-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4110d7
commit 83d4f0c
Showing
9 changed files
with
266 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
53 changes: 53 additions & 0 deletions
53
lib/src/main/kotlin/push/kotlin/sdk/PushNotification/ChannelAPI.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package push.kotlin.sdk.PushNotification | ||
|
||
import push.kotlin.sdk.ENV | ||
import push.kotlin.sdk.Signer | ||
import push.kotlin.sdk.channels.* | ||
|
||
class ChannelAPI( | ||
private val account: String, | ||
val env: ENV, | ||
private val decryptedPgpPvtKey: String, | ||
private val signer: Signer, | ||
) { | ||
|
||
data class ChannelInfoOptions( | ||
val channel: String, | ||
val page: Int = 1, | ||
val limit: Int = 10, | ||
val category: Int? = null, | ||
val setting: Boolean = false, | ||
) | ||
|
||
|
||
fun info(channel: String): PushChannel? { | ||
return Channel.getChannel(channel, env) | ||
} | ||
|
||
fun search(query: String, page: Int, limit: Int): Result<PushChannels> { | ||
return ChannelSearch.searchChannels(query, page, limit, "", env) | ||
} | ||
|
||
fun subscribers(options: ChannelInfoOptions): Result<ChannelSubscribers> { | ||
return ChannelSubscriber.getSubscribers(options.channel, options.page, options.limit, env) | ||
} | ||
|
||
fun notification(account: String, options: ChannelFeedsOptions = ChannelFeedsOptions()): Result<ChannelNotification.ChannelNotificationsData> { | ||
|
||
val option = ChannelNotification.GetChannelOptionsType( | ||
channel = account, env = env, page = options.page, limit = options.limit, raw = options.raw, filter = options.filter) | ||
|
||
return ChannelNotification.getChannelNotifications(option) | ||
} | ||
|
||
data class ChannelFeedsOptions( | ||
val page: Int = 1, | ||
val limit: Int = 10, | ||
val raw: Boolean = true, | ||
val filter: NotificationType? = null | ||
) | ||
|
||
fun list(){ | ||
|
||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
lib/src/main/kotlin/push/kotlin/sdk/channels/ChannelNotification.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package push.kotlin.sdk.channels | ||
|
||
import com.google.gson.Gson | ||
import com.google.gson.annotations.SerializedName | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Request | ||
import push.kotlin.sdk.ENV | ||
import push.kotlin.sdk.Helpers | ||
import push.kotlin.sdk.PushURI | ||
import java.net.URL | ||
|
||
enum class NotificationType(val value: Int) { | ||
BROADCAST(1), | ||
TARGETED(3), | ||
SUBSET(4) | ||
} | ||
class ChannelNotification { | ||
companion object { | ||
fun getChannelNotifications(options: GetChannelOptionsType): Result<ChannelNotificationsData> { | ||
val channel = Helpers.walletToCAIP(options.env, options.channel) | ||
val queryParams = Helpers. getQueryParams( | ||
if (options.filter != null) { | ||
mapOf( | ||
"page" to options.page.toString(), | ||
"limit" to options.limit.toString(), | ||
"notificationType" to options.filter.toString(), | ||
"raw" to options.raw.toString() | ||
) | ||
} else { | ||
mapOf( | ||
"page" to options.page.toString(), | ||
"limit" to options.limit.toString(), | ||
"raw" to options.raw.toString() | ||
) | ||
} | ||
) | ||
|
||
val url = PushURI.getChannelNotifications( channel, queryParams, options.env) | ||
val obj = URL(url) | ||
|
||
val client = OkHttpClient() | ||
val request = Request.Builder().url(obj).build() | ||
val response = client.newCall(request).execute() | ||
|
||
return if(response.isSuccessful) { | ||
val jsonResponse = response.body?.string() | ||
val gson = Gson() | ||
val apiResponse = gson.fromJson(jsonResponse, ChannelNotificationsData::class.java) | ||
Result.success(apiResponse) | ||
} else { | ||
Result.failure(IllegalStateException("Error ${response.code} ${response.message}")) | ||
} | ||
} | ||
} | ||
|
||
data class GetChannelOptionsType( | ||
val channel: String, | ||
val env: ENV, | ||
val page: Int = 1, | ||
val limit: Int = 10, | ||
val filter: NotificationType? = null, | ||
val raw: Boolean = true | ||
) | ||
|
||
|
||
|
||
data class Notification( | ||
val timestamp: String, | ||
val from: String, | ||
val to: List<String>, | ||
@SerializedName("notifID") val notifId: Long, | ||
val channel: Channel, | ||
val meta: Meta, | ||
val message: Message, | ||
val config: Config, | ||
val source: String, | ||
val raw: Raw | ||
) | ||
|
||
data class Channel( | ||
val name: String, | ||
val icon: String, | ||
val url: String | ||
) | ||
|
||
data class Meta( | ||
val type: String | ||
) | ||
|
||
data class Message( | ||
val notification: NotificationData, | ||
val payload: Payload | ||
) | ||
|
||
data class NotificationData( | ||
val title: String, | ||
val body: String | ||
) | ||
|
||
data class Payload( | ||
val title: String, | ||
val body: String, | ||
val cta: String, | ||
val embed: String, | ||
val meta: MetaData | ||
) | ||
|
||
data class MetaData( | ||
val domain: String | ||
) | ||
|
||
data class Config( | ||
val expiry: String?, // Adjust the type if expiry is not a String | ||
val silent: Boolean, | ||
val hidden: Boolean | ||
) | ||
|
||
data class Raw( | ||
val verificationProof: String | ||
) | ||
|
||
data class ChannelNotificationsData( | ||
val notifications: List<Notification>, | ||
val total: Int | ||
) | ||
|
||
} |
This file contains 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
This file contains 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
This file contains 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