Class: TrackerApi::Resources::Story

Inherits:
Object
  • Object
show all
Includes:
TrackerApi::Resources::Shared::Base
Defined in:
lib/tracker_api/resources/story.rb

Defined Under Namespace

Classes: UpdateRepresenter

Instance Method Summary collapse

Methods included from TrackerApi::Resources::Shared::Base

included

Instance Method Details

#activity(params = {}) ⇒ Array[Activity]

Provides a list of all the activity performed on the story.

Parameters:

  • params (Hash) (defaults to: {})

Returns:



120
121
122
# File 'lib/tracker_api/resources/story.rb', line 120

def activity(params = {})
  Endpoints::Activity.new(client).get_story(project_id, id, params)
end

#add_label(label) ⇒ Object

Adds a new label to the story.

Parameters:



90
91
92
93
94
95
96
97
98
99
# File 'lib/tracker_api/resources/story.rb', line 90

def add_label(label)
  new_label = if label.kind_of?(String)
    Label.new(name: label)
  else
    label
  end

  # Use attribute writer to get coercion and dirty tracking.
  self.labels = (labels ? labels.dup : []).push(new_label).uniq
end

#add_owner(owner) ⇒ Object

Adds a new owner to the story.

Parameters:



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/tracker_api/resources/story.rb', line 104

def add_owner(owner)
  owner_id = if owner.kind_of?(Integer)
    owner_id = owner
  else
    raise ArgumentError, 'Valid Person expected.' unless owner.instance_of?(Resources::Person)
    owner_id = owner.id
  end

  # Use attribute writer to get coercion and dirty tracking.
  self.owner_ids = (owner_ids ? owner_ids.dup : []).push(owner_id).uniq
end

#blockers(params = {}) ⇒ Object



124
125
126
# File 'lib/tracker_api/resources/story.rb', line 124

def blockers(params = {})
  Endpoints::Blockers.new(client).get(project_id, id, params)
end

#comments(reload: false) ⇒ Array[Comment]

Provides a list of all the comments on the story.

Parameters:

Returns:



132
133
134
135
136
137
138
# File 'lib/tracker_api/resources/story.rb', line 132

def comments(reload: false)
  if !reload && @comments.present?
    @comments
  else
    @comments = Endpoints::Comments.new(client).get(project_id, story_id: id)
  end
end

#create_comment(params) ⇒ Comment

Returns newly created Comment.

Parameters:

  • params (Hash)

    attributes to create the comment with

Returns:

  • (Comment)

    newly created Comment



195
196
197
198
199
200
# File 'lib/tracker_api/resources/story.rb', line 195

def create_comment(params)
  files = params.delete(:files)
  comment = Endpoints::Comment.new(client).create(project_id, story_id: id, params: params)
  comment.create_attachments(files: files) if files.present?
  comment
end

#create_task(params) ⇒ Task

Returns newly created Task.

Parameters:

  • params (Hash)

    attributes to create the task with

Returns:

  • (Task)

    newly created Task



189
190
191
# File 'lib/tracker_api/resources/story.rb', line 189

def create_task(params)
  Endpoints::Task.new(client).create(project_id, id, params)
end

#label_listString

Returns Comma separated list of labels.

Returns:

  • (String)

    Comma separated list of labels.



80
81
82
83
84
85
# File 'lib/tracker_api/resources/story.rb', line 80

def label_list
  @label_list ||= begin
    return if labels.nil?
    labels.collect(&:name).join(',')
  end
end

#owners(params = {}) ⇒ Array[Person]

Provides a list of all the owners of the story.

Parameters:

  • params (Hash) (defaults to: {})

Returns:



156
157
158
159
160
161
162
# File 'lib/tracker_api/resources/story.rb', line 156

def owners(params = {})
  if params.blank? && @owners.present?
    @owners
  else
    @owners = Endpoints::StoryOwners.new(client).get(project_id, id, params)
  end
end

#project_idObject

Returns the story’s original (“undirtied”) project_id

Returns:

  • Integer



179
180
181
182
183
184
185
# File 'lib/tracker_api/resources/story.rb', line 179

def project_id
  if dirty_attributes.key?(:project_id)
    original_attributes[:project_id]
  else
    @project_id
  end
end

#reviews(params = {}) ⇒ Object



210
211
212
213
214
215
216
# File 'lib/tracker_api/resources/story.rb', line 210

def reviews(params = {})
    if params.blank? && @reviews.present?
      @reviews
    else
      @reviews = Endpoints::Reviews.new(client).get(project_id, id, params)
    end
end

#saveObject

Save changes to an existing Story.

Raises:

  • (ArgumentError)


203
204
205
206
207
208
# File 'lib/tracker_api/resources/story.rb', line 203

def save
  raise ArgumentError, 'Can not update a story with an unknown project_id.' if project_id.nil?
  return self unless dirty?

  Endpoints::Story.new(client).update(self, UpdateRepresenter.new(Story.new(self.dirty_attributes)))
end

#tasks(params = {}) ⇒ Array[Task]

Provides a list of all the tasks on the story.

Parameters:

  • params (Hash) (defaults to: {})

Returns:



144
145
146
147
148
149
150
# File 'lib/tracker_api/resources/story.rb', line 144

def tasks(params = {})
  if params.blank? && @tasks.present?
    @tasks
  else
    @tasks = Endpoints::Tasks.new(client).get(project_id, id, params)
  end
end

#transitions(params = {}) ⇒ Array[StoryTransition]

Provides a list of all the transitions of the story.

Parameters:

  • params (Hash) (defaults to: {})

Returns:



168
169
170
171
172
173
174
# File 'lib/tracker_api/resources/story.rb', line 168

def transitions(params = {})
  if params.blank? && @transitions.present?
    @transitions
  else
    @transitions = Endpoints::StoryTransitions.new(client).get(project_id, id, params)
  end
end