tumblr_client 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -10
- data/lib/tumblr/blog.rb +6 -5
- data/lib/tumblr/helpers.rb +1 -0
- data/lib/tumblr/post.rb +63 -31
- data/tumblr.gemspec +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -5,13 +5,7 @@ currently available on the [Tumblr API](http://www.tumblr.com/docs/en/api/v2).
|
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
gem build tumblr.gemspec
|
11
|
-
|
12
|
-
Then you can just install with:
|
13
|
-
|
14
|
-
gem install tumblr-0.5.gem
|
8
|
+
gem install tumblr_client
|
15
9
|
|
16
10
|
## Usage
|
17
11
|
|
@@ -38,7 +32,7 @@ That's it! You now have a client that can make any request to the Tumblr API.
|
|
38
32
|
|
39
33
|
### Some quick examples
|
40
34
|
|
41
|
-
Getting
|
35
|
+
Getting user information:
|
42
36
|
|
43
37
|
>> client.info
|
44
38
|
|
@@ -47,8 +41,8 @@ Getting a specific blog's posts and type:
|
|
47
41
|
#Grabbing a specific blogs posts
|
48
42
|
>> client.posts("codingjester.tumblr.com")
|
49
43
|
|
50
|
-
#Grabbing only the last 10 photos off the blog
|
51
|
-
>> client.posts("codingjester.tumblr.com", "photo", :limit => 10)
|
44
|
+
#Grabbing only the last 10 photos off the blog
|
45
|
+
>> client.posts("codingjester.tumblr.com", :type => "photo", :limit => 10)
|
52
46
|
|
53
47
|
|
54
48
|
Posting some photos to Tumblr:
|
data/lib/tumblr/blog.rb
CHANGED
@@ -2,11 +2,12 @@ module Tumblr
|
|
2
2
|
class Client
|
3
3
|
module Blog
|
4
4
|
|
5
|
+
@@standard_options = [:type, :id, :tag, :limit, :offset, :reblog_info, :notes_info, :filter]
|
5
6
|
#
|
6
7
|
#Gets the info about the blog
|
7
8
|
#
|
8
9
|
def blog_info(blog_name)
|
9
|
-
|
10
|
+
get("v2/blog/#{blog_name}/info", {:api_key => Tumblr::consumer_key})
|
10
11
|
end
|
11
12
|
|
12
13
|
#
|
@@ -14,7 +15,7 @@ module Tumblr
|
|
14
15
|
#Defaults to 64
|
15
16
|
#
|
16
17
|
def avatar(blog_name, size=64)
|
17
|
-
|
18
|
+
get("v2/blog/#{blog_name}/avatar", {:size => size})
|
18
19
|
end
|
19
20
|
|
20
21
|
#
|
@@ -26,11 +27,11 @@ module Tumblr
|
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
|
-
def posts(blog_name,
|
30
|
+
def posts(blog_name, options={})
|
30
31
|
url = "v2/blog/#{blog_name}/posts"
|
31
32
|
|
32
|
-
if type
|
33
|
-
url = "#{url}/#{type}"
|
33
|
+
if options.has_key?(:type)
|
34
|
+
url = "#{url}/#{options[:type]}"
|
34
35
|
end
|
35
36
|
|
36
37
|
params = {:api_key => Tumblr::consumer_key}
|
data/lib/tumblr/helpers.rb
CHANGED
data/lib/tumblr/post.rb
CHANGED
@@ -2,6 +2,8 @@ module Tumblr
|
|
2
2
|
class Client
|
3
3
|
module Post
|
4
4
|
|
5
|
+
@@standard_post_options = [:state, :tags, :tweet, :date, :markdown, :slug]
|
6
|
+
|
5
7
|
def edit(blog_name, options={})
|
6
8
|
post("v2/blog/#{blog_name}/post/edit", options)
|
7
9
|
end
|
@@ -16,58 +18,88 @@ module Tumblr
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def photo(blog_name, options={})
|
19
|
-
|
20
|
-
if options
|
21
|
-
|
22
|
-
if options
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
valid_opts = @@standard_post_options + [:caption, :link, :data, :source]
|
22
|
+
if valid_options(valid_opts, options)
|
23
|
+
options[:type] = "photo"
|
24
|
+
if (options.has_key?(:data) && options.has_key?(:source))
|
25
|
+
raise Exception, "You can only use one parameter, either source or data."
|
26
|
+
end
|
27
|
+
if options.has_key?(:data)
|
28
|
+
#Probably can be refactored
|
29
|
+
if options[:data].kind_of?(Array)
|
30
|
+
count = 0
|
31
|
+
options[:data].each do |filepath|
|
32
|
+
options["data[#{count}]"] = File.open(filepath, 'rb').read()
|
33
|
+
count += 1
|
34
|
+
end
|
35
|
+
options.delete(:data)
|
36
|
+
else
|
37
|
+
options[:data] = File.open(options[:data],'rb').read()
|
27
38
|
end
|
28
|
-
options.delete(:data)
|
29
|
-
else
|
30
|
-
options[:data] = File.open(options[:data],'rb').read()
|
31
39
|
end
|
40
|
+
post("v2/blog/#{blog_name}/post", options)
|
32
41
|
end
|
33
|
-
post("v2/blog/#{blog_name}/post", options)
|
34
42
|
end
|
35
43
|
|
36
44
|
def quote(blog_name, options={})
|
37
|
-
|
38
|
-
|
45
|
+
valid_opts = @@standard_post_options + [:quote, :source]
|
46
|
+
if valid_options(valid_opts, options)
|
47
|
+
options[:type] = "quote"
|
48
|
+
post("v2/blog/#{blog_name}/post", options)
|
49
|
+
end
|
39
50
|
end
|
40
51
|
|
41
52
|
def text(blog_name, options={})
|
42
|
-
|
43
|
-
|
53
|
+
valid_opts = @@standard_post_options + [:title, :body]
|
54
|
+
if valid_options(valid_opts, options)
|
55
|
+
options[:type] = "text"
|
56
|
+
post("v2/blog/#{blog_name}/post", options)
|
57
|
+
end
|
44
58
|
end
|
45
59
|
|
46
60
|
def link(blog_name, options={})
|
47
|
-
|
48
|
-
|
61
|
+
valid_opts = @@standard_post_options + [:title, :url, :description]
|
62
|
+
if valid_options(valid_opts, options)
|
63
|
+
options[:type] = "link"
|
64
|
+
post("v2/blog/#{blog_name}/post", options)
|
65
|
+
end
|
49
66
|
end
|
50
67
|
|
51
68
|
def chat(blog_name, options={})
|
52
|
-
|
53
|
-
|
69
|
+
valid_opts = @@standard_post_options + [:title, :conversation]
|
70
|
+
if valid_options(valid_opts, options)
|
71
|
+
options[:type] = "chat"
|
72
|
+
post("v2/blog/#{blog_name}/post", options)
|
73
|
+
end
|
54
74
|
end
|
55
75
|
|
56
76
|
def audio(blog_name, options={})
|
57
|
-
|
58
|
-
|
77
|
+
valid_opts = @@standard_post_options + [:data, :caption, :external_url]
|
78
|
+
if valid_options(valid_opts, options)
|
79
|
+
options[:type] = "audio"
|
80
|
+
if (options.has_key?(:data) && options.has_key?(:external_url))
|
81
|
+
raise Exception, "You can only use one parameter, either data or external url."
|
82
|
+
end
|
83
|
+
if(options.has_key?(:data))
|
84
|
+
options[:data] = File.open(options[:data],'rb').read()
|
85
|
+
end
|
86
|
+
post("v2/blog/#{blog_name}/post", options)
|
87
|
+
end
|
59
88
|
end
|
60
89
|
|
61
90
|
def video(blog_name, options={})
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
91
|
+
valid_opts = @@standard_post_options + [:data, :embed, :caption]
|
92
|
+
if valid_options(valid_opts, options)
|
93
|
+
options[:type] = "video"
|
94
|
+
if (options.has_key?(:data) && options.has_key?(:embed))
|
95
|
+
raise Exception, "You can only use one parameter, either data or embed."
|
96
|
+
end
|
97
|
+
if(options.has_key?(:data))
|
98
|
+
options[:data] = File.open(options[:data],'rb').read()
|
99
|
+
end
|
100
|
+
post("v2/blog/#{blog_name}/post", options)
|
101
|
+
end
|
69
102
|
end
|
70
|
-
|
71
103
|
end
|
72
|
-
|
104
|
+
end
|
73
105
|
end
|
data/tumblr.gemspec
CHANGED
metadata
CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
version: "0.
|
7
|
+
- 6
|
8
|
+
version: "0.6"
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- John Bunting
|
@@ -13,7 +13,7 @@ autorequire:
|
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
15
|
|
16
|
-
date: 2012-
|
16
|
+
date: 2012-04-09 00:00:00 -04:00
|
17
17
|
default_executable:
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|