Class: Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/track-r/tracker.rb

Overview

The class is a wrapper for getting projects, stories and using tokens. It’s main purpose is relating the three allowing to interact with a project, and its stories using a token. Expects a token when initialized.

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Tracker

To generate a token, use the “Create New Token” link on the My Profile page (www.pivotaltracker.com/profile).

Raises:

  • (TypeError)


9
10
11
12
# File 'lib/track-r/tracker.rb', line 9

def initialize(token)
  @token = token
  raise TypeError unless @token.is_a? Token
end

Instance Method Details

#find_projectObject

Receives a block with the condition to find a project. Should work the same as Enumerable.find method Returns a Project object



34
35
36
37
38
39
# File 'lib/track-r/tracker.rb', line 34

def find_project
  get_projects unless defined?(@projects) && @projects.is_a?(Array)
  @projects.find do |project|
    yield(project)
  end
end

#project(project_id) ⇒ Object

Fetches project with given ID Returns a Project object



16
17
18
# File 'lib/track-r/tracker.rb', line 16

def project(project_id)
  @project = Project.new(:project_id => project_id , :token => @token)
end

#projectsObject

Alias for get_projects Returns an array of projects



29
# File 'lib/track-r/tracker.rb', line 29

def projects ; get_projects ; end

#syncObject

Refresh the projects from the server Returns an array of projects



22
23
24
25
# File 'lib/track-r/tracker.rb', line 22

def sync
  @projects = nil
  get_projects
end