Class: Patchboard::Response

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

Defined Under Namespace

Modules: Headers

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Response

Returns a new instance of Response.



47
48
49
50
51
52
53
54
55
56
# File 'lib/patchboard/response.rb', line 47

def initialize(raw)
  @raw = raw
  if @raw.headers["Content-Type"]
    if @raw.headers["Content-Type"] =~ %r{application/.*json}
      @data = JSON.parse @raw.body, :symbolize_names => true
    end
  end
  @parsed_headers = {}
  parse_headers
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/patchboard/response.rb', line 67

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

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



46
47
48
# File 'lib/patchboard/response.rb', line 46

def data
  @data
end

#parsed_headersObject (readonly)

Returns the value of attribute parsed_headers.



46
47
48
# File 'lib/patchboard/response.rb', line 46

def parsed_headers
  @parsed_headers
end

#rawObject (readonly)

Returns the value of attribute raw.



46
47
48
# File 'lib/patchboard/response.rb', line 46

def raw
  @raw
end

#resourceObject

Returns the value of attribute resource.



45
46
47
# File 'lib/patchboard/response.rb', line 45

def resource
  @resource
end

Instance Method Details

#parse_headersObject



58
59
60
61
62
63
64
65
# File 'lib/patchboard/response.rb', line 58

def parse_headers
  @raw.headers.each do |name, string|
    case name
    when /www-authenticate/i
      @parsed_headers["WWW-Authenticate"] = Headers.parse_www_auth(string)
    end
  end
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/patchboard/response.rb', line 75

def respond_to?(*args)
  @raw.respond_to?(*args) || super
end