Class: Avocado::Uploader
- Inherits:
-
Object
- Object
- Avocado::Uploader
- Includes:
- Singleton
- Defined in:
- lib/avocado/uploader.rb
Instance Attribute Summary collapse
-
#payload ⇒ Object
Returns the value of attribute payload.
Instance Method Summary collapse
-
#initialize ⇒ Uploader
constructor
A new instance of Uploader.
- #upload! ⇒ Object
Constructor Details
#initialize ⇒ Uploader
Returns a new instance of Uploader.
7 8 9 |
# File 'lib/avocado/uploader.rb', line 7 def initialize @payload = [] end |
Instance Attribute Details
#payload ⇒ Object
Returns the value of attribute payload.
5 6 7 |
# File 'lib/avocado/uploader.rb', line 5 def payload @payload end |
Instance Method Details
#upload! ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/avocado/uploader.rb', line 11 def upload! return unless should_upload? WebMock.allow_net_connect! if defined? WebMock write_payload_to_json_file do |file| request = Net::HTTP::Post::Multipart.new uri.path, 'file' => UploadIO.new(file, 'text/json', 'avocado.json') net_request = Net::HTTP.new(uri.host, uri.port) net_request.use_ssl = (uri.scheme == 'https') response = net_request.start { |http| http.request(request) } if response.is_a?(Net::HTTPRedirection) raise "Avocado was redirected to '#{response['location']}', update your initializer!" else response end end ensure WebMock.disable_net_connect! if defined? WebMock end |