Class: RealPush::Request
- Inherits:
-
Object
- Object
- RealPush::Request
- Defined in:
- lib/realpush/request.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(client, verb, uri, params = {}, body = nil) ⇒ Request
constructor
A new instance of Request.
- #send_async ⇒ Object
- #send_sync ⇒ Object
Constructor Details
#initialize(client, verb, uri, params = {}, body = nil) ⇒ Request
Returns a new instance of Request.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/realpush/request.rb', line 5 def initialize(client, verb, uri, params={}, body = nil) @client, @verb, @uri, @params = client, verb, uri, params raise ConfigurationError, "Invalid verb ('#{verb}')" unless %w{GET POST}.include? verb.to_s.upcase raise ConfigurationError, "Invalid client #{client.inspect}" unless client.is_a? Client raise ConfigurationError, "Invalid uri #{uri.inspect}" unless uri.is_a? URI @head = {} @body = body if body @params[:body_md5] = Digest::MD5.hexdigest(body) @head['Content-Type'] = 'application/json' end sign_params end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/realpush/request.rb', line 3 def body @body end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/realpush/request.rb', line 3 def params @params end |
Instance Method Details
#send_async ⇒ Object
56 57 58 59 |
# File 'lib/realpush/request.rb', line 56 def send_async http = @client.sync_http_client http.request_async(@verb, @uri, @params, @body, @head) end |
#send_sync ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/realpush/request.rb', line 39 def send_sync http = @client.sync_http_client begin response = http.request(@verb, @uri, @params, @body, @head) rescue HTTPClient::BadResponseError, HTTPClient::TimeoutError, SocketError, Errno::ECONNREFUSED => e raise RealPush::HTTPError, "#{e.message} (#{e.class})" end body = response.body ? response.body.chomp : nil return handle_response(response.code.to_i, body) end |