Skip to content

Commit

Permalink
version 1.4.0 - fix params tracking, update firebase to 22
Browse files Browse the repository at this point in the history
  • Loading branch information
PNixx committed Jun 29, 2021
1 parent 3cf0a16 commit bccf9c6
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 110 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
Add to `dependencies`:

```
implementation 'com.rees46:rees46-sdk:1.3.6'
implementation 'com.rees46:rees46-sdk:1.4.0'
implementation 'com.google.firebase:firebase-bom:28.2.0'
implementation 'com.google.firebase:firebase-messaging:22.0.0'
```

## Configure
Expand All @@ -17,7 +19,7 @@ Append to your project `build.gradle`
buildscript {
dependencies {
...
classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.google.gms:google-services:4.3.8'
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.google.gms:google-services:4.3.8'
}
}

Expand Down
10 changes: 5 additions & 5 deletions personalizatio-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'signing'

version='1.3.7'
version='1.4.0'

android {
compileSdkVersion 29
compileSdkVersion 30
flavorDimensions 'default'
// publishNonDefault true

defaultConfig {
minSdkVersion 19
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName version
buildConfigField "String", "VERSION_NAME", "\"" + version + "\""
Expand Down Expand Up @@ -65,8 +65,8 @@ configurations {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

api 'com.google.firebase:firebase-core:18.0.3'
api 'com.google.firebase:firebase-messaging:21.1.0'
api 'com.google.firebase:firebase-bom:28.2.0'
api 'com.google.firebase:firebase-messaging:22.0.0'
}

group='com.personalizatio'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.personalizatio;

import android.text.TextUtils;
import android.util.Log;

import java.util.HashMap;
import org.json.JSONException;
import org.json.JSONObject;

abstract class AbstractParams<P extends AbstractParams<P>> {
protected final HashMap<String, String> params = new HashMap<>();
protected final JSONObject params = new JSONObject();

public interface ParamInterface {
String getValue();
Expand All @@ -15,7 +17,11 @@ public interface ParamInterface {
* Вставка строковых параметров
*/
public P put(P.ParamInterface param, String value) {
params.put(param.getValue(), value);
try {
params.put(param.getValue(), value);
} catch(JSONException e) {
Log.e(SDK.TAG, e.getMessage(), e);
}
return (P) this;
}
public P put(P.ParamInterface param, int value) {
Expand All @@ -30,11 +36,15 @@ public P put(P.ParamInterface param, boolean value) {
* Вставка параметров с массивом
*/
public P put(P.ParamInterface param, String[] value) {
params.put(param.getValue(), TextUtils.join(",", value));
try {
params.put(param.getValue(), TextUtils.join(",", value));
} catch(JSONException e) {
Log.e(SDK.TAG, e.getMessage(), e);
}
return (P) this;
}

HashMap<String, String> build() {
JSONObject build() {
return params;
}
}
16 changes: 7 additions & 9 deletions personalizatio-sdk/src/main/java/com/personalizatio/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.Map;

/**
Expand Down Expand Up @@ -44,16 +45,13 @@ static void initialize(String url) {
* @param params request
* @param listener callback
*/
public static void send(final String request_type, final String method, final Map<String, String> params, @Nullable final OnApiCallbackListener listener) {
public static void send(final String request_type, final String method, final JSONObject params, @Nullable final OnApiCallbackListener listener) {
Thread thread = new Thread(() -> {
try {
JSONObject body = new JSONObject();
Uri.Builder builder = Uri.parse(instance.url + method).buildUpon();
for( Map.Entry<String, String> entry : params.entrySet() ) {
builder.appendQueryParameter(entry.getKey(), entry.getValue());
if( request_type.toUpperCase().equals("POST") ) {
body.put(entry.getKey(), entry.getValue());
}
for( Iterator<String> it = params.keys(); it.hasNext(); ) {
String key = it.next();
builder.appendQueryParameter(key, params.getString(key));
}

URL url;
Expand All @@ -73,15 +71,15 @@ public static void send(final String request_type, final String method, final Ma
conn.setDoOutput(true);
conn.setDoInput(true);
BufferedWriter os = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8));
os.write(body.toString());
os.write(params.toString());
os.flush();
os.close();
}

conn.connect();

if( request_type.toUpperCase().equals("POST") ) {
SDK.debug(conn.getResponseCode() + ": " + request_type.toUpperCase() + " " + url + " with body: " + body);
SDK.debug(conn.getResponseCode() + ": " + request_type.toUpperCase() + " " + url + " with body: " + params);
} else {
SDK.debug(conn.getResponseCode() + ": " + request_type.toUpperCase() + " " + builder.build().toString());
}
Expand Down
27 changes: 20 additions & 7 deletions personalizatio-sdk/src/main/java/com/personalizatio/Params.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.personalizatio;

import android.util.Log;

import androidx.annotation.NonNull;

import org.json.JSONArray;
import org.json.JSONException;

import java.util.HashMap;
import java.util.Map;

final public class Params extends AbstractParams<Params> {

private int item_count = 0;

/**
* Основные параметры
*/
Expand Down Expand Up @@ -126,9 +129,13 @@ public enum TrackEvent {
* Вставка параметров рекомендаций
*/
public Params put(RecommendedBy recommended_by) {
params.put(InternalParameter.RECOMMENDED_BY.getValue(), recommended_by.type);
if( recommended_by.code != null ) {
params.put(InternalParameter.RECOMMENDED_CODE.getValue(), recommended_by.code);
try {
params.put(InternalParameter.RECOMMENDED_BY.getValue(), recommended_by.type);
if( recommended_by.code != null ) {
params.put(InternalParameter.RECOMMENDED_CODE.getValue(), recommended_by.code);
}
} catch( JSONException e ) {
Log.e(SDK.TAG, e.getMessage(), e);
}
return this;
}
Expand All @@ -138,9 +145,15 @@ public Params put(RecommendedBy recommended_by) {
*/
public Params put(Item item) {
for( Map.Entry<String, String> entry : item.columns.entrySet() ) {
params.put(entry.getKey() + "[" + item_count + "]", entry.getValue());
try {
JSONArray array;
array = params.has(entry.getKey()) ? params.getJSONArray(entry.getKey()) : new JSONArray();
array.put(entry.getValue());
params.put(entry.getKey(), array);
} catch(JSONException e) {
Log.e(SDK.TAG, e.getMessage(), e);
}
}
item_count++;

return this;
}
Expand Down
Loading

0 comments on commit bccf9c6

Please sign in to comment.