Class: Story
- Inherits:
-
Object
- Object
- Story
- Defined in:
- lib/track-r/story.rb
Overview
Typhoon TODO: Documentation ☻
Instance Attribute Summary collapse
-
#accepted_at ⇒ Object
Returns the value of attribute accepted_at.
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#current_state ⇒ Object
Returns the value of attribute current_state.
-
#description ⇒ Object
Returns the value of attribute description.
-
#estimate ⇒ Object
Returns the value of attribute estimate.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#labels ⇒ Object
Returns the value of attribute labels.
-
#name ⇒ Object
Returns the value of attribute name.
-
#owned_by ⇒ Object
Returns the value of attribute owned_by.
-
#project_id ⇒ Object
Returns the value of attribute project_id.
-
#requested_by ⇒ Object
Returns the value of attribute requested_by.
-
#story_type ⇒ Object
Returns the value of attribute story_type.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #build_story ⇒ Object
-
#destroy ⇒ Object
TODO: test this method:.
-
#initialize(options = {}) ⇒ Story
constructor
A new instance of Story.
- #save ⇒ Object
-
#update(attrs = {}) ⇒ Object
TODO: Test this method.
Constructor Details
#initialize(options = {}) ⇒ Story
Returns a new instance of Story.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/track-r/story.rb', line 9 def initialize( = {}) @token = [:token].to_s if .include?(:project_id) && .include?(:story_id) && .include?(:token) @id = [:story_id] @project_id = [:project_id] @url = "http://www.pivotaltracker.com/story/show/#{@id}" @api_url = "http://www.pivotaltracker.com/services/v2/projects/#{@project_id}/stories/#{@id}" @story = Hpricot(open(@api_url, {"X-TrackerToken" => @token})) elsif .include?(:story) && .include?(:project_id) && .include?(:token) @project_id = [:project_id] @story = [:story] else raise ArgumentError, "Valid options are: :story (receives an Hpricot Object) + :project_id OR :project_id + :story_id + :token" end build_story end |
Instance Attribute Details
#accepted_at ⇒ Object
Returns the value of attribute accepted_at.
3 4 5 |
# File 'lib/track-r/story.rb', line 3 def accepted_at @accepted_at end |
#comments ⇒ Object
Returns the value of attribute comments.
3 4 5 |
# File 'lib/track-r/story.rb', line 3 def comments @comments end |
#created_at ⇒ Object
Returns the value of attribute created_at.
3 4 5 |
# File 'lib/track-r/story.rb', line 3 def created_at @created_at end |
#current_state ⇒ Object
Returns the value of attribute current_state.
3 4 5 |
# File 'lib/track-r/story.rb', line 3 def current_state @current_state end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/track-r/story.rb', line 3 def description @description end |
#estimate ⇒ Object
Returns the value of attribute estimate.
3 4 5 |
# File 'lib/track-r/story.rb', line 3 def estimate @estimate end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/track-r/story.rb', line 7 def id @id end |
#labels ⇒ Object
Returns the value of attribute labels.
3 4 5 |
# File 'lib/track-r/story.rb', line 3 def labels @labels end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/track-r/story.rb', line 3 def name @name end |
#owned_by ⇒ Object
Returns the value of attribute owned_by.
3 4 5 |
# File 'lib/track-r/story.rb', line 3 def owned_by @owned_by end |
#project_id ⇒ Object
Returns the value of attribute project_id.
3 4 5 |
# File 'lib/track-r/story.rb', line 3 def project_id @project_id end |
#requested_by ⇒ Object
Returns the value of attribute requested_by.
3 4 5 |
# File 'lib/track-r/story.rb', line 3 def requested_by @requested_by end |
#story_type ⇒ Object
Returns the value of attribute story_type.
3 4 5 |
# File 'lib/track-r/story.rb', line 3 def story_type @story_type end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
7 8 9 |
# File 'lib/track-r/story.rb', line 7 def url @url end |
Instance Method Details
#build_story ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/track-r/story.rb', line 26 def build_story @id ||= @story.at('id').inner_html @url ||= "http://www.pivotaltracker.com/story/show/#{@id}" @api_url ||= "http://www.pivotaltracker.com/services/v2/projects/#{@project_id}/stories/#{@id}" @story_type = @story.at('story_type').inner_html unless @story.at('story_type').nil? @estimate = @story.at('estimate').inner_html unless @story.at('estimate').nil? @current_state = @story.at('current_state').inner_html unless @story.at('current_state').nil? @description = @story.at('description').inner_html unless @story.at('description').nil? @name = @story.at('name').inner_html unless @story.at('name').nil? @requested_by = @story.at('requested_by').inner_html unless @story.at('requested_by').nil? @owned_by = @story.at('owned_by').inner_html unless @story.at('owned_by').nil? @created_at = @story.at('created_at').inner_html unless @story.at('created_at').nil? @accepted_at = @story.at('accepted_at').inner_html unless @story.at('accepted_at').nil? @labels = @story.at('labels').inner_html unless @story.at('labels').nil? @comments ||= build_comments(@story.at('notes').inner_html) unless @story.at('notes').nil? end |
#destroy ⇒ Object
TODO: test this method:
70 71 72 73 74 75 |
# File 'lib/track-r/story.rb', line 70 def destroy api_url = URI.parse("http://www.pivotaltracker.com/services/v2/projects/#{@project_id}/stories/#{@id}") response = Net::HTTP.start(api_url.host, api_url.port) do |http| http.delete(api_url.path, {"X-TrackerToken" => @token}) end end |
#save ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/track-r/story.rb', line 58 def save parameters = build_story_xml api_url = URI.parse("http://www.pivotaltracker.com/services/v2/projects/#{@project_id}/stories/#{@id}") response = Net::HTTP.start(api_url.host, api_url.port) do |http| http.put(api_url.path, parameters, {'X-TrackerToken' => @token, 'Content-Type' => 'application/xml'}) end @story = (Hpricot(response.body)/:story) build_story end |
#update(attrs = {}) ⇒ Object
TODO: Test this method
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/track-r/story.rb', line 44 def update(attrs = {}) unless attrs.empty? if validate_attributes(attrs) attrs.each do |attribute, value| virt_attr = "#{attribute}=" self.send(virt_attr, value) end return save else raise ArgumentError end end end |