Class: Avocado::Uploader

Inherits:
Object
  • Object
show all
Includes:
Logger, Singleton
Defined in:
lib/avocado/uploader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

#logger

Constructor Details

#initializeUploader

Returns a new instance of Uploader.



10
11
12
# File 'lib/avocado/uploader.rb', line 10

def initialize
  reset
end

Instance Attribute Details

#payloadObject

Returns the value of attribute payload.



8
9
10
# File 'lib/avocado/uploader.rb', line 8

def payload
  @payload
end

Instance Method Details

#resetObject



14
15
16
# File 'lib/avocado/uploader.rb', line 14

def reset
  @payload = []
end

#uploadObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/avocado/uploader.rb', line 18

def upload
  return if payload.blank? || url.blank?

  response = Net::HTTP.start(url.host, url.port, use_ssl: https?) do |http|
    http.request multipart_req
  end

  if success? response
    logger.info "Successfully uploaded to #{url}"
  else
    logger.error "Failed to upload to #{url} (response code #{response.code}). Full response:"
    logger.error response.body
  end
end

#urlObject



33
34
35
36
37
38
# File 'lib/avocado/uploader.rb', line 33

def url
  URI.parse Avocado.url.to_s if Avocado.url
rescue URI::InvalidURIError
  logger.error "Could not parse the URI #{Avocado.url}--Avocado will not upload documentation!"
  nil
end