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.
p NSBundle.mainBundle.pathForResource("Pods", ofType:"bridgesupport")
load_bridge_support_file NSBundle.mainBundle.pathForResource("Pods", ofType:"bridgesupport")
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)
@queue = NSOperationQueue.new
refreshData(nil)
end
#NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://gowalla.com/users/mattt.json"]];
#AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
#NSLog(@"Name: %@ %@", [JSON valueForKeyPath:@"first_name"], [JSON valueForKeyPath:@"last_name"]);
#} failure:nil];
def refreshData(sender)
url = NSURL.URLWithString(URL % @handleTextField.stringValue.strip)
@handleTextField.enabled = @reloadButton.enabled = false
@request = ASIHTTPRequest.requestWithURL(url)
@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
#NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
#[queue addOperation:operation];
def numberOfRowsInTableView(tableView)
@tweets.size
end
def refreshData(sender)
url = NSURL.URLWithString("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=alloy")
request = NSURLRequest.requestWithURL(url)
operation = AFJSONRequestOperation.JSONRequestOperationWithRequest(request, success:lambda { |request, response, json|
p json
}, failure:nil)
@queue.addOperation(operation)
p @queue
def tableView(tableView, objectValueForTableColumn:column, row:row)
if tweet = @tweets[row]
tweet['text']
end
end
end
......@@ -3,4 +3,4 @@ platform :osx
generate_bridge_support!
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