lib/tumblr/post.rb in tumblr_client-0.8.1 vs lib/tumblr/post.rb in tumblr_client-0.8.2
- old
+ new
@@ -100,20 +100,30 @@
# Look for the various ways that data can be passed, and normalize
# the result in this hash
def extract_data!(options)
if options.has_key?(:data)
data = options.delete :data
- data = [data] unless Array === data
- data.each.with_index do |filepath, idx|
- mime = MIME::Types.type_for(filepath)
- if (!mime.empty?)
- mime_type = MIME::Types.type_for(filepath)[0].content_type
- else
- mime_type = "application/octet-stream"
+
+ if Array === data
+ data.each.with_index do |filepath, idx|
+ mime_type = extract_mimetype(filepath)
+ options["data[#{idx}]"] = Faraday::UploadIO.new(filepath, mime_type)
end
- options["data[#{idx}]"] = Faraday::UploadIO.new(filepath, mime_type)
+ else
+ mime_type = extract_mimetype(data)
+ options["data"] = Faraday::UploadIO.new(data, mime_type)
end
end
+ end
+
+ def extract_mimetype(filepath)
+ mime = MIME::Types.type_for(filepath)
+ if (mime.empty?)
+ mime_type = "application/octet-stream"
+ else
+ mime_type = MIME::Types.type_for(filepath)[0].content_type
+ end
+ mime_type
end
end
end