Skip to content

Commit

Permalink
Rename offset to rywToken for future-proofing
Browse files Browse the repository at this point in the history
Motivation: we may need to send tokens as JWT to include more data in the future
  • Loading branch information
Rodrigo Gomez Palacio committed Sep 18, 2024
1 parent ae2ed04 commit 555dbc5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ internal class HttpClient(
}
}

if (headers?.offset != null) {
con.setRequestProperty("Onesignal-Offset", headers.offset.toString())
if (headers?.rywToken != null) {
con.setRequestProperty("OneSignal-RYW-Token", headers.rywToken.toString())
}

if (headers?.retryCount != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class OptionalHeaders(
/**
* Used for read your write consistency
*/
val offset: Long? = null,
val rywToken: Long? = null,
/**
* Current retry count
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ internal class SubscriptionBackendService(
return null
}

var offset: Long? = null
if (responseJSON.has("offset")) {
offset = responseJSON.getLong("offset")
var rywToken: Long? = null
if (responseJSON.has("ryw_token")) {
rywToken = responseJSON.getLong("ryw_token")
}

return Pair(subscriptionJSON.getString("id"), offset)
return Pair(subscriptionJSON.getString("id"), rywToken)
}

override suspend fun updateSubscription(
Expand All @@ -57,8 +57,8 @@ internal class SubscriptionBackendService(
}

val responseBody = JSONObject(response.payload)
return if (responseBody.has("offset")) {
responseBody.getLong("offset")
return if (responseBody.has("ryw_token")) {
responseBody.getLong("ryw_token")
} else {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ internal class UserBackendService(
}

val responseBody = JSONObject(response.payload)
return if (responseBody.has("offset")) {
responseBody.getLong("offset")
return if (responseBody.has("ryw_token")) {
responseBody.getLong("ryw_token")
} else {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ internal class InAppBackendService(
val retryCount = if (attempts > 1) attempts - 1 else null
val values =
OptionalHeaders(
offset = offset,
rywToken = offset,
sessionDuration = sessionDurationProvider(),
retryCount = retryCount,
)
Expand Down Expand Up @@ -259,7 +259,7 @@ internal class InAppBackendService(
url,
OptionalHeaders(
sessionDuration = sessionDurationProvider(),
offset = 0,
rywToken = 0,
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class InAppBackendServiceTests :
mockHttpClient.get(
"apps/appId/subscriptions/subscriptionId/iams",
match {
it.offset == 1234L && it.retryCount == null && it.sessionDuration == mockSessionDurationProvider()
it.rywToken == 1234L && it.retryCount == null && it.sessionDuration == mockSessionDurationProvider()
},
)
}
Expand All @@ -144,7 +144,7 @@ class InAppBackendServiceTests :
mockHttpClient.get(
"apps/appId/subscriptions/subscriptionId/iams",
match {
it.offset == 1234L && it.sessionDuration == mockSessionDurationProvider() && it.retryCount != null
it.rywToken == 1234L && it.sessionDuration == mockSessionDurationProvider() && it.retryCount != null
},
)
}
Expand All @@ -154,7 +154,7 @@ class InAppBackendServiceTests :
mockHttpClient.get(
"apps/appId/subscriptions/subscriptionId/iams",
match {
it.offset == 0L && it.sessionDuration == mockSessionDurationProvider() && it.retryCount == null
it.rywToken == 0L && it.sessionDuration == mockSessionDurationProvider() && it.retryCount == null
},
)
}
Expand Down

0 comments on commit 555dbc5

Please sign in to comment.