Class: TrackR::Story
- Inherits:
-
Object
- Object
- TrackR::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 ⇒ Object
Returns the value of attribute story.
-
#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.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/track-r/story.rb', line 10 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 = "#{CONFIG[:api_url]}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.
4 5 6 |
# File 'lib/track-r/story.rb', line 4 def accepted_at @accepted_at end |
#comments ⇒ Object
Returns the value of attribute comments.
4 5 6 |
# File 'lib/track-r/story.rb', line 4 def comments @comments end |
#created_at ⇒ Object
Returns the value of attribute created_at.
4 5 6 |
# File 'lib/track-r/story.rb', line 4 def created_at @created_at end |
#current_state ⇒ Object
Returns the value of attribute current_state.
4 5 6 |
# File 'lib/track-r/story.rb', line 4 def current_state @current_state end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/track-r/story.rb', line 4 def description @description end |
#estimate ⇒ Object
Returns the value of attribute estimate.
4 5 6 |
# File 'lib/track-r/story.rb', line 4 def estimate @estimate end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/track-r/story.rb', line 8 def id @id end |
#labels ⇒ Object
Returns the value of attribute labels.
4 5 6 |
# File 'lib/track-r/story.rb', line 4 def labels @labels end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/track-r/story.rb', line 4 def name @name end |
#owned_by ⇒ Object
Returns the value of attribute owned_by.
4 5 6 |
# File 'lib/track-r/story.rb', line 4 def owned_by @owned_by end |
#project_id ⇒ Object
Returns the value of attribute project_id.
4 5 6 |
# File 'lib/track-r/story.rb', line 4 def project_id @project_id end |
#requested_by ⇒ Object
Returns the value of attribute requested_by.
4 5 6 |
# File 'lib/track-r/story.rb', line 4 def requested_by @requested_by end |
#story ⇒ Object
Returns the value of attribute story.
4 5 6 |
# File 'lib/track-r/story.rb', line 4 def story @story end |
#story_type ⇒ Object
Returns the value of attribute story_type.
4 5 6 |
# File 'lib/track-r/story.rb', line 4 def story_type @story_type end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/track-r/story.rb', line 8 def url @url end |
Instance Method Details
#build_story ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/track-r/story.rb', line 27 def build_story @id ||= @story.at('id').inner_html if @story.at('id') @url ||= "http://www.pivotaltracker.com/story/show/#{@id}" @api_url ||= "#{CONFIG[:api_url]}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:
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/track-r/story.rb', line 79 def destroy api_url = URI.parse("#{CONFIG[:api_url]}projects/#{@project_id}/stories/#{@id}") 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 rescue ResponseError => e print "Got response code [#{response.code}]:\t" puts response. raise end end |
#save ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/track-r/story.rb', line 59 def save parameters = build_story_xml api_url = URI.parse("#{CONFIG[:api_url]}projects/#{@project_id}/stories/#{@id}") begin http = Net::HTTP.new(api_url.host, api_url.port) http.use_ssl = true response, data = http.put(api_url.path, parameters, {'X-TrackerToken' => @token, 'Content-Type' => 'application/xml'}) raise ResponseError, "Wrong response code" unless response.code.to_i == 200 rescue ResponseError => e print "Got response code [#{response.code}]:\t" puts response. raise end @story = (Hpricot(response.body)/:story) build_story end |
#update(attrs = {}) ⇒ Object
TODO: Test this method
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/track-r/story.rb', line 45 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 |