Class: Wavefront::Type::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/wavefront-sdk/types/status.rb

Overview

An object which provides information about whether the request was successful or not. Ordinarily this is easy to construct from the API’s JSON response, but some classes, for instance Wavefront::Write fake it by constructing their own.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, status) ⇒ Status

Returns a new instance of Status.

Parameters:

  • response (Hash)

    the API response, turned into a hash

  • status (Integer)

    HTTP status code



30
31
32
33
# File 'lib/wavefront-sdk/types/status.rb', line 30

def initialize(response, status)
  @obj = response.fetch(:status, response)
  @status = status
end

Instance Attribute Details

#codeInteger (readonly)

Returns the HTTP response code from the API request.

Returns:

  • (Integer)

    the HTTP response code from the API request



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/wavefront-sdk/types/status.rb', line 24

class Status
  attr_reader :obj, :status

  # @param response [Hash] the API response, turned into a hash
  # @param status [Integer] HTTP status code
  #
  def initialize(response, status)
    @obj = response.fetch(:status, response)
    @status = status
  end

  def to_s
    obj.inspect.to_s
  end

  def message
    return obj[:message] if obj[:message]
    return obj[:error] if obj[:error]

    nil
  end

  def code
    obj[:code] || status
  end

  def result
    return obj[:result] if obj[:result]
    return 'OK' if status.between?(200, 299)

    'ERROR'
  end
end

#messageString (readonly)

Returns Any informational message from the API.

Returns:

  • (String)

    Any informational message from the API



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/wavefront-sdk/types/status.rb', line 24

class Status
  attr_reader :obj, :status

  # @param response [Hash] the API response, turned into a hash
  # @param status [Integer] HTTP status code
  #
  def initialize(response, status)
    @obj = response.fetch(:status, response)
    @status = status
  end

  def to_s
    obj.inspect.to_s
  end

  def message
    return obj[:message] if obj[:message]
    return obj[:error] if obj[:error]

    nil
  end

  def code
    obj[:code] || status
  end

  def result
    return obj[:result] if obj[:result]
    return 'OK' if status.between?(200, 299)

    'ERROR'
  end
end

#objObject (readonly)

Returns the value of attribute obj.



25
26
27
# File 'lib/wavefront-sdk/types/status.rb', line 25

def obj
  @obj
end

#resultOK, ERROR (readonly)

Returns a string telling us how the request went.

Returns:

  • (OK, ERROR)

    a string telling us how the request went



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/wavefront-sdk/types/status.rb', line 24

class Status
  attr_reader :obj, :status

  # @param response [Hash] the API response, turned into a hash
  # @param status [Integer] HTTP status code
  #
  def initialize(response, status)
    @obj = response.fetch(:status, response)
    @status = status
  end

  def to_s
    obj.inspect.to_s
  end

  def message
    return obj[:message] if obj[:message]
    return obj[:error] if obj[:error]

    nil
  end

  def code
    obj[:code] || status
  end

  def result
    return obj[:result] if obj[:result]
    return 'OK' if status.between?(200, 299)

    'ERROR'
  end
end

#statusObject (readonly)

Returns the value of attribute status.



25
26
27
# File 'lib/wavefront-sdk/types/status.rb', line 25

def status
  @status
end

Instance Method Details

#to_sObject



35
36
37
# File 'lib/wavefront-sdk/types/status.rb', line 35

def to_s
  obj.inspect.to_s
end