Skip to content

Commit

Permalink
Reading pages
Browse files Browse the repository at this point in the history
  • Loading branch information
mwunsch committed Mar 26, 2010
1 parent bd419dd commit 7ca0d48
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/tumblr/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ def read(username, params={})
self.class.read username, :get, parameters(params)
end

# http://www.tumblr.com/docs/en/api#api_pages
def pages(username)
Weary.get("http://#{username}.tumblr.com/api/pages")
end

def all_pages(username)
raise 'You must provide an email address and password' if defaults.blank?
Weary.post("http://#{username}.tumblr.com/api/pages") do |req|
req.with = {:email => defaults[:email], :password => defaults[:password]}
end
end

# http://www.tumblr.com/docs/en/api#authenticated_read
def authenticated_read(username, params={})
raise 'You must provide an email address and password' unless (params.include?(:email) && params.include?(:password)) || defaults
Expand Down
34 changes: 34 additions & 0 deletions test/fixtures/vcr_cassettes/read/all_pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- !ruby/struct:VCR::RecordedResponse
method: :post
uri: http://tumblrgemtest.tumblr.com:80/api/pages
response: !ruby/object:Net::HTTPOK
body: |
<?xml version="1.0" encoding="UTF-8"?>
<tumblr version="1.0"><pages><page url="http://tumblrgemtest.tumblr.com/test1" render-in-theme="true" title="Page Test 1" link-title="Page Test 1">Test #1</page><page url="http://tumblrgemtest.tumblr.com/test2" render-in-theme="true" title="Page Test 2">Whatsup</page></pages></tumblr>
body_exist: true
code: "200"
header:
p3p:
- CP="ALL ADM DEV PSAi COM OUR OTRo STP IND ONL"
content-type:
- text/xml
connection:
- close
x-tumblr-usec:
- D=86883
server:
- Apache/2.2.3 (Red Hat)
date:
- Fri, 26 Mar 2010 17:35:45 GMT
content-length:
- "325"
x-tumblr-perf:
- "\"ch:0/ cm:0/ ce:0/ c:0/0 d:0/0 e:0/0\""
vary:
- Accept-Encoding
http_version: "1.1"
message: OK
read: true
socket:
36 changes: 36 additions & 0 deletions test/fixtures/vcr_cassettes/read/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
- !ruby/struct:VCR::RecordedResponse
method: :get
uri: http://tumblrgemtest.tumblr.com:80/api/pages
response: !ruby/object:Net::HTTPOK
body: |
<?xml version="1.0" encoding="UTF-8"?>
<tumblr version="1.0"><pages><page url="http://tumblrgemtest.tumblr.com/test1" render-in-theme="true" title="Page Test 1" link-title="Page Test 1">Test #1</page></pages></tumblr>
body_exist: true
code: "200"
header:
p3p:
- CP="ALL ADM DEV PSAi COM OUR OTRo STP IND ONL"
content-type:
- text/xml
connection:
- close
x-tumblr-usec:
- D=18293
server:
- Apache/2.2.3 (Red Hat)
date:
- Fri, 26 Mar 2010 17:21:33 GMT
content-length:
- "218"
x-cache-auto:
- miss
x-tumblr-perf:
- "\"ch:0/ cm:0/ ce:0/ c:0/0 d:0/0 e:0/0\""
vary:
- Accept-Encoding
http_version: "1.1"
message: OK
read: true
socket:
15 changes: 14 additions & 1 deletion test/test_tumblr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,20 @@ class TestTumblr < Test::Unit::TestCase
assert_equal 66, posts.count
end

# test 'pages'
test 'read pages' do
reader = Tumblr::Reader.new
assert_respond_to reader, :pages
response = hijack! reader.pages('tumblrgemtest'), 'read/pages'
assert response['tumblr'].has_key?("pages")
end

test 'reads all pages by authenticating' do
reader = Tumblr::Reader.new('test@testermcgee.com','dontrevealmysecrets')
assert_respond_to reader, :all_pages
response = hijack! reader.all_pages('tumblrgemtest'), 'read/all_pages'
assert_equal 200, response.code
assert_equal 2, response['tumblr']['pages']['page'].count
end
end

describe 'Writer' do
Expand Down

0 comments on commit 7ca0d48

Please sign in to comment.