Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin refactor #6

Merged
merged 5 commits into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sleet-api-service/src/main/java/com/sleet/api/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ object Constants {
const val CLIENT_ID = "client_id"
const val CODE = "code"
const val CONTENT_TYPE = "Content-Type"
const val DEFAULT_TIMEOUT_MILLIS = 5000
const val DEFAULT_TIMEOUT_MILLIS = 5000L
const val DEFAULT_STRIKE_COUNT = "100"
const val DEFAULT_REDIRECT_URI = "https://127.0.0.1"
const val EQUALS = '='
const val GRANT_TYPE = "grant_type"
const val MARKETDATA = "marketdata"
Expand Down
10 changes: 0 additions & 10 deletions sleet-api-service/src/main/java/com/sleet/api/Handler.java

This file was deleted.

160 changes: 0 additions & 160 deletions sleet-api-service/src/main/java/com/sleet/api/HttpClient.java

This file was deleted.

43 changes: 43 additions & 0 deletions sleet-api-service/src/main/java/com/sleet/api/RequestUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.sleet.api

import org.asynchttpclient.Request
import org.asynchttpclient.RequestBuilder

class RequestUtil {

companion object {

/**
* Create a [Request] for GET methods
*
* @param url to send a GET request
* @param headerParams to add to request
* @return a [Request] to fire with the http client
*/
@JvmStatic
fun createGetRequest(url: String, headerParams: Map<String, String>?): Request? {
val requestBuilder = RequestBuilder("GET").setUrl(url)
headerParams?.forEach { (name: String, value: String) ->
requestBuilder.setHeader(name, value)
}
return requestBuilder.build()
}

/**
* Create a [Request] for POST methods
*
* @param url to send a POST request
* @param body to send in request
* @param headerParams to add to request
* @return a [Request] to fire with the http client
*/
@JvmStatic
fun createPostRequest(url: String, body: String, headerParams: Map<String, String>?): Request? {
val requestBuilder = RequestBuilder("POST").setUrl(url).setBody(body)
headerParams?.forEach { (name: String, value: String) ->
requestBuilder.setHeader(name, value)
}
return requestBuilder.build()
}
}
}
28 changes: 28 additions & 0 deletions sleet-api-service/src/main/java/com/sleet/api/TDClient.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.sleet.api

import com.sleet.api.Constants.DEFAULT_REDIRECT_URI
import com.sleet.api.Constants.DEFAULT_TIMEOUT_MILLIS
import com.sleet.api.service.AuthService
import com.sleet.api.service.QuoteService
import com.sleet.api.service.TradingService
import org.asynchttpclient.AsyncHttpClient
import org.asynchttpclient.Dsl

/**
* Client interface to TD Ameritrade's API with sub-services grouped by common functionalities
*
* @author mautomic
*/
class TDClient @JvmOverloads constructor(apiKey: String, redirectUri: String = DEFAULT_REDIRECT_URI) {

private val httpClient: AsyncHttpClient =
Dsl.asyncHttpClient(
Dsl.config()
.setReadTimeout(DEFAULT_TIMEOUT_MILLIS.toInt())
.setConnectTimeout(DEFAULT_TIMEOUT_MILLIS.toInt())
)

val authenticator: AuthService = AuthService(apiKey, redirectUri, httpClient)
val trader: TradingService = TradingService(httpClient)
val quoter: QuoteService = QuoteService(apiKey, httpClient)
}

This file was deleted.

Loading