Class: Project
- Inherits:
-
Object
- Object
- Project
- Defined in:
- lib/track-r/project.rb
Overview
Container for project’s attributes. Receives a hash with either :project key pointing to an hpricot object or a project_id and a token with which to fetch and build the project object
Instance Attribute Summary collapse
-
#api_url ⇒ Object
readonly
Returns the value of attribute api_url.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#iteration_length ⇒ Object
readonly
Returns the value of attribute iteration_length.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#point_scale ⇒ Object
readonly
Returns the value of attribute point_scale.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#week_start_day ⇒ Object
readonly
Returns the value of attribute week_start_day.
Instance Method Summary collapse
-
#backlog ⇒ Object
Gets the backlog’s stories.
-
#create_story(attributes = {}) ⇒ Object
Creates a story for this project.
-
#current ⇒ Object
Gets the current iteration’s stories.
-
#delete_story(story) ⇒ Object
Deletes a story given a Story object or a story_id.
-
#done ⇒ Object
Gets the done iteration’s stories.
-
#icebox ⇒ Object
Gets the icebox iteration’s stories.
-
#initialize(options = {}) ⇒ Project
constructor
A new instance of Project.
-
#stories ⇒ Object
Builds an array containing the project’s story.
-
#story(id) ⇒ Object
Fetches a story with given id.
Constructor Details
#initialize(options = {}) ⇒ Project
Returns a new instance of Project.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/track-r/project.rb', line 8 def initialize( = {}) if .include?(:project_id) && .include?(:token) @id = [:project_id] @token = [:token].to_s @api_url = "http://www.pivotaltracker.com/services/v2/projects/#{@id}" @url = "http://www.pivotaltracker.com/projects/#{@id}" @project = Hpricot(open(@api_url, {"X-TrackerToken" => @token})) @stories = nil elsif .include?(:project) && .include?(:token) @project = [:project] @token = [:token].to_s else raise ArgumentError, "Valid options are: :project (receives an Hpricot Object) OR :project_id + :token" end build_project end |
Instance Attribute Details
#api_url ⇒ Object (readonly)
Returns the value of attribute api_url.
5 6 7 |
# File 'lib/track-r/project.rb', line 5 def api_url @api_url end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/track-r/project.rb', line 5 def id @id end |
#iteration_length ⇒ Object (readonly)
Returns the value of attribute iteration_length.
5 6 7 |
# File 'lib/track-r/project.rb', line 5 def iteration_length @iteration_length end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/track-r/project.rb', line 5 def name @name end |
#point_scale ⇒ Object (readonly)
Returns the value of attribute point_scale.
5 6 7 |
# File 'lib/track-r/project.rb', line 5 def point_scale @point_scale end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
5 6 7 |
# File 'lib/track-r/project.rb', line 5 def token @token end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/track-r/project.rb', line 5 def url @url end |
#week_start_day ⇒ Object (readonly)
Returns the value of attribute week_start_day.
5 6 7 |
# File 'lib/track-r/project.rb', line 5 def week_start_day @week_start_day end |
Instance Method Details
#backlog ⇒ Object
Gets the backlog’s stories
64 65 66 |
# File 'lib/track-r/project.rb', line 64 def backlog get_stories_by_iteration("backlog") end |
#create_story(attributes = {}) ⇒ Object
Creates a story for this project. Receives a set of valid attributes. Returns a Story object TODO: Validate attributes
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/track-r/project.rb', line 36 def create_story(attributes = {}) api_url = URI.parse("http://www.pivotaltracker.com/services/v2/projects/#{@id}/stories") query_string = attributes.map { |key, value| "story[#{key}]=#{CGI::escape(value)}"}.join('&') response = Net::HTTP.start(api_url.host, api_url.port) do |http| http.post(api_url.path, query_string.concat("&token=#{@token}")) end story = (Hpricot(response.body)/:story) Story.new(:story => story, :project_id => @id, :token => @token) end |
#current ⇒ Object
Gets the current iteration’s stories
69 70 71 |
# File 'lib/track-r/project.rb', line 69 def current get_stories_by_iteration("current") end |
#delete_story(story) ⇒ Object
Deletes a story given a Story object or a story_id
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/track-r/project.rb', line 48 def delete_story(story) if story.is_a?(Story) api_url = URI.parse("http://www.pivotaltracker.com/services/v2/projects/#{@id}/stories/#{story.id}") elsif story.is_a?(Integer) || story.to_i.is_a?(Integer) api_url = URI.parse("http://www.pivotaltracker.com/services/v2/projects/#{@id}/stories/#{story}") else raise ArgumentError, "Should receive a story id or a Story object." end response = Net::HTTP.start(api_url.host, api_url.port) do |http| http.delete(api_url.path, {"X-TrackerToken" => @token}) end story = (Hpricot(response.body)/:story) Story.new(:story => story, :project_id => @id, :token => @token) end |
#done ⇒ Object
Gets the done iteration’s stories
79 80 81 |
# File 'lib/track-r/project.rb', line 79 def done get_stories_by_iteration("done") end |
#icebox ⇒ Object
Gets the icebox iteration’s stories
74 75 76 |
# File 'lib/track-r/project.rb', line 74 def icebox get_stories_by_iteration("icebox") end |
#stories ⇒ Object
Builds an array containing the project’s story
26 |
# File 'lib/track-r/project.rb', line 26 def stories ; @stories || get_stories ; end |