tumblr-rb 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/tumblr.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'weary'
2
2
 
3
3
  class Tumblr
4
- VERSION = "1.1.1"
4
+ VERSION = "1.2.0"
5
5
  GENERATOR = "The Tumblr Gem v#{VERSION}"
6
6
  USER_AGENT = "TumblrGem/#{VERSION} (+http://github.com/mwunsch/tumblr)"
7
7
 
@@ -36,9 +36,18 @@ class Tumblr
36
36
  reader.dashboard(parameters)
37
37
  end
38
38
 
39
- def authenticate
39
+ def authenticate(theme = false)
40
40
  raise 'Requires an e-mail address and password' unless @credentials
41
- Authenticator.new(@credentials[:email],@credentials[:password]).authenticate
41
+ params = theme ? {:'include-theme' => 1} : {}
42
+ Authenticator.new(@credentials[:email],@credentials[:password]).authenticate(params)
43
+ end
44
+
45
+ def pages(username)
46
+ reader.pages(username)
47
+ end
48
+
49
+ def all_pages(username)
50
+ reader.all_pages(username)
42
51
  end
43
52
 
44
53
  def reader
@@ -11,6 +11,7 @@ class Tumblr
11
11
  post :authenticate do |auth|
12
12
  auth.url = 'http://www.tumblr.com/api/authenticate'
13
13
  auth.requires = [:email, :password]
14
+ auth.with = [:'include-theme']
14
15
  end
15
16
 
16
17
  end
data/lib/tumblr/reader.rb CHANGED
@@ -13,6 +13,18 @@ class Tumblr
13
13
  self.class.read username, :get, parameters(params)
14
14
  end
15
15
 
16
+ # http://www.tumblr.com/docs/en/api#api_pages
17
+ def pages(username)
18
+ Weary.get("http://#{username}.tumblr.com/api/pages")
19
+ end
20
+
21
+ def all_pages(username)
22
+ raise 'You must provide an email address and password' if defaults.blank?
23
+ Weary.post("http://#{username}.tumblr.com/api/pages") do |req|
24
+ req.with = {:email => defaults[:email], :password => defaults[:password]}
25
+ end
26
+ end
27
+
16
28
  # http://www.tumblr.com/docs/en/api#authenticated_read
17
29
  def authenticated_read(username, params={})
18
30
  raise 'You must provide an email address and password' unless (params.include?(:email) && params.include?(:password)) || defaults
@@ -0,0 +1,34 @@
1
+ ---
2
+ - !ruby/struct:VCR::RecordedResponse
3
+ method: :post
4
+ uri: http://tumblrgemtest.tumblr.com:80/api/pages
5
+ response: !ruby/object:Net::HTTPOK
6
+ body: |
7
+ <?xml version="1.0" encoding="UTF-8"?>
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>
9
+
10
+ body_exist: true
11
+ code: "200"
12
+ header:
13
+ p3p:
14
+ - CP="ALL ADM DEV PSAi COM OUR OTRo STP IND ONL"
15
+ content-type:
16
+ - text/xml
17
+ connection:
18
+ - close
19
+ x-tumblr-usec:
20
+ - D=86883
21
+ server:
22
+ - Apache/2.2.3 (Red Hat)
23
+ date:
24
+ - Fri, 26 Mar 2010 17:35:45 GMT
25
+ content-length:
26
+ - "325"
27
+ x-tumblr-perf:
28
+ - "\"ch:0/ cm:0/ ce:0/ c:0/0 d:0/0 e:0/0\""
29
+ vary:
30
+ - Accept-Encoding
31
+ http_version: "1.1"
32
+ message: OK
33
+ read: true
34
+ socket:
@@ -0,0 +1,36 @@
1
+ ---
2
+ - !ruby/struct:VCR::RecordedResponse
3
+ method: :get
4
+ uri: http://tumblrgemtest.tumblr.com:80/api/pages
5
+ response: !ruby/object:Net::HTTPOK
6
+ body: |
7
+ <?xml version="1.0" encoding="UTF-8"?>
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>
9
+
10
+ body_exist: true
11
+ code: "200"
12
+ header:
13
+ p3p:
14
+ - CP="ALL ADM DEV PSAi COM OUR OTRo STP IND ONL"
15
+ content-type:
16
+ - text/xml
17
+ connection:
18
+ - close
19
+ x-tumblr-usec:
20
+ - D=18293
21
+ server:
22
+ - Apache/2.2.3 (Red Hat)
23
+ date:
24
+ - Fri, 26 Mar 2010 17:21:33 GMT
25
+ content-length:
26
+ - "218"
27
+ x-cache-auto:
28
+ - miss
29
+ x-tumblr-perf:
30
+ - "\"ch:0/ cm:0/ ce:0/ c:0/0 d:0/0 e:0/0\""
31
+ vary:
32
+ - Accept-Encoding
33
+ http_version: "1.1"
34
+ message: OK
35
+ read: true
36
+ socket:
data/test/test_tumblr.rb CHANGED
@@ -110,6 +110,12 @@ link
110
110
  assert_equal auth.uri, tumbl.authenticate.uri
