Permalink
Browse files

Reading pages

  • Loading branch information...
mwunsch committed Mar 26, 2010
1 parent bd419dd commit 7ca0d48e16ae2be30b8609a7543271b780e87b96
View
@@ -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
@@ -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:
@@ -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:
View
@@ -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

0 comments on commit 7ca0d48

Please sign in to comment.