Skip to content

Instantly share code, notes, and snippets.

@dummied
Last active December 25, 2015 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dummied/7051472 to your computer and use it in GitHub Desktop.
Save dummied/7051472 to your computer and use it in GitHub Desktop.
The guts of PinboardDigest, an OSX System Service to produce link roundup text based on Pinboard bookmarks as painlessly as possible.
#!/usr/bin/ruby
require 'net/https'
require 'cgi'
require 'rubygems'
require 'json'
AUTH_TOKEN = "YOUR_AUTH_CODE_GOES_HERE"
NUMBER_OF_RESULTS = 10
input = STDIN.read
starter = "https://api.pinboard.in/v1/posts/all?auth_token=#{AUTH_TOKEN}&results=#{NUMBER_OF_RESULTS}&format=json"
url = URI.parse(input != "" ? starter + "&tag=#{CGI.escape(input)}" : starter)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # You should use VERIFY_PEER in production
request = Net::HTTP::Get.new(url.request_uri)
res = http.request(request)
result = JSON.parse(res.body)
text << "# Links for #{Time.now.strftime("%B %e ")}\n\n"
result.each do |link|
text << "* **[#{link["description"]}](#{link["href"]}):** #{link["extended"]}\n\n"
end
print text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment