Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #44 from 8bytes/master
Browse files Browse the repository at this point in the history
Release 1.2.6
  • Loading branch information
eoinoconnell authored Mar 5, 2019
2 parents f195356 + 09deacc commit db508f3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ You can then add drift as a dependency in your app build.gradle file

```
dependencies {
compile 'com.github.driftt:drift-sdk-android:v1.2.5'
compile 'com.github.driftt:drift-sdk-android:v1.2.6'
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,9 @@ internal interface APIConversationAPIBuilder {
@GET("attachments")
fun getAttachments(@Query("id") attachmentIds: List<Int>, @QueryMap imgixOptions: Map<String, String>): Call<ArrayList<Attachment>>


@GET("conversations/end_users/{endUserId}/extra")
fun getConversationsForEndUser(@Path("endUserId") endUserId: Long?): Call<ArrayList<ConversationExtra>>

@POST("conversations/{conversationId}/messages")
fun postMessage(@Path("conversationId") conversationId: Long?, @Body messageRequest: MessageRequest): Call<Message>

@POST("messages")
fun createConversation(@Body payload: HashMap<String, Any>): Call<Message>

@POST("https://conversation2.api.drift.com/messages/{messageId}/read")
fun markMessageAsRead(@Path("messageId") messageId: Long?): Call<ResponseBody>

Expand Down
15 changes: 15 additions & 0 deletions drift/src/main/java/drift/com/drift/api/APIManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ internal object APIManager {

private val API_CUSTOMER_URL = "https://customer.api.drift.com/"
private val API_CONVERSATION_URL = "https://conversation.api.drift.com/"
private val API_MESSAGING_URL = "https://messaging.api.drift.com/"


lateinit var conversationClient: APIConversationAPIBuilder
lateinit var messagingClient: APIMessagingAPIBulder
lateinit var customerClient: APICustomerAPIBuilder
lateinit var authlessClient: APIAuthlessBuilder

Expand Down Expand Up @@ -95,6 +98,18 @@ internal object APIManager {

this.authlessClient = retrofitV3.create(APIAuthlessBuilder::class.java)

val messagingClient = baseOkHttpClient.newBuilder()
.addInterceptor(APIAuthTokenInterceptor())
.addInterceptor(UserAgentInterceptor(userAgent))
.build()

val retrofitV4 = Retrofit.Builder()
.baseUrl(API_MESSAGING_URL)
.callFactory(messagingClient)
.addConverterFactory(GsonConverterFactory.create(gson))
.build()

this.messagingClient = retrofitV4.create(APIMessagingAPIBulder::class.java)

}

Expand Down
20 changes: 20 additions & 0 deletions drift/src/main/java/drift/com/drift/api/APIMessagingAPIBulder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package drift.com.drift.api

import drift.com.drift.model.Message
import drift.com.drift.model.MessageRequest
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.POST
import retrofit2.http.Path
import java.util.HashMap

internal interface APIMessagingAPIBulder {

@POST("conversations/{conversationId}/messages")
fun postMessage(@Path("conversationId") conversationId: Long?, @Body messageRequest: MessageRequest): Call<Message>

@POST("messages")
fun createConversation(@Body payload: HashMap<String, Any>): Call<Message>


}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal object MessagesWrapper {

fun sendMessageToConversation(conversationId: Long, message: MessageRequest, callback: (response: Message?) -> Unit) {

APIManager.conversationClient.postMessage(conversationId, message).enqueue(object : Callback<Message> {
APIManager.messagingClient.postMessage(conversationId, message).enqueue(object : Callback<Message> {
override fun onResponse(call: Call<Message>, response: Response<Message>) {
if (response.code() != 200 && response.code() != 201 || response.body() == null) {
callback(null)
Expand Down Expand Up @@ -86,7 +86,7 @@ internal object MessagesWrapper {
payload["attributes"] = attributes
}

APIManager.conversationClient.createConversation(payload).enqueue(object : Callback<Message> {
APIManager.messagingClient.createConversation(payload).enqueue(object : Callback<Message> {
override fun onResponse(call: Call<Message>, response: Response<Message>) {
if (response.code() != 200 && response.code() != 201 || response.body() == null) {
callback(null)
Expand Down

0 comments on commit db508f3

Please sign in to comment.