Skip to content

Commit

Permalink
Use period serialization extension (#17)
Browse files Browse the repository at this point in the history
* Changes to extension

* adds convertomap function
  • Loading branch information
vegaro authored Apr 23, 2020
1 parent b0e0409 commit 724bc4e
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,8 @@ private fun SkuDetails.mapIntroPriceDeprecated(): Map<String, Any?> {
"intro_price" to null,
"intro_price_string" to null,
"intro_price_period" to null,
"intro_price_cycles" to null,
"intro_price_period_unit" to null,
"intro_price_period_number_of_units" to null
)
"intro_price_cycles" to null
) + introductoryPricePeriod.mapPeriodDeprecated()
}
}

Expand Down Expand Up @@ -163,10 +161,8 @@ private fun SkuDetails.mapIntroPrice(): Map<String, Any?> {
"price" to null,
"priceString" to null,
"period" to null,
"cycles" to null,
"periodUnit" to null,
"periodNumberOfUnits" to null
)
"cycles" to null
) + introductoryPricePeriod.mapPeriod()
}
}

Expand Down Expand Up @@ -258,6 +254,15 @@ fun List<*>.convertToJsonArray(): JSONArray {
return writableArray
}

fun JSONObject.convertToMap(): Map<String, String?> =
this.keys().asSequence<String>().associate { key ->
if (this.isNull(key)) {
key to null
} else {
key to this.getString(key)
}
}

private fun Date.toMillis(): Double = this.time.div(1000.0)

private fun Date.toIso8601(): String = Iso8601Utils.format(this)

0 comments on commit 724bc4e

Please sign in to comment.