Module: OmniFocus::Extrabrain
- Defined in:
- lib/omnifocus/extrabrain/version.rb,
lib/omnifocus/extrabrain.rb
Defined Under Namespace
Classes: Task
Constant Summary collapse
- VERSION =
"1.0.2"
- PREFIX =
'EB'
Instance Method Summary collapse
- #client(url) ⇒ Object
- #get_tasks(team, page) ⇒ Object
- #keychain_user ⇒ Object
- #password ⇒ Object
-
#populate_extrabrain_tasks ⇒ Object
This is the method ‘of sync` calls.
- #process_extrabrain_task(task, team) ⇒ Object
- #resource ⇒ Object
- #teams ⇒ Object
- #user_id ⇒ Object
- #username ⇒ Object
Instance Method Details
#client(url) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/omnifocus/extrabrain.rb', line 63 def client(url) headers = { :accept => :json, :content_type => :json, } RestClient::Resource.new(url, :headers => headers, user: username, password: password) end |
#get_tasks(team, page) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/omnifocus/extrabrain.rb', line 86 def get_tasks(team, page) team_resource = client("https://#{team['subdomain']}.extrabrain.se") json = JSON.parse team_resource["tasks.json?user_id=#{user_id}&page=#{page}"].get return nil if json.nil? || json.empty? json.map { |task_attributes| Task.new(task_attributes.merge team: team) } end |
#keychain_user ⇒ Object
39 40 41 42 |
# File 'lib/omnifocus/extrabrain.rb', line 39 def keychain_user params = { server: 'extrabrain.se', protocol: Keychain::Protocols::HTTPS } Keychain.internet_passwords.where(params).first end |
#password ⇒ Object
48 49 50 |
# File 'lib/omnifocus/extrabrain.rb', line 48 def password @password ||= keychain_user.password end |
#populate_extrabrain_tasks ⇒ Object
This is the method ‘of sync` calls.
53 54 55 56 57 58 59 60 61 |
# File 'lib/omnifocus/extrabrain.rb', line 53 def populate_extrabrain_tasks teams.each do |team| page = 1 while tasks = get_tasks(team, page) do tasks.each { |task| process_extrabrain_task(task, team) } page = page + 1 end end end |
#process_extrabrain_task(task, team) ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/omnifocus/extrabrain.rb', line 93 def process_extrabrain_task(task, team) if existing[task.ticket_id] bug_db[existing[task.ticket_id]][task.ticket_id] = true else title = "#{task.ticket_id}: #{task.title}" description = task.url bug_db[task.project_title][task.ticket_id] = [title, description] end end |
#resource ⇒ Object
82 83 84 |
# File 'lib/omnifocus/extrabrain.rb', line 82 def resource @resource ||= client('https://extrabrain.se') end |
#teams ⇒ Object
71 72 73 |
# File 'lib/omnifocus/extrabrain.rb', line 71 def teams JSON.parse resource['teams.json'].get end |
#user_id ⇒ Object
75 76 77 78 79 80 |
# File 'lib/omnifocus/extrabrain.rb', line 75 def user_id @user_id ||= begin current_user = JSON.parse resource['users/current.json'].get current_user['user']['id'] end end |
#username ⇒ Object
44 45 46 |
# File 'lib/omnifocus/extrabrain.rb', line 44 def username @username ||= keychain_user.account end |