Class: Wavefront::Type::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/wavefront-sdk/response.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(raw, status) ⇒ Status



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/wavefront-sdk/response.rb', line 92

def initialize(raw, status)
  obj = raw.key?(:status) ? raw[:status] : raw

  @message = obj[:message] || nil
  @code = obj[:code] || status

  @result = if obj[:result]
              obj[:result]
            elsif status == 200
              'OK'
            else
              'ERROR'
            end
end

Instance Attribute Details

#codeInteger (readonly)



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/wavefront-sdk/response.rb', line 86

class Status
  attr_reader :result, :message, :code

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

    @message = obj[:message] || nil
    @code = obj[:code] || status

    @result = if obj[:result]
                obj[:result]
              elsif status == 200
                'OK'
              else
                'ERROR'
              end
  end
end

#messageString (readonly)



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/wavefront-sdk/response.rb', line 86

class Status
  attr_reader :result, :message, :code

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

    @message = obj[:message] || nil
    @code = obj[:code] || status

    @result = if obj[:result]
                obj[:result]
              elsif status == 200
                'OK'
              else
                'ERROR'
              end
  end
end

#resultOK, ERROR (readonly)



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/wavefront-sdk/response.rb', line 86

class Status
  attr_reader :result, :message, :code

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

    @message = obj[:message] || nil
    @code = obj[:code] || status

    @result = if obj[:result]
                obj[:result]
              elsif status == 200
                'OK'
              else
                'ERROR'
              end
  end
end