Commit 9dac9aad authored by Winnie's avatar Winnie 🐤
Browse files

fix: update api format

parent 385deed4
......@@ -237,7 +237,7 @@ class MainActivity : AppCompatActivity() {
toolbar = supportActionBar!!
navigationView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
api = ApplicationInterface(resources.getString(R.string.api_url), resources.getString(R.string.email), resources.getString(R.string.token), resources.getString(R.string.session))
api = ApplicationInterface(resources.getString(R.string.api_url), resources.getString(R.string.account), resources.getString(R.string.token), resources.getString(R.string.session))
mUI = Handler()
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT)
......@@ -539,13 +539,14 @@ class MainActivity : AppCompatActivity() {
var answer: String
answer = when (res.getStatus()) {
STATUS.OK -> {
when (res.isMultipleChoice()) {
true -> {
res.setOptionsHashMap(res.getOptionsHashMap())
res.getAnswer()
}
false -> res.getAnswer()
}
res.getAnswer()
// when (res.isMultipleChoice()) {
// true -> {
// res.setOptionsHashMap(res.getOptionsHashMap())
// res.getAnswer()
// }
// false -> res.getAnswer()
// }
}
STATUS.NO_PERMISSION -> res.getReply() // resources.getString(R.string.no_permission_message)
STATUS.ERROR -> resources.getString(R.string.error_message)
......
package com.nuwarobotics.sdk.sample.tutorial.api.apmic
import khttp.post
import khttp.get
import khttp.responses.Response
import org.json.JSONException
var optionsHashMap: HashMap<String, String> = hashMapOf()
data class ApplicationInterface(private val url: String, private val email: String, private val token: String, private val session: String) {
data class ApplicationInterface(private val url: String, private val account: String, private val token: String, private val uuid: String) {
private lateinit var response: Response
fun call(text: String): ApplicationInterface {
response = post(
response = get(
url = url,
json = mapOf(
"email" to email,
headers = mapOf(
"account" to account,
"token" to token,
"tag" to text,
"tsession" to session
)
"uuid" to uuid
),
params = mapOf( "text" to text)
)
return this
}
......@@ -69,20 +70,20 @@ data class ApplicationInterface(private val url: String, private val email: Stri
}
fun getAnswer(): String {
return response.jsonObject.getJSONArray("reply").getJSONObject(0).getString("answer")
return response.jsonObject.getJSONArray("result").getJSONObject(0).getJSONArray("send").getJSONObject(0).getString("text")
}
fun getReply(): String {
return response.jsonObject.getString("reply")
return response.jsonObject.getString("result")
}
/* New */
fun getAction(): String {
return response.jsonObject.getJSONArray("reply").getJSONObject(0).getString("action")
return response.jsonObject.getJSONArray("result").getJSONObject(0).getString("action")
}
fun getMedia(): String {
return response.jsonObject.getJSONArray("reply").getJSONObject(0).getString("media")
return response.jsonObject.getJSONArray("result").getJSONObject(0).getString("media")
}
/* Boolean Status */
......@@ -93,7 +94,7 @@ data class ApplicationInterface(private val url: String, private val email: Stri
}
fun isFinalStep(): Boolean {
if (response.jsonObject.getJSONArray("reply").getJSONObject(0).getInt("step") != 0) return false
if (response.jsonObject.getJSONArray("result").getJSONObject(0).getInt("step") != 0) return false
return true
}
}
......
<resources>
<string name="app_name">APMIC with KEBBI</string>
<string name="api_url">https://jerry.ap-mic.com/apidisplay/DLMR7OA/</string>
<string name="email">katelee@iii.org.tw</string>
<string name="session">87</string>
<string name="token">c6dbbe98553d72a23ace71fcecf9afd11f34b58a</string>
<string name="api_url">https://opentalk.ap-mic.com/api/analysis/match/</string>
<string name="account">katelee@iii.org.tw</string>
<string name="uuid">87</string>
<string name="token">3zTQ8J7MR3OwRMjv6DBzE9cDNIlTZ6TLEOqYJ5jJ</string>
<string name="welcome_message">我是凱比,很高興認識你!我可以幫你介紹小太陽親子館、說故事,或是玩文字接龍、剪刀石頭布。</string>
<string name="no_permission_message">請開通我的權限好嗎 拜託拜託</string>
<string name="error_message">API去上廁所了</string>
......
......@@ -7,7 +7,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.android.tools.build:gradle:3.4.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
......
#Thu Jan 24 21:47:27 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
#Tue May 14 19:28:40 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment