This repository has been archived by the owner on Jul 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
679 additions
and
1 deletion.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
spring-mobile-urbanairship/src/main/java/org/springframework/mobile/urbanairship/Feed.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2012 the original author or authors. | ||
* | ||
* 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 the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.mobile.urbanairship; | ||
|
||
import java.util.Date; | ||
|
||
public class Feed { | ||
|
||
private final String id; | ||
|
||
private final String url; | ||
|
||
private final String feedUrl; | ||
|
||
private final Date lastChecked; | ||
|
||
private final FeedNotificationTemplate template; | ||
|
||
private final boolean broadcast; | ||
|
||
private Feed(String id, String url, String feedUrl, Date lastChecked, FeedNotificationTemplate template, boolean broadcast) { | ||
this.id = id; | ||
this.url = url; | ||
this.feedUrl = feedUrl; | ||
this.lastChecked = lastChecked; | ||
this.template = template; | ||
this.broadcast = broadcast; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public String getFeedUrl() { | ||
return feedUrl; | ||
} | ||
|
||
public Date getLastChecked() { | ||
return lastChecked; | ||
} | ||
|
||
public FeedNotificationTemplate getTemplate() { | ||
return template; | ||
} | ||
|
||
public boolean isBroadcast() { | ||
return broadcast; | ||
} | ||
|
||
} | ||
|
150 changes: 150 additions & 0 deletions
150
...mobile-urbanairship/src/main/java/org/springframework/mobile/urbanairship/FeedConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright 2012 the original author or authors. | ||
* | ||
* 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 the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.mobile.urbanairship; | ||
|
||
import java.util.Map; | ||
|
||
|
||
public class FeedConfig { | ||
|
||
private String url; | ||
|
||
private Boolean broadcast; | ||
|
||
private FeedNotificationTemplate template; | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public Boolean isBroadcast() { | ||
return broadcast; | ||
} | ||
|
||
public FeedNotificationTemplate getTemplate() { | ||
return template; | ||
} | ||
|
||
private FeedConfig(String url) { | ||
this.url = url; | ||
} | ||
|
||
public static FeedConfigBuilder builder(String url, String messageTemplate) { | ||
return new FeedConfigBuilder(url, messageTemplate); | ||
} | ||
|
||
public static class FeedConfigBuilder { | ||
private String url; | ||
private String messageTemplate; | ||
private String sound; | ||
private Integer badgeCount; | ||
private String autoBadge; | ||
private Boolean broadcast; | ||
private Map<String, String> extra; | ||
|
||
public FeedConfigBuilder(String url, String messageTemplate) { | ||
this.url = url; | ||
this.messageTemplate = messageTemplate; | ||
} | ||
|
||
/** | ||
* Sets the badge to a specific value. | ||
* @param badgeCount the value to set the badge to | ||
*/ | ||
public FeedConfigBuilder badge(int badgeCount) { | ||
this.autoBadge = null; | ||
this.badgeCount = badgeCount; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the badge to "auto" to enable auto-badging. | ||
*/ | ||
public FeedConfigBuilder autoBadge() { | ||
this.badgeCount = null; | ||
this.autoBadge = "auto"; | ||
return this; | ||
} | ||
|
||
/** | ||
* Increments the badge by the given value. | ||
* @param count the amount to increment the badge by. | ||
*/ | ||
public FeedConfigBuilder badgeIncrement(int count) { | ||
this.badgeCount = null; | ||
this.autoBadge = "+" + count; | ||
return this; | ||
} | ||
|
||
/** | ||
* Decrements the badge by the given value. | ||
* @param count the amount to decrement the badge by. | ||
*/ | ||
public FeedConfigBuilder badgeDecrement(int count) { | ||
this.badgeCount = null; | ||
this.autoBadge = "-" + count; | ||
return this; | ||
} | ||
|
||
public FeedConfigBuilder broadcast(boolean broadcast) { | ||
this.broadcast = broadcast; | ||
return this; | ||
} | ||
|
||
public FeedConfigBuilder sound(String sound) { | ||
this.sound = sound; | ||
return this; | ||
} | ||
|
||
public FeedConfigBuilder extra(Map<String, String> extra) { | ||
this.extra = extra; | ||
return this; | ||
} | ||
|
||
|
||
public FeedConfig build() { | ||
FeedConfig feedConfig = new FeedConfig(url); | ||
feedConfig.broadcast = broadcast; | ||
feedConfig.template = new FeedNotificationTemplate(createAps(), createAndroid(), createBlackberry()); | ||
return feedConfig; | ||
} | ||
|
||
private Aps createAps() { | ||
Aps aps = new Aps(messageTemplate); | ||
aps.setSound(sound); | ||
if (badgeCount != null) { | ||
aps.setBadge(badgeCount); | ||
} else if (autoBadge != null) { | ||
aps.setBadge(autoBadge); | ||
} | ||
return aps; | ||
} | ||
|
||
private Android createAndroid() { | ||
Android android = new Android(messageTemplate); | ||
if (extra != null) { | ||
android.setExtra(extra); | ||
} | ||
return android; | ||
} | ||
|
||
private Blackberry createBlackberry() { | ||
return new Blackberry(messageTemplate); | ||
} | ||
|
||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...rship/src/main/java/org/springframework/mobile/urbanairship/FeedNotificationTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2012 the original author or authors. | ||
* | ||
* 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 the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.mobile.urbanairship; | ||
|
||
import org.codehaus.jackson.annotate.JsonProperty; | ||
|
||
public class FeedNotificationTemplate { | ||
|
||
@JsonProperty("aps") | ||
private Aps aps; | ||
|
||
@JsonProperty("android") | ||
private Android android; | ||
|
||
@JsonProperty("blackberry") | ||
private Blackberry blackberry; | ||
|
||
public FeedNotificationTemplate(Aps aps, Android android, Blackberry blackberry) { | ||
this.aps = aps; | ||
this.android = android; | ||
this.blackberry = blackberry; | ||
} | ||
|
||
public Aps getAps() { | ||
return aps; | ||
} | ||
|
||
public Android getAndroid() { | ||
return android; | ||
} | ||
|
||
public Blackberry getBlackberry() { | ||
return blackberry; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...le-urbanairship/src/main/java/org/springframework/mobile/urbanairship/FeedOperations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2012 the original author or authors. | ||
* | ||
* 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 the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.mobile.urbanairship; | ||
|
||
import java.util.List; | ||
|
||
public interface FeedOperations { | ||
|
||
Feed createFeed(FeedConfig feedConfig); | ||
|
||
Feed getFeed(String feedId); | ||
|
||
List<Feed> getFeeds(); | ||
|
||
void updateFeed(String feedId, FeedConfig feedConfig); | ||
|
||
void deleteFeed(String feedId); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...urbanairship/src/main/java/org/springframework/mobile/urbanairship/impl/FeedTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2012 the original author or authors. | ||
* | ||
* 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 the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.mobile.urbanairship.impl; | ||
|
||
import static org.springframework.mobile.urbanairship.impl.UrbanAirshipTemplate.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.mobile.urbanairship.Feed; | ||
import org.springframework.mobile.urbanairship.FeedConfig; | ||
import org.springframework.mobile.urbanairship.FeedOperations; | ||
import org.springframework.web.client.RestOperations; | ||
|
||
public class FeedTemplate implements FeedOperations { | ||
|
||
private final RestOperations restOperations; | ||
|
||
public FeedTemplate(RestOperations restOperations) { | ||
this.restOperations = restOperations; | ||
} | ||
|
||
public Feed createFeed(FeedConfig feedConfig) { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
HttpEntity<FeedConfig> requestEntity = new HttpEntity<FeedConfig>(feedConfig, headers); | ||
return restOperations.exchange(FEED_URL, HttpMethod.POST, requestEntity, Feed.class).getBody(); | ||
} | ||
|
||
public Feed getFeed(String feedId) { | ||
return restOperations.getForObject(FEED_URL + "/" + feedId, Feed.class); | ||
} | ||
|
||
public List<Feed> getFeeds() { | ||
return restOperations.getForObject(FEED_URL, FeedList.class); | ||
} | ||
|
||
public void updateFeed(String feedId, FeedConfig feedConfig) { | ||
restOperations.put(FEED_URL + "/" + feedId, feedConfig); | ||
} | ||
|
||
public void deleteFeed(String feedId) { | ||
restOperations.delete(FEED_URL + "/" + feedId); | ||
} | ||
|
||
private static final String FEED_URL = URBANAIRSHIP_API_URL + "feeds"; | ||
|
||
@SuppressWarnings("serial") | ||
private static class FeedList extends ArrayList<Feed> {} | ||
|
||
} |
Oops, something went wrong.