Skip to content

Commit

Permalink
Merge pull request google#116 from google/topicMessaging
Browse files Browse the repository at this point in the history
Support topic messaging by using "to" field.
  • Loading branch information
silvolu committed Oct 26, 2015
2 parents 399e88c + c82e13b commit a650a61
Show file tree
Hide file tree
Showing 8 changed files with 292 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012 Google Inc.
* Copyright Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
Expand All @@ -24,7 +24,17 @@ public final class Constants {
* Endpoint for sending messages.
*/
public static final String GCM_SEND_ENDPOINT =
"https://android.googleapis.com/gcm/send";
"https://gcm-http.googleapis.com/gcm/send";

/**
* Parameter for to field.
*/
public static final String PARAM_TO = "to";

/**
* Prefix of the topic.
*/
public static final String TOPIC_PREFIX = "/topics/";

/**
* HTTP parameter for registration id.
Expand Down Expand Up @@ -166,6 +176,11 @@ public final class Constants {
*/
public static final String JSON_REGISTRATION_IDS = "registration_ids";

/**
* JSON-only field representing the to recipient.
*/
public static final String JSON_TO = "to";

/**
* JSON-only field representing the payload data.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012 Google Inc.
* Copyright Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012 Google Inc.
* Copyright Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012 Google Inc.
* Copyright Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Google Inc.
* Copyright Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
Expand All @@ -16,7 +16,8 @@
package com.google.android.gcm.server;

import java.io.Serializable;
import java.util.*;
import java.util.Collections;
import java.util.List;

/**
* GCM message notification part.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012 Google Inc.
* Copyright Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
Expand All @@ -16,6 +16,7 @@
package com.google.android.gcm.server;

import java.io.Serializable;
import java.util.List;

/**
* Result of a GCM message request that returned HTTP status code 200.
Expand Down Expand Up @@ -48,13 +49,19 @@ public final class Result implements Serializable {
private final String messageId;
private final String canonicalRegistrationId;
private final String errorCode;
private final Integer success;
private final Integer failure;
private final List<String> failedRegistrationIds;

public static final class Builder {

// optional parameters
private String messageId;
private String canonicalRegistrationId;
private String errorCode;
private Integer success;
private Integer failure;
private List<String> failedRegistrationIds;

public Builder canonicalRegistrationId(String value) {
canonicalRegistrationId = value;
Expand All @@ -71,6 +78,21 @@ public Builder errorCode(String value) {
return this;
}

public Builder success(Integer value) {
success = value;
return this;
}

public Builder failure(Integer value) {
failure = value;
return this;
}

public Builder failedRegistrationIds(List<String> value) {
failedRegistrationIds = value;
return this;
}

public Result build() {
return new Result(this);
}
Expand All @@ -80,6 +102,9 @@ private Result(Builder builder) {
canonicalRegistrationId = builder.canonicalRegistrationId;
messageId = builder.messageId;
errorCode = builder.errorCode;
success = builder.success;
failure = builder.failure;
failedRegistrationIds = builder.failedRegistrationIds;
}

/**
Expand All @@ -103,6 +128,18 @@ public String getErrorCodeName() {
return errorCode;
}

public Integer getSuccess() {
return success;
}

public Integer getFailure() {
return failure;
}

public List<String> getFailedRegistrationIds() {
return failedRegistrationIds;
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder("[");
Expand All @@ -116,6 +153,15 @@ public String toString() {
if (errorCode != null) {
builder.append(" errorCode=").append(errorCode);
}
if (success != null) {
builder.append(" groupSuccess=").append(success);
}
if (failure != null) {
builder.append(" groupFailure=").append(failure);
}
if (failedRegistrationIds != null) {
builder.append(" failedRegistrationIds=").append(failedRegistrationIds);
}
return builder.append(" ]").toString();
}

Expand Down
Loading

0 comments on commit a650a61

Please sign in to comment.