Class: IletiMerkezi::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ileti_merkezi/response.rb

Overview

Response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



14
15
16
17
18
# File 'lib/ileti_merkezi/response.rb', line 14

def initialize(response)
  @response = response
  @code     = response.code.to_i
  @body     = response.body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



12
13
14
# File 'lib/ileti_merkezi/response.rb', line 12

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



12
13
14
# File 'lib/ileti_merkezi/response.rb', line 12

def code
  @code
end

#responseObject (readonly)

Returns the value of attribute response.



12
13
14
# File 'lib/ileti_merkezi/response.rb', line 12

def response
  @response
end

Instance Method Details

#statusObject



20
21
22
# File 'lib/ileti_merkezi/response.rb', line 20

def status
  Status.find(code)
end

#to_hObject Also known as: to_hash



24
25
26
27
28
29
30
31
32
# File 'lib/ileti_merkezi/response.rb', line 24

def to_h
  hash = Ox.load(
    body.force_encoding('utf-8'),
    mode: :hash
  )
  hash.fetch(:response, hash)
rescue Ox::ParseError
  {}
end