Class: TrackR::Project
- Inherits:
-
Object
- Object
- TrackR::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 TrackR::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.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/track-r/project.rb', line 9 def initialize( = {}) if .include?(:project_id) && .include?(:token) @id = [:project_id] @token = [:token].to_s @api_url = "#{CONFIG[:api_url]}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.
6 7 8 |
# File 'lib/track-r/project.rb', line 6 def api_url @api_url end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/track-r/project.rb', line 6 def id @id end |
#iteration_length ⇒ Object (readonly)
Returns the value of attribute iteration_length.
6 7 8 |
# File 'lib/track-r/project.rb', line 6 def iteration_length @iteration_length end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/track-r/project.rb', line 6 def name @name end |
#point_scale ⇒ Object (readonly)
Returns the value of attribute point_scale.
6 7 8 |
# File 'lib/track-r/project.rb', line 6 def point_scale @point_scale end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
6 7 8 |
# File 'lib/track-r/project.rb', line 6 def token @token end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/track-r/project.rb', line 6 def url @url end |
#week_start_day ⇒ Object (readonly)
Returns the value of attribute week_start_day.
6 7 8 |
# File 'lib/track-r/project.rb', line 6 def week_start_day @week_start_day end |
Instance Method Details
#backlog ⇒ Object
Gets the backlog’s stories
79 80 81 |
# File 'lib/track-r/project.rb', line 79 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 TrackR::Story object TODO: Validate attributes
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/track-r/project.rb', line 37 def create_story(attributes = {}) api_url = URI.parse("#{CONFIG[:api_url]}projects/#{@id}/stories") query_string = attributes.map { |key, value| "story[#{key}]=#{CGI::escape(value)}"}.join('&') begin http = Net::HTTP.new(api_url.host, api_url.port) http.use_ssl = true response, data = http.post(api_url.path, query_string.concat("&token=#{@token}")) raise ResponseError, "Wrong response code" unless response.code.to_i == 200 story = (Hpricot(response.body)/:story) TrackR::Story.new(:story => story, :project_id => @id, :token => @token) rescue ResponseError => e print "Got response code [#{response.code}]:\t" puts response. raise end end |
#current ⇒ Object
Gets the current iteration’s stories
84 85 86 |
# File 'lib/track-r/project.rb', line 84 def current get_stories_by_iteration("current") end |
#delete_story(story) ⇒ Object
Deletes a story given a TrackR::Story object or a story_id
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/track-r/project.rb', line 56 def delete_story(story) if story.is_a?(TrackR::Story) api_url = URI.parse("#{CONFIG[:api_url]}projects/#{@id}/stories/#{story.id}") elsif story.is_a?(Integer) || story.to_i.is_a?(Integer) api_url = URI.parse("#{CONFIG[:api_url]}projects/#{@id}/stories/#{story}") else raise ArgumentError, "Should receive a story id or a TrackR::Story object." end begin http = Net::HTTP.new(api_url.host, api_url.port) http.use_ssl = true response, data = http.delete(api_url.path, {"X-TrackerToken" => @token}) raise ResponseError, "Wrong response code" unless response.code.to_i == 200 story = (Hpricot(response.body)/:story) TrackR::Story.new(:story => story, :project_id => @id, :token => @token) rescue ResponseError => e print "Got response code [#{response.code}]:\t" puts response. raise end end |
#done ⇒ Object
Gets the done iteration’s stories
94 95 96 |
# File 'lib/track-r/project.rb', line 94 def done get_stories_by_iteration("done") end |
#icebox ⇒ Object
Gets the icebox iteration’s stories
89 90 91 |
# File 'lib/track-r/project.rb', line 89 def icebox get_stories_by_iteration("icebox") end |
#stories ⇒ Object
Builds an array containing the project’s story
27 |
# File 'lib/track-r/project.rb', line 27 def stories ; @stories || get_stories ; end |