Class: Redpomo::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/redpomo/tracker.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ Tracker

Returns a new instance of Tracker.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/redpomo/tracker.rb', line 25

def initialize(name, options)
  options.symbolize_keys!
  @name = name
  @base_url = options[:url]
  @api_key = options[:token]
  @default_project_id = options[:default_project_id]
  @default_priority_id = options[:default_priority_id]
  @closed_status_id = options[:closed_status_id].to_i
  @default_activity_id = options[:default_activity_id]
  @priorities = options[:priority_ids]
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



23
24
25
# File 'lib/redpomo/tracker.rb', line 23

def base_url
  @base_url
end

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/redpomo/tracker.rb', line 23

def name
  @name
end

Class Method Details

.allObject



17
18
19
20
21
# File 'lib/redpomo/tracker.rb', line 17

def self.all
  Config.trackers_data.map do |name, data|
    Tracker.new(name.to_sym, data)
  end
end

.find(name) ⇒ Object



11
12
13
14
15
# File 'lib/redpomo/tracker.rb', line 11

def self.find(name)
  if data = Config.trackers_data[name.to_sym]
    Tracker.new(name.to_sym, data)
  end
end

Instance Method Details

#close_issue!(id, message = nil) ⇒ Object



85
86
87
88
89
# File 'lib/redpomo/tracker.rb', line 85

def close_issue!(id, message = nil)
  issue = { status_id: @closed_status_id }
  issue[:notes] = message if message.present?
  put("/issues/#{id}", issue: issue)
end

#create_issue!(issue) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/redpomo/tracker.rb', line 59

def create_issue!(issue)
  data = {
    subject: issue.subject,
    description: issue.description,
    due_date: issue.due_date,
    project_id: issue.project_id || @default_project_id,
    priority_id: issue.priority_id || @default_priority_id,
    assigned_to_id: current_user_id
  }

  post("/issues", issue: data)
end

#issue_priority_id(priority_val) ⇒ Object



45
46
47
48
49
# File 'lib/redpomo/tracker.rb', line 45

def issue_priority_id(priority_val)
  if index = ('A' .. 'Z').to_a.index(priority_val)
    @priorities[index]
  end
end

#issuesObject



51
52
53
54
55
56
57
# File 'lib/redpomo/tracker.rb', line 51

def issues
  data = get("/issues", assigned_to_id: current_user_id, status_id: "open", limit: 100)
  data["issues"].map do |issue|
    issue["project_id"] = project_identifier_for(issue["project"]["id"])
    Issue.new(self, issue)
  end
end

#push_entry!(entry) ⇒ Object



81
82
83
# File 'lib/redpomo/tracker.rb', line 81

def push_entry!(entry)
  post("/time_entries", time_entry: entry_data(entry))
end

#pushable_entry?(entry) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
76
77
78
79
# File 'lib/redpomo/tracker.rb', line 72

def pushable_entry?(entry)
  data = entry_data(entry)
  if data[:project_id]
    project_exists?(data[:project_id])
  else
    issue_exists?(data[:issue_id])
  end
end

#todo_priority(priority_name) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/redpomo/tracker.rb', line 37

def todo_priority(priority_name)
  return nil if @priorities.nil?
  alphabet = ('A' .. 'Z').to_a.join
  if index = @priorities.index(priority_name)
    "(#{alphabet[index]})"
  end
end