diff --git a/lib/readlist.rb b/lib/readlist.rb index eba7ff7..8b9fec2 100644 --- a/lib/readlist.rb +++ b/lib/readlist.rb @@ -22,4 +22,19 @@ def initialize(params={}) @url = params[:url] @session_id = params[:session_id] end + + def title + remote_doc["readlist_title"] + end + + def description + remote_doc["description"] + end + + private + def remote_doc + response = RestClient.get(@url, :content_type => :json, :accept => :json) + raise "#{response.code} is not a 200 response" unless response.code == 200 + JSON.parse(response.body) + end end \ No newline at end of file diff --git a/test/test_readlist.rb b/test/test_readlist.rb index c3269f4..f4334e3 100644 --- a/test/test_readlist.rb +++ b/test/test_readlist.rb @@ -15,6 +15,19 @@ def setup "Location" => "http://readlists.com/api/v1/readlists/075c62a3/", "Set-Cookie" => "sessionid=2847c36286d39d7f10f7c0a9b6a1dd48; expires=Sun, 05-Aug-2012 14:10:48 GMT; httponly; Max-Age=1209600; Path=/" }) + @stubbed_get = stub_request(:get, "http://readlists.com/api/v1/readlists/075c62a3/") + .with( + :body => {}, + :headers => {"Content-Type" => "application/json", "Accept" => "application/json"} + ) + .to_return( + :status => 200, + :headers => { + "Location" => "http://readlists.com/api/v1/readlists/075c62a3/", + "Set-Cookie" => "sessionid=2847c36286d39d7f10f7c0a9b6a1dd48; expires=Sun, 05-Aug-2012 14:10:48 GMT; httponly; Max-Age=1209600; Path=/" + }, + :body => ' +{"date_added": "2012-06-24T18:05:34", "date_updated": "2012-06-24T18:05:35", "description": "", "entries": [{"article": {"article_title": "Surface: Between a Rock and a Hardware\u00a0Place", "author": "John\u00a0Gruber", "date_published": "2012-06-20 00:00:00", "dek": null, "direction": "ltr", "domain": "daringfireball.net", "excerpt": "Watching the Microsoft Surface event video, I sensed uneasiness. Not panic, but discomfort. Some will argue that I’m simply spoiled by Apple’s on-stage polish, but Monday’s…", "id": "bwcylm5k", "lead_image_url": null, "next_page_id": null, "rendered_pages": 1, "short_url": "http://rdd.me/bwcylm5k", "total_pages": 0, "url": "http://daringfireball.net/2012/06/surface_between_rock_and_hardware_place", "word_count": 1388}, "article_url": "http://daringfireball.net/2012/06/surface_between_rock_and_hardware_place", "date_added": "2012-06-24T18:05:35", "date_updated": "2012-06-24T18:05:35", "description": "Watching the Microsoft Surface event video, I sensed uneasiness. Not panic, but discomfort. Some will argue that I’m simply spoiled by Apple’s on-stage polish, but Monday’s…", "entry_title": "Surface: Between a Rock and a Hardware\u00a0Place", "id": "87310", "ordering": 1, "resource_uri": "/api/v1/readlists/075c62a3/entries/87310/"}], "id": "075c62a3", "is_from_edit_id": false, "is_owner": false, "readlist_title": "Untitled Readlist", "resource_uri": "/api/v1/readlists/075c62a3/", "user": null}') end def test_creates_anonymous_readlist @@ -27,4 +40,10 @@ def test_stores_session_for_future_requests readlist = ReadList.create assert_equal "2847c36286d39d7f10f7c0a9b6a1dd48", readlist.session_id end + + def test_gets_title_and_description + readlist = ReadList.create + assert "Untitled Readlist", readlist.title + assert "", readlist.description + end end \ No newline at end of file