Class: ChefHandlerLrc::LrcUploader

Inherits:
Object
  • Object
show all
Defined in:
lib/lbn_report_chef/lrc_uploader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ LrcUploader

Returns a new instance of LrcUploader.



8
9
10
# File 'lib/lbn_report_chef/lrc_uploader.rb', line 8

def initialize(opts)
  @options = opts
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/lbn_report_chef/lrc_uploader.rb', line 6

def options
  @options
end

Instance Method Details

#lrc_request(path, body, method = 'post') ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/lbn_report_chef/lrc_uploader.rb', line 12

def lrc_request(path, body, method = 'post')
  uri  = URI.parse(options[:url])
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  req = Net::HTTP.const_get(method.capitalize).new("#{uri}#{path}")
  req.add_field('Accept', 'application/json')
  req.add_field('Content-Type', 'application/json')
  req.body = body.to_json
  response = http.request(req)
  Chef::Log.info("The report API has return: #{response.inspect} from #{uri}#{path}")
  Chef::Log.debug("Report Content: #{body.to_json}")
end