Created
October 3, 2013 04:30
-
-
Save czarrar/6805001 to your computer and use it in GitHub Desktop.
Bookmark a webpage to readability
This file contains 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
#!/usr/bin/env ruby | |
# WHAT WE DO HERE | |
# Take a link | |
# Add it as a bookmark | |
# Two inputs needed | |
if ARGV.count != 4 | |
abort "$0 username email password weblink" | |
end | |
username = ARGV[0] | |
email = ARGV[1] | |
password = ARGV[2] | |
link = ARGV[3] | |
### | |
# SETUP | |
### | |
# Note: | |
# OAUTH code borrowed from github:brandur | |
# https://gist.github.com/brandur/6258226 | |
require 'oauth' | |
require 'readit' | |
# For some reason this doesn't work, get redirection 302? | |
# Overload the API class | |
# module Readit | |
# class API | |
# def send_to_kindle(args={}) | |
# raise ReaditError.new('expect hash arguments with keys :id and :email') unless args["id"] and args["email"] | |
# | |
# # DON'T CALL REQUEST FUNCTION | |
# # so redo some calls here | |
# #SITE_URL = 'www.readability.com/' | |
# | |
# consumer = ::OAuth::Consumer.new(Readit::Config.consumer_key,Readit::Config.consumer_secret,:site=>"https://#{SITE_URL}") | |
# atoken = ::OAuth::AccessToken.new(consumer, @access_token, @access_token_secret) | |
# | |
# response = atoken.send(:post, "/api/kindle/v1/generator", args) | |
# # request(:post, '/generator', args) | |
# | |
# if block_given? | |
# yield response | |
# else | |
# hashie_response(response) | |
# end | |
# end | |
# end | |
# end | |
# Set consumer tokens | |
# Find these on the api section of readability | |
# The first two refer to the reader api while the third one refers to the parser api | |
Readit::Config.consumer_key = 'XXX' | |
Readit::Config.consumer_secret = 'XXX' | |
Readit::Config.parser_token = 'XXX' | |
# Get user tokens | |
consumer = ::OAuth::Consumer.new( | |
Readit::Config.consumer_key, | |
Readit::Config.consumer_secret, | |
:site=>"https://www.readability.com/", | |
:access_token_path => "/api/rest/v1/oauth/access_token/" | |
) | |
tokens = consumer.get_access_token(nil, {}, { | |
:x_auth_mode =>'client_auth', | |
:x_auth_username => username, | |
:x_auth_password => password | |
}) | |
# Load the reader API | |
@api = Readit::API.new tokens.params[:oauth_token], tokens.params[:oauth_token_secret] | |
### | |
# ADD BOOKMARK | |
### | |
# Add the link | |
bookmark_info = @api.bookmark(:url => link) | |
puts bookmark_info[:article_id] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment