Twitter and Nu with MGTwitterEngine

Here’s a quick demo of Matt Gemmell’s MGTwitterEngine with Nu.

You’ll have to build MGTwitterEngine as a framework; if you don’t know how to do that, post a comment and I’ll add more detail, or see my SmallSockets post for an example Nukefile (or you can use Xcode to build that framework. But you’re not still using Xcode, are you?).

Then put the following in a file, call it “twitter.nu”:

(load "MGTwitterEngine")

(class TwitterDelegate is NSObject
     (- (void) requestSucceeded:(id) identifier is
        (NSLog "success #{identifier}"))
     (- (void) requestFailed:(id) identifier withError:(id *) error is
        (NSLog "failed #{identifier}"))
     (- (void) statusesReceived:(id) statuses forRequest:(id) identifier is
        (NSLog "statusesReceived #{identifier}")
        (set $statuses statuses)
        (puts ($statuses description)))
     (- (void) directMessagesReceived:(id) messages forRequest:(id) identifier is
        (NSLog "directMessagesReceived #{identifier}")
        (set $messages messages)))

(set td ((TwitterDelegate alloc) init))
(set tw ((MGTwitterEngine alloc) initWithDelegate:td))

(tw setUsername:"yourname" password:"yourpassword")

(function run ()
     ((NSRunLoop mainRunLoop) runUntilDate:(NSDate dateWithTimeIntervalSinceNow:0.5)))

(tw sendUpdate:"Post to Twitter with Nu and MGTwitterEngine, details here: http://blog.neontology.com/posts/2008/03/04/twitter-and-nu")
(run)

Set the username and password to your own, then run this in nush.

% nush twitter.nu

That’s it! See Matt’s header files for lots more that you can do with MGTwitterEngine.

Update: build MGTwitterEngine.framework with nuke

Here’s my Nukefile. Put all the Objective-C sources in a subdirectory called “objc”. Build the framework with nuke.

;; source files
(set @m_files     (filelist "^objc/.*.m$"))
(set @frameworks  '("Cocoa" "Nu"))

;; framework description
(set @framework              "MGTwitterEngine")
(set @framework_identifier   "nu.programming.mgte")
(set @framework_creator_code "????")

(compilation-tasks)
(framework-tasks)

(task "clobber" => "clean" is
      (SH "rm -rf #{@framework_dir}"))

(task "default" => "framework")

(task "install" => "framework" is
      (SH "sudo rm -rf /Library/Frameworks/#{@framework}.framework")
      (SH "ditto #{@framework}.framework /Library/Frameworks/#{@framework}.framework"))

Comment on this post ↓

Leave a Comment (sign in with Twitter)