Skip to content

Commit

Permalink
Create new empty readlist
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewn committed Jul 22, 2012
1 parent 5dd6d8b commit fa0020b
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Gemfile
@@ -1,8 +1,9 @@
source :rubygems

#gem "mechanize"
gem "rest-client"
gem "rest-client", :require => 'rest_client'

group :test, :development do
gem "minitest", :require => 'minitest/autorun'
gem "webmock"
end
20 changes: 20 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,20 @@
GEM
remote: http://rubygems.org/
specs:
addressable (2.3.1)
crack (0.3.1)
mime-types (1.19)
minitest (3.2.0)
rest-client (1.6.7)
mime-types (>= 1.16)
webmock (1.8.7)
addressable (>= 2.2.7)
crack (>= 0.1.7)

PLATFORMS
ruby

DEPENDENCIES
minitest
rest-client
webmock
2 changes: 0 additions & 2 deletions lib/read_list.rb

This file was deleted.

22 changes: 22 additions & 0 deletions lib/readlist.rb
@@ -0,0 +1,22 @@
require "rubygems"
require "bundler/setup"
Bundler.require(:default)

require "json"

class ReadList
attr_reader :url

def self.create
response = RestClient.post('http://readlists.com/api/v1/readlists/', {}.to_json, :content_type => :json, :accept => :json)

raise "#{response.code} is not a 201 response" unless response.code == 201
raise "No location given" unless response.headers[:location]

new({ :url => response.headers[:location] })
end

def initialize(params={})
@url = params[:url]
end
end
9 changes: 0 additions & 9 deletions test/test_read_list.rb

This file was deleted.

24 changes: 24 additions & 0 deletions test/test_readlist.rb
@@ -0,0 +1,24 @@
require 'minitest/autorun'
require 'webmock/minitest'
require './lib/readlist'

class TestReadList < MiniTest::Unit::TestCase
def test_creates_anonymous_readlist
readlist = ReadList.new
refute_nil readlist
end

def test_has_url
stub = stub_request(:post, 'http://readlists.com/api/v1/readlists/')
.with(
:body => {},
:headers => {"Content-Type" => "application/json", "Accept" => "application/json"}
)
.to_return(:status => 201, :headers => { "Location" => "http://readlists.com/api/v1/readlists/075c62a3/"})

readlist = ReadList.create

assert_requested stub
assert_equal readlist.url, 'http://readlists.com/api/v1/readlists/075c62a3/'
end
end

0 comments on commit fa0020b

Please sign in to comment.