Skip to content

Commit

Permalink
Merge pull request #27 from ringpublishing/feature/client-type
Browse files Browse the repository at this point in the history
Add client platform identifier RDLC
  • Loading branch information
gmalopolski authored Apr 12, 2022
2 parents 9cc6670 + ef4a105 commit 5fd7207
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Changelogs/1.2.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1.2.2 Release notes (2022-04-12)
=============================================================

Improvements to the 'RingPublishingTracking' module.

### Changes

* Added additional field to each request, 'RDLC' containing information that events come from native mobile app
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Created by Grzegorz Małopolski on 4/12/22, 10:23 AM
* Copyright © 2021 Ringier Axel Springer Tech. All rights reserved.
*
*/

package com.ringpublishing.tracking.internal.decorator

import android.util.Base64
import com.google.gson.GsonBuilder
import com.ringpublishing.tracking.data.Event
import org.junit.Assert
import org.junit.Test

internal class ClientDecoratorTest
{

@Test
fun decorate_When_Correct_Client_Then_Decoded_Result()
{
val gson = GsonBuilder().create()
val clientDecorator = ClientDecorator(gson)

val event = Event()
clientDecorator.decorate(event)

val result = event.parameters[EventParam.CLIENT_ID.text] as String?

val decodedResult = String(Base64.decode(result, Base64.NO_WRAP))

Assert.assertTrue(decodedResult.contains("{\"client\":{\"type\":\"native_app\"}}"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Created by Grzegorz Małopolski on 4/12/22, 9:55 AM
* Copyright © 2021 Ringier Axel Springer Tech. All rights reserved.
*
*/

package com.ringpublishing.tracking.internal.data

class Client(val client: ClientType)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Created by Grzegorz Małopolski on 4/12/22, 9:56 AM
* Copyright © 2021 Ringier Axel Springer Tech. All rights reserved.
*
*/

package com.ringpublishing.tracking.internal.data

enum class ClientPlatform
{
native_app
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Created by Grzegorz Małopolski on 4/12/22, 9:55 AM
* Copyright © 2021 Ringier Axel Springer Tech. All rights reserved.
*
*/

package com.ringpublishing.tracking.internal.data

class ClientType(val type: ClientPlatform)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Created by Grzegorz Małopolski on 10/6/21, 11:28 AM
* Copyright © 2021 Ringier Axel Springer Tech. All rights reserved.
*
*/

package com.ringpublishing.tracking.internal.decorator

import android.util.Base64
import com.google.gson.Gson
import com.ringpublishing.tracking.data.Event
import com.ringpublishing.tracking.internal.data.Client
import com.ringpublishing.tracking.internal.data.ClientPlatform
import com.ringpublishing.tracking.internal.data.ClientType
import com.ringpublishing.tracking.internal.log.Logger
import java.io.UnsupportedEncodingException

internal class ClientDecorator(private val gson: Gson) : BaseDecorator()
{
private val client = Client(ClientType(ClientPlatform.native_app))

override fun decorate(event: Event)
{
val clientId = encodeClientId(client)
clientId.let { event.add(EventParam.CLIENT_ID, it) }
}

private fun encodeClientId(client: Client): String?
{
val jsonClient = gson.toJson(client)

val data: ByteArray?

try
{
data = jsonClient.toByteArray(Charsets.UTF_8)
} catch (e: UnsupportedEncodingException)
{
Logger.warn("Parse jsonClient UnsupportedEncodingException $e")
return null
}
return Base64.encodeToString(data, Base64.NO_WRAP)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ internal class EventDecorator(
add(ContentUrlDecorator(configurationManager))
add(StructurePathDecorator(configurationManager))
add(ReferrerDecorator(configurationManager))
add(ClientDecorator(gson))
}

Logger.debug("Decorators for event: $decorators")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ internal enum class EventParam(val text: String)
SCREEN_SIZE("CS"),
WINDOW_SIZE("CW"),
CONSENT("_adpc"),
CLIENT_ID("RDLC"),
}
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript

plugins
{
id "org.jlleitschuh.gradle.ktlint" version "10.1.0"
id "org.jlleitschuh.gradle.ktlint" version "10.2.1"
id "io.gitlab.arturbosch.detekt" version "1.18.1"
}

Expand All @@ -40,3 +40,9 @@ ext
COMPILE_SDK_VERSION = 30
BUILD_TOOLS_VERSION = '30.0.2'
}

allprojects {
configurations.all {
resolutionStrategy.force 'org.objenesis:objenesis:2.6'
}
}
6 changes: 6 additions & 0 deletions detekt-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ formatting:
NoLineBreakAfterElse:
active: false
autoCorrect: false
SpacingAroundCurly:
active: false
autoCorrect: false
Indentation:
active: false
autoCorrect: false
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ android.useAndroidX=true
android.enableJetifier=true

#Library version name
sdk_version_name=1.2.1
sdk_version_name=1.2.2
#Library version code
sdk_version_code=10
sdk_version_code=11

0 comments on commit 5fd7207

Please sign in to comment.