Created
May 17, 2012 16:57
-
-
Save MikeLarned/2720182 to your computer and use it in GitHub Desktop.
UrbanAirship Update Registration Alias
This file contains hidden or 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
| 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> | |
| } |
This file contains hidden or 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
| 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