lib/checkr/api_class.rb in checkr-official-1.0.0 vs lib/checkr/api_class.rb in checkr-official-1.0.1

- old
+ new

@@ -155,15 +155,19 @@ end end def inspect id_string = (self.respond_to?(:id) && !self.id.nil?) ? " id=#{self.id}" : "" - "#<#{self.class}:0x#{self.object_id.to_s(16)}#{id_string}> JSON: " + JSON.pretty_generate(json) + "#<#{self.class}:0x#{self.object_id.to_s(16)}#{id_string}> JSON: " + JSON.pretty_generate(attributes) end + def to_s(*args) + JSON.pretty_generate(non_nil_attributes) + end + def to_json(*a) - JSON.generate(json) + JSON.generate(non_nil_attributes) end private @@ -238,11 +242,11 @@ arg_names = out_arg_names.dup if out_arg_names default_params = out_default_params # dont need to dup this since it isn't modified directly validate_args(arg_names, *args) arguments = compose_arguments(method, arg_names, *args) - composed_path = compose_api_path(path, arguments) + composed_path = compose_api_path(path, arguments, arguments[:params]) unused_args = determine_unused_args(path, arg_names, arguments) arguments[:params] = compose_params(arguments[:params], unused_args, default_params) resp = Checkr.request(method, composed_path, arguments[:params], arguments[:opts]) @@ -334,21 +338,22 @@ end def compose_arguments(method, arg_names, *args) self.class.compose_arguments(method, arg_names, *args) end - def self.compose_api_path(path, arguments, this=self) + def self.compose_api_path(path, arguments, params={}, this=self) # Setup the path using the following attribute order: # 1. Args passed in # 2. Args on this # 3. Args on this.class ret = (path || this.path || "").dup if ret.include?(":") missing = Set.new matches = ret.scan(/:([^\/]*)/).flatten.map(&:to_sym) matches.each do |match| value = arguments[match] + value ||= params[match] || params[match.to_s] begin value ||= this.send(match) rescue NoMethodError end begin @@ -367,11 +372,11 @@ raise InvalidRequestError.new("Could not determine the full URL to request. Missing the following values: #{missing.to_a.join(', ')}.") end end ret end - def compose_api_path(path, arguments) - self.class.compose_api_path(path, arguments, self) + def compose_api_path(path, arguments, params={}) + self.class.compose_api_path(path, arguments, params, self) end def self.determine_unused_args(path, arg_names, arguments, this=self) unused = Set.new(arg_names) path ||= this.path