Created
December 4, 2012 16:37
-
-
Save hboon/4205927 to your computer and use it in GitHub Desktop.
Write a string to a Campfire room synchronously.
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
// This goes into the header file. | |
void moCampfireSpeak(NSString* aString, NSString* aRoomIDString, NSString* aSubdomainString, NSString* aTokenString); | |
// This goes into the implementation file. | |
// You need the room ID, not room name. You can get it from the campfire room URL. | |
void moCampfireSpeak(NSString* aString, NSString* aRoomIDString, NSString* aSubdomainString, NSString* aTokenString) { | |
NSString* url = [NSString stringWithFormat:@"https://%@.campfirenow.com/room/%@/speak.json", aSubdomainString, aRoomIDString]; | |
NSString* postString = [NSString stringWithFormat:@"<message><type>%@</type><body>%@</body></message>", @"TextMessage", aString]; | |
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0]; | |
NSString* auth = [NSString stringWithFormat:@"%@:%@", aTokenString, @"X"]; | |
NSString* authValue = [NSString stringWithFormat:@"Basic %@", [[auth dataUsingEncoding:NSUTF8StringEncoding] base64EncodingWithLineLength:80]]; | |
[request setValue:authValue forHTTPHeaderField:@"Authorization"]; | |
[request addValue:@"application/xml" forHTTPHeaderField:@"Content-Type"]; | |
[request setHTTPMethod:@"POST"]; | |
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]]; | |
NSHTTPURLResponse* response; | |
NSError* error; | |
NSData* res = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; | |
NSString* result = [[NSString alloc] initWithData:res encoding:NSUTF8StringEncoding]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment