module HNsearch
The driver
Constants
- VERSION
Public Class Methods
filter(result)
click to toggle source
Example:
>> HNsearch.filter(some_json_object) => Returns result key-value from the JSON object
Arguments:
result: (JSON object)
# File lib/HNsearch.rb, line 43 def self.filter(result) return result.fetch("results") end
items(query)
click to toggle source
Example:
>> HNsearch.items("awesome") => Returns JSON object of the result and then runs print_items
Arguments:
query: (String)
# File lib/HNsearch.rb, line 29 def self.items(query) result = HNsearchAPI.new.query_items(query) print_items filter(result) end
print_items(result)
click to toggle source
# File lib/HNsearch.rb, line 73 def self.print_items(result) result.each { |e| e = e.fetch("item") title = e.fetch("title") url = e.fetch("url") username = e.fetch("username") out = [] out.push "Title: #{title}" out.push "URL: #{url}" out.push "Posted by: https://news.ycombinator.com/user?id=#{username} (#{username})" puts out.join("\n") puts("\n") } end
print_users(result)
click to toggle source
Example:
>> HNsearch.filter(some_json_object) => Returns result key-value from the JSON object
Arguments:
result: (JSON object)
# File lib/HNsearch.rb, line 56 def self.print_users(result) result.each { |e| e = e.fetch("item") username = e.fetch("username") karma = e.fetch("karma") out = [] out.push "Username: #{username}" out.push "Karma: #{karma}" out.push "Profile URL: https://news.ycombinator.com/user?id=#{username}" puts out.join("\n") puts("\n") } end
users(query)
click to toggle source
Example:
>> HNsearch.users("aniketpant") => Returns JSON object of the result and then runs print_users
Arguments:
query: (String)
# File lib/HNsearch.rb, line 15 def self.users(query) result = HNsearchAPI.new.query_users(query) print_users filter(result) end