Class: TNSPayments::Request
- Inherits:
-
Object
- Object
- TNSPayments::Request
- Defined in:
- lib/tns_payments/request.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#method ⇒ Object
Returns the value of attribute method.
-
#path ⇒ Object
Returns the value of attribute path.
-
#payload ⇒ Object
Returns the value of attribute payload.
Instance Method Summary collapse
-
#headers ⇒ Object
Public: A hash representing the headers for the request.
-
#initialize(connection, method, path, payload = nil) ⇒ Request
constructor
A new instance of Request.
-
#perform ⇒ Object
Public: Execute the request.
Constructor Details
#initialize(connection, method, path, payload = nil) ⇒ Request
Returns a new instance of Request.
8 9 10 11 12 13 |
# File 'lib/tns_payments/request.rb', line 8 def initialize connection, method, path, payload = nil self.connection = connection self.method = method self.path = path self.payload = payload end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
6 7 8 |
# File 'lib/tns_payments/request.rb', line 6 def connection @connection end |
#method ⇒ Object
Returns the value of attribute method.
6 7 8 |
# File 'lib/tns_payments/request.rb', line 6 def method @method end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/tns_payments/request.rb', line 6 def path @path end |
#payload ⇒ Object
Returns the value of attribute payload.
6 7 8 |
# File 'lib/tns_payments/request.rb', line 6 def payload @payload end |
Instance Method Details
#headers ⇒ Object
Public: A hash representing the headers for the request.
Returns a hash of headers.
18 19 20 21 22 23 24 |
# File 'lib/tns_payments/request.rb', line 18 def headers headers = {} headers[:accept] = '*/*' headers[:content_type] = 'Application/json;charset=UTF-8' headers[:Authorization] = encode_credentials headers end |
#perform ⇒ Object
Public: Execute the request.
Returns a response object.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tns_payments/request.rb', line 29 def perform args = { :method => method, :url => url, :headers => headers, :timeout => 120, :open_timeout => 30 } args[:payload] = payload.to_json if payload Response.new RestClient::Request.execute(args) rescue RestClient::Exception => e response = e.response if e.is_a?(RestClient::RequestTimeout) response = JSON.generate({:error => {:cause => 'REQUEST_TIMEDOUT'}}) end ErrorResponse.new response end |