Skip to content

Instantly share code, notes, and snippets.

@zapo
Last active August 29, 2015 14:22
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 zapo/b081d2a8b07e7b411f14 to your computer and use it in GitHub Desktop.
Save zapo/b081d2a8b07e7b411f14 to your computer and use it in GitHub Desktop.
Podio tasks sync with todotxt
#!/usr/bin/env ruby
require 'rubygems'
require 'ostruct'
require 'yaml'
require 'active_support'
require 'active_support/core_ext'
require 'podio'
def usage
STDOUT.puts " Usage: #{ENV['TODO_SH']} podio <option>"
STDOUT.puts " Options:"
STDOUT.puts " pull:\t Create/Complete local tasks"
STDOUT.puts " push:\t Create/Complete remote tasks"
STDOUT.puts " sync:\t Runs both pull and push"
STDOUT.puts " usage:\t show this help"
end
def auth! info = {}
Podio.setup(:api_key => info.fetch(:client_id), :api_secret => info.fetch(:client_secret))
Podio.client.authenticate_with_credentials(info.fetch(:username), info.fetch(:password))
end
def get_todo_tasks
`$TODO_SH ls | grep '^[0-9]'`.split("\n").map { |t|
info = t.split(' ')
id = info.shift
text = info.join(' ')
OpenStruct.new(:id => id, :text => text)
}
end
def get_podio_tasks
Podio::Task.find_all(:completed => false, :responsible => Podio::UserStatus.current.user.user_id)
end
def add_todo_task(task)
`$TODO_SH add "#{task}"`
end
def add_podio_task(task)
Podio::Task.create(:text => task)
end
def do_todo_task(id)
`$TODO_SH do #{id}`
end
def do_podio_task(id)
Podio::Task.complete(id)
end
def pull
todo_tasks = get_todo_tasks.index_by(&:text)
podio_tasks = get_podio_tasks.index_by(&:text)
podio_tasks.each do |text, task|
if !todo_tasks.has_key?(text)
STDOUT.puts "Create todotxt: #{text}"
add_todo_task(text)
end
end
todo_tasks.each do |text, task|
if !podio_tasks.has_key?(text)
STDOUT.puts "Do todotxt: #{text}"
do_todo_task(task.id)
end
end
end
def push
todo_tasks = get_todo_tasks.index_by(&:text)
podio_tasks = get_podio_tasks.index_by(&:text)
todo_tasks.each do |text, task|
if !podio_tasks.has_key?(text)
STDOUT.puts "Create podio: #{text}"
add_podio_task(text)
end
end
podio_tasks.each do |text, task|
if !todo_tasks.has_key?(text)
STDOUT.puts "Do podio: #{text}"
do_podio_task(task.id)
end
end
end
if __FILE__ == $0
auth_file = ENV.has_key?('PODIO_AUTH_PATH') ? ENV['PODIO_AUTH_PATH'] : File.join(File.expand_path(File.dirname(__FILE__)), 'podio.auth.yml')
auth_info = YAML.load_file(auth_file).symbolize_keys
auth!(auth_info)
case ARGV[1].to_s.to_sym
when :pull
pull
when :push
push
when :sync
pull
push
else
usage
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment