-
-
Save csaunders/a02850510c182d31324e to your computer and use it in GitHub Desktop.
Pocket Lint: Remove the paradox of choice from your pocket articles.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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