Class: FileTurn::Upload
- Defined in:
- lib/fileturn/resources/upload.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params) ⇒ Upload
constructor
A new instance of Upload.
- #method_missing(m, *args, &block) ⇒ Object
- #reload! ⇒ Object
- #upload_file!(file) ⇒ Object
Methods inherited from Resource
Constructor Details
#initialize(params) ⇒ Upload
Returns a new instance of Upload.
23 24 25 |
# File 'lib/fileturn/resources/upload.rb', line 23 def initialize(params) @params = RecursiveOpenStruct.new(params, recurse_over_arrays: true) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
27 28 29 |
# File 'lib/fileturn/resources/upload.rb', line 27 def method_missing(m, *args, &block) @params.send(m) end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
21 22 23 |
# File 'lib/fileturn/resources/upload.rb', line 21 def params @params end |
Class Method Details
Instance Method Details
#reload! ⇒ Object
31 32 33 34 |
# File 'lib/fileturn/resources/upload.rb', line 31 def reload! @params = FileTurn::Upload.find(id).params self end |
#upload_file!(file) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fileturn/resources/upload.rb', line 36 def upload_file!(file) faraday = Faraday.new(:url => url) do |conn| conn.request :multipart conn.adapter :net_http end response = faraday.post '/', fields.to_h.merge(file: Faraday::UploadIO.new(file.path, '')) if response.status != 204 raise FileTurn::BadRequestError.new(response.body) end end |