Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Added a constructor that passes the endpoint #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public class Sender {
Logger.getLogger(Sender.class.getName());

private final String key;
private final String endpoint;

/**
* Default constructor.
Expand All @@ -100,6 +101,18 @@ public class Sender {
*/
public Sender(String key) {
this.key = nonNull(key);
this.endpoint = GCM_SEND_ENDPOINT;
}

/**
* Additional constructor that passes the endpoint as well. Can be used for testing with a mock.
*
* @param key API key obtained through the Google API Console.
* @param endpoint An endpoint that can accept notification requests. Normally the GCM Endpoint.
*/
public Sender(String key, String endpoint) {
this.key = nonNull(key);
this.endpoint = nonNull(endpoint);
}

/**
Expand Down Expand Up @@ -417,7 +430,7 @@ private String makeGcmHttpRequest(Map<Object, Object> jsonRequest) throws Invali
HttpURLConnection conn;
int status;
try {
conn = post(GCM_SEND_ENDPOINT, "application/json", requestBody);
conn = post(endpoint, "application/json", requestBody);
status = conn.getResponseCode();
} catch (IOException e) {
logger.log(Level.FINE, "IOException posting to GCM", e);
Expand Down Expand Up @@ -618,7 +631,7 @@ protected static StringBuilder newBody(String name, String value) {
protected static void addParameter(StringBuilder body, String name,
String value) {
nonNull(body).append('&')
.append(nonNull(name)).append('=').append(nonNull(value));
.append(nonNull(name)).append('=').append(nonNull(value));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove additional indentation please.

}

/**
Expand Down