Skip to content

Commit

Permalink
Merge pull request #7 from nurigo/impr/get-message-list
Browse files Browse the repository at this point in the history
Release Nurigo Java SDK 4.2.5:
  • Loading branch information
Palbahngmiyine authored Nov 21, 2022
2 parents c925ebd + e89ced4 commit c9d620c
Show file tree
Hide file tree
Showing 10 changed files with 315 additions and 56 deletions.
12 changes: 6 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
}

group = "net.nurigo"
version = "4.2.4"
version = "4.2.5"

repositories {
mavenCentral()
Expand All @@ -22,15 +22,15 @@ repositories {
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
implementation("org.jetbrains.kotlinx:kotlinx-datetime-jvm:0.3.3")
implementation("org.jetbrains.kotlinx:kotlinx-datetime-jvm:0.4.0")
implementation("commons-codec:commons-codec:1.15")
implementation("com.squareup.okhttp3:okhttp:4.9.3")
implementation("com.squareup.okhttp3:logging-interceptor:4.9.3")
implementation("com.squareup.okhttp3:okhttp:4.10.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.10.0")
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
implementation("com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0")

dokkaHtmlPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.6.21")
dokkaHtmlPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.7.20")
}

java {
Expand Down

This file was deleted.

27 changes: 27 additions & 0 deletions src/main/java/net/nurigo/sdk/message/lib/MapHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.nurigo.sdk.message.lib

import kotlinx.serialization.json.*

class MapHelper {

companion object {
inline fun <reified T> toMap(obj: T): Map<String, Any?> {
return jsonObjectToMap(Json.encodeToJsonElement(obj).jsonObject)
}

fun jsonObjectToMap(element: JsonObject): Map<String, Any?> {
return element.entries.associate {
it.key to extractValue(it.value)
}
}

private fun extractValue(element: JsonElement): Any? {
return when (element) {
is JsonNull -> null
is JsonPrimitive -> element.content
is JsonArray -> element.map { extractValue(it) }
is JsonObject -> jsonObjectToMap(element)
}
}
}
}
13 changes: 11 additions & 2 deletions src/main/java/net/nurigo/sdk/message/model/Message.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ data class Message(
var imageId: String? = null,

/**
* * 발송 접수일자
* * 발송 접수일자
*/
var dateProcessed: Instant? = null,

Expand Down Expand Up @@ -76,6 +76,7 @@ data class Message(
/**
* 문자 상태
* 예) 대기, 접수, 발송완료 등
* 해당 프로퍼티는 MessageStatusType과 다른 값입니다!
*/
var status: String? = null,

Expand Down Expand Up @@ -118,7 +119,13 @@ data class Message(
* 발신번호, 반드시 계정 내 등록하신 발신번호를 입력하셔야 합니다.
* 예) 029302266
*/
var from: String? = null
var from: String? = null,

/**
* 사용자(누리고 서비스 이용자)를 위한 발송 요청 시 커스텀 값을 넣을 수 있는 필드
* 메시지 조회 시에도 표시됩니다!
*/
var customFields: Map<String, String>? = null
) {

override fun equals(other: Any?): Boolean {
Expand Down Expand Up @@ -148,6 +155,7 @@ data class Message(
if (dateUpdated != other.dateUpdated) return false
if (from != other.from) return false
if (to != other.to) return false
if (customFields != other.customFields) return false

return true
}
Expand All @@ -174,6 +182,7 @@ data class Message(
result = 31 * result + (dateUpdated?.hashCode() ?: 0)
result = 31 * result + (from?.hashCode() ?: 0)
result = 31 * result + (to?.hashCode() ?: 0)
result = 31 * result + (customFields?.hashCode() ?: 0)
return result
}
}
28 changes: 28 additions & 0 deletions src/main/java/net/nurigo/sdk/message/model/MessageStatusType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.nurigo.sdk.message.model

/**
* 메시지 조회를 위한 Custom Message Status.
* 실제 메시지 발송 API 규격에 따르지 않아 주의가 필요합니다.
* Message 모델의 status와는 다른 값입니다!
*/
enum class MessageStatusType {
/**
* 대기 상태, 상태코드 2000
*/
PENDING,

/**
* 발송 중 상태, 상태코드 3000
*/
SENDING,

/**
* 발송 완료 상태, 상태코드 4000
*/
COMPLETE,

/**
* 발송 실패(접수 실패 포함) 상태, 상태코드가 2000, 3000, 4000번이 아닌 모든 상태코드
*/
FAILED
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import kotlinx.serialization.Serializable

@Serializable
data class DefaultAgent(
val sdkVersion: String = "java/4.2.4",
val sdkVersion: String = "java/4.2.5",
val osPlatform: String = "${System.getProperty("os.name")} | ${System.getProperty("java.version")}"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package net.nurigo.sdk.message.request

import kotlinx.datetime.Instant
import kotlinx.serialization.Serializable
import net.nurigo.sdk.message.model.CommonMessageProperty

@Serializable
data class MessageListBaseRequest(
override var to: String? = null,
override var from: String? = null,
var startKey: String? = null,
var limit: Int? = null,
var startDate: Instant? = null,
var endDate: Instant? = null,
var messageId: String? = null,
var groupId: String? = null,
var type: String? = null,
var statusCode: String? = null,
var criteria: String? = null,
var cond: String? = null,
var value: String? = null
) : CommonMessageProperty {

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as MessageListBaseRequest

if (to != other.to) return false
if (from != other.from) return false
if (startKey != other.startKey) return false
if (limit != other.limit) return false
if (startDate != other.startDate) return false
if (endDate != other.endDate) return false
if (messageId != other.messageId) return false
if (groupId != other.groupId) return false
if (type != other.type) return false
if (statusCode != other.statusCode) return false

return true
}

override fun hashCode(): Int {
var result = to?.hashCode() ?: 0
result = 31 * result + (from?.hashCode() ?: 0)
result = 31 * result + (startKey?.hashCode() ?: 0)
result = 31 * result + (limit ?: 0)
result = 31 * result + (startDate?.hashCode() ?: 0)
result = 31 * result + (endDate?.hashCode() ?: 0)
result = 31 * result + (messageId?.hashCode() ?: 0)
result = 31 * result + (groupId?.hashCode() ?: 0)
result = 31 * result + (type?.hashCode() ?: 0)
result = 31 * result + (statusCode?.hashCode() ?: 0)
return result
}
}
65 changes: 54 additions & 11 deletions src/main/java/net/nurigo/sdk/message/request/MessageListRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,70 @@ package net.nurigo.sdk.message.request
import kotlinx.datetime.Instant
import kotlinx.serialization.Serializable
import net.nurigo.sdk.message.model.CommonMessageProperty
import net.nurigo.sdk.message.model.MessageStatusType

@Serializable
data class MessageListRequest(
/**
* 수신번호
*/
override var to: String? = null,

/**
* 발신번호
*/
override var from: String? = null,

/**
* Pagination을 위한 key
* 조회 후 다음 페이지로 넘어가려면 조회 당시 마지막의 messageId를 입력해주셔야 합니다.
*/
var startKey: String? = null,

/**
* 조회할 건 수
*/
var limit: Int? = null,
var dateType: String? = null,
var startDate: Instant? = null,
var endDate: Instant? = null,

/**
* 메시지 ID
*/
var messageId: String? = null,

/**
* 메시지 ID 목록
*/
var messageIds: List<String>? = null,

/**
* 메시지 그룹 ID
*/
var groupId: String? = null,

/**
* 메시지 유형 (예) ATA, SMS 등)
*/
var type: String? = null,

/**
* 상태코드 (예) -> 2000: 발송 대기, 3000: 발송 중, 4000: 발송완료)
*/
var statusCode: String? = null,
var dateCreated: Instant? = null,
var dateUpdated: Instant? = null

/**
* 조회 할 시작 날짜
*/
var startDate: Instant? = null,

/**
* 조회 할 종료 날짜
*/
var endDate: Instant? = null,

/**
* 발송 상태
*/
var status: MessageStatusType? = null
) : CommonMessageProperty {

override fun equals(other: Any?): Boolean {
Expand All @@ -32,16 +79,14 @@ data class MessageListRequest(
if (from != other.from) return false
if (startKey != other.startKey) return false
if (limit != other.limit) return false
if (dateType != other.dateType) return false
if (startDate != other.startDate) return false
if (endDate != other.endDate) return false
if (messageId != other.messageId) return false
if (messageIds != other.messageIds) return false
if (groupId != other.groupId) return false
if (type != other.type) return false
if (statusCode != other.statusCode) return false
if (dateCreated != other.dateCreated) return false
if (dateUpdated != other.dateUpdated) return false
if (status != other.status) return false

return true
}
Expand All @@ -51,16 +96,14 @@ data class MessageListRequest(
result = 31 * result + (from?.hashCode() ?: 0)
result = 31 * result + (startKey?.hashCode() ?: 0)
result = 31 * result + (limit ?: 0)
result = 31 * result + (dateType?.hashCode() ?: 0)
result = 31 * result + (startDate?.hashCode() ?: 0)
result = 31 * result + (endDate?.hashCode() ?: 0)
result = 31 * result + (messageId?.hashCode() ?: 0)
result = 31 * result + (messageIds?.hashCode() ?: 0)
result = 31 * result + (groupId?.hashCode() ?: 0)
result = 31 * result + (type?.hashCode() ?: 0)
result = 31 * result + (statusCode?.hashCode() ?: 0)
result = 31 * result + (dateCreated?.hashCode() ?: 0)
result = 31 * result + (dateUpdated?.hashCode() ?: 0)
result = 31 * result + (status?.hashCode() ?: 0)
return result
}
}
Loading

0 comments on commit c9d620c

Please sign in to comment.