Class: PhoenixRails::Request
- Inherits:
-
Object
- Object
- PhoenixRails::Request
- Defined in:
- lib/phoenix_rails/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 ⇒ Object
Constructor Details
#initialize(client, verb, uri, params, body = nil) ⇒ Request
Returns a new instance of Request.
9 10 11 12 13 14 15 |
# File 'lib/phoenix_rails/request.rb', line 9 def initialize(client, verb, uri, params, body = nil) @client, @verb, @uri = client, verb, uri @head = { 'Content-Type' => 'application/json'} @body = body @head[:Authorization] = "Bearer #{@client.generate_authentication_token}" end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/phoenix_rails/request.rb', line 7 def body @body end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
7 8 9 |
# File 'lib/phoenix_rails/request.rb', line 7 def params @params end |
Instance Method Details
#send ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/phoenix_rails/request.rb', line 17 def send http = @client.http_client begin response = http.request(@verb, @uri, @params, @body, @head) rescue HTTPClient::BadResponseError, HTTPClient::TimeoutError, SocketError, Errno::ECONNREFUSED => e error = PhoenixRails::HTTPError.new("#{e.} (#{e.class})") error.original_error = e raise error end body = response.body ? response.body.chomp : nil handle_response(response.code.to_i, body) end |