parent
8ddcadfb00
commit
968a694df9
@ -1,80 +0,0 @@ |
||||
package net.pokeranalytics.android.api |
||||
|
||||
import android.content.Context |
||||
import net.pokeranalytics.android.BuildConfig |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.model.retrofit.CurrencyConverterValue |
||||
import net.pokeranalytics.android.util.URL |
||||
import okhttp3.Interceptor |
||||
import okhttp3.OkHttpClient |
||||
import okhttp3.logging.HttpLoggingInterceptor |
||||
import retrofit2.Call |
||||
import retrofit2.Retrofit |
||||
import retrofit2.converter.gson.GsonConverterFactory |
||||
import retrofit2.http.GET |
||||
import retrofit2.http.Query |
||||
import java.util.concurrent.TimeUnit |
||||
|
||||
/** |
||||
* CurrencyCode Converter API |
||||
*/ |
||||
interface CurrencyConverterApi { |
||||
|
||||
companion object { |
||||
|
||||
private var currencyConverterApi: CurrencyConverterApi? = null |
||||
|
||||
fun getApi(context: Context): CurrencyConverterApi? { |
||||
|
||||
if (currencyConverterApi == null) { |
||||
|
||||
val serviceEndpoint = URL.API_CURRENCY_CONVERTER |
||||
|
||||
val httpClient = OkHttpClient.Builder() |
||||
|
||||
// Logging interceptor |
||||
if (BuildConfig.DEBUG) { |
||||
val interceptor = HttpLoggingInterceptor() |
||||
interceptor.level = HttpLoggingInterceptor.Level.BASIC |
||||
httpClient.addInterceptor(interceptor) |
||||
} |
||||
|
||||
// Add headers |
||||
val interceptor = Interceptor { chain -> |
||||
val original = chain.request() |
||||
val originalHttpUrl = original.url() |
||||
|
||||
val url = originalHttpUrl.newBuilder() |
||||
.addQueryParameter("apiKey", context.getString(R.string.currency_converter_api)) |
||||
.build() |
||||
|
||||
val requestBuilder = original.newBuilder() |
||||
.url(url) |
||||
|
||||
chain.proceed(requestBuilder.build()) |
||||
} |
||||
httpClient.addInterceptor(interceptor) |
||||
|
||||
val client = httpClient |
||||
.readTimeout(60, TimeUnit.SECONDS) |
||||
.connectTimeout(60, TimeUnit.SECONDS) |
||||
.build() |
||||
|
||||
val retrofit = Retrofit.Builder() |
||||
.addConverterFactory(GsonConverterFactory.create()) |
||||
.baseUrl(serviceEndpoint.value) |
||||
.client(client) |
||||
.build() |
||||
|
||||
currencyConverterApi = retrofit.create(CurrencyConverterApi::class.java) |
||||
} |
||||
|
||||
return currencyConverterApi |
||||
} |
||||
|
||||
} |
||||
|
||||
@GET("convert") |
||||
fun convert(@Query("q") currencies: String, @Query("compact") compact: String = "ultra"): Call<Map<String, CurrencyConverterValue>> |
||||
|
||||
} |
||||
@ -0,0 +1,51 @@ |
||||
package net.pokeranalytics.android.api |
||||
|
||||
import android.content.Context |
||||
import android.util.JsonReader |
||||
import com.android.volley.Request |
||||
import com.android.volley.Response |
||||
import com.android.volley.VolleyError |
||||
import com.android.volley.toolbox.StringRequest |
||||
import com.android.volley.toolbox.Volley |
||||
import kotlinx.serialization.json.Json |
||||
import kotlinx.serialization.json.JsonConfiguration |
||||
import timber.log.Timber |
||||
|
||||
|
||||
class FreeConverterApi { |
||||
|
||||
companion object { |
||||
|
||||
fun currencyRate(pair: String, context: Context, callback: (Double) -> (Unit)) { |
||||
|
||||
val queue = Volley.newRequestQueue(context) |
||||
val url = "https://free.currconv.com/api/v7/convert?q=${pair}&compact=ultra&apiKey=5ba8d38995282fe8b1c8" |
||||
|
||||
// https://free.currconv.com/api/v7/convert?q=GBP_USD&compact=ultra&apiKey=5ba8d38995282fe8b1c8 |
||||
// { "USD_PHP": 44.1105, "PHP_USD": 0.0227 } |
||||
|
||||
val stringRequest = StringRequest( |
||||
Request.Method.GET, url, |
||||
Response.Listener { response -> |
||||
|
||||
val json = Json(JsonConfiguration.Stable) |
||||
val f = json.parseJson(response) |
||||
f.jsonObject[pair]?.primitive?.double?.let { rate -> |
||||
callback(rate) |
||||
} ?: run { |
||||
Timber.d("no rate: $response") |
||||
} |
||||
|
||||
}, |
||||
Response.ErrorListener { |
||||
Timber.d("Api call failed: ${it.message}") |
||||
}) |
||||
|
||||
queue.add(stringRequest) |
||||
|
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
} |
||||
@ -1,5 +0,0 @@ |
||||
<<<<<<< HEAD |
||||
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":79,"versionName":"3.0","enabled":true,"outputFile":"PokerAnalytics_3.0(79)_200428_1456_release.apk","fullName":"standardRelease","baseName":"standard-release","dirName":""},"path":"PokerAnalytics_3.0(79)_200428_1456_release.apk","properties":{}}] |
||||
======= |
||||
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":84,"versionName":"2.4.3","enabled":true,"outputFile":"PokerAnalytics_2.4.3(84)_200526_1106_release.apk","fullName":"standardRelease","baseName":"standard-release","dirName":""},"path":"PokerAnalytics_2.4.3(84)_200526_1106_release.apk","properties":{}}] |
||||
>>>>>>> master |
||||
Loading…
Reference in new issue