Sha256: 4919e68799ed58f4a6653f226b6b0793a7b8c5b812b3fb519dd3b4a0a3f73a8a

Contents?: true

Size: 687 Bytes

Versions: 2

Compression:

Stored size: 687 Bytes

Contents

class Sfn::Search
  attr_reader :results, :root_url, :loader
  
  def initialize(root_url, loader)
    @root_url = root_url
    @loader = loader
    @results = {}
  end
  
  def for_likely_matches_to(name, entities = %w(companies products))
    @results = entities.inject({}) {|hash, entity|
      query_string = "#{@root_url}/#{entity}.json?q=#{name}"
      #result = Net::HTTP.get_response(URI.parse(query_string)).body
      answer = @loader.get(query_string)
      if answer[0] == :ok
        result = answer[1]
        hash.merge({entity => JSON.parse(result)})
      else
        raise "Search service not available at the moment, please try again later."
      end
    }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pius-ruby-satisfaction-0.3.0 lib/satisfaction/search.rb
pius-ruby-satisfaction-0.4.0 lib/satisfaction/search.rb