-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from hossain-khan/feat/add-parser
[ADDED] New parser class to abstract out moshi specifics
- Loading branch information
Showing
6 changed files
with
65 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package dev.hossain.timeline | ||
|
||
import ZonedDateTimeAdapter | ||
import com.squareup.moshi.Moshi | ||
import dev.hossain.timeline.model.Records | ||
import dev.hossain.timeline.model.SemanticTimeline | ||
import dev.hossain.timeline.model.Settings | ||
|
||
/** | ||
* Parser to parse Google Location Timeline JSON to Kotlin objects. | ||
*/ | ||
class Parser constructor() { | ||
// Moshi instance with custom adapter to parse the timeline data. | ||
private val moshi: Moshi = | ||
Moshi.Builder() | ||
.add(ZonedDateTimeAdapter()) | ||
.build() | ||
|
||
/** | ||
* Parse JSON string to [Records] object. | ||
*/ | ||
fun parseRecords(json: String): Records { | ||
val adapter = moshi.adapter(Records::class.java) | ||
return adapter.fromJson(json)!! | ||
} | ||
|
||
/** | ||
* Parse JSON string to [Settings] object. | ||
*/ | ||
fun parseSettings(json: String): Settings { | ||
val adapter = moshi.adapter(Settings::class.java) | ||
return adapter.fromJson(json)!! | ||
} | ||
|
||
/** | ||
* Parse JSON string to [SemanticTimeline] object. | ||
*/ | ||
fun parseSemanticTimeline(json: String): SemanticTimeline { | ||
val adapter = moshi.adapter(SemanticTimeline::class.java) | ||
return adapter.fromJson(json)!! | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 3 additions & 7 deletions
10
parser/src/test/kotlin/dev/hossain/timeline/model/RecordsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
parser/src/test/kotlin/dev/hossain/timeline/model/SettingsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
plugins { | ||
kotlin("jvm") | ||
kotlin("jvm") | ||
} | ||
|
||
group = "dev.hossain.timeline" | ||
version = "1.0-SNAPSHOT" | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation("org.jetbrains.kotlin:kotlin-test") | ||
implementation(project(":parser")) | ||
implementation("com.squareup.moshi:moshi-kotlin:1.15.1") | ||
implementation("com.jakewharton.picnic:picnic:0.7.0") | ||
testImplementation("org.jetbrains.kotlin:kotlin-test") | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
useJUnitPlatform() | ||
} | ||
kotlin { | ||
jvmToolchain(21) | ||
} | ||
jvmToolchain(21) | ||
} |