Skip to content

Instantly share code, notes, and snippets.

@timfall
Last active December 16, 2015 08:39
Show Gist options
  • Save timfall/5407500 to your computer and use it in GitHub Desktop.
Save timfall/5407500 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'json'
require 'oauth'
#require '../lib/OauthFigsharesync'
#require '../lib/FigshareClasses'
workingdir = "~/.figsharesync/"
consumerkey
consumersecret
accesstoken
accesstokensecret
#First run setup
absworkingdir = File.expand_path(workingdir)
if File.exist?("#{absworkingdir}/FirstRun.lock")
break
else
puts "This appears to be the first run of FigShare Sync. We'll setup a few things."
print "Where would you like to store settings and files? [~./figsharesync]: "
@input = gets.chomp
if @input != nil
workingdir = @input
absworkingdir = File.expand_path(workingdir)
else
break
end
print "Please enter OAuth consumer key: "
consumerkey = gets.chomp
print "Please enter OAuth consumer key secret: "
consumersecret = gets.chomp
print "Please enter OAuth access token: "
accesstoken = gets.chomp
print "Please enter OAuth access token secret: "
accesstokensecret = gets.chomp
puts "Great! we'll get running now..."
File.new("#{absworkingdir}/FirstRun.lock", "r")
end
#oauth authenticate
auth = OauthFighshare.new(consumerkey, consumersecret, accesstoken, accesstokensecret)
if auth.head (v1/my_data/articles) =! #http auth error
puts "Figshare returned #{auth.head (v1/my_data/articles)}"
end
puts "Successfully authenticated"
#Create article database and populate from local sources
if File.exists?("#{absworkingdir}/localdb.json")
puts "Local database detected, populating from there"
ldb = JSON.parse("#{absworkingdir}/localdb.json")
i = lab['count']
for i.times do
Article.new(JSON.parse("#{absworkingdir}/localdb.json"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment