Commit 78c554e3 authored by Eloy Duran's avatar Eloy Duran

Make the MacRubySample load a twitter feed by using ASIHTTPRequest and SBJson.

parent ecbb384d
# Load the BridgeSupport metadata generated by CocoaPods from all dependencies. # Load the BridgeSupport metadata generated by CocoaPods from all dependencies.
p NSBundle.mainBundle.pathForResource("Pods", ofType:"bridgesupport")
load_bridge_support_file NSBundle.mainBundle.pathForResource("Pods", ofType:"bridgesupport") load_bridge_support_file NSBundle.mainBundle.pathForResource("Pods", ofType:"bridgesupport")
class AppDelegate class AppDelegate
attr_accessor :window URL = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=%s"
attr_accessor :window, :tableView, :reloadButton, :handleTextField
def awakeFromNib
@tweets = []
@handleTextField.stringValue = "alloy"
end
def applicationDidFinishLaunching(notification) def applicationDidFinishLaunching(notification)
@queue = NSOperationQueue.new refreshData(nil)
end end
#NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://gowalla.com/users/mattt.json"]]; def refreshData(sender)
#AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { url = NSURL.URLWithString(URL % @handleTextField.stringValue.strip)
#NSLog(@"Name: %@ %@", [JSON valueForKeyPath:@"first_name"], [JSON valueForKeyPath:@"last_name"]); @handleTextField.enabled = @reloadButton.enabled = false
#} failure:nil];
#NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; @request = ASIHTTPRequest.requestWithURL(url)
#[queue addOperation:operation]; @request.completionBlock = lambda do
puts "Request completed!"
@tweets = @request.responseString.JSONValue
@tableView.reloadData
@handleTextField.enabled = @reloadButton.enabled = true
end
@request.failedBlock = lambda do
puts "Request failed :("
puts @request.error.localizedDescription
@handleTextField.enabled = @reloadButton.enabled = true
end
@request.startAsynchronous
end
def refreshData(sender) def numberOfRowsInTableView(tableView)
url = NSURL.URLWithString("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=alloy") @tweets.size
request = NSURLRequest.requestWithURL(url) end
operation = AFJSONRequestOperation.JSONRequestOperationWithRequest(request, success:lambda { |request, response, json|
p json def tableView(tableView, objectValueForTableColumn:column, row:row)
}, failure:nil) if tweet = @tweets[row]
@queue.addOperation(operation) tweet['text']
p @queue end
end end
end end
...@@ -3,4 +3,4 @@ platform :osx ...@@ -3,4 +3,4 @@ platform :osx
generate_bridge_support! generate_bridge_support!
dependency 'ASIHTTPRequest' dependency 'ASIHTTPRequest'
dependency 'CocoaLumberjack' dependency 'SBJson'
This example uses MacRuby which needs Garbage Collection support. Since CocoaPods
does not yet have a way to make a project build with GC support, you will have to
do this manually in the generated Pods.xcodeproj project.
You can find it in the build settings of the target app.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment