Begin main content

AQXMLParser + OAuth

I've been enjoying using Jim Dovey's excellent AQXMLParser lately, and in fact am giving a talk on it tonight at Sydney CocoaHeads. To use it in a new project, I need to be able to authorise the outbound REST request with some OAuth 1 tokens etc.

OAuth can be a right pain, and the Cocoa implementations aren't awesome. gtm-oauth (the OAuth 1 library from the Google Toolbox for Mac) is a little odd in its implementation, but doing your own OAuth implementation would be so tedious it's one of the better options out there.

It's all pretty easy. Firstly, use gtm-oauth like normal to have your user authorise your app and receive a token.

Next, to make a request, gtm-oauth provides a way to authorise an NSMutableURLRequest, but AQXMLParser uses it's own HTTPMessage class (which wraps the lower level CFHTTPMessage from Core Foundation).

What I have done is extend HTTPMessage to provide a copy of itself as an NSURLRequest, and then write a category that auths that with gtm-oauth and then cribs the headers from that and applies them to the HTTPMessage. It's a little roundabout, but because of the need to sign the whole request and the way that gtm-oauth internals work, anything else would be very complicated. So in use, it looks like this:

#import "HTTPMessage+GTMOAuth.h"

...

GTMOAuthAuthentication * oauth = ...; // setup gtm-oauth like normal

HTTPMessage * myMessage = ...; // create the http request like normal

[myMessage authorizeWithGTMOAuth:oauth];

// now create the parser and use the http message etc. like normal

For now the changes and category are only in my fork, but I have a pending pull request with Jim that I will work out the best way to incorporate them into his master repository. My fork also contains tweaks to work with the latest llvm and ARC (although note neither gtm-oauth nor HTTPMessage or AQXMLParser use ARC, so you'll have to add the -fno-objc-arc compiler flag where appropriate).

gtm-outh: http://code.google.com/p/gtm-oauth/

My fork of aqtoolkit: https://github.com/aufflick/aqtoolkit

02:25 AM, 02 Aug 2012 by Mark Aufflick Permalink | Comments (0)

supervisord supervisorctl cheat sheet

On my new server I made the switch from daemontools to supervisor. As if to make daemontools users feel at home the documentation for supervisorctl use is a bit thin :)
So far my biggest gotcha was that after adding a new .conf file in your includes (or to the main file itself, but you wouldn't do that would you?) is that you need to do *both* of the following:

> supervisorctl reread
new.app.conf: available
> supervisorctl update
new.app.conf: added process group
> supervisorctl
new.app         RUNNING ...

 

haproxy

Unfortunately supervisor doesn't offer a way to provide a custom restart command, so doing an uninterrupted haproxy restart via supervisor isn't possible. Instead make sure you have autorestart set to unexpected (the default) rather than true (which is what I usually do) - that way if you want a clean haproxy restart you can just do it yourself at the commandline using the -sf option as normal.

11:14 PM, 25 Mar 2012 by Mark Aufflick Permalink | Comments (0)

SAPI Cocoa SDK

The Cocoa Sensis SAPI SDK is live, ready for this weekend's Sensis SAPI hackathon. https://github.com/pumptheory/SAPI-Cocoa-SDK

SAPI LogoYellow Pages Logo

01:13 AM, 24 Mar 2012 by Mark Aufflick Permalink | Comments (0)

XML

Loading

www.flickr.com