Class: Progstr::Filer::Uploader
- Inherits:
-
Object
- Object
- Progstr::Filer::Uploader
- Defined in:
- lib/filer/uploader.rb
Instance Method Summary collapse
- #delete_attachment(attachment) ⇒ Object
- #file_info(attachment) ⇒ Object
- #json_headers ⇒ Object
- #upload_attachment(attachment) ⇒ Object
Instance Method Details
#delete_attachment(attachment) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/filer/uploader.rb', line 49 def () raise ApiError.new("message" => "Deleting a blank attachment.") if .blank? url = "#{Progstr::Filer.url_prefix}files/#{.id}" begin response = RestClient.delete(url, json_headers) UploadStatus.new MultiJson.decode(response) rescue MultiJson::DecodeError => unknown_error raise ApiError.new("message" => "Unknown server error when requesting #{url}:\r\n#{unknown_error}") rescue => e raise ApiError.new(MultiJson.decode(e.response)) end end |
#file_info(attachment) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/filer/uploader.rb', line 62 def file_info() raise ApiError.new("message" => "Getting info for a blank attachment.") if .blank? url = "#{Progstr::Filer.url_prefix}files/info/#{.id}" begin response = RestClient.get(url, json_headers) FileInfo.new MultiJson.decode(response) rescue MultiJson::DecodeError => unknown_error raise ApiError.new("message" => "Unknown server error when requesting #{url}:\r\n#{unknown_error}") rescue => e raise ApiError.new(MultiJson.decode(e.response)) end end |
#json_headers ⇒ Object
20 21 22 23 24 25 |
# File 'lib/filer/uploader.rb', line 20 def json_headers { :accept => "application/json", :"X-Progstr-Filer-Auth-Token" => Progstr::Filer.generate_auth_token, } end |
#upload_attachment(attachment) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/filer/uploader.rb', line 27 def () url = "#{Progstr::Filer.url_prefix}upload/new" puts "upload to: #{url}" begin response = RestClient.post(url, { :upload1 => .file, :authToken => Progstr::Filer.generate_auth_token, :uploader => self.class.name, :id => .id }, json_headers) result = UploadStatus.new MultiJson.decode(response) .mark_uploaded! result rescue => e if e.respond_to?(:response) && !e.response.nil? raise ApiError.new(MultiJson.decode(e.response)) else raise end end end |