Sha256: 97cbca528089100a5a81ea374e778a2b9d12dbd6d6182fa268f7ace321494aef

Contents?: true

Size: 741 Bytes

Versions: 2

Compression:

Stored size: 741 Bytes

Contents

class Sfn::Search
  attr_reader :results, :root_url, :loader
  
  def initialize(root_url, loader)
    @root_url = root_url ? root_url : "http://api.getsatisfaction.com"
    @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)['data']})
      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.4.3 lib/satisfaction/search.rb
pius-ruby-satisfaction-0.4.4 lib/satisfaction/search.rb