require "consumer_score/version" require "unirest" module Consumer class Score attr_accessor :income, :zipcode, :age def initialize(query_hash) @income = query_hash["income"] @zipcode = query_hash["zipcode"] @age = query_hash["age"] end def self.where(query_hash) search_string = convert_query_hash_to_string(query_hash) response = Unirest.get("http://localhost:3000/customer_scoring.json?#{search_string}").body end def self.convert_query_hash_to_string(query_hash) search_array = [] query_hash.each do |key, value| search_array << "#{key}=#{value}" end search_string = search_array.join("&") end end end