Skip to content

Commit

Permalink
Construct epub url
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewn committed Jul 22, 2012
1 parent 0c0399a commit 1a1d90b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/readlist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ class ReadList

module Util
def extract_id_from_url(url)
begin
url.match(%r{http://readlists.com/api/v1/readlists/(.*)/})[1]
rescue
nil
end
end
end

Expand All @@ -25,6 +30,8 @@ def self.create
new({ :url => response.headers[:location], :session_id => session_id })
end

include Util

def initialize(params={})
@url = params[:url]
@session_id = params[:session_id]
Expand Down Expand Up @@ -60,7 +67,8 @@ def add_article(article_url)
end

def epub_url

id = extract_id_from_url(@url)
"http://readlists.com/#{id}/download/epub"
end

private
Expand Down
9 changes: 8 additions & 1 deletion test/test_readlist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,15 @@ def test_persists_articles
assert_requested @stubbed_create_entry
end

# :todo move into own unit test
def test_extracts_id_from_url
assert_equal "12345", ReadList::Helper.extract_id_from_url("http://readlists.com/api/v1/readlists/12345/")
util = Class.new do
include ReadList::Util
end.new

assert_equal "12345", util.extract_id_from_url("http://readlists.com/api/v1/readlists/12345/")
assert_equal "075c62a3", util.extract_id_from_url("http://readlists.com/api/v1/readlists/075c62a3/")
assert_equal nil, util.extract_id_from_url("http://www.bbc.co.uk/news/business-18944097")
end

def test_exposes_epub_url
Expand Down

0 comments on commit 1a1d90b

Please sign in to comment.