Class: CabbageDoc::Response

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, params, response) ⇒ Response

Returns a new instance of Response.



13
14
15
16
17
18
19
# File 'lib/cabbage_doc/response.rb', line 13

def initialize(url, params, response)
  @url = url
  @params = params
  @headers = convert_headers(response)
  @code = response.code
  @body = response.parsed_response
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.parse(s, tag = TAG) ⇒ Object



8
9
10
# File 'lib/cabbage_doc/response.rb', line 8

def parse(s, tag = TAG)
  YAML.load(s)
end

Instance Method Details

#to_jsonObject



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

def to_json
  { 
    url: url,
    query: params.to_query, 
    code: code, 
    headers: prettify(headers),
    body: prettify(body) 
  }.to_json
end

#to_yamlObject



21
22
23
# File 'lib/cabbage_doc/response.rb', line 21

def to_yaml
  YAML.dump(self)
end