# frozen_string_literal: true module StrikeMe module API # The BaseClient module is to be included in objects using the Strike client # to make calls and transform the responses to objects. # Factory of BaseModel instances module BaseClient extend ActiveSupport::Concern def client @client ||= Client.new end module ClassMethods def autoload_default(name) autoload name, "#{"#{self.name}/#{name}".underscore}.rb" end end # cumbersome, but better for later debugging and handling class ResponseError < StandardError attr_reader :url, :response_body, :status, :reason def initialize(url, response_body) @reason = response_body.try(:[], 'data').try(:[], 'message') @status = response_body.try(:[], 'data').try(:[], 'status') super "[#{status}, {}, [\"#{reason}\"]]" if reason @url = url @response_body = response_body end # def inspect # "StrikeMe::API::BaseClient::ResponseError: #{url} status: #{faraday_response.status}" # end end end end end