Skip to content

Instantly share code, notes, and snippets.

@csaunders
Last active August 29, 2015 14:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csaunders/a02850510c182d31324e to your computer and use it in GitHub Desktop.
Save csaunders/a02850510c182d31324e to your computer and use it in GitHub Desktop.
Pocket Lint: Remove the paradox of choice from your pocket articles.
#!/bin/bash
#run the app to grab a random URL then die
bundle exec ruby app.rb &
PID=$!
sleep 3
open http://localhost:4567
sleep 10
kill $PID
require 'rack'
require 'sinatra'
require 'pocket'
require 'omniauth-pocket'
# Use dotenv or something instead if you are going
# to deploy this code
POCKET_KEY = 'YOUR SECRET'
SESSION_SECRET = 'YOUR SESSION SECRET'
use Rack::Session::Cookie, secret: SESSION_SECRET
use OmniAuth::Builder do
provider :pocket, POCKET_KEY
end
Pocket.configure do |config|
config.consumer_key = POCKET_KEY
end
get '/' do
redirect '/auth/pocket' unless client
unread_articles = client.retrieve(state: 'unread')['list'].keys
article_id = unread_articles.shuffle.first
redirect "https://getpocket.com/a/read/#{article_id}"
end
get '/auth/:name/callback' do
session[:token] = request.env['omniauth.auth']['credentials']['token']
redirect '/'
end
def client
@client ||= Pocket.client(access_token: session[:token]) if session[:token]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment