Created
February 21, 2015 01:54
-
-
Save htakeuchi/0da1e1614e3b85a6c3b1 to your computer and use it in GitHub Desktop.
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
class TimelineController < UIViewController | |
def viewDidLoad | |
super | |
@tweets = [] | |
@table = UITableView.alloc.initWithFrame(self.view.bounds) | |
@table.registerClass(TWTRTweetTableViewCell, forCellReuseIdentifier: 'Cell') | |
@table.dataSource = self | |
@table.delegate = self | |
self.view.addSubview @table | |
load_tweets | |
end | |
def load_tweets | |
endpoint = 'https://api.twitter.com/1.1/statuses/home_timeline.json' | |
parameters = {} | |
error = nil | |
client = Twitter.sharedInstance.APIClient | |
request = client.URLRequestWithMethod('GET', | |
URL: endpoint, | |
parameters: parameters, | |
error: error) | |
if error | |
NSLog("Error: #{error}") | |
return | |
end | |
client.sendTwitterRequest(request, | |
completion: Proc.new {|response, data, connectionError| | |
if connectionError | |
NSLog("Error: #{connectionError}") | |
return | |
end | |
jsonError = nil | |
jsonData = NSJSONSerialization.JSONObjectWithData(data, | |
options:NSJSONReadingMutableContainers, | |
error:jsonError) | |
if jsonError | |
NSLog("Error: #{jsonError}") | |
return | |
end | |
@tweets = TWTRTweet.tweetsWithJSONArray(jsonData) | |
@table.reloadData | |
} | |
) | |
end | |
def tableView(tableView, numberOfRowsInSection:section) | |
@tweets.size | |
end | |
def tableView(tableView, cellForRowAtIndexPath:indexPath) | |
cell = @table.dequeueReusableCellWithIdentifier 'Cell' | |
cell.configureWithTweet @tweets[indexPath.row] | |
cell | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment