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 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
- It hasn't been submitted to ruby gems yet so you'll have to build your gem first.
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 use information:
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
- info = get("v2/blog/#{blog_name}/info", {:api_key => Tumblr::consumer_key})
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
- avatar = get("v2/blog/#{blog_name}/avatar", {:size => size})
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, type=false, options={})
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}
@@ -1,6 +1,7 @@
1
1
  module Tumblr
2
2
  class Client
3
3
  module Helper
4
+
4
5
  def valid_options(valid_opts, opts)
5
6
  bad_opts = opts.select { |val| !valid_opts.include?(val) }
6
7
  if !bad_opts.empty?
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
- options[:type] = "photo"
20
- if options.has_key?(:data)
21
- #Probably can be refactored
22
- if options[:data].kind_of?(Array)
23
- count = 0
24
- options[:data].each do |filepath|
25
- options["data[#{count}]"] = File.open(filepath, 'rb').read()
26
- count += 1
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
- options[:type] = "quote"
38
- post("v2/blog/#{blog_name}/post", options)
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
- options[:type] = "text"
43
- post("v2/blog/#{blog_name}/post", options)
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
- options[:type] = "link"
48
- post("v2/blog/#{blog_name}/post", options)
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
- options[:type] = "chat"
53
- post("v2/blog/#{blog_name}/post", options)
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
- options[:type] = "audio"
58
- post("v2/blog/#{blog_name}/post", options)
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
- options[:type] = "video"
63
- post("v2/blog/#{blog_name}/post", options)
64
- end
65
-
66
- def answer(blog_name, options={})
67
- options[:type] = "answer"
68
- post("v2/blog/#{blog_name}/post", options)
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
- end
104
+ end
73
105
  end
data/tumblr.gemspec CHANGED
@@ -18,5 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
19
19
  gem.summary = %q{Tumblr API wrapper}
20
20
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
- gem.version = "0.5"
21
+ gem.version = "0.6"
22
22
  end
metadata CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 5
8
- version: "0.5"
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-03-31 00:00:00 -04:00
16
+ date: 2012-04-09 00:00:00 -04:00
17
17
  default_executable:
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency