Class: Asana::Resources::Story

Inherits:
StoriesBase show all
Defined in:
lib/asana/resources/story.rb

Overview

A story represents an activity associated with an object in the Asana system. Stories are generated by the system whenever users take actions such as creating or assigning tasks, or moving tasks between projects. Comments are also a form of user-generated story.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from StoriesBase

create_story_for_task, delete_story, get_stories_for_task, get_story, inherited, update_story

Methods inherited from Resource

#initialize, #method_missing, #refresh, #respond_to_missing?, #to_h, #to_s

Methods included from ResponseHelper

#parse

Constructor Details

This class inherits a constructor from Asana::Resources::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Asana::Resources::Resource

Instance Attribute Details

#created_atObject (readonly)



18
19
20
# File 'lib/asana/resources/story.rb', line 18

def created_at
  @created_at
end

#created_byObject (readonly)



20
21
22
# File 'lib/asana/resources/story.rb', line 20

def created_by
  @created_by
end

#gidObject (readonly)



12
13
14
# File 'lib/asana/resources/story.rb', line 12

def gid
  @gid
end

#html_textObject (readonly)



32
33
34
# File 'lib/asana/resources/story.rb', line 32

def html_text
  @html_text
end

#is_editedObject (readonly)



38
39
40
# File 'lib/asana/resources/story.rb', line 38

def is_edited
  @is_edited
end

#is_pinnedObject (readonly)



36
37
38
# File 'lib/asana/resources/story.rb', line 36

def is_pinned
  @is_pinned
end

#likedObject (readonly) Also known as: hearted



22
23
24
# File 'lib/asana/resources/story.rb', line 22

def liked
  @liked
end

#likesObject (readonly) Also known as: hearts



25
26
27
# File 'lib/asana/resources/story.rb', line 25

def likes
  @likes
end

#num_likesObject (readonly)



28
29
30
# File 'lib/asana/resources/story.rb', line 28

def num_likes
  @num_likes
end

#resource_subtypeObject (readonly)



16
17
18
# File 'lib/asana/resources/story.rb', line 16

def resource_subtype
  @resource_subtype
end

#resource_typeObject (readonly)



14
15
16
# File 'lib/asana/resources/story.rb', line 14

def resource_type
  @resource_type
end

#sourceObject (readonly)



40
41
42
# File 'lib/asana/resources/story.rb', line 40

def source
  @source
end

#targetObject (readonly)



34
35
36
# File 'lib/asana/resources/story.rb', line 34

def target
  @target
end

#textObject (readonly)



30
31
32
# File 'lib/asana/resources/story.rb', line 30

def text
  @text
end

#typeObject (readonly)



42
43
44
# File 'lib/asana/resources/story.rb', line 42

def type
  @type
end

Class Method Details

.create_on_task(client, task: required("task"), text: required("text"), options: {}, **data) ⇒ Object

Adds a comment to a task. The comment will be authored by the currently authenticated user, and timestamped when the server receives the request.



82
83
84
85
# File 'lib/asana/resources/story.rb', line 82

def create_on_task(client, task: required("task"), text: required("text"), options: {}, **data)
  with_params = data.merge(text: text).reject { |_,v| v.nil? || Array(v).empty? }
  self.new(parse(client.post("/tasks/#{task}/stories", body: with_params, options: options)).first, client: client)
end

.find_by_id(client, id, options: {}) ⇒ Object

Returns the full record for a single story.



66
67
68
69
# File 'lib/asana/resources/story.rb', line 66

def find_by_id(client, id, options: {})

  self.new(parse(client.get("/stories/#{id}", options: options)).first, client: client)
end

.find_by_task(client, task: required("task"), per_page: 20, options: {}) ⇒ Object

Returns the compact records for all stories on the task.



56
57
58
59
# File 'lib/asana/resources/story.rb', line 56

def find_by_task(client, task: required("task"), per_page: 20, options: {})
  params = { limit: per_page }.reject { |_,v| v.nil? || Array(v).empty? }
  Collection.new(parse(client.get("/tasks/#{task}/stories", params: params, options: options)), type: self, client: client)
end

.plural_nameObject

Returns the plural name of the resource.



46
47
48
# File 'lib/asana/resources/story.rb', line 46

def plural_name
  'stories'
end

Instance Method Details

#deleteObject

Deletes a story. A user can only delete stories they have created. Returns an empty data record.



104
105
106
107
# File 'lib/asana/resources/story.rb', line 104

def delete()

  client.delete("/stories/#{gid}") && true
end

#update(text: nil, html_text: nil, is_pinned: nil, options: {}, **data) ⇒ Object

Updates the story and returns the full record for the updated story. Only comment stories can have their text updated, and only comment stories and attachment stories can be pinned. Only one of ‘text` and `html_text` can be specified.



98
99
100
101
# File 'lib/asana/resources/story.rb', line 98

def update(text: nil, html_text: nil, is_pinned: nil, options: {}, **data)
  with_params = data.merge(text: text, html_text: html_text, is_pinned: is_pinned).reject { |_,v| v.nil? || Array(v).empty? }
  refresh_with(parse(client.put("/stories/#{gid}", body: with_params, options: options)).first)
end