Module: OmniFocus::Lighthouse

Defined in:
lib/omnifocus/lighthouse/version.rb,
lib/omnifocus/lighthouse.rb

Constant Summary collapse

VERSION =
"0.0.3"
PREFIX =
"LH"

Instance Method Summary collapse

Instance Method Details

#create_config_file(path) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/omnifocus/lighthouse.rb', line 18

def create_config_file(path)
	config = { :account => "ACCOUNT", 
             :api_token => "TOKEN",
             :queries => {:projectId => ["responsible:me state:open sort:priority milestone:next"] }
            }

    File.open(path, "w") { |f|
      YAML.dump(config, f)
    }
end

#load_or_create_configObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/omnifocus/lighthouse.rb', line 6

def load_or_create_config
  path   = File.expand_path "~/.omnifocus-lighthouse.yml"
  config = YAML.load(File.read(path)) rescue nil

  unless config then
    create_config_file(path)
    abort "Created default config in #{path}. Go fill it out."
  end

  config
end

#populate_lighthouse_tasksObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/omnifocus/lighthouse.rb', line 29

def populate_lighthouse_tasks
	config = load_or_create_config
  Lighthouse. = config[:account]
	Lighthouse.token = config[:api_token]
  queries = config[:queries]

  queries.each do |project_id, queries|
    project = Lighthouse::Project.find(project_id)
    process_project(project, queries)
  end
end

#process_project(project, queries) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/omnifocus/lighthouse.rb', line 41

def process_project(project, queries)
   queries.each do |query|
      tickets = project.tickets( :q => query)
      tickets.each do |ticket|
        process_ticket(project, ticket)
      end
    end
end

#process_ticket(project, ticket) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/omnifocus/lighthouse.rb', line 50

def process_ticket(project, ticket)
	ticket_id = "#{PREFIX}##{ticket.id}"

  if existing[ticket_id]
    of_project = existing[ticket_id]
    bug_db[of_project][ticket_id] = true
  else
    description = "#{ticket.latest_body}\n\n--------------------------------------------------------\n#{ticket.url}"
    of_project = "#{project.name}"

    bug_db[of_project][ticket_id] = ["#{ticket_id}: #{ticket.title}", description]
  end
end