Class: PkgLookup::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pkglookup/client.rb

Class Method Summary collapse

Class Method Details

.search(term) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pkglookup/client.rb', line 7

def search(term)
    q = URI.escape(term, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
    url = "http://labs.floatboth.com/pkglookup/lookup.json?q=#{q}"

    resp = Net::HTTP.get_response(URI.parse(url))
    data = resp.body

    if data.empty?
        return nil
    end
    result = JSON.parse(data)
    result["results"]

end