Class: Namira::Response

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

Overview

HTTP response

Instance Method Summary collapse

Constructor Details

#initialize(backing) ⇒ Response

Create a new Namira::Response



7
8
9
# File 'lib/namira/response.rb', line 7

def initialize(backing)
  @backing = backing
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

Proxies methods to the backing object



31
32
33
34
35
36
37
# File 'lib/namira/response.rb', line 31

def method_missing(name, *args)
  if @backing.respond_to?(name)
    @backing.send(name, *args)
  else
    super
  end
end

Instance Method Details

#from_jsonHash, Array

Returns Parse the response body as JSON.

Returns:

  • (Hash, Array)

    Parse the response body as JSON



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

def from_json
  @json ||= JSON.parse(@backing.body)
end

#ok?Bool

Returns If the response status 2xx.

Returns:

  • (Bool)

    If the response status 2xx



25
26
27
# File 'lib/namira/response.rb', line 25

def ok?
  (200...300).cover?(@backing.status)
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/namira/response.rb', line 39

def respond_to_missing?(method_name, include_private = false)
  @backing.respond_to?(method_name) || super
end

#to_sString

Returns the response as a string

Returns:

  • (String)

    Returns the response as a string



19
20
21
# File 'lib/namira/response.rb', line 19

def to_s
  @backing.to_s
end