111
111
  end
112
112
 
113
+ test 'can pass include theme params to authenticate method' do
114
+ tumbl = Tumblr.new('test@testermcgee.com','dontrevealmysecrets')
115
+ include_theme = tumbl.authenticate(true)
116
+ assert include_theme.with.split('&').include?("include-theme=1")
117
+ end
118
+
113
119
  test 'executes' do
114
120
  cred = {:email => 'test@testermcgee.com', :password => 'dontrevealmysecrets'}
115
121
  response = VCR.with_cassette('write/write') do
@@ -252,6 +258,21 @@ link
252
258
  end
253
259
  assert_equal 66, posts.count
254
260
  end
261
+
262
+ test 'read pages' do
263
+ reader = Tumblr::Reader.new
264
+ assert_respond_to reader, :pages
265
+ response = hijack! reader.pages('tumblrgemtest'), 'read/pages'
266
+ assert response['tumblr'].has_key?("pages")
267
+ end
268
+
269
+ test 'reads all pages by authenticating' do
270
+ reader = Tumblr::Reader.new('test@testermcgee.com','dontrevealmysecrets')
271
+ assert_respond_to reader, :all_pages
272
+ response = hijack! reader.all_pages('tumblrgemtest'), 'read/all_pages'
273
+ assert_equal 200, response.code
274
+ assert_equal 2, response['tumblr']['pages']['page'].count
275
+ end
255
276
  end
256
277
 
257
278
  describe 'Writer' do
@@ -306,6 +327,11 @@ link
306
327
  assert response.success?
307
328
  assert_equal 'mwunsch', response["tumblr"]["tumblelog"].first["name"]
308
329
  end
330
+
331
+ test 'can include an optional theme' do
332
+ user = Tumblr::Authenticator.new('test@testermcgee.com','dontrevealmysecrets')
333
+ assert user.authenticate(:'include-theme' => 1).with.split('&').include?("include-theme=1")
334
+ end
309
335
  end
310
336
 
311
337
  describe 'Post' do
data/tumblr-rb.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tumblr-rb}
8
- s.version = "1.1.1"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mark Wunsch"]
12
- s.date = %q{2010-03-18}
12
+ s.date = %q{2010-03-26}
13
13
  s.default_executable = %q{tumblr}
14
14
  s.description = %q{Ruby library and command line utility to work with the Tumblr Blogging Platform, powered by Weary.}
15
15
  s.email = %q{mark@markwunsch.com}
@@ -45,11 +45,13 @@ Gem::Specification.new do |s|
45
45
  "man/tumblr.5.html",
46
46
  "man/tumblr.5.ronn",
47
47
  "test/fixtures/vcr_cassettes/authenticate/authenticate.yml",
48
+ "test/fixtures/vcr_cassettes/read/all_pages.yml",
48
49
  "test/fixtures/vcr_cassettes/read/authenticated.yml",
49
50
  "test/fixtures/vcr_cassettes/read/authentication_failure.yml",
50
51
  "test/fixtures/vcr_cassettes/read/like.yml",
51
52
  "test/fixtures/vcr_cassettes/read/mwunsch.yml",
52
53
  "test/fixtures/vcr_cassettes/read/optional.yml",
54
+ "test/fixtures/vcr_cassettes/read/pages.yml",
53
55
  "test/fixtures/vcr_cassettes/read/tumblrgemtest.yml",
54
56
  "test/fixtures/vcr_cassettes/read/unlike.yml",
55
57
  "test/fixtures/vcr_cassettes/write/delete.yml",
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 1
8
- - 1
9
- version: 1.1.1
7
+ - 2
8
+ - 0
9
+ version: 1.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mark Wunsch
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-18 00:00:00 -04:00
17
+ date: 2010-03-26 00:00:00 -04:00
18
18
  default_executable: tumblr
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -95,11 +95,13 @@ files:
95
95
  - man/tumblr.5.html
96
96
  - man/tumblr.5.ronn
97
97
  - test/fixtures/vcr_cassettes/authenticate/authenticate.yml
98
+ - test/fixtures/vcr_cassettes/read/all_pages.yml
98
99
  - test/fixtures/vcr_cassettes/read/authenticated.yml
99
100
  - test/fixtures/vcr_cassettes/read/authentication_failure.yml
100
101
  - test/fixtures/vcr_cassettes/read/like.yml
101
102
  - test/fixtures/vcr_cassettes/read/mwunsch.yml
102
103
  - test/fixtures/vcr_cassettes/read/optional.yml
104
+ - test/fixtures/vcr_cassettes/read/pages.yml
103
105
  - test/fixtures/vcr_cassettes/read/tumblrgemtest.yml
104
106
  - test/fixtures/vcr_cassettes/read/unlike.yml
105
107
  - test/fixtures/vcr_cassettes/write/delete.yml