Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
Release v1.5.0 (#119)
Browse files Browse the repository at this point in the history
* Change loginByNameParams from GET to POST

* Change mock-data for test to POST-method-login

* Feature POST-method-login

* プッシュ通知検索機能の追加 (#117)

* Bump buildToolsVersion to 30.0.2

* Feature Query for Push

* Add test for query-for-push

* Fix valid_get_push_response.json

* Fix mbaas_query.yml to distinguaish between get-push and search-push

* [WIP] Add test for Query-for-NCMBPush

* Fix test about query for push

---------

Co-authored-by: tanaka-kokoro <[email protected]>

* Bump version to v1.5.0 (#118)

Co-authored-by: tanaka-kokoro <[email protected]>

---------

Co-authored-by: tanaka-kokoro <[email protected]>
Co-authored-by: Duong Thuy Dinh <[email protected]>
  • Loading branch information
3 people authored Apr 14, 2023
1 parent 920d9b1 commit 877c596
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 134 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
- Android 8.x ~ 13.x
- API levels 26 ~ 33
- Android Studio 2020.3.1 Patch 2 ~ 2021.3.1
(※2023年3月時点)
(※2023年4月時点)

## テクニカルサポート窓口対応バージョン

Expand All @@ -31,7 +31,7 @@
※なお、mobile backend にて大規模な改修が行われた際は、1年半以内のSDKであっても対応出来ない場合がございます。<br>
その際は[informationブログ](https://mbaas.nifcloud.com/info/)にてお知らせいたします。予めご了承ください。

- v1.0.0 ~ (※2023年3月時点)
- v1.0.0 ~ (※2023年4月時点)

# インストール
Android Studioでプロジェクトを開き、以下の手順でSDKをインストールしてください。
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ buildscript {
android {
compileSdkVersion 31

buildToolsVersion "29.0.2"
buildToolsVersion "30.0.2"
defaultConfig {
minSdkVersion 20
targetSdkVersion 31
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/nifcloud/mbaas/core/NCMB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class NCMB {
/**
* Version of this SDK
*/
const val SDK_VERSION = "1.4.0"
const val SDK_VERSION = "1.5.0"

/**
* Prefix of keys in metadata for NCMB settings
Expand Down
90 changes: 67 additions & 23 deletions src/main/java/com/nifcloud/mbaas/core/NCMBPushService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,22 @@ import java.util.*
/**
* Service class for push notification api
*/
internal class NCMBPushService : NCMBService() {
internal class NCMBPushService : NCMBObjectService() {


/** service path for API category */
override val SERVICE_PATH = "push"


/**
* Constructor
*
* @param context NCMBContext object for current context
*/
init {
this.mServicePath = this.SERVICE_PATH
}

/**
* Create push object
*
Expand All @@ -32,7 +47,8 @@ internal class NCMBPushService : NCMBService() {
*/
@Throws(NCMBException::class)
fun sendPush(params: JSONObject): JSONObject {
val request = createRequestParams(null, params, null, NCMBRequest.HTTP_METHOD_POST)
// val request = createRequestParams(null, params, null, NCMBRequest.HTTP_METHOD_POST)
val request = createRequestParamsPush(null, params, null, NCMBRequest.HTTP_METHOD_POST, null, null)
val response = sendRequest(request)
when (response) {
is NCMBResponse.Success -> {
Expand All @@ -55,7 +71,7 @@ internal class NCMBPushService : NCMBService() {
*/
@Throws(NCMBException::class)
fun updatePush(pushId: String?, params: JSONObject): JSONObject {
val request = createRequestParams(pushId, params, null, NCMBRequest.HTTP_METHOD_PUT)
val request = createRequestParamsPush(pushId, params, null, NCMBRequest.HTTP_METHOD_PUT, null, null)
val response = sendRequest(request)
when (response) {
is NCMBResponse.Success -> {
Expand Down Expand Up @@ -87,11 +103,13 @@ internal class NCMBPushService : NCMBService() {
}

//connect
val paramsRequest = createRequestParams(
val paramsRequest = createRequestParamsPush(
"$pushId/openNumber",
params,
null,
NCMBRequest.HTTP_METHOD_POST
NCMBRequest.HTTP_METHOD_POST,
null,
null
)
val pushReceiptStatusHandler = NCMBHandler { callback, response ->
when (response) {
Expand All @@ -114,26 +132,28 @@ internal class NCMBPushService : NCMBService() {
}

/**
* Setup params to installation
* Setup params to push
*
* @param installationId installation id
* @param params installation parameters
* @param pushId push id
* @param params push parameters
* @param queryParams query parameters
* @param method method
* @return parameters in object
*/
@Throws(NCMBException::class)
fun createRequestParams(
installationId: String?,
fun createRequestParamsPush(
pushId: String?,
params: JSONObject,
queryParams: JSONObject?,
method: String
method: String,
callback: NCMBCallback?,
handler: NCMBHandler?
): RequestParams {

//url set
val url: String = if (installationId != null) {
val url: String = if (pushId != null) {
//PUT,GET(fetch)
NCMB.getApiBaseUrl() + mServicePath + "/" + installationId
NCMB.getApiBaseUrl() + mServicePath + "/" + pushId
} else {
//POST,GET(search)
NCMB.getApiBaseUrl() + this.mServicePath
Expand All @@ -142,21 +162,45 @@ internal class NCMBPushService : NCMBService() {
url = url,
method = method,
params = params,
contentType = NCMBRequest.HEADER_CONTENT_TYPE_JSON
contentType = NCMBRequest.HEADER_CONTENT_TYPE_JSON,
callback = callback,
handler = handler
)
}

companion object {
/** service path for API category */
const val SERVICE_PATH = "push"
}

/**
* Constructor
* Setup params to do find request for Query search functions
*
* @param context NCMBContext object for current context
* @param className Class name
* @param query JSONObject
* @return parameters in object
* @throws NCMBException
*/
init {
mServicePath = SERVICE_PATH
@Throws(NCMBException::class)
override fun findObjectParams(className: String, query:JSONObject): RequestParams {
var url = NCMB.getApiBaseUrl() + this.mServicePath
if(query.length() > 0) {
url = url.plus("?" + queryUrlStringGenerate(query))
}
val method = NCMBRequest.HTTP_METHOD_GET
val contentType = NCMBRequest.HEADER_CONTENT_TYPE_JSON
return RequestParams(url = url, method = method, contentType = contentType, query=query)
}

@Throws(NCMBException::class)
override fun createSearchResponseList(className: String, responseData: JSONObject): List<NCMBPush> {
return try {
val results = responseData.getJSONArray(NCMBQueryConstants.RESPONSE_PARAMETER_RESULTS)
val array: MutableList<NCMBPush> = ArrayList()
for (i in 0 until results.length()) {
val tmpObj = NCMBPush(results.getJSONObject(i))
array.add(tmpObj)
}
array
} catch (e: JSONException) {
throw NCMBException(NCMBException.INVALID_JSON, "Invalid JSON format.")
}
}
}


4 changes: 4 additions & 0 deletions src/main/java/com/nifcloud/mbaas/core/NCMBQuery.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class NCMBQuery<T : NCMBObject> private constructor(val mClassName: String, val
fun forFile(): NCMBQuery<NCMBFile> {
return NCMBQuery("file", NCMBFileService()) as NCMBQuery<NCMBFile>
}

fun forPush(): NCMBQuery<NCMBPush> {
return NCMBQuery("push", NCMBPushService()) as NCMBQuery<NCMBPush>
}
}

/**
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/com/nifcloud/mbaas/core/NCMBUserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ internal class NCMBUserService : NCMBObjectService() {
* @throws NCMBException
*/
@Throws(NCMBException::class)
protected fun loginUser(query: JSONObject): NCMBUser {
val reqParams = loginByNameParams(query, null, null)
protected fun loginUser(param: JSONObject): NCMBUser {
val reqParams = loginByNameParams(param, null, null)
val response = sendRequest(reqParams)
val responseData = loginByNameCheckResponse(response)
return postLoginProcess(responseData)
Expand Down Expand Up @@ -213,7 +213,7 @@ internal class NCMBUserService : NCMBObjectService() {
* @throws NCMBException
*/
@Throws(NCMBException::class)
protected fun loginUserInBackground(query: JSONObject, loginCallback: NCMBCallback){
protected fun loginUserInBackground(param: JSONObject, loginCallback: NCMBCallback){
val loginHandler = NCMBHandler { logincallback, response ->
when (response) {
is NCMBResponse.Success -> {
Expand All @@ -227,7 +227,7 @@ internal class NCMBUserService : NCMBObjectService() {
}
}
}
val reqParams : RequestParams = loginByNameParams(query, loginCallback, loginHandler)
val reqParams : RequestParams = loginByNameParams(param, loginCallback, loginHandler)
sendRequestAsync(reqParams, loginCallback, loginHandler)
}

Expand Down Expand Up @@ -289,11 +289,13 @@ internal class NCMBUserService : NCMBObjectService() {
* @throws NCMBException
*/
@Throws(NCMBException::class)
fun loginByNameParams(query: JSONObject, loginCallback: NCMBCallback?, loginHandler: NCMBHandler?): RequestParams {
val url = NCMB.getApiBaseUrl() + "login?" + queryUrlStringGenerate(query)
val method = NCMBRequest.HTTP_METHOD_GET

fun loginByNameParams(params: JSONObject, loginCallback: NCMBCallback?, loginHandler: NCMBHandler?): RequestParams {
val url = NCMB.getApiBaseUrl() + "login"

val method = NCMBRequest.HTTP_METHOD_POST
val contentType = NCMBRequest.HEADER_CONTENT_TYPE_JSON
return RequestParams(url = url, method = method, contentType = contentType, query = query, callback = loginCallback, handler = loginHandler)
return RequestParams(url = url, method = method, contentType = contentType, params = params, callback = loginCallback, handler = loginHandler)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/test/assets/json/valid_get_push_response.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"objectId":"7FrmPTBKSNtVjajm","deliveryTime":{"iso":"2015-07-09T15:10:00.000Z","__type":"Date"},"deliveryExpirationDate":null,"richUrl":"http:\/\/www.yahoo.co.jp\/","searchCondition":{},"badgeIncrementFlag":true,"sound":"default","userSettingValue":{"score":100},"acl":{"*":{"read":true,"write":true}},"message":"message","deliveryExpirationTime":"10 day","title":"title","error":null,"target":["android","ios"],"dialog":true,"action":"com.sample.NCMBReceiver","category":"Category","contentAvailable":false,"badgeSetting":null,"deliveryNumber":0,"deliveryPlanNumber":3,"status":0,"createDate":"2015-07-09T06:08:45.668Z","updateDate":"2015-07-09T06:08:45.669Z"}
{"results":[{"objectId":"7FrmPTBKSNtVjajm","deliveryTime":{"iso":"2015-07-09T15:10:00.000Z","__type":"Date"},"deliveryExpirationDate":null,"richUrl":"http:\/\/www.yahoo.co.jp\/","searchCondition":{},"badgeIncrementFlag":true,"sound":"default","userSettingValue":{"score":100},"acl":{"*":{"read":true,"write":true}},"message":"message","deliveryExpirationTime":"10 day","title":"title1","error":null,"target":["android","ios"],"dialog":true,"action":"com.sample.NCMBReceiver","category":"Category","contentAvailable":false,"badgeSetting":null,"deliveryNumber":0,"deliveryPlanNumber":3,"status":0,"createDate":"2015-07-09T06:08:45.668Z","updateDate":"2015-07-09T06:08:45.669Z"},{"objectId":"raCwV9E8HjPWO5yW","deliveryTime":{"iso":"2015-07-10T15:10:00.000Z","__type":"Date"},"target":["ios"],"searchCondition":null,"message":null,"userSettingValue":null,"deliveryExpirationDate":null,"deliveryExpirationTime":null,"deliveryPlanNumber":1,"deliveryNumber":0,"status":4,"action":null,"badgeIncrementFlag":true,"sound":null,"contentAvailable":false,"title":"title2","createDate":"2015-07-08T14:00:02.805Z","updateDate":"2015-07-08T14:00:02.921Z","acl":{"*":{"read":true,"write":true}}}]}
72 changes: 1 addition & 71 deletions src/test/assets/json/valid_get_searchPush_response.json
Original file line number Diff line number Diff line change
@@ -1,71 +1 @@
{
"results": [
{
"objectId": "dummyObjectId01",
"deliveryTime": {
"iso": "2014-12-18T08:59:05.351Z",
"__type": "Date"
},
"deliveryExpirationDate": null,
"richUrl": null,
"searchCondition": null,
"badgeIncrementFlag": true,
"sound": null,
"userSettingValue": null,
"message": "message1",
"deliveryExpirationTime": null,
"title": "title1",
"error": null,
"target": [
"android"
],
"dialog": true,
"action": "Ncmb.com.push.unity.RECEIVE_PUSH",
"category": null,
"contentAvailable": false,
"badgeSetting": null,
"deliveryNumber": 1,
"deliveryPlanNumber": 1,
"status": 2,
"createDate": "2014-12-18T08:59:05.354Z",
"updateDate": "2014-12-18T08:59:15.987Z",
"acl": {
"*": {
"read": true,
"write": true
}
}
},
{
"objectId":"dummyObjectId02",
"deliveryTime":{"iso":"2014-12-18T08:59:05.351Z","__type":"Date"},
"deliveryExpirationDate":null,
"richUrl":null,
"searchCondition":null,
"badgeIncrementFlag":true,
"sound":null,
"userSettingValue":null,
"message":"message2",
"deliveryExpirationTime":null,
"title":"title2",
"error":null,
"target":["android"],
"dialog":true,
"action":"Ncmb.com.push.unity.RECEIVE_PUSH",
"category":null,
"contentAvailable":false,
"badgeSetting":null,
"deliveryNumber":2,
"deliveryPlanNumber":2,
"status":2,
"createDate":"2014-12-19T08:59:05.354Z",
"updateDate":"2014-12-19T08:59:15.987Z",
"acl":{
"*":{
"read":true,
"write":true
}
}
}
]
}
{"results":[{"objectId":"ukAwn7IKAG4Lgt0H","deliveryTime":{"iso":"2014-12-18T08:59:05.351Z","__type":"Date"},"deliveryExpirationDate":null,"richUrl":null,"searchCondition":null,"badgeIncrementFlag":true,"sound":null,"userSettingValue":null,"message":"message1","deliveryExpirationTime":null,"title":"title1","error":null,"target":["android"],"dialog":true,"action":"Ncmb.com.push.unity.RECEIVE_PUSH","category":null,"contentAvailable":false,"badgeSetting":null,"deliveryNumber":1,"deliveryPlanNumber":1,"status":2,"createDate":"2014-12-18T08:59:05.354Z","updateDate":"2014-12-18T08:59:15.987Z","acl":{"*":{"read":true,"write":true}}},{"objectId":"zsps3o9UkhYxO9p9","deliveryTime":{"iso":"2014-12-18T08:59:05.351Z","__type":"Date"},"deliveryExpirationDate":null,"richUrl":null,"searchCondition":null,"badgeIncrementFlag":true,"sound":null,"userSettingValue":null,"message":"message2","deliveryExpirationTime":null,"title":"title2","error":null,"target":["android"],"dialog":true,"action":"Ncmb.com.push.unity.RECEIVE_PUSH","category":null,"contentAvailable":false,"badgeSetting":null,"deliveryNumber":2,"deliveryPlanNumber":2,"status":2,"createDate":"2014-12-19T08:59:05.354Z","updateDate":"2014-12-19T08:59:15.987Z","acl":{"*":{"read":true,"write":true}}}]}
12 changes: 6 additions & 6 deletions src/test/assets/yaml/mbaas_error.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ response:
---
request:
url: /2013-09-01/login
query:
method: POST
body:
userName: "Ncmb Ichiro"
password: invalidPassword
method: GET
response:
status: 401
file: invalid_get_login_response.json
---
request:
url: /2013-09-01/login
query:
method: POST
body:
userName: "invalidUser"
password: Password
method: GET
response:
status: 401
file: invalid_get_login_response.json
---
request:
url: /2013-09-01/login
query:
method: POST
body:
userName: "Ncmb Jirou"
password: dummyPassword
method: GET
response:
status: 200
file: valid_get_login_response.json
Expand Down
7 changes: 2 additions & 5 deletions src/test/assets/yaml/mbaas_query.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
request:
url: /2013-09-01/push
method: GET
query:
where: '{"target":["android"]}'
limit: 2
response:
status: 200
file: valid_get_searchPush_response.json
file: valid_get_push_response.json
---
request:
url: /2013-09-01/push
method: GET
query:
where: '{"target":["android"]}'
where: '{"target":"android"}'
response:
status: 200
file: valid_get_searchPush_response.json
Expand Down
Loading

0 comments on commit 877c596

Please sign in to comment.