Class: Upload::ImageForest
- Inherits:
-
Object
- Object
- Upload::ImageForest
- Defined in:
- lib/upload/image_forest.rb
Constant Summary collapse
- HOST =
"http://uploads.im/api"
Instance Attribute Summary collapse
-
#image ⇒ Object
readonly
Returns the value of attribute image.
Instance Method Summary collapse
-
#initialize(path) ⇒ ImageForest
constructor
Public: Init a ImageForest Object.
-
#upload ⇒ Object
Public: upload an image to HOST.
Constructor Details
#initialize(path) ⇒ ImageForest
Public: Init a ImageForest Object
path - Image’s path, right now must be an absolute path
Example
path = '/Users/kevin/Desktop/image.jpeg'
image_forest = ImageForest.new(path)
Returns an ImageForest object
TODO:
- path can be a relative path
- how about upload a list of images (idea)
23 24 25 |
# File 'lib/upload/image_forest.rb', line 23 def initialize(path) @image = Image.new(path) end |
Instance Attribute Details
#image ⇒ Object (readonly)
Returns the value of attribute image.
7 8 9 |
# File 'lib/upload/image_forest.rb', line 7 def image @image end |
Instance Method Details
#upload ⇒ Object
Public: upload an image to HOST
Example
Upload::ImageForest.new(path).upload
Returns an Response object
Can be Response::Failure and Response::Success
- If @image isn't exist -> return a Response::Failure with status "File not found
- If response.code is 200 -> return a Response::Success with response object
- If response.code isn't 200 (4x, 5x) -> return a Response::Failure
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/upload/image_forest.rb', line 39 def upload return Response::Failure.new(nil, message: "File is not exist") unless @image.exist? response = RestClient.post HOST, thumb_width: '500', upload: @image.file if response.code == 200 Response::Success.new(response) else Response::Failure.new(response) end end |