Class: Pingen::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/pingen/response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, code) ⇒ Response

Returns a new instance of Response.



13
14
15
16
# File 'lib/pingen/response.rb', line 13

def initialize(json, code)
  @json = json
  @code = code
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



5
6
7
# File 'lib/pingen/response.rb', line 5

def code
  @code
end

#jsonObject

Returns the value of attribute json.



5
6
7
# File 'lib/pingen/response.rb', line 5

def json
  @json
end

Class Method Details

.from(response) ⇒ Object



7
8
9
10
11
# File 'lib/pingen/response.rb', line 7

def self.from(response)
  new(JSON.parse(response.body, symbolize_names: true), response.code.to_i)
rescue JSON::ParserError
  new(response.body, response.code.to_i)
end

Instance Method Details

#ok?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/pingen/response.rb', line 18

def ok?
  code == 200
end