Skip to content

Instantly share code, notes, and snippets.

@commuterjoy
Created September 9, 2013 13:27
Show Gist options
  • Save commuterjoy/6495563 to your computer and use it in GitHub Desktop.
Save commuterjoy/6495563 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'trollop'
require 'json'
require 'cgi'
require 'rest_client'
require 'time'
CONF = Trollop::options do
opt :since, "Seconds elapsed between now and the publication date", :type => :int, :required => true, :short => "-s"
end
class ContentApi
def initialize
@host = 'http://content.guardianapis.com/search?format=json&page-size=50'
end
def recently_published(since = 60) # seconds
JSON.parse(RestClient.get(@host).body)['response']['results'].select { |result|
(Time.now.gmtime - Time.parse(result['webPublicationDate']).gmtime).to_i < since
}
end
end
class OpenGraph
def initialize
@host = 'https://developers.facebook.com/tools/debug/og/object'
end
def ping(resource)
RestClient.get(@host, { :params => { :q => CGI::escape(resource) }})
end
end
# ----
ContentApi.new.recently_published(CONF.since).each { |item|
puts item.to_json
puts OpenGraph.new.ping(item['webUrl']).body
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment