Skip to content

Instantly share code, notes, and snippets.

@HopperMCS
Created July 20, 2020 21:34
Show Gist options
  • Save HopperMCS/1fab507d105bcf29b4e4775bccf5f10a to your computer and use it in GitHub Desktop.
Save HopperMCS/1fab507d105bcf29b4e4775bccf5f10a to your computer and use it in GitHub Desktop.
def self.search_by_query(query)
query_f = ERB::Util.url_encode("#{query}")
url = "https://newsapi.org/v2/everything?qInTitle=#{query_f}&pageSize=10&page=1&apiKey=#{self.api_public_key}"
req = URI.open(url)
response_body = req.read
json = JSON.parse(response_body)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment