Class: VW::HTTPResult

Inherits:
Object show all
Defined in:
lib/project/volley_wrap/http_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, response_object, error) ⇒ HTTPResult

Returns a new instance of HTTPResult.



5
6
7
8
9
# File 'lib/project/volley_wrap/http_result.rb', line 5

def initialize(response, response_object, error)
  @response = response
  @object = response_object
  @error = error
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



3
4
5
# File 'lib/project/volley_wrap/http_result.rb', line 3

def error
  @error
end

#objectObject

Returns the value of attribute object.



3
4
5
# File 'lib/project/volley_wrap/http_result.rb', line 3

def object
  @object
end

#request_methodObject

Returns the value of attribute request_method.



3
4
5
# File 'lib/project/volley_wrap/http_result.rb', line 3

def request_method
  @request_method
end

#request_paramsObject

Returns the value of attribute request_params.



3
4
5
# File 'lib/project/volley_wrap/http_result.rb', line 3

def request_params
  @request_params
end

#request_urlObject

Returns the value of attribute request_url.



3
4
5
# File 'lib/project/volley_wrap/http_result.rb', line 3

def request_url
  @request_url
end

#responseObject

Returns the value of attribute response.



3
4
5
# File 'lib/project/volley_wrap/http_result.rb', line 3

def response
  @response
end

Instance Method Details

#bodyObject



19
20
21
# File 'lib/project/volley_wrap/http_result.rb', line 19

def body
  @object.to_s if @object
end

#failure?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/project/volley_wrap/http_result.rb', line 48

def failure?
  !!error
end

#headersObject



38
39
40
41
42
# File 'lib/project/volley_wrap/http_result.rb', line 38

def headers
  if @response
    @_headers ||= @response.headers.inject({}){|h, entry_set| h[entry_set[0]] = entry_set[1] ; h }
  end
end

#inspectObject



52
53
54
# File 'lib/project/volley_wrap/http_result.rb', line 52

def inspect
  "<VW::HTTPResult:#{self.object_id} #{@request_url}>"
end

#method_descriptionObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/project/volley_wrap/http_result.rb', line 23

def method_description
  case @request_method
  when 0
    "GET"
  when 1
    "POST"
  when 2
    "PUT"
  when 3
    "DELETE"
  else
    "Unknown"
  end
end

#not_modified?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/project/volley_wrap/http_result.rb', line 15

def not_modified?
  @response.notModified if @response
end

#status_codeObject



11
12
13
# File 'lib/project/volley_wrap/http_result.rb', line 11

def status_code
  @response.statusCode if @response
end

#success?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/project/volley_wrap/http_result.rb', line 44

def success?
  !failure?
end

#to_sObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/project/volley_wrap/http_result.rb', line 56

def to_s
  header_string = if (h = headers)
    h.map{|k,v| "  #{k} = #{v}"}.join("\n")
  else
    "none"
  end

  params_string = if @request_params
    @request_params.map{|k,v| "  #{k} = #{v}"}.join("\n")
  else
    "none"
  end

  %(

Request -------------------------

URL: #{@request_url}
Method: #{method_description}
Params:
#{params_string}

Response -------------------------

Status code: #{status_code}
Not modified?: #{not_modified?}
Success: #{success?}

Error: #{error.toString if error}

Headers:
#{header_string}

Body:
#{body}
-----------------------------------

)
end