Sha256: ba236956a7fb6578875b32de8e1cc8f9cda3f2852bebb25923c137f4cf44137f

Contents?: true

Size: 1.11 KB

Versions: 53

Compression:

Stored size: 1.11 KB

Contents

class Ey::Core::Client
  class Real
    def upload_file(_params={})
      params = Cistern::Hash.stringify_keys(_params)

      mime_type  = params["mime_type"]
      upload_url = params["upload_url"]

      if string = params["body"]
        request(
          :method  => :put,
          :headers => {"Content-Type" => mime_type},
          :url     => upload_url,
          :body    => string,
        )
      else
        request(
          :method  => :put,
          :headers => {"Content-Type" => "multipart/form-data"},
          :url     => upload_url,
          :body    => Faraday::UploadIO.new(params.fetch("file"), mime_type),
        )
      end
    end
  end # Real

  class Mock
    def upload_file(_params={})
      params = Cistern::Hash.stringify_keys(_params)
      upload_url = params["upload_url"]

      temp_file = Tempfile.new("ey-core")
      temp_file.write(params["body"] || File.read(params.fetch("file")))
      temp_file.close

      self.data[:temp_files][upload_url] = temp_file.path

      response(
        :body   => "",
        :status => 200,
      )
    end
  end # Mock
end # Ey::Core::Client

Version data entries

53 entries across 53 versions & 3 rubygems

Version Path
ey-core-3.6.4 lib/ey-core/requests/upload_file.rb
ey-core-3.6.3 lib/ey-core/requests/upload_file.rb
ey-core-3.6.1 lib/ey-core/requests/upload_file.rb
groove-ey-core-3.6.3 lib/ey-core/requests/upload_file.rb
groove-ey-core-3.6.2 lib/ey-core/requests/upload_file.rb
groove-ey-core-3.6.1 lib/ey-core/requests/upload_file.rb
ey-core-3.5.0 lib/ey-core/requests/upload_file.rb
ey-core-3.4.4 lib/ey-core/requests/upload_file.rb
ey-core-3.4.2 lib/ey-core/requests/upload_file.rb
ey-core-3.4.1 lib/ey-core/requests/upload_file.rb
ey-core-3.4.0 lib/ey-core/requests/upload_file.rb
ey-core-3.3.1 lib/ey-core/requests/upload_file.rb
ey-core-3.3.0 lib/ey-core/requests/upload_file.rb
ey-core-3.2.6 lib/ey-core/requests/upload_file.rb
ey-core-3.2.5 lib/ey-core/requests/upload_file.rb
ey-core-3.2.4 lib/ey-core/requests/upload_file.rb
ey-core-3.2.3 lib/ey-core/requests/upload_file.rb
ey-core-3.2.2 lib/ey-core/requests/upload_file.rb
ey-core-3.2.1 lib/ey-core/requests/upload_file.rb
ey-core-3.2.0 lib/ey-core/requests/upload_file.rb