Class: FinAppsCore::REST::BaseClient
- Inherits:
-
Object
- Object
- FinAppsCore::REST::BaseClient
- Includes:
- Connection, Utils::Loggeable, Utils::Validatable
- Defined in:
- lib/finapps_core/rest/base_client.rb
Overview
base client functionality
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#connection ⇒ Object
Returns an initialized Faraday connection object.
-
#initialize(options, logger = nil) ⇒ BaseClient
constructor
A new instance of BaseClient.
-
#method_missing(method_id, *arguments, &block) ⇒ Object
Defines methods to perform HTTP GET, POST, PUT and DELETE requests.
- #respond_to_missing?(method_sym, include_private = false) ⇒ Boolean
-
#send_request(path, method, params = {}) ⇒ Hash, Array<String>
Performs HTTP GET, POST, UPDATE and DELETE requests.
Methods included from Connection
#connection_options, #faraday, #init_connection_auth, #init_connection_request, #init_connection_response
Methods included from Utils::Validatable
Methods included from Utils::Loggeable
Constructor Details
#initialize(options, logger = nil) ⇒ BaseClient
Returns a new instance of BaseClient.
21 22 23 24 |
# File 'lib/finapps_core/rest/base_client.rb', line 21 def initialize(, logger = nil) @config = ::FinAppsCore::REST::Configuration.new @logger = logger end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *arguments, &block) ⇒ Object
Defines methods to perform HTTP GET, POST, PUT and DELETE requests. Returns a hash obtained from parsing the JSON object in the response body.
55 56 57 58 59 60 61 |
# File 'lib/finapps_core/rest/base_client.rb', line 55 def method_missing(method_id, *arguments, &block) if %i[get post put delete].include? method_id send_to_connection method_id, arguments else super end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
19 20 21 |
# File 'lib/finapps_core/rest/base_client.rb', line 19 def config @config end |
Instance Method Details
#connection ⇒ Object
Returns an initialized Faraday connection object.
29 30 31 |
# File 'lib/finapps_core/rest/base_client.rb', line 29 def connection @connection ||= faraday(config, logger) end |
#respond_to_missing?(method_sym, include_private = false) ⇒ Boolean
63 64 65 |
# File 'lib/finapps_core/rest/base_client.rb', line 63 def respond_to_missing?(method_sym, include_private = false) %i[get post put delete].include?(method_sym) ? true : super end |
#send_request(path, method, params = {}) ⇒ Hash, Array<String>
Performs HTTP GET, POST, UPDATE and DELETE requests. You shouldn’t need to use this method directly, but it can be useful for debugging. Returns a hash obtained from parsing the JSON object in the response body.
42 43 44 45 46 47 48 49 50 |
# File 'lib/finapps_core/rest/base_client.rb', line 42 def send_request(path, method, params = {}) not_blank(path, :path) not_blank(method, :method) response, = execute_request(method, path, params) result = block_given? ? yield(response) : response_body(response) [result, ] end |