This commit is contained in:
Erik C. Thauvin 2021-05-08 23:09:50 -07:00
parent aac0d273cf
commit 1a80f6ab89
13 changed files with 154 additions and 21 deletions

3
.idea/.gitignore generated vendored Normal file
View file

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

18
.idea/codeStyles/Project.xml generated Normal file
View file

@ -0,0 +1,18 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CALL_PARAMETERS_WRAP" value="5" />
<option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
<option name="CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
<option name="METHOD_PARAMETERS_WRAP" value="5" />
<option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
<option name="METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
<option name="EXTENDS_LIST_WRAP" value="1" />
<option name="METHOD_CALL_CHAIN_WRAP" value="1" />
<option name="ASSIGNMENT_WRAP" value="1" />
</codeStyleSettings>
</code_scheme>
</component>

5
.idea/codeStyles/codeStyleConfig.xml generated Normal file
View file

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

6
.idea/compiler.xml generated Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
</component>
</project>

25
.idea/jarRepositories.xml generated Normal file
View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="MavenRepo" />
<option name="name" value="MavenRepo" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://oss.sonatype.org/content/repositories/snapshots" />
</remote-repository>
</component>
</project>

View file

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="libraries-with-intellij-classes">
<option name="intellijApiContainingLibraries">
<list>
<LibraryCoordinatesState>
<option name="artifactId" value="ideaIU" />
<option name="groupId" value="com.jetbrains.intellij.idea" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="ideaIU" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="ideaIC" />
<option name="groupId" value="com.jetbrains.intellij.idea" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="ideaIC" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="pycharmPY" />
<option name="groupId" value="com.jetbrains.intellij.pycharm" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="pycharmPY" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="pycharmPC" />
<option name="groupId" value="com.jetbrains.intellij.pycharm" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="pycharmPC" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="clion" />
<option name="groupId" value="com.jetbrains.intellij.clion" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="clion" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="riderRD" />
<option name="groupId" value="com.jetbrains.intellij.rider" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="riderRD" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="goland" />
<option name="groupId" value="com.jetbrains.intellij.goland" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="goland" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
</list>
</option>
</component>
</project>

5
.idea/misc.xml generated Normal file
View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="15" project-jdk-type="JavaSDK" />
</project>

6
.idea/vcs.xml generated Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View file

@ -41,7 +41,7 @@ dependencies {
} }
application { application {
mainClassName = "net.thauvin.erik.crypto.CryptoPrice" mainClass.set("net.thauvin.erik.crypto.CryptoPrice")
} }
java { java {
@ -133,7 +133,7 @@ publishing {
scm { scm {
connection.set("scm:git:git://github.com/$gitHub.git") connection.set("scm:git:git://github.com/$gitHub.git")
developerConnection.set("scm:git:git@github.com:$gitHub.git") developerConnection.set("scm:git:git@github.com:$gitHub.git")
url.set("$mavenUrl") url.set(mavenUrl)
} }
issueManagement { issueManagement {
system.set("GitHub") system.set("GitHub")

View file

@ -19,7 +19,7 @@ dependencies {
} }
application { application {
mainClassName = "com.example.CryptoPriceExampleKt" mainClass.set("com.example.CryptoPriceExampleKt")
} }
tasks { tasks {

View file

@ -32,11 +32,11 @@
package net.thauvin.erik.crypto package net.thauvin.erik.crypto
@Suppress("EmptySecondaryConstructor") @Suppress("EmptySecondaryConstructor", "unused")
class CryptoException : Exception { class CryptoException : Exception {
constructor(message: String, cause: Throwable) : super(message, cause) {} constructor(message: String, cause: Throwable) : super(message, cause)
constructor(message: String) : super(message) {} constructor(message: String) : super(message)
constructor(cause: Throwable) : super(cause) {} constructor(cause: Throwable) : super(cause)
companion object { companion object {
private const val serialVersionUID = 1L private const val serialVersionUID = 1L

View file

@ -36,8 +36,6 @@ import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
import org.json.JSONObject import org.json.JSONObject
import java.io.IOException
import java.net.URL
import java.time.LocalDate import java.time.LocalDate
/** /**
@ -54,7 +52,8 @@ open class CryptoPrice(val base: String, val currency: String, val amount: Doubl
val json = JSONObject(this) val json = JSONObject(this)
if (json.has("data")) { if (json.has("data")) {
with(json.getJSONObject("data")) { with(json.getJSONObject("data")) {
return CryptoPrice(getString("base"), getString("currency"), getString("amount").toDouble() return CryptoPrice(
getString("base"), getString("currency"), getString("amount").toDouble()
) )
} }
} else { } else {

View file

@ -2,11 +2,11 @@ package net.thauvin.erik.crypto
import net.thauvin.erik.crypto.CryptoPrice.Companion.marketPrice import net.thauvin.erik.crypto.CryptoPrice.Companion.marketPrice
import net.thauvin.erik.crypto.CryptoPrice.Companion.toPrice import net.thauvin.erik.crypto.CryptoPrice.Companion.toPrice
import java.time.LocalDate
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
import kotlin.test.assertTrue import kotlin.test.assertTrue
import java.time.LocalDate
/** /**
* The `CryptoPriceTest` class. * The `CryptoPriceTest` class.
@ -67,9 +67,10 @@ class CryptoPriceTest {
@Test @Test
@Throws(CryptoException::class) @Throws(CryptoException::class)
fun testToPrice() { fun testToPrice() {
val price = "{\"data\":{\"base\":\"BTC\",\"currency\":\"USD\",\"amount\":\"57515.69\"}}".toPrice() val d = 57515.69
val price = "{\"data\":{\"base\":\"BTC\",\"currency\":\"USD\",\"amount\":\"$d\"}}".toPrice()
assertEquals(price.base, "BTC", "base is BTC") assertEquals(price.base, "BTC", "base is BTC")
assertEquals(price.currency, "USD", "currency is USD") assertEquals(price.currency, "USD", "currency is USD")
assertEquals(price.amount, "57515.69".toDouble(), "amount is 57515.69") assertEquals(price.amount, d, "amount is 57515.69")
} }
} }