Class: Jirarest2::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/jirarest2/result.rb

Overview

An object of Result contians the result of a Net::HTTP REST request that has a JSON-Body with easily accessable parameters.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(httpResponse) ⇒ Result

Show the result in a more usable form

Parameters:

  • httpResponse (Net::HTTPResponse)


39
40
41
42
43
44
45
46
47
48
# File 'lib/jirarest2/result.rb', line 39

def initialize(httpResponse)
  @code = httpResponse.code
  @header = httpResponse.to_hash
  @body = httpResponse.body
  if httpResponse.instance_of?(Net::HTTPNoContent) or httpResponse.body == "" or httpResponse.body.nil? then # If there is nothing in the body it would be hard to parse it.
    @result = @body
  else
    @result = JSON.parse(@body)
  end
end

Instance Attribute Details

#bodyObject (readonly)

The original body of the result



32
33
34
# File 'lib/jirarest2/result.rb', line 32

def body
  @body
end

#codeObject (readonly)

The statuscode of the result



28
29
30
# File 'lib/jirarest2/result.rb', line 28

def code
  @code
end

#headerObject (readonly)

header lines



30
31
32
# File 'lib/jirarest2/result.rb', line 30

def header
  @header
end

#resultObject (readonly)

The JSON part of the body



34
35
36
# File 'lib/jirarest2/result.rb', line 34

def result
  @result
end