Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 9b5950d

Browse files
committed
Initial commit.
0 parents  commit 9b5950d

15 files changed

+1150
-0
lines changed

.gitignore

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
*.pydevproject
2+
.metadata
3+
.gradle
4+
bin/
5+
tmp/
6+
*.tmp
7+
*.bak
8+
*.swp
9+
*~.nib
10+
local.properties
11+
.settings/*
12+
.settings
13+
.loadpath
14+
target/
15+
16+
# Eclipse Core
17+
.project
18+
19+
# External tool builders
20+
.externalToolBuilders/
21+
22+
# Locally stored "Eclipse launch configurations"
23+
*.launch
24+
25+
# CDT-specific
26+
.cproject
27+
28+
# JDT-specific (Eclipse Java Development Tools)
29+
.classpath
30+
31+
# Java annotation processor (APT)
32+
.factorypath
33+
34+
# PDT-specific
35+
.buildpath
36+
37+
# sbteclipse plugin
38+
.target
39+
40+
# TeXlipse plugin
41+
.texlipse
42+
43+
# STS (Spring Tool Suite)
44+
.springBeans

LICENSE.TXT

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2015 Devsu Software
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

README.MD

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Push Sender #
2+
3+
Push Sender is a Java library that allows sending push messages easily, based on the awesome libraries [gcm-server](https://github.com/theganyo/gcm-server) by [theganyo](https://github.com/theganyo) and (java-apns)[https://github.com/notnoop/java-apns] by (notnoop)[https://github.com/notnoop]. Send push messages with one line of code, forget about the rest, and focus on making on your application's business logic!
4+
5+
## Overview ###
6+
7+
Using Push Sender is very simple. You can import Push Sender on your POM file using:
8+
9+
```
10+
<dependency>
11+
<groupId>com.devsu</groupId>
12+
<artifactId>push-sender</artifactId>
13+
<version>1.0.0</version>
14+
</dependency>
15+
```
16+
17+
## Synchronous and asynchronous push services ###
18+
19+
You can send your push messages synchronously and asynchronously by choosing any of the implementations of `PushService`.
20+
21+
```java
22+
public class MySender {
23+
24+
SyncAndroidPushService syncAndroidService = new SyncAndroidPushService(GCM_API_KEY);
25+
AsyncAndroidPushService asyncAndroidService = new SyncAndroidPushService(GCM_API_KEY, null);
26+
27+
SyncApplePushService syncAppleService = new SyncApplePushService(P12_FILEPATH, P12_PASSWORD, IS_PRODUCTION_ENVIRONMENT);
28+
AsyncApplePushService asyncAppleService = new AsyncApplePushService(P12_FILEPATH, P12_PASSWORD, IS_PRODUCTION_ENVIRONMENT, null);
29+
30+
...
31+
32+
public void sendSomePushMessages() {
33+
String title = "My Push Message Title";
34+
String content = "Hello! This is a push message!";
35+
36+
syncAndroidService.sendPush(title, content, ANDROID_PUSH_TOKEN);
37+
asyncAndroidService.sendPush(title, content, ANDROID_PUSH_TOKEN);
38+
39+
syncAppleService.sendPush(title, content, IOS_PUSH_TOKEN);
40+
asyncAppleService.sendPush(title, content, IOS_PUSH_TOKEN);
41+
}
42+
43+
...
44+
}
45+
```
46+
47+
## PushCallback ###
48+
49+
You can implement a PushCallback for any of the asynchronous services.
50+
51+
```java
52+
public class MySender {
53+
54+
...
55+
56+
public void sendSomePushMessages() {
57+
AsyncAndroidPushService asyncAndroidService = new SyncAndroidPushService(GCM_API_KEY, new PushCallback() {
58+
59+
@Override
60+
public void onSingleSuccess(boolean result, String title, String message,
61+
Map<String, String> additionalFields, String token) {
62+
System.out.println("The single message was successfully sent!");
63+
}
64+
65+
@Override
66+
public void onError(Throwable t) {
67+
System.err.println("Oops... Something happened!");
68+
}
69+
70+
@Override
71+
public void onBulkSuccess(boolean result, String title, String message,
72+
Map<String, String> additionalFields, String[] tokens) {
73+
System.out.println("The bulk message was successfully sent!");
74+
}
75+
});
76+
}
77+
78+
...
79+
}
80+
```
81+
82+
## Authors ##
83+
Feel free to contact Alvaro López at [email protected]!
84+
85+
## License ###
86+
87+
Copyright 2015 Devsu Software
88+
89+
Licensed under the Apache License, Version 2.0 (the "License");
90+
you may not use this file except in compliance with the License.
91+
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
92+
93+
Unless required by applicable law or agreed to in writing, software
94+
distributed under the License is distributed on an "AS IS" BASIS,
95+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
96+
See the License for the specific language governing permissions and
97+
limitations under the License.

open_source_licenses.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## theganyo/gcm-server
2+
3+
Copyright 2009, Mahmood Ali.
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are
8+
met:
9+
10+
* Redistributions of source code must retain the above copyright
11+
notice, this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above
13+
copyright notice, this list of conditions and the following disclaimer
14+
in the documentation and/or other materials provided with the
15+
distribution.
16+
* Neither the name of Mahmood Ali. nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pom.xml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.devsu</groupId>
7+
<artifactId>push-sender</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<java.version>1.7</java.version>
14+
</properties>
15+
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<groupId>org.apache.maven.plugins</groupId>
20+
<artifactId>maven-compiler-plugin</artifactId>
21+
<version>3.1</version>
22+
<configuration>
23+
<source>${java.version}</source>
24+
<target>${java.version}</target>
25+
</configuration>
26+
</plugin>
27+
</plugins>
28+
</build>
29+
<dependencies>
30+
<dependency>
31+
<groupId>junit</groupId>
32+
<artifactId>junit</artifactId>
33+
<version>4.11</version>
34+
<scope>test</scope>
35+
</dependency>
36+
<!-- Push Services -->
37+
<dependency>
38+
<groupId>com.notnoop.apns</groupId>
39+
<artifactId>apns</artifactId>
40+
<version>1.0.0.Beta6</version>
41+
<scope>compile</scope>
42+
</dependency>
43+
<dependency>
44+
<groupId>com.ganyo</groupId>
45+
<artifactId>gcm-server</artifactId>
46+
<version>1.0.2</version>
47+
<scope>compile</scope>
48+
</dependency>
49+
<!-- Logging -->
50+
<dependency>
51+
<groupId>org.slf4j</groupId>
52+
<artifactId>slf4j-simple</artifactId>
53+
<version>1.7.13</version>
54+
<scope>compile</scope>
55+
</dependency>
56+
</dependencies>
57+
</project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.devsu.push.sender.callback;
2+
3+
import java.util.Map;
4+
5+
/**
6+
* Callback used for the async services.
7+
*/
8+
public interface PushCallback {
9+
10+
/**
11+
* Callback that is executed when a single push message is sent.
12+
* @param result Value that indicates if a push message request was correctly sent to APNS/GCM.
13+
* @param title The push message title.
14+
* @param message The push message content.
15+
* @param additionalFields The additional fields sent on the push message.
16+
* @param token The push token.
17+
*/
18+
void onSingleSuccess(boolean result, String title, String message, Map<String, String> additionalFields, String token);
19+
20+
/**
21+
* Callback that is executed when a bulk push message is sent.
22+
* @param result Value that indicates if a push message request was correctly sent to APNS/GCM.
23+
* @param title The push message title.
24+
* @param message The push message content.
25+
* @param additionalFields The additional fields sent on the push message.
26+
* @param tokens The push tokens.
27+
*/
28+
void onBulkSuccess(boolean result, String title, String message, Map<String, String> additionalFields, String[] tokens);
29+
30+
/**
31+
* Callback that is executed when a push message request throws an exception.
32+
* @param t The exception that occurred.
33+
*/
34+
void onError(Throwable t);
35+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.devsu.push.sender.service.async;
2+
3+
import com.devsu.push.sender.callback.PushCallback;
4+
import com.devsu.push.sender.service.sync.SyncAndroidPushService;
5+
6+
/**
7+
* The async push service for Android (GCM).
8+
*/
9+
public class AsyncAndroidPushService extends AsyncPushServiceBase {
10+
11+
/**
12+
* @see com.devsu.push.sender.service.sync.SyncAndroidPushService#AndroidPushService(String)
13+
*/
14+
public AsyncAndroidPushService(String gcmApiKey){
15+
super(new SyncAndroidPushService(gcmApiKey), null);
16+
}
17+
18+
/**
19+
* 2 param constructor.
20+
* @param gcmApiKey The GCM API Key (also known as Sender ID).
21+
* @param pushCallback The push callback.
22+
*/
23+
public AsyncAndroidPushService(String gcmApiKey, PushCallback pushCallback) {
24+
super(new SyncAndroidPushService(gcmApiKey), pushCallback);
25+
}
26+
27+
/**
28+
* @see com.devsu.push.sender.service.sync.SyncAndroidPushService#setMaxRetries(int)
29+
*/
30+
public void setMaxRetries(int maxRetries) {
31+
((SyncAndroidPushService)pushService).setMaxRetries(maxRetries);
32+
}
33+
34+
/**
35+
* @see com.devsu.push.sender.service.sync.SyncAndroidPushService#setMessageKey(java.lang.String)
36+
*/
37+
public void setMessageKey(String messageKey) {
38+
((SyncAndroidPushService)pushService).setMessageKey(messageKey);
39+
}
40+
41+
/**
42+
* @see com.devsu.push.sender.service.sync.SyncAndroidPushService#setTitleKey(java.lang.String)
43+
*/
44+
public void setTitleKey(String titleKey) {
45+
((SyncAndroidPushService)pushService).setTitleKey(titleKey);
46+
}
47+
48+
/**
49+
* @see com.devsu.push.sender.service.sync.SyncAndroidPushService#setMaxBulkSize(int)
50+
*/
51+
public void setMaxBulkSize(int maxBulkSize) {
52+
((SyncAndroidPushService)pushService).setMaxBulkSize(maxBulkSize);
53+
}
54+
55+
/**
56+
* @see com.devsu.push.sender.service.sync.SyncAndroidPushService#setCollapseKeySingle(java.lang.String)
57+
*/
58+
public void setCollapseKeySingle(String collapseKeySingle) {
59+
((SyncAndroidPushService)pushService).setCollapseKeySingle(collapseKeySingle);
60+
}
61+
62+
/**
63+
* @see com.devsu.push.sender.service.sync.SyncAndroidPushService#setCollapseKeyBulk(java.lang.String)
64+
*/
65+
public void setCollapseKeyBulk(String collapseKeyBulk) {
66+
((SyncAndroidPushService)pushService).setCollapseKeyBulk(collapseKeyBulk);
67+
}
68+
69+
/**
70+
* @see com.devsu.push.sender.service.sync.SyncAndroidPushService#setGcmApiKey(java.lang.String)
71+
*/
72+
public void setGcmApiKey(String gcmApiKey) {
73+
((SyncAndroidPushService)pushService).setGcmApiKey(gcmApiKey);
74+
}
75+
76+
/**
77+
* @see com.devsu.push.sender.service.sync.SyncPushServiceBase#setPushEnabled(boolean)
78+
*/
79+
public void setPushEnabled(boolean pushEnabled) {
80+
((SyncAndroidPushService)pushService).setPushEnabled(pushEnabled);
81+
}
82+
}

0 commit comments

Comments
 (0)