lib/tumblr/post.rb in tumblr_client-0.8.2 vs lib/tumblr/post.rb in tumblr_client-0.8.3

- old
+ new

@@ -2,13 +2,17 @@ module Tumblr module Post STANDARD_POST_OPTIONS = [:state, :tags, :tweet, :date, :markdown, :slug, :format] + DATA_POST_TYPES = [:audio, :video, :photo] + VALID_POST_TYPES = DATA_POST_TYPES + [:quote, :text, :link, :chat] def edit(blog_name, options = {}) convert_source_array :source, options + extract_data!(options) if DATA_POST_TYPES.include?(options[:type]) + post(blog_path(blog_name, 'post/edit'), options) end def reblog(blog_name, options = {}) post(blog_path(blog_name, 'post/reblog'), options) @@ -79,10 +83,18 @@ options[:type] = 'video' extract_data!(options) post(post_path(blog_name), options) end + def create_post(type, blog_name, options = {}) + if VALID_POST_TYPES.include?(type) + send(type, blog_name, options) + else + raise ArgumentError.new "\"#{type}\" is not a valid post type" + end + end + private def post_path(blog_name) blog_path(blog_name, 'post') end @@ -103,12 +115,18 @@ if options.has_key?(:data) data = options.delete :data if Array === data data.each.with_index do |filepath, idx| - mime_type = extract_mimetype(filepath) - options["data[#{idx}]"] = Faraday::UploadIO.new(filepath, mime_type) + if filepath.is_a?(Faraday::UploadIO) + options["data[#{idx}]"] = filepath + else + mime_type = extract_mimetype(filepath) + options["data[#{idx}]"] = Faraday::UploadIO.new(filepath, mime_type) + end end + elsif data.is_a?(Faraday::UploadIO) + options["data"] = data else mime_type = extract_mimetype(data) options["data"] = Faraday::UploadIO.new(data, mime_type) end end