Skip to content

Commit

Permalink
Reads remote title and description
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewn committed Jul 22, 2012
1 parent 8625cc1 commit 46f4a9a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/readlist.rb
Expand Up @@ -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
19 changes: 19 additions & 0 deletions test/test_readlist.rb
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 46f4a9a

Please sign in to comment.