Skip to content

Instantly share code, notes, and snippets.

@MikeLarned
Created May 18, 2012 16:34
Show Gist options
  • Save MikeLarned/2726262 to your computer and use it in GitHub Desktop.
Save MikeLarned/2726262 to your computer and use it in GitHub Desktop.
UrbanAirshipMessageTags
Authorization: Basic <key:secret>
Content-Type: application/json
Host: go.urbanairship.com
Content-Length: 243
POST - https://go.urbanairship.com/api/push/
Request Body:
{
"aliases" : ["MikePhone"],
"tags" : [""],
"android" : {
"alert" : "Messaging",
"extra" : {
"url" : "http://www.google.com"
}
},
"aps" : {
"alert" : "Messaging",
"url" : "http://www.google.com"
}
}
public void MessageTags(string message, Dictionary<string, string> extras, IEnumerable<string> tags)
{
var push = GetPushMessage(message, extras, tags);
Http.Post(GetApiUrl("push/"), WithSecret, push);
}
private object GetPushMessage(string message, Dictionary<string, string> extras, IEnumerable<string> tags = null, IEnumerable<string> aliases = null)
{
if (tags == null)
tags = new List<string> {""};
if (aliases == null)
aliases = new List<string> { "" };
var iosPush = new Dictionary<string, object> { { "alert", message } };
foreach (var kvp in extras)
{
iosPush.Add(kvp.Key, kvp.Value);
}
var androidBroadcast = new { alert = message , extra = extras };
var push =
new
{
aliases,
tags,
android = androidBroadcast,
aps = iosPush
};
return push;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment