Skip to content

Commit

Permalink
Merge pull request #89 from visenze/feature/get_uid
Browse files Browse the repository at this point in the history
[API-8115] add method to get uid and sid
  • Loading branch information
thehung111 authored Jun 9, 2022
2 parents 667711a + 0173b5a commit 8a2fd8d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
28 changes: 25 additions & 3 deletions doc/ProductSearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ With the release of ViSenze's Catalog system, ViSearch Android SDK will now incl
- Aggregate search results on a product level instead of image level
- Consistent data type in API response with Catalog’s schema

> Current stable version: 2.2.0
> Current stable version: 2.2.1
> Minimum Android SDK Version: API 9, Android 2.3
Expand Down Expand Up @@ -64,7 +64,7 @@ allprojects {
include the dependency in your project using gradle:
```gradle
implementation 'com.github.visenze:visenze-tracking-android:0.2.1'
implementation 'com.github.visenze:visearch-sdk-android:2.2.0'
implementation 'com.github.visenze:visearch-sdk-android:2.2.1'
```

### 1.3 Add User Permissions
Expand Down Expand Up @@ -175,7 +175,29 @@ public void OnImageCaptured(Image image, String imagePath) {
}
```

> Image File refers to an actual file with bytes representing the image (i.e. opened from file upload, or taken from camera). The example above is in a scenario where the android camera captures an image.
> Image File refers to an actual file with bytes representing the image (i.e. opened from file upload, or taken from camera). The example above is in a scenario where the android camera captures an image. You can construct the Image object by doing 1 of the following:
- Using an image from a local file path:

```java
Image image = new Image("/local/path/to/image.jpg");
```

- Using an image by providing the Uri of the image in photo gallery:

```java
Image image = new Image(context, uri);
```

- Construct the `image` from the byte array returned by the camera preview callback:

```java
@Override
public void onPictureTaken(byte[] bytes, Camera camera) {
Image image = new Image(bytes);
}
```


### 3.2 Recommendations

Expand Down
4 changes: 2 additions & 2 deletions visearch-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ plugins {

def versionMajor = 2
def versionMinor = 2
def versionPatch = 0
version = '2.2.0'
def versionPatch = 1
version = '2.2.1'

android {
compileSdkVersion 29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ public class ProductSearch {
private static final String USER_AGENT = "productsearch-android-sdk";
private static final String SEARCH_URL = "https://search.visenze.com/v1/";



private String uid;
private String trackCode;
private VisenzeAnalytics visenzeAnalytics;
private ProductSearchService productSearchService;


private ProductSearch(Context context, String appKey, int placementId, String endPoint, String userAgent, String uid) {

this.uid = uid;
Expand All @@ -32,7 +29,6 @@ private ProductSearch(Context context, String appKey, int placementId, String en
this.productSearchService = new ProductSearchService(endPoint, appKey, placementId, userAgent);
}


public void searchByImage(ProductSearchByImageParams imageSearchParams, ResultListener listener) {
addAnalyticsParams(imageSearchParams);
productSearchService.searchByImage(imageSearchParams, listener);
Expand All @@ -47,15 +43,22 @@ public void recommendations(ProductSearchByIdParams visualSimilarParams, ResultL
searchById(visualSimilarParams, listener);
}

// get auto-generated uid string (va_uid) for Analytics purpose
public String getUid() {
return visenzeAnalytics.getSessionManager().getUid();
}

// get auto-generated session ID string (va_sid) for Analytics purpose
public String getSid() {
return visenzeAnalytics.getSessionManager().getSessionId();
}

private void addAnalyticsParams(BaseProductSearchParams searchParams) {
if (searchParams == null) return;

SessionManager sessionManager = visenzeAnalytics.getSessionManager();
DataCollection dataCollection = visenzeAnalytics.getDataCollection();



if (searchParams.getVaUid() == null) {
searchParams.setVaUid(sessionManager.getUid());
}
Expand Down

0 comments on commit 8a2fd8d

Please sign in to comment.