Class: BubbleWrap::HTTP::Query
- Inherits:
-
Object
- Object
- BubbleWrap::HTTP::Query
- Defined in:
- motion/http.rb
Overview
Class wrapping NSConnection and often used indirectly by the BubbleWrap::HTTP module methods.
Constant Summary collapse
- CLRF =
"\r\n"
Instance Attribute Summary collapse
-
#connection(connection, didReceiveAuthenticationChallenge: challenge) ⇒ Object
This delegate method get called every time a chunk of data is being received.
-
#credentials ⇒ Object
username & password has a hash.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#post_data ⇒ Object
Returns the value of attribute post_data.
-
#proxy_credential ⇒ Object
credential supplied to proxy servers.
-
#request ⇒ Object
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#response_headers ⇒ Object
readonly
Returns the value of attribute response_headers.
-
#response_size ⇒ Object
readonly
Returns the value of attribute response_size.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Instance Method Summary collapse
- #connectionDidFinishLoading(connection) ⇒ Object
-
#initialize(url_string, http_method = :get, options = {}) ⇒ Query
constructor
Parameters url<String>:: url of the resource to download http_method<Symbol>:: Value representing the HTTP method to use options<Hash>:: optional options used for the query.
- #to_s ⇒ Object (also: #description)
Constructor Details
#initialize(url_string, http_method = :get, options = {}) ⇒ Query
Parameters
- url<String>
-
url of the resource to download
- http_method<Symbol>
-
Value representing the HTTP method to use
- options<Hash>
-
optional options used for the query
Options
:payload<String> - data to pass to a POST, PUT, DELETE query. :delegator - Proc, class or object to call when the file is downloaded. a proc will receive a Response object while the passed object will receive the handle_query_response method :headers<Hash> - headers send with the request Anything else will be available via the options attribute reader.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'motion/http.rb', line 111 def initialize(url_string, http_method = :get, ={}) @method = http_method.upcase.to_s @delegator = .delete(:action) || self @payload = .delete(:payload) @files = .delete(:files) @boundary = .delete(:boundary) || BW.create_uuid @credentials = .delete(:credentials) || {} @credentials = {:username => '', :password => ''}.merge(@credentials) @timeout = .delete(:timeout) || 30.0 @headers = escape_line_feeds(.delete :headers) @format = .delete(:format) @cache_policy = .delete(:cache_policy) || NSURLRequestUseProtocolCachePolicy = @response = HTTP::Response.new @url = create_url(url_string) @body = create_request_body @request = create_request @connection = create_connection(request, self) @connection.start UIApplication.sharedApplication.networkActivityIndicatorVisible = true end |
Instance Attribute Details
#connection(connection, didReceiveAuthenticationChallenge: challenge) ⇒ Object
This delegate method get called every time a chunk of data is being received
149 150 151 |
# File 'motion/http.rb', line 149 def connection @connection end |
#credentials ⇒ Object
username & password has a hash
87 88 89 |
# File 'motion/http.rb', line 87 def credentials @credentials end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
90 91 92 |
# File 'motion/http.rb', line 90 def method @method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
96 97 98 |
# File 'motion/http.rb', line 96 def end |
#post_data ⇒ Object
Returns the value of attribute post_data.
89 90 91 |
# File 'motion/http.rb', line 89 def post_data @post_data end |
#proxy_credential ⇒ Object
credential supplied to proxy servers
88 89 90 |
# File 'motion/http.rb', line 88 def proxy_credential @proxy_credential end |
#request ⇒ Object
Returns the value of attribute request.
85 86 87 |
# File 'motion/http.rb', line 85 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
92 93 94 |
# File 'motion/http.rb', line 92 def response @response end |
#response_headers ⇒ Object (readonly)
Returns the value of attribute response_headers.
94 95 96 |
# File 'motion/http.rb', line 94 def response_headers @response_headers end |
#response_size ⇒ Object (readonly)
Returns the value of attribute response_size.
95 96 97 |
# File 'motion/http.rb', line 95 def response_size @response_size end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
93 94 95 |
# File 'motion/http.rb', line 93 def status_code @status_code end |
Instance Method Details
#connectionDidFinishLoading(connection) ⇒ Object
187 188 189 190 191 192 193 194 |
# File 'motion/http.rb', line 187 def connectionDidFinishLoading(connection) UIApplication.sharedApplication.networkActivityIndicatorVisible = false @request.done_loading! response_body = NSData.dataWithData(@received_data) if @received_data @response.update(status_code: status_code, body: response_body, headers: response_headers, url: @url) call_delegator_with_response end |
#to_s ⇒ Object Also known as: description
136 137 138 139 |
# File 'motion/http.rb', line 136 def to_s "#<#{self.class}:#{self.object_id} - Method: #{@method}, url: #{@url.description}, body: #{@body.description}, Payload: #{@payload}, Headers: #{@headers} Credentials: #{@credentials}, Timeout: #{@timeout}, \ Cache policy: #{@cache_policy}, response: #{@response.inspect} >" end |