Module: OmniFocus::AtTask

Defined in:
lib/omnifocus/attask.rb

Constant Summary collapse

VERSION =
'1.0.3'
PREFIX =
'AT'
AT_API_DEFAULT =
"https://pragma.attask-ondemand.com/attask/api"
OBJCODE_GROUP =
"GROUP"
OBJCODE_PROJECT =
"PROJ"
OBJCODE_TASK =
"TASK"
OBJCODE_OPTTASK =
"OPTASK"

Instance Method Summary collapse

Instance Method Details

#load_or_create_configObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/omnifocus/attask.rb', line 46

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

  unless config then
    config = { :username => "USER", :password => "PASSWORD" }

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

    abort "Created default config in #{path}. Go fill it out."
  end

  config
end

#populate_attask_tasksObject



63
64
65
66
67
68
69
# File 'lib/omnifocus/attask.rb', line 63

def populate_attask_tasks
  @projects = {}
  config = load_or_create_config
  user_name = config[:username]
  password = config[:password]
  process(user_name, password)
end

#process(user_name, password) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/omnifocus/attask.rb', line 71

def process(user_name, password)

  begin
    sc = StreamClient.new(AT_API_DEFAULT)
    sc.(user_name, password)
    taskList = []
    # get tasks by doing a search
    %w(TASK).each do |opcode|
      taskList << sc.search(opcode, {'assignedToID' => sc.userID}, ["name", "projectID", "taskNumber", "description"])
    end

    taskList.each do |tasks|
      tasks.each do |task|
        if(@projects.include? task['projectID'])
          project = @projects[task['projectID']]
          project.add_task task
        else
          project = sc.get('PROJECT', task['projectID'], ["name"])
          id = project['ID']
          project = Project.new(project['name'], project['ID'])
          project.add_task task
          @projects[id] = project
        end
      end
    end

    @projects.each do |id, p|
      project = p.name
      p.tasks.each do |task|
        ticket_id = "#{PREFIX}-#{project.gsub(/ /,'')}##{task['taskNumber']}"
        title = task['name']
        note = task['description'] || ""

        if existing[ticket_id] then
          bug_db[existing[ticket_id]][ticket_id] = true
          next
        end

        bug_db[project][ticket_id] = [title, note]
      end
    end

  rescue Exception => e
    puts e
  end

  sc.logout()

end