Class: PivotalTracker::Story
- Inherits:
-
Object
- Object
- PivotalTracker::Story
show all
- Includes:
- HappyMapper, Validation
- Defined in:
- lib/pivotal-tracker/story.rb,
lib/pivotal-tracker/story.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Validation
#create_with_validations, #errors, included, #update_with_validations
Constructor Details
#initialize(attributes = {}) ⇒ Story
Returns a new instance of Story.
52
53
54
55
56
57
|
# File 'lib/pivotal-tracker/story.rb', line 52
def initialize(attributes={})
if attributes[:owner]
self.project_id = attributes.delete(:owner).id
end
update_attributes(attributes)
end
|
Class Method Details
.all(project, options = {}) ⇒ Object
6
7
8
9
10
11
|
# File 'lib/pivotal-tracker/story.rb', line 6
def all(project, options={})
params = PivotalTracker.encode_options(options)
stories = parse(Client.connection["/projects/#{project.id}/stories#{params}"].get)
stories.each { |s| s.project_id = project.id }
return stories
end
|
.find(param, project_id) ⇒ Object
13
14
15
16
17
18
19
20
21
|
# File 'lib/pivotal-tracker/story.rb', line 13
def find(param, project_id)
begin
story = parse(Client.connection["/projects/#{project_id}/stories/#{param}"].get)
story.project_id = project_id
rescue RestClient::ExceptionWithResponse
story = nil
end
return story
end
|
.parse_stories(xml_string) ⇒ Object
23
24
25
|
# File 'lib/pivotal-tracker/story.rb', line 23
def parse_stories(xml_string)
parse(xml_string)
end
|
Instance Method Details
#create ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/pivotal-tracker/story.rb', line 59
def create
return self if project_id.nil?
response = Client.connection["/projects/#{project_id}/stories"].post(self.to_xml, :content_type => 'application/xml')
new_story = Story.parse(response)
new_story.project_id = project_id
return new_story
end
|
#delete ⇒ Object
78
79
80
|
# File 'lib/pivotal-tracker/story.rb', line 78
def delete
Client.connection["/projects/#{project_id}/stories/#{id}"].delete
end
|
#move(position, story) ⇒ Object
73
74
75
76
|
# File 'lib/pivotal-tracker/story.rb', line 73
def move(position, story)
raise ArgumentError, "Can only move :before or :after" unless [:before, :after].include? position
Story.parse(Client.connection["/projects/#{project_id}/stories/#{id}/moves?move\[move\]=#{position}&move\[target\]=#{story.id}"].post(''))
end
|
#move_to_project(new_project) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/pivotal-tracker/story.rb', line 94
def move_to_project(new_project)
move = true
old_project_id = self.project_id
target_project = -1
case new_project.class.to_s
when 'PivotalTracker::Story'
target_project = new_project.project_id
when 'PivotalTracker::Project'
target_project = new_project.id
when 'String'
target_project = new_project.to_i
when 'Fixnum', 'Integer'
target_project = new_project
else
move = false
end
if move
move_builder = Nokogiri::XML::Builder.new do |story|
story.story {
story.project_id "#{target_project}"
}
end
Story.parse(Client.connection["/projects/#{old_project_id}/stories/#{id}"].put(move_builder.to_xml, :content_type => 'application/xml'))
end
end
|
#notes ⇒ Object
82
83
84
|
# File 'lib/pivotal-tracker/story.rb', line 82
def notes
@notes ||= Proxy.new(self, Note)
end
|
#tasks ⇒ Object
86
87
88
|
# File 'lib/pivotal-tracker/story.rb', line 86
def tasks
@tasks ||= Proxy.new(self, Task)
end
|
#update(attrs = {}) ⇒ Object
67
68
69
70
71
|
# File 'lib/pivotal-tracker/story.rb', line 67
def update(attrs={})
update_attributes(attrs)
response = Client.connection["/projects/#{project_id}/stories/#{id}"].put(self.to_xml, :content_type => 'application/xml')
return Story.parse(response)
end
|
#upload_attachment(filename) ⇒ Object
90
91
92
|
# File 'lib/pivotal-tracker/story.rb', line 90
def upload_attachment(filename)
Attachment.parse(Client.connection["/projects/#{project_id}/stories/#{id}/attachments"].post(:Filedata => File.new(filename)))
end
|