Class: Kinu::HttpClient::UploadFile

Inherits:
Object
  • Object
show all
Defined in:
lib/kinu/http_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ UploadFile

Returns a new instance of UploadFile.



52
53
54
# File 'lib/kinu/http_client.rb', line 52

def initialize(file)
  @file = file
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object



77
78
79
# File 'lib/kinu/http_client.rb', line 77

def method_missing(*args)
  io.send(*args)
end

Instance Method Details

#content_typeObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/kinu/http_client.rb', line 56

def content_type
  case File.extname(@file.path)
  when '.jpg', '.jpeg'
    'image/jpeg'
  when '.png'
    'image/png'
  when '.gif'
    'image/gif'
  else
    'application/octet-stream'
  end
end

#ioObject



81
82
83
# File 'lib/kinu/http_client.rb', line 81

def io
  @io ||= Faraday::UploadIO.new(@file, content_type, original_filename)
end

#original_filenameObject



69
70
71
# File 'lib/kinu/http_client.rb', line 69

def original_filename
  File.basename(@file.path)
end

#respond_to?(name, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/kinu/http_client.rb', line 73

def respond_to?(name, include_all = false)
  io.respond_to?(name, include_all)
end