Copy
grpcurl \
-d '
{
"records": [
{
"subscriberNumber": {
"e164": "+46712345678"
},
"operatorCode": "A21",
"routingCode": "006",
"validFrom": "2024-04-01T00:00:00Z",
"metadata": {
"test_key": "test_value"
}
}
]
}
' \
sandbox.api.shamrock.wgtwo.com:443 \
wgtwo.number_portability.v0.NumberPortabilityService/CreatePortingRecords
Copy
package com.example.numberPortability
import com.google.protobuf.Timestamp
import com.wgtwo.api.v0.number_portability.NumberPortabilityServiceGrpcKt
import com.wgtwo.api.v0.number_portability.createPortingRecordsRequest
import com.wgtwo.api.v0.number_portability.portingRecord
import com.wgtwo.api.v1.common.e164
import io.grpc.ManagedChannelBuilder
import io.grpc.Status
import io.grpc.StatusException
import kotlinx.coroutines.runBlocking
private val channel = ManagedChannelBuilder.forAddress("sandbox.api.shamrock.wgtwo.com", 443).build()
private val stub = NumberPortabilityServiceGrpcKt.NumberPortabilityServiceCoroutineStub(channel)
fun main() = runBlocking {
val createPortingRecordsRequest = createPortingRecordsRequest {
records += listOf(
portingRecord {
subscriberNumber = e164 { e164 = "+46700000001" }
validFrom = Timestamp.newBuilder().setSeconds(System.currentTimeMillis() / 1000).build()
operatorCode = "A21"
routingCode = "010"
metadata.put("test_key", "test_value")
},
portingRecord {
subscriberNumber = e164 { e164 = "+46700000002" }
validFrom = Timestamp.newBuilder().setSeconds(System.currentTimeMillis() / 1000).build()
operatorCode = "C39"
routingCode = "005"
metadata.putAll(mapOf("test_key1" to "test_value", "test_key2" to "test_value2"))
},
)
}
println("createPortingRecordsRequest:
$createPortingRecordsRequest")
val createPortingRecordsResponse = stub.createPortingRecords(createPortingRecordsRequest)
println("createPortingRecordsResponse:
$createPortingRecordsResponse")
val createPortingRecordsRequestWithInvalidSubscriberNumber = createPortingRecordsRequest {
records += listOf(
portingRecord {
subscriberNumber = e164 { e164 = "invalid" }
validFrom = Timestamp.newBuilder().setSeconds(System.currentTimeMillis() / 1000).build()
operatorCode = "A21"
routingCode = "010"
},
)
}
val errorResponse = runCatching {
stub.createPortingRecords(createPortingRecordsRequestWithInvalidSubscriberNumber)
}
assert(errorResponse.isFailure) { "result is not a failure" }
assert((errorResponse.exceptionOrNull() as? StatusException)?.status?.code == Status.INVALID_ARGUMENT.code) {
"exception is not a StatusException with INVALID_ARGUMENT status code: ${errorResponse.exceptionOrNull()}"
}
println("Status code: ${(errorResponse.exceptionOrNull() as StatusException).status.code}")
println("Status description: ${(errorResponse.exceptionOrNull() as StatusException).status.description}")
}