Module: DevCreek::Transmitter

Defined in:
lib/devcreek_transmitter.rb

Constant Summary collapse

SUBMIT_URL =
"https://devcreek.com/submitData2/"

Class Method Summary collapse

Class Method Details

.submit(the_payload) ⇒ Object

Raises:

  • (Exception)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/devcreek_transmitter.rb', line 16

def Transmitter.submit(the_payload)

  raise Exception.new("Invalid argument: payload cannot be nil") if the_payload.nil?   
  raise Exception.new("Core data not initialized") if DevCreek::Core.instance().project.nil? or 
                                                DevCreek::Core.instance().user.nil?   or
                                                DevCreek::Core.instance().password.nil?
  
  url = URI.parse("#{SUBMIT_URL}#{DevCreek::Core.instance().project}")
  response = nil
  Net::HTTP.start(url.host) do |http|
    http.head(url.request_uri)
    req = Net::HTTP::Post.new(url.path)
    
    #gzip the request_data
    strio = StringIO.new('', 'w')
    gz = Zlib::GzipWriter.new(strio)
    gz.write the_payload
    gz.close
    req.body= strio.string
    req.add_field('Content-Encoding', 'gzip')
    req.add_field('Content-Type', 'application/xml')
    req.basic_auth(DevCreek::Core.instance().user, DevCreek::Core.instance().password) 
    response = http.request(req)
  end
  return response
end