Skip to content

Commit

Permalink
Minor upgrade to handle NPE cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sc-shaikh5 committed Feb 9, 2023
1 parent 6f391a1 commit 04d0e66
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 13 deletions.
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# exclude jar for gradle wrapper
!gradle/wrapper/*.jar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# build files
**/target
target
.gradle
build

#intellij files
*.iws
*.ipr
*.iml

10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# capi-java
# business-sdk-java

Snap Conversions API
- SDK version: 1.1.3

## Requirements

Expand All @@ -21,7 +19,7 @@ Add this dependency to your project's POM:
<dependency>
<groupId>com.snap.business.sdk</groupId>
<artifactId>capi-java</artifactId>
<version>1.1.3</version>
<version>1.1.4</version>
<scope>compile</scope>
</dependency>
```
Expand All @@ -37,7 +35,7 @@ Add this dependency to your project's build file:
}
dependencies {
implementation "com.snap.business.sdk:capi-java:1.1.3"
implementation "com.snap.business.sdk:capi-java:1.1.4"
}
```

Expand Down Expand Up @@ -117,8 +115,6 @@ public class SendEvents {

```

## Notes

### Initiate ConversionApi
- Please use ConversionApi(String longLivedToken, String launchPadUrl) if the Launch Pad has been set up under your domain. Conversion events will be forwarded to Snap transparently. (Other MPC features will be introduced in later versions).
- Otherwise, you can initiate the instance using ConversionApi(String longLivedToken).Conversion events are sent back to Snap from the business SDK directly.
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ apply plugin: 'com.diffplug.spotless'

ext {
PUBLISH_GROUP_ID = 'com.snap.business.sdk'
PUBLISH_VERSION = '1.1.3'
PUBLISH_VERSION = '1.1.4'
PUBLISH_ARTIFACT_ID = 'capi-java'
}

buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.com/m2/"
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>capi-java</artifactId>
<packaging>jar</packaging>
<name>capi-java</name>
<version>1.1.3</version>
<version>1.1.4</version>
<url>https://github.com/openapitools/openapi-generator</url>
<description>OpenAPI Java</description>
<scm>
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/snap/business/sdk/ApiException.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ public Map<String, List<String>> getResponseHeaders() {
return responseHeaders;
}

/**
* Get the HTTP response headers in string format
*
* @return Response headers in the form of string, none if null
*/
public String getResponseHeadersString() {
return responseHeaders != null ? responseHeaders.toString() : "none";
}


/**
* Get the HTTP response body.
*
Expand All @@ -161,6 +171,6 @@ public String getResponseBody() {
*/
public String getMessage() {
return String.format("Message: %s%nHTTP response code: %s%nHTTP response body: %s%nHTTP response headers: %s",
super.getMessage(), this.getCode(), this.getResponseBody(), this.getResponseHeaders().toString());
super.getMessage(), this.getCode(), this.getResponseBody(), this.getResponseHeadersString());
}
}
12 changes: 11 additions & 1 deletion src/main/java/com/snap/business/sdk/api/ConversionApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ConversionApi {
private DefaultApi capi = new DefaultApi(client);
private boolean isLaunchPadEnabled = false;
private boolean isDebugEnabled = false;
private boolean isInternalDebugEnabled = false;

public ConversionApi(String longLivedToken) {
this(longLivedToken, "");
Expand Down Expand Up @@ -94,7 +95,15 @@ public ResponseStats getTestEventStats(String assetId) {

public void setDebugging(boolean isEnabled) {
this.isDebugEnabled = isEnabled;
logger.info("[Snap Business SDK] Debug mode is enabled");
String logMsg = isEnabled ? "[Snap Business SDK] Debug mode is enabled" : "[Snap Business SDK] Debug mode is disabled";
logger.info(logMsg);
}

public void setInternalDebugging(boolean isEnabled) {
this.isInternalDebugEnabled = isEnabled;
this.capi.getApiClient().setDebugging(this.isInternalDebugEnabled);
String logMsg = isEnabled ? "[Snap Business SDK] Internal debug mode is enabled" : "[Snap Business SDK] Internal debug mode is disabled";
logger.info(logMsg);
}

public Logger getLogger() {
Expand Down Expand Up @@ -131,6 +140,7 @@ public Response castToResponse(ApiException e) {
// Parse from response body if possible
try {
result = Response.fromJson(e.getResponseBody());
result = result == null ? new Response().status("FAILED").reason(ExceptionUtils.getStackTrace(e)) : result;
} catch (Exception ex) {
result = new Response().status("FAILED").reason(ExceptionUtils.getStackTrace(e));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class CapiConstants {
public final static String SDK_LANGUAGE = "java";
public final static String SDK_VERSION = "1.0.2";
public final static String SDK_VERSION = "1.1.4";
public final static String API_VERSION = "v2";
public final static String PROD_URL = "https://tr.snapchat.com/" + API_VERSION;
public final static String STAGING_URL = "https://tr-shadow.snapchat.com/" + API_VERSION;
Expand Down

0 comments on commit 04d0e66

Please sign in to comment.