tumblr-rb 1.3.0 → 2.0.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +7 -0
- data/Gemfile +15 -8
- data/Gemfile.lock +65 -65
- data/LICENSE +4 -2
- data/README.md +31 -84
- data/Rakefile +8 -68
- data/bin/tumblr +3 -133
- data/lib/tumblr.rb +7 -184
- data/lib/tumblr/authentication.rb +71 -0
- data/lib/tumblr/client.rb +148 -0
- data/lib/tumblr/command_line_interface.rb +222 -0
- data/lib/tumblr/credentials.rb +31 -0
- data/lib/tumblr/post.rb +253 -171
- data/lib/tumblr/post/answer.rb +17 -0
- data/lib/tumblr/post/audio.rb +22 -10
- data/lib/tumblr/post/chat.rb +25 -0
- data/lib/tumblr/post/link.rb +22 -9
- data/lib/tumblr/post/photo.rb +29 -10
- data/lib/tumblr/post/quote.rb +17 -10
- data/lib/tumblr/post/text.rb +18 -0
- data/lib/tumblr/post/video.rb +26 -11
- data/lib/tumblr/version.rb +3 -0
- data/lib/tumblr/views/error.erb +6 -0
- data/lib/tumblr/views/form.erb +11 -0
- data/lib/tumblr/views/layout.erb +41 -0
- data/lib/tumblr/views/success.erb +6 -0
- data/man/tumblr.1 +67 -65
- data/man/tumblr.1.html +131 -108
- data/man/tumblr.1.ronn +76 -57
- data/man/tumblr.5 +48 -68
- data/man/tumblr.5.html +106 -114
- data/man/tumblr.5.ronn +38 -51
- data/spec/fixtures/posts.json +10 -0
- data/spec/fixtures/typical_animated_gif.gif +0 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/tumblr/authentication_spec.rb +57 -0
- data/spec/tumblr/client_spec.rb +223 -0
- data/spec/tumblr/credentials_spec.rb +63 -0
- data/spec/tumblr/post_spec.rb +125 -0
- data/tumblr-rb.gemspec +16 -89
- metadata +101 -102
- data/lib/tumblr/authenticator.rb +0 -18
- data/lib/tumblr/post/conversation.rb +0 -15
- data/lib/tumblr/post/regular.rb +0 -14
- data/lib/tumblr/reader.rb +0 -191
- data/lib/tumblr/writer.rb +0 -39
- data/test/fixtures/vcr_cassettes/authenticate/authenticate.yml +0 -39
- data/test/fixtures/vcr_cassettes/read/all_pages.yml +0 -34
- data/test/fixtures/vcr_cassettes/read/authenticated.yml +0 -40
- data/test/fixtures/vcr_cassettes/read/authentication_failure.yml +0 -33
- data/test/fixtures/vcr_cassettes/read/like.yml +0 -31
- data/test/fixtures/vcr_cassettes/read/mwunsch.yml +0 -101
- data/test/fixtures/vcr_cassettes/read/optional.yml +0 -48
- data/test/fixtures/vcr_cassettes/read/pages.yml +0 -36
- data/test/fixtures/vcr_cassettes/read/tumblrgemtest.yml +0 -42
- data/test/fixtures/vcr_cassettes/read/unlike.yml +0 -31
- data/test/fixtures/vcr_cassettes/write/delete.yml +0 -31
- data/test/fixtures/vcr_cassettes/write/edit.yml +0 -31
- data/test/fixtures/vcr_cassettes/write/reblog.yml +0 -31
- data/test/fixtures/vcr_cassettes/write/write.yml +0 -31
- data/test/helper.rb +0 -44
- data/test/test_tumblr.rb +0 -710
data/tumblr-rb.gemspec
CHANGED
@@ -1,94 +1,21 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/tumblr/version', __FILE__)
|
5
3
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Mark Wunsch"]
|
6
|
+
gem.email = ["mark@markwunsch.com"]
|
7
|
+
gem.description = %q{Ruby library and command line utility to interact with the Tumblr API.}
|
8
|
+
gem.summary = %q{Ruby library and command line utility to interact with Tumblr.}
|
9
|
+
gem.homepage = %q{http://github.com/mwunsch/tumblr}
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
s.executables = ["tumblr"]
|
17
|
-
s.extra_rdoc_files = [
|
18
|
-
"LICENSE",
|
19
|
-
"README.md"
|
20
|
-
]
|
21
|
-
s.files = [
|
22
|
-
".gitignore",
|
23
|
-
"Gemfile",
|
24
|
-
"Gemfile.lock",
|
25
|
-
"LICENSE",
|
26
|
-
"README.md",
|
27
|
-
"Rakefile",
|
28
|
-
"bin/tumblr",
|
29
|
-
"lib/tumblr.rb",
|
30
|
-
"lib/tumblr/authenticator.rb",
|
31
|
-
"lib/tumblr/post.rb",
|
32
|
-
"lib/tumblr/post/audio.rb",
|
33
|
-
"lib/tumblr/post/conversation.rb",
|
34
|
-
"lib/tumblr/post/link.rb",
|
35
|
-
"lib/tumblr/post/photo.rb",
|
36
|
-
"lib/tumblr/post/quote.rb",
|
37
|
-
"lib/tumblr/post/regular.rb",
|
38
|
-
"lib/tumblr/post/video.rb",
|
39
|
-
"lib/tumblr/reader.rb",
|
40
|
-
"lib/tumblr/writer.rb",
|
41
|
-
"man/tumblr.1",
|
42
|
-
"man/tumblr.1.html",
|
43
|
-
"man/tumblr.1.ronn",
|
44
|
-
"man/tumblr.5",
|
45
|
-
"man/tumblr.5.html",
|
46
|
-
"man/tumblr.5.ronn",
|
47
|
-
"test/fixtures/vcr_cassettes/authenticate/authenticate.yml",
|
48
|
-
"test/fixtures/vcr_cassettes/read/all_pages.yml",
|
49
|
-
"test/fixtures/vcr_cassettes/read/authenticated.yml",
|
50
|
-
"test/fixtures/vcr_cassettes/read/authentication_failure.yml",
|
51
|
-
"test/fixtures/vcr_cassettes/read/like.yml",
|
52
|
-
"test/fixtures/vcr_cassettes/read/mwunsch.yml",
|
53
|
-
"test/fixtures/vcr_cassettes/read/optional.yml",
|
54
|
-
"test/fixtures/vcr_cassettes/read/pages.yml",
|
55
|
-
"test/fixtures/vcr_cassettes/read/tumblrgemtest.yml",
|
56
|
-
"test/fixtures/vcr_cassettes/read/unlike.yml",
|
57
|
-
"test/fixtures/vcr_cassettes/write/delete.yml",
|
58
|
-
"test/fixtures/vcr_cassettes/write/edit.yml",
|
59
|
-
"test/fixtures/vcr_cassettes/write/reblog.yml",
|
60
|
-
"test/fixtures/vcr_cassettes/write/write.yml",
|
61
|
-
"test/helper.rb",
|
62
|
-
"test/test_tumblr.rb",
|
63
|
-
"tumblr-rb.gemspec"
|
64
|
-
]
|
65
|
-
s.homepage = %q{http://github.com/mwunsch/tumblr}
|
66
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
67
|
-
s.require_paths = ["lib"]
|
68
|
-
s.rubygems_version = %q{1.3.6}
|
69
|
-
s.summary = %q{Ruby wrapper and command line interface to the Tumblr API.}
|
70
|
-
s.test_files = [
|
71
|
-
"test/helper.rb",
|
72
|
-
"test/test_tumblr.rb"
|
73
|
-
]
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "tumblr-rb"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Tumblr::VERSION
|
74
17
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
80
|
-
s.add_runtime_dependency(%q<weary>, [">= 0.7.1"])
|
81
|
-
s.add_runtime_dependency(%q<highline>, [">= 1.5.2"])
|
82
|
-
s.add_development_dependency(%q<bundler>, [">= 0.9.19"])
|
83
|
-
else
|
84
|
-
s.add_dependency(%q<weary>, [">= 0.7.1"])
|
85
|
-
s.add_dependency(%q<highline>, [">= 1.5.2"])
|
86
|
-
s.add_dependency(%q<bundler>, [">= 0.9.19"])
|
87
|
-
end
|
88
|
-
else
|
89
|
-
s.add_dependency(%q<weary>, [">= 0.7.1"])
|
90
|
-
s.add_dependency(%q<highline>, [">= 1.5.2"])
|
91
|
-
s.add_dependency(%q<bundler>, [">= 0.9.19"])
|
92
|
-
end
|
18
|
+
gem.add_runtime_dependency "weary", "~> 1.1.0"
|
19
|
+
gem.add_runtime_dependency "sinatra", "~> 1.3.2"
|
20
|
+
gem.add_runtime_dependency "thor", "~> 0.16.0"
|
93
21
|
end
|
94
|
-
|
metadata
CHANGED
@@ -1,75 +1,74 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: tumblr-rb
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 3
|
8
|
-
- 0
|
9
|
-
version: 1.3.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0.alpha
|
5
|
+
prerelease: 6
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Mark Wunsch
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-10-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: weary
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.1.0
|
22
|
+
type: :runtime
|
22
23
|
prerelease: false
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.1.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sinatra
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.3.2
|
32
38
|
type: :runtime
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: highline
|
36
39
|
prerelease: false
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.3.2
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: thor
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.16.0
|
46
54
|
type: :runtime
|
47
|
-
version_requirements: *id002
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: bundler
|
50
55
|
prerelease: false
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
version_requirements: *id003
|
62
|
-
description: Ruby library and command line utility to work with the Tumblr Blogging Platform, powered by Weary.
|
63
|
-
email: mark@markwunsch.com
|
64
|
-
executables:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.16.0
|
62
|
+
description: Ruby library and command line utility to interact with the Tumblr API.
|
63
|
+
email:
|
64
|
+
- mark@markwunsch.com
|
65
|
+
executables:
|
65
66
|
- tumblr
|
66
67
|
extensions: []
|
67
|
-
|
68
|
-
|
69
|
-
- LICENSE
|
70
|
-
- README.md
|
71
|
-
files:
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
72
70
|
- .gitignore
|
71
|
+
- .travis.yml
|
73
72
|
- Gemfile
|
74
73
|
- Gemfile.lock
|
75
74
|
- LICENSE
|
@@ -77,70 +76,70 @@ files:
|
|
77
76
|
- Rakefile
|
78
77
|
- bin/tumblr
|
79
78
|
- lib/tumblr.rb
|
80
|
-
- lib/tumblr/
|
79
|
+
- lib/tumblr/authentication.rb
|
80
|
+
- lib/tumblr/client.rb
|
81
|
+
- lib/tumblr/command_line_interface.rb
|
82
|
+
- lib/tumblr/credentials.rb
|
81
83
|
- lib/tumblr/post.rb
|
84
|
+
- lib/tumblr/post/answer.rb
|
82
85
|
- lib/tumblr/post/audio.rb
|
83
|
-
- lib/tumblr/post/
|
86
|
+
- lib/tumblr/post/chat.rb
|
84
87
|
- lib/tumblr/post/link.rb
|
85
88
|
- lib/tumblr/post/photo.rb
|
86
89
|
- lib/tumblr/post/quote.rb
|
87
|
-
- lib/tumblr/post/
|
90
|
+
- lib/tumblr/post/text.rb
|
88
91
|
- lib/tumblr/post/video.rb
|
89
|
-
- lib/tumblr/
|
90
|
-
- lib/tumblr/
|
92
|
+
- lib/tumblr/version.rb
|
93
|
+
- lib/tumblr/views/error.erb
|
94
|
+
- lib/tumblr/views/form.erb
|
95
|
+
- lib/tumblr/views/layout.erb
|
96
|
+
- lib/tumblr/views/success.erb
|
91
97
|
- man/tumblr.1
|
92
98
|
- man/tumblr.1.html
|
93
99
|
- man/tumblr.1.ronn
|
94
100
|
- man/tumblr.5
|
95
101
|
- man/tumblr.5.html
|
96
102
|
- man/tumblr.5.ronn
|
97
|
-
-
|
98
|
-
-
|
99
|
-
-
|
100
|
-
-
|
101
|
-
-
|
102
|
-
-
|
103
|
-
-
|
104
|
-
- test/fixtures/vcr_cassettes/read/pages.yml
|
105
|
-
- test/fixtures/vcr_cassettes/read/tumblrgemtest.yml
|
106
|
-
- test/fixtures/vcr_cassettes/read/unlike.yml
|
107
|
-
- test/fixtures/vcr_cassettes/write/delete.yml
|
108
|
-
- test/fixtures/vcr_cassettes/write/edit.yml
|
109
|
-
- test/fixtures/vcr_cassettes/write/reblog.yml
|
110
|
-
- test/fixtures/vcr_cassettes/write/write.yml
|
111
|
-
- test/helper.rb
|
112
|
-
- test/test_tumblr.rb
|
103
|
+
- spec/fixtures/posts.json
|
104
|
+
- spec/fixtures/typical_animated_gif.gif
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
- spec/tumblr/authentication_spec.rb
|
107
|
+
- spec/tumblr/client_spec.rb
|
108
|
+
- spec/tumblr/credentials_spec.rb
|
109
|
+
- spec/tumblr/post_spec.rb
|
113
110
|
- tumblr-rb.gemspec
|
114
|
-
has_rdoc: true
|
115
111
|
homepage: http://github.com/mwunsch/tumblr
|
116
112
|
licenses: []
|
117
|
-
|
118
113
|
post_install_message:
|
119
|
-
rdoc_options:
|
120
|
-
|
121
|
-
require_paths:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
122
116
|
- lib
|
123
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
-
requirements:
|
132
|
-
- - ">="
|
133
|
-
- !ruby/object:Gem::Version
|
134
|
-
segments:
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
segments:
|
135
124
|
- 0
|
136
|
-
|
125
|
+
hash: 1099195226141486085
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>'
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.3.1
|
137
132
|
requirements: []
|
138
|
-
|
139
133
|
rubyforge_project:
|
140
|
-
rubygems_version: 1.
|
134
|
+
rubygems_version: 1.8.23
|
141
135
|
signing_key:
|
142
136
|
specification_version: 3
|
143
|
-
summary: Ruby
|
144
|
-
test_files:
|
145
|
-
-
|
146
|
-
-
|
137
|
+
summary: Ruby library and command line utility to interact with Tumblr.
|
138
|
+
test_files:
|
139
|
+
- spec/fixtures/posts.json
|
140
|
+
- spec/fixtures/typical_animated_gif.gif
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
- spec/tumblr/authentication_spec.rb
|
143
|
+
- spec/tumblr/client_spec.rb
|
144
|
+
- spec/tumblr/credentials_spec.rb
|
145
|
+
- spec/tumblr/post_spec.rb
|
data/lib/tumblr/authenticator.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
class Tumblr
|
2
|
-
class Authenticator < Weary::Base
|
3
|
-
|
4
|
-
headers({"User-Agent" => Tumblr::USER_AGENT})
|
5
|
-
|
6
|
-
def initialize(*credentials)
|
7
|
-
@defaults = {:email => credentials[0], :password => credentials[1]} unless credentials.blank?
|
8
|
-
end
|
9
|
-
|
10
|
-
# http://www.tumblr.com/docs/en/api#authenticate
|
11
|
-
post :authenticate do |auth|
|
12
|
-
auth.url = 'http://www.tumblr.com/api/authenticate'
|
13
|
-
auth.requires = [:email, :password]
|
14
|
-
auth.with = [:'include-theme']
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
data/lib/tumblr/post/regular.rb
DELETED
data/lib/tumblr/reader.rb
DELETED
@@ -1,191 +0,0 @@
|
|
1
|
-
#TODO: Documentation
|
2
|
-
class Tumblr
|
3
|
-
class Reader < Weary::Base
|
4
|
-
|
5
|
-
headers({"User-Agent" => Tumblr::USER_AGENT})
|
6
|
-
|
7
|
-
def initialize(*credentials)
|
8
|
-
@defaults = {:email => credentials[0], :password => credentials[1]} unless credentials.blank?
|
9
|
-
end
|
10
|
-
|
11
|
-
# http://www.tumblr.com/docs/en/api#api_read
|
12
|
-
def read(username, params={})
|
13
|
-
self.class.read username, :get, parameters(params)
|
14
|
-
end
|
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
|
-
|
28
|
-
# http://www.tumblr.com/docs/en/api#authenticated_read
|
29
|
-
def authenticated_read(username, params={})
|
30
|
-
raise 'You must provide an email address and password' unless (params.include?(:email) && params.include?(:password)) || defaults
|
31
|
-
self.class.read username, :post, parameters(params)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Setup parameters for Reads
|
35
|
-
def parameters(params)
|
36
|
-
allowed = [:start,:num,:type,:id,:filter,:tagged,:search,:state,:email,:password]
|
37
|
-
params.merge! defaults if defaults
|
38
|
-
params.reject {|key,value| !allowed.include? key }
|
39
|
-
end
|
40
|
-
|
41
|
-
# Transform ALL of the posts for user/group to Post objects.
|
42
|
-
# This could take a while...
|
43
|
-
def get_all_posts(username, start = 0, total = nil)
|
44
|
-
first_read = authenticated_read(username, {:num => 50,:start => start}).perform
|
45
|
-
raise %Q(Tumblr response was not successful, "#{first_read.code}: #{first_read.message}") if !first_read.success?
|
46
|
-
posts = self.class.get_posts(first_read)
|
47
|
-
offset = start + posts.count
|
48
|
-
post_total = total || first_read['tumblr']['posts']['total'].to_i
|
49
|
-
if post_total > offset
|
50
|
-
posts |= get_all_posts(username, offset, post_total)
|
51
|
-
end
|
52
|
-
posts
|
53
|
-
end
|
54
|
-
|
55
|
-
# Get the Posts as Post objects from a Read response.
|
56
|
-
# Pass an additional type parameter to only get Posts of a certain type.
|
57
|
-
def self.get_posts(response, type = nil)
|
58
|
-
tumblr_post = response['tumblr']['posts']['post']
|
59
|
-
if tumblr_post
|
60
|
-
posts = tumblr_post.respond_to?(:each_pair) ? [tumblr_post] : tumblr_post
|
61
|
-
posts.collect! { |post| build_post(post) }
|
62
|
-
return posts.select {|post| post.is_a?(Tumblr.map(type)) } if type
|
63
|
-
posts
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# Build a Post object from Reader's Post XML
|
68
|
-
def self.build_post(post)
|
69
|
-
setup_post(post) do |tumblr_post|
|
70
|
-
tumblr_post.date = post['date_gmt']
|
71
|
-
tumblr_post.format = post['format'].to_sym if post['format']
|
72
|
-
tumblr_post.slug = post['slug']
|
73
|
-
tumblr_post.tags post['tag'] if post['tag']
|
74
|
-
tumblr_post.reblog_key = post['reblog_key'] if post['reblog_key']
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# Helper method to facilitate standard GET Read and Authenticated Read
|
79
|
-
def self.read(username, via = :get, params = {})
|
80
|
-
Weary.request("http://#{username}.tumblr.com/api/read/", via) do |req|
|
81
|
-
req.with = params unless params.blank?
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# http://www.tumblr.com/docs/en/api#api_dashboard
|
86
|
-
post :dashboard do |dashboard|
|
87
|
-
dashboard.url = "http://www.tumblr.com/api/dashboard"
|
88
|
-
dashboard.requires = [:email,:password]
|
89
|
-
dashboard.with = [:start,:num,:type,:filter,:likes]
|
90
|
-
end
|
91
|
-
|
92
|
-
# http://www.tumblr.com/docs/en/api#api_likes
|
93
|
-
post :likes do |likes|
|
94
|
-
likes.url = "http://www.tumblr.com/api/likes"
|
95
|
-
likes.requires = [:email, :password]
|
96
|
-
likes.with = [:start, :num, :filter]
|
97
|
-
end
|
98
|
-
|
99
|
-
# http://www.tumblr.com/docs/en/api#api_liking
|
100
|
-
post :like do |like|
|
101
|
-
like.url = "http://www.tumblr.com/api/like"
|
102
|
-
like.requires = [:email, :password, :'post-id', :'reblog-key']
|
103
|
-
end
|
104
|
-
|
105
|
-
# http://www.tumblr.com/docs/en/api#api_liking
|
106
|
-
post :unlike do |unlike|
|
107
|
-
unlike.url = "http://www.tumblr.com/api/unlike"
|
108
|
-
unlike.requires = [:email, :password, :'post-id', :'reblog-key']
|
109
|
-
end
|
110
|
-
|
111
|
-
private
|
112
|
-
|
113
|
-
def self.setup_post(post)
|
114
|
-
post_type = post['type'].to_sym
|
115
|
-
tumblr_post = case post_type
|
116
|
-
when :regular
|
117
|
-
build_regular(post)
|
118
|
-
when :photo
|
119
|
-
build_photo(post)
|
120
|
-
when :quote
|
121
|
-
build_quote(post)
|
122
|
-
when :link
|
123
|
-
build_link(post)
|
124
|
-
when :conversation
|
125
|
-
build_conversation(post)
|
126
|
-
when :video
|
127
|
-
build_video(post)
|
128
|
-
when :audio
|
129
|
-
build_audio(post)
|
130
|
-
else
|
131
|
-
raise "#{post_type} is not a recognized Tumblr post type."
|
132
|
-
end
|
133
|
-
yield tumblr_post if block_given?
|
134
|
-
tumblr_post
|
135
|
-
end
|
136
|
-
|
137
|
-
def self.build_regular(post)
|
138
|
-
post_id = post['id']
|
139
|
-
regular = Tumblr::Post::Regular.new(post_id)
|
140
|
-
regular.body = post['regular_body']
|
141
|
-
regular.title = post['regular_title']
|
142
|
-
regular
|
143
|
-
end
|
144
|
-
|
145
|
-
def self.build_photo(post)
|
146
|
-
post_id = post['id']
|
147
|
-
photo = Tumblr::Post::Photo.new(post_id)
|
148
|
-
photo.source = post['photo_url'].first
|
149
|
-
photo.caption = post['photo_caption']
|
150
|
-
photo.click_through_url = post['photo_link_url']
|
151
|
-
photo
|
152
|
-
end
|
153
|
-
|
154
|
-
def self.build_quote(post)
|
155
|
-
post_id = post['id']
|
156
|
-
quote = Tumblr::Post::Quote.new(post['quote_text'], post_id)
|
157
|
-
quote.source = post['quote_source']
|
158
|
-
quote
|
159
|
-
end
|
160
|
-
|
161
|
-
def self.build_link(post)
|
162
|
-
post_id = post['id']
|
163
|
-
link = Tumblr::Post::Link.new(post['link_url'], post_id)
|
164
|
-
link.name = post['link_text']
|
165
|
-
link.description = post['link_description']
|
166
|
-
link
|
167
|
-
end
|
168
|
-
|
169
|
-
def self.build_conversation(post)
|
170
|
-
post_id = post['id']
|
171
|
-
chat = Tumblr::Post::Conversation.new(post['conversation_text'], post_id)
|
172
|
-
chat.title = post['conversation_title']
|
173
|
-
chat
|
174
|
-
end
|
175
|
-
|
176
|
-
def self.build_video(post)
|
177
|
-
post_id = post['id']
|
178
|
-
video = Tumblr::Post::Video.new(post['video_player'], post_id)
|
179
|
-
video.caption = post['video_caption']
|
180
|
-
video
|
181
|
-
end
|
182
|
-
|
183
|
-
def self.build_audio(post)
|
184
|
-
post_id = post['id']
|
185
|
-
audio = Tumblr::Post::Audio.new(post_id)
|
186
|
-
audio.caption = post['audio_caption']
|
187
|
-
audio
|
188
|
-
end
|
189
|
-
|
190
|
-
end
|
191
|
-
end
|