Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updates to restrict some stuff when sending data for posts. Bumping v…

…ersion to 0.6
  • Loading branch information...
commit c6d97d7d13a155848ac8535ea317def14c4e472f 1 parent d31fe94
@codingjester authored
View
5 lib/tumblr/blog.rb
@@ -2,11 +2,12 @@ module Tumblr
class Client
module Blog
+ @@standard_options = [:type, :id, :tag, :limit, :offset, :reblog_info, :notes_info, :filter]
#
#Gets the info about the blog
#
def blog_info(blog_name)
- info = get("v2/blog/#{blog_name}/info", {:api_key => Tumblr::consumer_key})
+ get("v2/blog/#{blog_name}/info", {:api_key => Tumblr::consumer_key})
end
#
@@ -14,7 +15,7 @@ def blog_info(blog_name)
#Defaults to 64
#
def avatar(blog_name, size=64)
- avatar = get("v2/blog/#{blog_name}/avatar", {:size => size})
+ get("v2/blog/#{blog_name}/avatar", {:size => size})
end
#
View
1  lib/tumblr/helpers.rb
@@ -1,6 +1,7 @@
module Tumblr
class Client
module Helper
+
def valid_options(valid_opts, opts)
bad_opts = opts.select { |val| !valid_opts.include?(val) }
if !bad_opts.empty?
View
94 lib/tumblr/post.rb
@@ -2,6 +2,8 @@ module Tumblr
class Client
module Post
+ @@standard_post_options = [:state, :tags, :tweet, :date, :markdown, :slug]
+
def edit(blog_name, options={})
post("v2/blog/#{blog_name}/post/edit", options)
end
@@ -16,58 +18,88 @@ def delete(blog_name, id)
end
def photo(blog_name, options={})
- options[:type] = "photo"
- if options.has_key?(:data)
- #Probably can be refactored
- if options[:data].kind_of?(Array)
- count = 0
- options[:data].each do |filepath|
- options["data[#{count}]"] = File.open(filepath, 'rb').read()
- count += 1
+ valid_opts = @@standard_post_options + [:caption, :link, :data, :source]
+ if valid_options(valid_opts, options)
+ options[:type] = "photo"
+ if (options.has_key?(:data) && options.has_key?(:source))
+ raise Exception, "You can only use one parameter, either source or data."
+ end
+ if options.has_key?(:data)
+ #Probably can be refactored
+ if options[:data].kind_of?(Array)
+ count = 0
+ options[:data].each do |filepath|
+ options["data[#{count}]"] = File.open(filepath, 'rb').read()
+ count += 1
+ end
+ options.delete(:data)
+ else
+ options[:data] = File.open(options[:data],'rb').read()
end
- options.delete(:data)
- else
- options[:data] = File.open(options[:data],'rb').read()
end
+ post("v2/blog/#{blog_name}/post", options)
end
- post("v2/blog/#{blog_name}/post", options)
end
def quote(blog_name, options={})
- options[:type] = "quote"
- post("v2/blog/#{blog_name}/post", options)
+ valid_opts = @@standard_post_options + [:quote, :source]
+ if valid_options(valid_opts, options)
+ options[:type] = "quote"
+ post("v2/blog/#{blog_name}/post", options)
+ end
end
def text(blog_name, options={})
- options[:type] = "text"
- post("v2/blog/#{blog_name}/post", options)
+ valid_opts = @@standard_post_options + [:title, :body]
+ if valid_options(valid_opts, options)
+ options[:type] = "text"
+ post("v2/blog/#{blog_name}/post", options)
+ end
end
def link(blog_name, options={})
- options[:type] = "link"
- post("v2/blog/#{blog_name}/post", options)
+ valid_opts = @@standard_post_options + [:title, :url, :description]
+ if valid_options(valid_opts, options)
+ options[:type] = "link"
+ post("v2/blog/#{blog_name}/post", options)
+ end
end
def chat(blog_name, options={})
- options[:type] = "chat"
- post("v2/blog/#{blog_name}/post", options)
+ valid_opts = @@standard_post_options + [:title, :conversation]
+ if valid_options(valid_opts, options)
+ options[:type] = "chat"
+ post("v2/blog/#{blog_name}/post", options)
+ end
end
def audio(blog_name, options={})
- options[:type] = "audio"
- post("v2/blog/#{blog_name}/post", options)
+ valid_opts = @@standard_post_options + [:data, :caption, :external_url]
+ if valid_options(valid_opts, options)
+ options[:type] = "audio"
+ if (options.has_key?(:data) && options.has_key?(:external_url))
+ raise Exception, "You can only use one parameter, either data or external url."
+ end
+ if(options.has_key?(:data))
+ options[:data] = File.open(options[:data],'rb').read()
+ end
+ post("v2/blog/#{blog_name}/post", options)
+ end
end
def video(blog_name, options={})
- options[:type] = "video"
- post("v2/blog/#{blog_name}/post", options)
- end
-
- def answer(blog_name, options={})
- options[:type] = "answer"
- post("v2/blog/#{blog_name}/post", options)
+ valid_opts = @@standard_post_options + [:data, :embed, :caption]
+ if valid_options(valid_opts, options)
+ options[:type] = "video"
+ if (options.has_key?(:data) && options.has_key?(:embed))
+ raise Exception, "You can only use one parameter, either data or embed."
+ end
+ if(options.has_key?(:data))
+ options[:data] = File.open(options[:data],'rb').read()
+ end
+ post("v2/blog/#{blog_name}/post", options)
+ end
end
-
end
- end
+ end
end
View
2  tumblr.gemspec
@@ -18,5 +18,5 @@ Gem::Specification.new do |gem|
gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
gem.summary = %q{Tumblr API wrapper}
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
- gem.version = "0.5"
+ gem.version = "0.6"
end
Please sign in to comment.
Something went wrong with that request. Please try again.