Class: Toolshed::PivotalTracker

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/toolshed/pivotal_tracker.rb

Constant Summary collapse

STORY_STATUS_DEFAULT =
'finished'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PivotalTracker

Returns a new instance of PivotalTracker.



9
10
11
12
13
14
# File 'lib/toolshed/pivotal_tracker.rb', line 9

def initialize(options={})
  self.token = ::PivotalTracker::Client.token(Toolshed::Client.pivotal_tracker_username, Toolshed::Client.pivotal_tracker_password)

  self.project_id = (options[:project_id].nil?) ? Toolshed::Client.default_pivotal_tracker_project_id : options[:project_id]
  @pt_project = ::PivotalTracker::Project.find(self.project_id)
end

Instance Attribute Details

#project_idObject

Returns the value of attribute project_id.



7
8
9
# File 'lib/toolshed/pivotal_tracker.rb', line 7

def project_id
  @project_id
end

#tokenObject

Returns the value of attribute token.



7
8
9
# File 'lib/toolshed/pivotal_tracker.rb', line 7

def token
  @token
end

Class Method Details

.story_id_from_branch_name(branch_name) ⇒ Object



16
17
18
# File 'lib/toolshed/pivotal_tracker.rb', line 16

def self.story_id_from_branch_name(branch_name)
  story_id = branch_name.split("_")[0]
end

Instance Method Details

#add_note(story_id, note_text) ⇒ Object



24
25
26
27
# File 'lib/toolshed/pivotal_tracker.rb', line 24

def add_note(story_id, note_text)
  story = @pt_project.stories.find(story_id)
  results = story.notes.create(text: note_text)
end

#story_information(story_id) ⇒ Object



20
21
22
# File 'lib/toolshed/pivotal_tracker.rb', line 20

def (story_id)
  return @pt_project.stories.find(story_id)
end

#update_story_state(story_id, current_state, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/toolshed/pivotal_tracker.rb', line 29

def update_story_state(story_id, current_state, options={})
  options.merge!({
    :headers => {
        "X-TrackerToken"  => self.token,
        "User-Agent"      => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17",
        "Content-Type"    => "application/json",
    },
    body: {
      current_state: current_state
    }.to_json
  })

  response = HTTParty.put("#{Toolshed::Client::PIVOTAL_TRACKER_BASE_API_URL}projects/#{self.project_id}/stories/#{story_id}", options).response
  response = JSON.parse(response.body)

  if (response["error"].nil?)
    response
  else
    raise "validation errors #{response.inspect}"
  end
end