Class: ScrumNinja::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/scrumninja/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Client

Returns a new instance of Client.



5
6
7
# File 'lib/scrumninja/client.rb', line 5

def initialize(key)
  @api_key = key
end

Instance Method Details

#project(project_id, options = {}) ⇒ Object



14
15
16
17
# File 'lib/scrumninja/client.rb', line 14

def project(project_id,options={})
  response = get "http://scrumninja.com/projects/#{project_id}.xml", options
  response.project
end

#project_backlog(project_id, options = {}) ⇒ Object



24
25
26
27
# File 'lib/scrumninja/client.rb', line 24

def project_backlog(project_id,options={})
  response = get "http://scrumninja.com/projects/#{project_id}/backlog/index.xml", options
  response.sprints
end

#project_burndown(project_id, options = {}) ⇒ Object



64
65
66
67
68
69
70
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
# File 'lib/scrumninja/client.rb', line 64

def project_burndown(project_id,options={})
  burndown = ::Hashie::Mash.new
  card_wall = project_card_wall project_id, options
  sprints = project_sprints project_id, options

  card_wall = [] if card_wall.nil?
  sprints = [] if sprints.nil?

  start_date = sprints[0].starts_on.to_date
  end_date =  sprints[0].ends_on.to_date

  burndown.start = start_date.to_time.to_i * 1000
  burndown.sprint_length = (end_date - start_date).to_i + 1
  days_passed = (Date.today - start_date).to_i + 1
  # for each day in the sprint
  burndown.estimates = []
  days_passed.times do |i|
    start_time = (start_date + i).to_time
    end_time = (start_date + i + 1).to_time
    total_hours = 0
    card_wall.each do |task|
      if task.created_at < end_time
        if task.done_at.nil? or task.done_at > end_time
          # we have a task that counts towards today, dig into estimates
          if task.estimates.estimate.is_a? Array then
            estimate_hours = 0
            task.estimates.estimate.each do |estimate|
              estimate_day = estimate.date.to_date
              break if(estimate_day.to_time > end_time)
              estimate_hours = task.estimates.estimate[0].hours.to_f
            end
            total_hours += estimate_hours
          else
            total_hours += task.estimates.estimate.hours.to_f
          end
        end
      end
    end
    burndown.estimates << total_hours
  end
  burndown
end

#project_card_wall(project_id, options = {}) ⇒ Object



34
35
36
37
# File 'lib/scrumninja/client.rb', line 34

def project_card_wall(project_id,options={})
  response = get "http://scrumninja.com/projects/#{project_id}/card_wall.xml", options
  response.tasks
end

#project_roles(project_id, options = {}) ⇒ Object



44
45
46
47
# File 'lib/scrumninja/client.rb', line 44

def project_roles(project_id,options={})
  response = get "http://scrumninja.com/projects/#{project_id}/project_roles.xml", options
  response.project_roles
end

#project_sprint(project_id, sprint_id, options = {}) ⇒ Object



49
50
51
52
# File 'lib/scrumninja/client.rb', line 49

def project_sprint(project_id,sprint_id,options={})
  response = get "http://scrumninja.com/projects/#{project_id}/sprints/#{sprint_id}.xml", options
  response.sprint
end

#project_sprint_burndown(project_id, sprint_id, options = {}) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/scrumninja/client.rb', line 107

def project_sprint_burndown(project_id,sprint_id,options={})
  burndown = ::Hashie::Mash.new
  card_wall = project_sprint_card_wall project_id, sprint_id, options
  sprint = project_sprint project_id, sprint_id, options

  card_wall = [] if card_wall.nil?

  start_date = sprint.starts_on.to_date
  end_date =  sprint.ends_on.to_date

  burndown.start = start_date.to_time.to_i * 1000
  burndown.sprint_length = (end_date - start_date).to_i + 1
  days_passed = (Date.today - start_date).to_i + 1
  # for each day in the sprint
  burndown.estimates = []
  days_passed.times do |i|
    start_time = (start_date + i).to_time
    end_time = (start_date + i + 1).to_time
    total_hours = 0
    card_wall.each do |task|
      if task.created_at < end_time
        if task.done_at.nil? or task.done_at > end_time
          # we have a task that counts towards today, dig into estimates
          if task.estimates.estimate.is_a? Array then
            estimate_hours = 0
            task.estimates.estimate.each do |estimate|
              estimate_day = estimate.date.to_date
              break if(estimate_day.to_time > end_time)
              estimate_hours = task.estimates.estimate[0].hours.to_f
            end
            total_hours += estimate_hours
          else
            total_hours += task.estimates.estimate.hours.to_f
          end
        end
      end
    end
    burndown.estimates << total_hours
  end
  burndown
end

#project_sprint_card_wall(project_id, sprint_id, options = {}) ⇒ Object



39
40
41
42
# File 'lib/scrumninja/client.rb', line 39

def project_sprint_card_wall(project_id,sprint_id,options={})
  response = get "http://scrumninja.com/projects/#{project_id}/sprints/#{sprint_id}/card_wall.xml", options
  response.tasks
end

#project_sprints(project_id, options = {}) ⇒ Object



29
30
31
32
# File 'lib/scrumninja/client.rb', line 29

def project_sprints(project_id,options={})
  response = get "http://scrumninja.com/projects/#{project_id}/sprints.xml", options
  response.sprints
end

#project_stories(project_id, options = {}) ⇒ Object



19
20
21
22
# File 'lib/scrumninja/client.rb', line 19

def project_stories(project_id,options={})
  response = get "http://scrumninja.com/projects/#{project_id}/stories.xml", options
  response.stories
end

#project_story(project_id, story_id, options = {}) ⇒ Object



54
55
56
57
# File 'lib/scrumninja/client.rb', line 54

def project_story(project_id,story_id,options={})
  response = get "http://scrumninja.com/projects/#{project_id}/stories/#{story_id}.xml", options
  response.story
end

#projects(options = {}) ⇒ Object



9
10
11
12
# File 'lib/scrumninja/client.rb', line 9

def projects(options={})
  response = get 'https://scrumninja.com/projects.xml', options
  response.projects
end

#story_tasks(story_id, options = {}) ⇒ Object



59
60
61
62
# File 'lib/scrumninja/client.rb', line 59

def story_tasks(story_id,options={})
  response = get "http://scrumninja.com/stories/#{story_id}/tasks.xml", options
  response.tasks
end