Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# onesignal-java-client

OneSignal
- API version: 5.6.0
- API version: 5.7.0

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com

Expand All @@ -19,14 +19,14 @@ Building the API client library requires:
<dependency>
<groupId>com.onesignal</groupId>
<artifactId>onesignal-java-client</artifactId>
<version>5.6.0</version>
<version>5.7.0</version>
</dependency>
```

### Gradle

```groovy
implementation "com.onesignal:onesignal-java-client:5.6.0"
implementation "com.onesignal:onesignal-java-client:5.7.0"
```

## Configuration
Expand Down
2 changes: 1 addition & 1 deletion api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ info:
customer engagement strategies. Learn more at onesignal.com
termsOfService: https://onesignal.com/tos
title: OneSignal
version: 5.6.0
version: 5.7.0
servers:
- url: https://api.onesignal.com
paths:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'com.diffplug.spotless'
apply plugin: 'com.vanniktech.maven.publish'

group = 'com.onesignal'
version = '5.6.0'
version = '5.7.0'

buildscript {
repositories {
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ lazy val root = (project in file(".")).
settings(
organization := "com.onesignal",
name := "onesignal-java-client",
version := "5.6.0",
version := "5.7.0",
scalaVersion := "2.11.4",
scalacOptions ++= Seq("-feature"),
javacOptions in compile ++= Seq("-Xlint:deprecation"),
Expand Down
131 changes: 130 additions & 1 deletion docs/DefaultApi.md

Large diffs are not rendered by default.

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>onesignal-java-client</artifactId>
<packaging>jar</packaging>
<name>onesignal-java-client</name>
<version>5.6.0</version>
<version>5.7.0</version>
<url>https://github.com/OneSignal/onesignal-java-api</url>
<description>OneSignal Java API Client</description>
<scm>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/onesignal/client/ApiCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OneSignal
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
*
* The version of the OpenAPI document: 5.6.0
* The version of the OpenAPI document: 5.7.0
* Contact: devrel@onesignal.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/onesignal/client/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OneSignal
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
*
* The version of the OpenAPI document: 5.6.0
* The version of the OpenAPI document: 5.7.0
* Contact: devrel@onesignal.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down Expand Up @@ -133,7 +133,7 @@ private void init() {
json = new JSON();

// Set default User-Agent.
setUserAgent("OpenAPI-Generator/5.6.0/java");
setUserAgent("OpenAPI-Generator/5.7.0/java");

authentications = new HashMap<String, Authentication>();
}
Expand Down
80 changes: 79 additions & 1 deletion src/main/java/com/onesignal/client/ApiException.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OneSignal
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
*
* The version of the OpenAPI document: 5.6.0
* The version of the OpenAPI document: 5.7.0
* Contact: devrel@onesignal.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand All @@ -13,6 +13,12 @@

package com.onesignal.client;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.List;

Expand Down Expand Up @@ -163,4 +169,76 @@ 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());
}

/**
* Get the error messages carried by the response body, normalized to a flat
* list of strings regardless of which envelope shape the API returned
* ({@code {"errors": "..."}}, {@code {"errors": ["..."]}},
* {@code {"errors": [{"code": ..., "title": ...}]}}, or an object map such as
* {@code {"errors": {"invalid_aliases": {...}}}}, surfaced as
* {@code "<key>: <value>"} entries). Returns an empty list when the body is
* not a recognizable error envelope. The raw body remains available via
* {@link #getResponseBody()}.
*
* @return the normalized error messages
*/
public List<String> getErrorMessages() {
List<String> messages = new ArrayList<String>();
if (responseBody == null || responseBody.isEmpty()) {
return messages;
}

try {
JsonElement root = JsonParser.parseString(responseBody);
if (!root.isJsonObject()) {
return messages;
}

JsonElement errors = root.getAsJsonObject().get("errors");
if (errors == null || errors.isJsonNull()) {
return messages;
}

if (errors.isJsonPrimitive()) {
if (errors.getAsJsonPrimitive().isString()) {
messages.add(errors.getAsString());
}
} else if (errors.isJsonArray()) {
for (JsonElement item : errors.getAsJsonArray()) {
if (item.isJsonPrimitive()) {
if (item.getAsJsonPrimitive().isString()) {
messages.add(item.getAsString());
}
} else if (item.isJsonObject()) {
JsonObject object = item.getAsJsonObject();
JsonElement title = object.get("title");
JsonElement code = object.get("code");
if (title != null && title.isJsonPrimitive() && title.getAsJsonPrimitive().isString()
&& !title.getAsString().isEmpty()) {
messages.add(title.getAsString());
} else if (code != null && !code.isJsonNull()) {
messages.add(code.isJsonPrimitive() ? code.getAsString() : code.toString());
}
}
}
} else if (errors.isJsonObject()) {
// Object-shaped envelopes (e.g. {"invalid_aliases": {...}}) carry
// data under arbitrary keys; surface each so it isn't silently
// dropped. Key order is unspecified, so sort for deterministic output.
JsonObject object = errors.getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
JsonElement value = entry.getValue();
String rendered = value.isJsonPrimitive() && value.getAsJsonPrimitive().isString()
? value.getAsString()
: value.toString();
messages.add(entry.getKey() + ": " + rendered);
}
Collections.sort(messages);
}
} catch (RuntimeException e) {
return messages;
}

return messages;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/onesignal/client/ApiResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OneSignal
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
*
* The version of the OpenAPI document: 5.6.0
* The version of the OpenAPI document: 5.7.0
* Contact: devrel@onesignal.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/onesignal/client/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OneSignal
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
*
* The version of the OpenAPI document: 5.6.0
* The version of the OpenAPI document: 5.7.0
* Contact: devrel@onesignal.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OneSignal
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
*
* The version of the OpenAPI document: 5.6.0
* The version of the OpenAPI document: 5.7.0
* Contact: devrel@onesignal.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/onesignal/client/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OneSignal
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
*
* The version of the OpenAPI document: 5.6.0
* The version of the OpenAPI document: 5.7.0
* Contact: devrel@onesignal.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/onesignal/client/Pair.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OneSignal
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
*
* The version of the OpenAPI document: 5.6.0
* The version of the OpenAPI document: 5.7.0
* Contact: devrel@onesignal.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OneSignal
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
*
* The version of the OpenAPI document: 5.6.0
* The version of the OpenAPI document: 5.7.0
* Contact: devrel@onesignal.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OneSignal
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
*
* The version of the OpenAPI document: 5.6.0
* The version of the OpenAPI document: 5.7.0
* Contact: devrel@onesignal.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/onesignal/client/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OneSignal
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
*
* The version of the OpenAPI document: 5.6.0
* The version of the OpenAPI document: 5.7.0
* Contact: devrel@onesignal.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Loading