lib/ribose/file_uploader.rb in ribose-0.3.1 vs lib/ribose/file_uploader.rb in ribose-0.3.2

- old
+ new

@@ -1,6 +1,8 @@ +require "json" require "faraday" +require "ostruct" module Ribose class FileUploader # Initialize the file uploader # @@ -47,11 +49,12 @@ end end def notify_ribose_file_upload_endpoint(response, key) if response.status.to_i == 200 - Ribose::Request.post(space_file_path, file_attributes.merge(key: key)) + content = Request.post(space_file_path, file_attributes.merge(key: key)) + content.is_a?(Sawyer::Resource) ? content : parse_to_ribose_os(content) end end def faraday_file_io Faraday::UploadIO.new(file.path, file_attributes[:filetype]) @@ -68,10 +71,14 @@ def content_type_form_file require "mime/types" MIME::Types.type_for(file.path).first.content_type end + def parse_to_ribose_os(content) + JSON.parse(content, object_class: Ribose::OpenStruct) + end + def file_attributes @file_attributes ||= { filesize: file.size, filetype: file_content_type, filename: File.basename(file), @@ -87,7 +94,11 @@ builder.request :multipart builder.request :url_encoded Ribose.configuration.add_default_middleware(builder) end end + end + + class OpenStruct < ::OpenStruct + alias :read_attribute_for_serialization :send end end