lib/finapps/rest/base_client.rb in finapps-2.0.22 vs lib/finapps/rest/base_client.rb in finapps-2.0.23

- old
+ new

@@ -46,10 +46,28 @@ end [result, error_messages] end + # Defines methods to perform HTTP GET, POST, PUT and DELETE requests. + # Returns a hash obtained from parsing the JSON object in the response body. + # + def method_missing(method_id, *arguments, &block) + if %i(get post put delete).include? method_id + connection.send(method_id) do |req| + req.url arguments.first + req.body = arguments[1] unless method_id == :get + end + else + super + end + end + + def respond_to_missing?(method_sym, include_private=false) + [:get, :post, :put, :delete].include?(method_sym) ? true : super + end + private def empty?(response) response.blank? || (response.respond_to?(:body) && response.body.blank?) end @@ -76,11 +94,11 @@ raise error end def handle_client_error(error) logger.warn "#{self.class}##{__method__} => Faraday::Error::ClientError, #{error}" - error.response[:error_messages] || [error.message] + error.response.present? && error.response[:error_messages] ? error.response[:error_messages] : [error.message] end def execute_method(path, method, params) case method when :get @@ -92,27 +110,9 @@ when :delete delete(path, params) else raise FinApps::InvalidArgumentsError.new "Method not supported: #{method}." end - end - - # Defines methods to perform HTTP GET, POST, PUT and DELETE requests. - # Returns a hash obtained from parsing the JSON object in the response body. - # - def method_missing(method_id, *arguments, &block) - if %i(get post put delete).include? method_id - connection.send(method_id) do |req| - req.url arguments.first - req.body = arguments[1] unless method_id == :get - end - else - super - end - end - - def respond_to_missing?(method_name, include_private=false) - %i(get post put delete).include? method_name ? true : super end end end end