Class: Namira::Response

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

Overview

HTTP response

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, url, redirect_count, backing) ⇒ Response

Create a new Namira::Response



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

def initialize(method, url, redirect_count, backing)
  @method = method
  @url = url
  @redirect_count = redirect_count
  @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



46
47
48
49
50
51
52
# File 'lib/namira/response.rb', line 46

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

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

#redirect_countObject (readonly)

Returns the value of attribute redirect_count.



11
12
13
# File 'lib/namira/response.rb', line 11

def redirect_count
  @redirect_count
end

#urlObject (readonly)

Returns the value of attribute url.



9
10
11
# File 'lib/namira/response.rb', line 9

def url
  @url
end

Class Method Details

.serialized(raw_response) ⇒ Object



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

def self.serialized(raw_response)
  Namira::Async::Serializer.unserialize_response(raw_response)
end

Instance Method Details

#from_jsonHash, Array

Returns Parse the response body as JSON.

Returns:

  • (Hash, Array)

    Parse the response body as JSON



28
29
30
# File 'lib/namira/response.rb', line 28

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

#ok?Bool

Returns If the response status 2xx.

Returns:

  • (Bool)

    If the response status 2xx



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

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

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

Returns:

  • (Boolean)


54
55
56
# File 'lib/namira/response.rb', line 54

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



34
35
36
# File 'lib/namira/response.rb', line 34

def to_s
  @backing.to_s
end