Support to get raw json
takke opened this issue · comments
Like Twitter4J's feature
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey(...)
...
.setJSONStoreEnabled(true);
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
// Status -> json
timeline = twitter.getHomeTimeline();
for (final Status status : timeline) {
jsonText = TwitterObjectFactory.getRawJSON(status);
}
// json -> Status
Status status = TwitterObjectFactory.createStatus(jsonText);
idea1
// base class
open class Entity {
@Transient
var rawJson: String?
}
class Status : Entity {
//
}
- add Mastodon4jConfiguration
class Mastodon4jConfiguration
@JvmOverloads
constructor(
private val instanceName: String,
private val client: OkHttpClient,
private val gson: Gson,
private val accessToken: String? = null,
private val jsonStoreEnabled: Boolean = false
)
idea2
class MastodonRequest<T> {
fun <T> transform(transformer: (String) -> T): MastodonRequest<T>
fun <T> doOnJsonConverting(action: (String) -> Unit): MastodonRequest<T>
fun execute(): T
}
usecase
val statues = timelins.getPublicTimeline()
.doOnJsonConverting {
save(it) // save to database
}
.execute()