mattt/Orbiter — pull request #8 by coryalder (2013-03-21 21:30:43+00:00)
Title: Refactored payload creation, to allow for an overridable "default" payload.

I've been playing with Orbiter for a couple of days now, and I like it a lot. One issue I've run into is with the payload. The way it's implemented now means you can either use the default payload, or specify your own. I like the default payload, but want to add a couple of tags of my own.

I refactored the payloads into a property (`NSMutableDictionary *payload;`), moved setting the default values into a method (`-configureDefaultPayload`) and then refactored the rest of the code to take advantage of the changes. e.g. the `-registerDeviceToken:withAlias:success:failure` in the Urban Airship and Parse subclasses are no longer needed.

I believe all the changes I have made to the Urban Airship / Parse code should be a nop, but I have not tested them because I don't use them.

------

The main change this pull request results in in is that this code:

Orbiter *orbiter = [[Orbiter alloc] initWithBaseURL:serverURL credential:nil];
[orbiter.payload setObject:@"tlh" forKey:@"language"];
[orbiter registerDeviceToken:deviceToken withAlias:@"alias1234" success:^(id responseObject) {
NSLog(@"Registration Success: %@", responseObject);
} failure:^(NSError *error) {
NSLog(@"Registration Error: %@", error);
}];

Results in this sent to the server:

{
"language": "tlh",
"tags": [
"iPhone OS 6.1.2",
"v1.0",
"iPhone"
],
"locale": "en_CA",
"alias": "alias1234",
"lat": 49.496675,
"timezone": "America/Vancouver",
"lng": -122.519531
}

Rather than the previous output:

{
"language": "tlh",
"alias": "alias1234"
}