Skip to content

ldodds/fullfact.rb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Full Fact API Ruby Client

Quickly hacked together client for the FullFact Alpha API

The API itself is simple and easy to use. This code just provides some convenience methods for interacting with the API to grab a list of fact checks, search the API, etc.

Searching and walking the API

#supply token to authenticate
api = FullFact::API.new(token: ...)

first = true

#optionally provide search term to restrict results
#recommended: include a sleep (ms) parameter to be polite
#block is called for each page until API doesn't return further results
api.harvest(search: ..., sleep: 1) do |page|
  $stderr.puts "Found #{page.count} results" if first
  first = false

  #walk through results
  page.results.each do |result|
    #result is a minimal fact check response
    #to do an extra request to grab the full detail
    #factcheck = api.fact_check(result["detail_url"])

    #do something with the data
    #factcheck.parse_body will parse the HTML and return a Nokogiri Document
    #if you just want the links in the article
    #factcheck.extract_links
  end
end

Usage Examples

See

  • bin/sample.rb -- grabs the first page of fact checks and prints headline and author
  • bin/harvest.rb -- perform a search against the API and dump the slug, url, headline to CSV

By default these scripts read the API token from an environment variable called FF_TOKEN.

About

Ruby Client Library for the Full Fact API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages