Skip to content

Instantly share code, notes, and snippets.

@MikeLarned
Created May 17, 2012 16:57
Show Gist options
  • Select an option

  • Save MikeLarned/2720182 to your computer and use it in GitHub Desktop.

Select an option

Save MikeLarned/2720182 to your computer and use it in GitHub Desktop.
UrbanAirship Update Registration Alias
User-Agent: Fiddler
Authorization: Basic <key:secret>
Content-Type: applicaiton/json
Host: go.urbanairship.com
Content-Length: 16
PUT - https://go.urbanairship.com/api/apids/{apid} (Android)
PUT - https://go.urbanairship.com/api/device_tokens/{device_token} (iOS)
Request Body iOS:
{
"alias": "example_alias",
"tags": ["tag1", "tag2"]
}
Request Body Android:
{
"alias": "example_alias",
"tags": ["tag1", "tag2"],
"c2dm_registration_id" : <c2dm_registration_id>
}
public void UpdateDevice(string alias, IEnumerable<string> tags, string id, DeviceType type)
{
var deviceUrl = ResolveDeviceUrl(id, type);
//Android requires posting current C2DMNRegistrationID or the value will be overwritten. Requery UA API for current C2DMNRegistrationID
if(type == DeviceType.Android)
{
var android = GetDevice(id, type) as AndroidPushId;
Http.Put(deviceUrl, WithSecret, new { alias, tags, c2dm_registration_id = android.c2dm_registration_id });
}
else
{
Http.Put(deviceUrl, WithSecret, new { alias, tags });
}
}
private string ResolveDeviceUrl(string id, DeviceType type)
{
switch (type)
{
case DeviceType.iOS:
return GetApiUrl(string.Format("device_tokens/{0}", id));
case DeviceType.Android:
return GetApiUrl(string.Format("apids/{0}", id));
default:
throw new ArgumentException("Device type was not iOS or Android");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment