Skip to content

Commit 62969fa

Browse files
author
Mariam Eskander
committed
init
1 parent a2f5d51 commit 62969fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1941
-0
lines changed

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties
16+
/.idea/
17+
/gradle/

PixelSDK.zip

636 KB
Binary file not shown.

PixelSDK/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/build
2+
*.pro

PixelSDK/build.gradle

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
plugins {
2+
id 'com.android.library'
3+
id 'org.jetbrains.kotlin.android'
4+
id 'kotlin-android'
5+
id 'maven-publish'
6+
}
7+
8+
android {
9+
compileSdk 33
10+
11+
defaultConfig {
12+
minSdk 21
13+
targetSdk 33
14+
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16+
consumerProguardFiles "consumer-rules.pro"
17+
}
18+
19+
buildTypes {
20+
release {
21+
minifyEnabled false
22+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23+
}
24+
}
25+
compileOptions {
26+
sourceCompatibility JavaVersion.VERSION_1_8
27+
targetCompatibility JavaVersion.VERSION_1_8
28+
}
29+
kotlinOptions {
30+
jvmTarget = '1.8'
31+
}
32+
}
33+
34+
dependencies {
35+
// RxJava
36+
implementation("io.reactivex.rxjava2:rxjava:2.2.19")
37+
implementation("io.reactivex.rxjava2:rxandroid:2.1.1")
38+
39+
// Retrofit 2
40+
implementation("com.squareup.retrofit2:retrofit:2.9.0")
41+
implementation("com.squareup.retrofit2:adapter-rxjava2:2.9.0")
42+
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
43+
implementation("com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.5")
44+
}
45+
46+
afterEvaluate {
47+
publishing {
48+
publications {
49+
release(MavenPublication) {
50+
from components.release
51+
groupId 'com.github.convertedin'
52+
artifactId 'mobile-pixel-sdk'
53+
version '1.0.0'
54+
}
55+
}
56+
}
57+
}

PixelSDK/src/main/AndroidManifest.xml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="convertedin.pixel.pixelsdk">
4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5+
<uses-permission android:name="android.permission.INTERNET"/>
6+
7+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package convertedin.pixel.pixelsdk
2+
3+
import android.content.Context
4+
import android.util.Log
5+
import convertedin.pixel.pixelsdk.data.entities.EventContent
6+
import convertedin.pixel.pixelsdk.utils.PixelHelper
7+
8+
class ConvertedInSdk {
9+
10+
11+
companion object {
12+
var apiUrl: String = "https://test.convertedin.com/api/"
13+
private var sInstance: ConvertedInSdk? = null
14+
private var helper: PixelHelper? = null
15+
16+
private fun getInstance(context: Context) : ConvertedInSdk {
17+
if (sInstance == null) {
18+
sInstance = ConvertedInSdk()
19+
if (helper == null)
20+
helper = PixelHelper(context)
21+
22+
}
23+
return sInstance!!
24+
}
25+
26+
}
27+
28+
//initialize SDK, pixel id and store url
29+
//u can obtain these data from converted in dashboard
30+
fun initialize(context: Context, pixelId: String, storeUrl: String) {
31+
getInstance(context)
32+
helper?.saveData(pixelId, storeUrl)
33+
helper?.saveDeviceId()
34+
Log.d("Pixel SDK", "$apiUrl$pixelId")
35+
}
36+
37+
//identify user to get customer id
38+
fun identifyUser(
39+
email: String? = "",
40+
phone: String? = "",
41+
countryCode: String? = ""
42+
) {
43+
if (email.isNullOrEmpty() &&
44+
phone.isNullOrEmpty() &&
45+
countryCode.isNullOrEmpty()
46+
) {
47+
Log.e("pixel sdk error", "error, provide data for identity")
48+
} else
49+
helper?.identifyUser(email, if (countryCode.isNullOrEmpty()) null else phone, countryCode)
50+
}
51+
52+
53+
// add any event
54+
fun addEvent(
55+
eventName: String,
56+
currency: String?,
57+
total: String?,
58+
products: ArrayList<EventContent>?
59+
) {
60+
helper?.addEvent(eventName, currency, total, products)
61+
}
62+
63+
// add view content event
64+
fun viewContentEvent(
65+
currency: String?,
66+
total: String?,
67+
products: ArrayList<EventContent>?
68+
) {
69+
helper?.viewContentEvent(currency, total, products)
70+
}
71+
72+
// add view page event
73+
fun pageViewEvent(
74+
currency: String?,
75+
total: String?,
76+
products: ArrayList<EventContent>?
77+
) {
78+
helper?.pageViewEvent(currency, total, products)
79+
}
80+
81+
// add to cart event
82+
fun addToCartEvent(
83+
currency: String?,
84+
total: String?,
85+
products: ArrayList<EventContent>?
86+
) {
87+
helper?.addToCartEvent(currency, total, products)
88+
}
89+
90+
// add init checkout event
91+
fun initiateCheckoutEvent(
92+
currency: String?,
93+
total: String?,
94+
products: ArrayList<EventContent>?
95+
) {
96+
helper?.initiateCheckoutEvent(currency, total, products)
97+
}
98+
99+
// add purchase event
100+
fun purchaseEvent(
101+
currency: String?,
102+
total: String?,
103+
products: ArrayList<EventContent>?
104+
) {
105+
helper?.purchaseEvent(currency, total, products)
106+
}
107+
108+
// add device id
109+
fun saveDeviceToken(token: String) {
110+
helper?.saveDeviceToken(token)
111+
}
112+
113+
// delete token
114+
fun deleteDeviceToken() {
115+
helper?.deleteDeviceToken()
116+
}
117+
118+
119+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package convertedin.pixel.pixelsdk.apis
2+
3+
import convertedin.pixel.pixelsdk.ConvertedInSdk
4+
import convertedin.pixel.pixelsdk.apis.EventApis.Companion.API_EVENTS
5+
import convertedin.pixel.pixelsdk.apis.EventApis.Companion.API_IDENTITY
6+
import convertedin.pixel.pixelsdk.data.entities.EventRequest
7+
import convertedin.pixel.pixelsdk.data.entities.IdentifyRequest
8+
import convertedin.pixel.pixelsdk.data.entities.IdentifyResponse
9+
import io.reactivex.Single
10+
11+
12+
class EventApiCalls(private val apis: EventApis) {
13+
14+
internal fun identifyUser(
15+
pixelId: String,
16+
storeUrl: String,
17+
identifyRequest: IdentifyRequest
18+
): Single<IdentifyResponse> =
19+
apis.identifyUser(
20+
ConvertedInSdk.apiUrl + "v1/" + pixelId + "/" + API_IDENTITY,
21+
storeUrl,
22+
identifyRequest = identifyRequest
23+
)
24+
25+
internal fun addEvent(
26+
pixelId: String,
27+
storeUrl: String,
28+
eventRequest: EventRequest
29+
): Single<Any> =
30+
apis.addEvent(
31+
ConvertedInSdk.apiUrl + "v1/" + pixelId + "/" + API_EVENTS,
32+
storeUrl,
33+
eventRequest = eventRequest
34+
)
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package convertedin.pixel.pixelsdk.apis
2+
3+
import convertedin.pixel.pixelsdk.data.entities.EventRequest
4+
import convertedin.pixel.pixelsdk.data.entities.IdentifyRequest
5+
import convertedin.pixel.pixelsdk.data.entities.IdentifyResponse
6+
import io.reactivex.Single
7+
import retrofit2.http.Body
8+
import retrofit2.http.Header
9+
import retrofit2.http.POST
10+
import retrofit2.http.Url
11+
12+
13+
14+
interface EventApis {
15+
16+
@POST
17+
fun identifyUser(
18+
@Url url: String,
19+
@Header("Referer") storeUrl: String,
20+
@Body identifyRequest: IdentifyRequest
21+
): Single<IdentifyResponse>
22+
23+
@POST
24+
fun addEvent(
25+
@Url url: String,
26+
@Header("Referer") storeUrl: String,
27+
@Body eventRequest: EventRequest
28+
): Single<Any>
29+
30+
companion object {
31+
const val API_IDENTITY = "identity"
32+
const val API_EVENTS = "events"
33+
}
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package convertedin.pixel.pixelsdk.apis
2+
3+
import convertedin.pixel.pixelsdk.ConvertedInSdk
4+
import convertedin.pixel.pixelsdk.apis.NotificationApis.Companion.API_DELETE_DEVICE_TOKEN
5+
import convertedin.pixel.pixelsdk.apis.NotificationApis.Companion.API_REFRESH_DEVICE_TOKEN
6+
import convertedin.pixel.pixelsdk.apis.NotificationApis.Companion.API_SAVE_DEVICE_TOKEN
7+
import convertedin.pixel.pixelsdk.data.entities.DeleteTokenRequest
8+
import convertedin.pixel.pixelsdk.data.entities.RefreshTokenRequest
9+
import convertedin.pixel.pixelsdk.data.entities.SaveTokenRequest
10+
import io.reactivex.Single
11+
12+
class NotificationApiCalls(private val apis: NotificationApis) {
13+
14+
fun saveDeviceToken(
15+
pixelId: String,
16+
saveTokenRequest: SaveTokenRequest
17+
): Single<Any> =
18+
apis.saveDeviceToken(
19+
ConvertedInSdk.apiUrl + "webhooks/push-notification/" + pixelId + "/" + API_SAVE_DEVICE_TOKEN,
20+
saveTokenRequest
21+
)
22+
23+
24+
fun deleteDeviceToken(
25+
pixelId: String,
26+
deleteTokenRequest: DeleteTokenRequest
27+
): Single<Any> =
28+
apis.deleteDeviceToken(
29+
ConvertedInSdk.apiUrl + "webhooks/push-notification/" + pixelId + "/" + API_DELETE_DEVICE_TOKEN,
30+
deleteTokenRequest
31+
)
32+
33+
34+
fun refreshDeviceToken(
35+
pixelId: String,
36+
refreshTokenRequest: RefreshTokenRequest
37+
): Single<Any> =
38+
apis.refreshDeviceToken(
39+
ConvertedInSdk.apiUrl + "webhooks/push-notification/" + pixelId + "/" + API_REFRESH_DEVICE_TOKEN,
40+
refreshTokenRequest
41+
)
42+
43+
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package convertedin.pixel.pixelsdk.apis
2+
3+
import convertedin.pixel.pixelsdk.data.entities.DeleteTokenRequest
4+
import convertedin.pixel.pixelsdk.data.entities.RefreshTokenRequest
5+
import convertedin.pixel.pixelsdk.data.entities.SaveTokenRequest
6+
import io.reactivex.Single
7+
import retrofit2.http.Body
8+
import retrofit2.http.POST
9+
import retrofit2.http.Url
10+
11+
12+
interface NotificationApis {
13+
14+
@POST
15+
fun saveDeviceToken(@Url url: String, @Body saveTokenRequest: SaveTokenRequest): Single<Any>
16+
17+
@POST
18+
fun deleteDeviceToken(
19+
@Url url: String,
20+
@Body deleteTokenRequest: DeleteTokenRequest
21+
): Single<Any>
22+
23+
@POST
24+
fun refreshDeviceToken(
25+
@Url url: String,
26+
@Body refreshTokenRequest: RefreshTokenRequest
27+
): Single<Any>
28+
29+
30+
companion object {
31+
const val API_SAVE_DEVICE_TOKEN = "deviceTokens/save"
32+
const val API_DELETE_DEVICE_TOKEN = "deviceTokens/delete"
33+
const val API_REFRESH_DEVICE_TOKEN = "deviceTokens/refresh"
34+
}
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package convertedin.pixel.pixelsdk.data.entities
2+
import com.google.gson.annotations.SerializedName
3+
4+
internal class BaseResponse<T> {
5+
@field:SerializedName("code")
6+
val code: Int? = null
7+
8+
@field:SerializedName("message")
9+
val message: String? = ""
10+
11+
@field:SerializedName("data")
12+
val data: T? = null
13+
}

0 commit comments

Comments
 (0)