Class: Neows::REST::Request
- Inherits:
-
Object
- Object
- Neows::REST::Request
- Defined in:
- lib/neows/rest/request.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(client, request_method, path, klass, options = {}) ⇒ Neows::REST::Request
constructor
Creates an instance of Request.
-
#perform ⇒ Class
Makes the request passing the response into the given class.
- #uri ⇒ String
Constructor Details
#initialize(client, request_method, path, klass, options = {}) ⇒ Neows::REST::Request
Creates an instance of Request
15 16 17 18 19 20 21 |
# File 'lib/neows/rest/request.rb', line 15 def initialize(client, request_method, path, klass, = {}) @client = client @request_method = request_method @path = path.gsub @client.base_url, '' @options = @klass = klass end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6 7 8 |
# File 'lib/neows/rest/request.rb', line 6 def client @client end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/neows/rest/request.rb', line 6 def @options end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/neows/rest/request.rb', line 6 def path @path end |
Instance Method Details
#perform ⇒ Class
Makes the request passing the response into the given class. If a class provides a coerce! method, it will be called to handle custom coercion of data.
32 33 34 35 36 37 |
# File 'lib/neows/rest/request.rb', line 32 def perform response = HTTP.with(request_headers).public_send(@request_method, uri, params: @options) klass = @klass.new JSON.parse(response.to_s).merge(client: @client) klass.coerce! if klass.respond_to?(:coerce!) klass end |
#uri ⇒ String
24 25 26 |
# File 'lib/neows/rest/request.rb', line 24 def uri @client.base_url + @path end |