Class: Clubhouse::Story
- Inherits:
-
ClubhouseResource
- Object
- ClubhouseResource
- Clubhouse::Story
- Defined in:
- lib/clubhouse2/story.rb
Class Method Summary collapse
Instance Method Summary collapse
- #branches(**args) ⇒ Object
- #comment(**args) ⇒ Object
- #comments(**args) ⇒ Object
- #commits(**args) ⇒ Object
- #create_comment(**args) ⇒ Object
- #create_task(**args) ⇒ Object
- #files(**args) ⇒ Object
- #full_story(**args) ⇒ Object
- #labels(**args) ⇒ Object
- #linked_files(**args) ⇒ Object
- #story_link(**args) ⇒ Object
- #story_links(**args) ⇒ Object
- #task(**args) ⇒ Object
- #tasks(**args) ⇒ Object
- #to_h ⇒ Object
- #update(**args) ⇒ Object
- #validate(**args) ⇒ Object
Methods inherited from ClubhouseResource
#api_url, #delete!, #flush, inherited, #initialize, property_filter_create, property_filter_update, #resolve_to_ids, #set_properties, subclass, validate, #value_format
Constructor Details
This class inherits a constructor from Clubhouse::ClubhouseResource
Class Method Details
.api_url ⇒ Object
12 13 14 |
# File 'lib/clubhouse2/story.rb', line 12 def self.api_url 'stories' end |
.properties ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/clubhouse2/story.rb', line 3 def self.properties [ :archived, :blocker, :blocked, :comment_ids, :completed, :completed_at, :completed_at_override, :created_at, :deadline, :entity_type, :epic_id, :estimate, :external_id, :file_ids, :follower_ids, :id, :linked_file_ids, :moved_at, :name, :owner_ids, :position, :project_id, :requested_by_id, :started, :started_at, :started_at_override, :story_type, :task_ids, :updated_at, :workflow_state_id, :app_url ] end |
Instance Method Details
#branches(**args) ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/clubhouse2/story.rb', line 124 def branches(**args) @branches ||= begin full_story['branches'].collect do |branch_data| Branch.new(client: @client, object: branch_data) end end end |
#comment(**args) ⇒ Object
138 |
# File 'lib/clubhouse2/story.rb', line 138 def comment(**args); comments(args).first; end |
#comments(**args) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/clubhouse2/story.rb', line 58 def comments(**args) @comments ||= @comment_ids.collect do |this_comment_id| comment_data = JSON.parse(@client.api_request(:get, @client.url("#{api_url}/comments/#{this_comment_id}"))) Storycomment.new(client: @client, object: comment_data) end @comments.reject { |s| args.collect { |k,v| s.send(k) != v }.reduce(:|) } end |
#commits(**args) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/clubhouse2/story.rb', line 116 def commits(**args) @commits ||= begin full_story['commits'].collect do |commit_data| Commit.new(client: @client, object: commit_data) end end end |
#create_comment(**args) ⇒ Object
132 133 134 135 136 |
# File 'lib/clubhouse2/story.rb', line 132 def create_comment(**args) Task.validate(**args) @comments = nil JSON.parse(@client.api_request(:post, @client.url("#{api_url}/#{Storycomment.api_url}"), :json => args)) end |
#create_task(**args) ⇒ Object
52 53 54 55 56 |
# File 'lib/clubhouse2/story.rb', line 52 def create_task(**args) Task.validate(**args) @tasks = nil JSON.parse(@client.api_request(:post, @client.url("#{api_url}/#{Task.api_url}"), :json => args)) end |
#files(**args) ⇒ Object
90 91 92 |
# File 'lib/clubhouse2/story.rb', line 90 def files(**args) @client.files(story_ids: @id, **args) end |
#full_story(**args) ⇒ Object
110 111 112 113 114 |
# File 'lib/clubhouse2/story.rb', line 110 def full_story(**args) @full_story ||= begin JSON.parse(@client.api_request(:get, @client.url("#{Story.api_url}/#{id}"))) end end |
#labels(**args) ⇒ Object
94 95 96 |
# File 'lib/clubhouse2/story.rb', line 94 def labels(**args) @labels.collect { |l| @client.label(id: l['id'], **args) } end |
#linked_files(**args) ⇒ Object
86 87 88 |
# File 'lib/clubhouse2/story.rb', line 86 def linked_files(**args) @client.linked_files(story_ids: @id, **args) end |
#story_link(**args) ⇒ Object
139 |
# File 'lib/clubhouse2/story.rb', line 139 def story_link(**args); story_links(args).first; end |
#story_links(**args) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/clubhouse2/story.rb', line 67 def story_links(**args) @story_link_objects ||= @story_links.collect do |this_story_link| link_data = JSON.parse(@client.api_request(:get, @client.url("#{Storylink.api_url}/#{this_story_link['id']}"))) link_data.reject { |k, v| v == @id} Storylink.new(client: @client, object: link_data) end @story_link_objects.reject { |s| args.collect { |k,v| s.send(k) != v }.reduce(:|) } end |
#task(**args) ⇒ Object
140 |
# File 'lib/clubhouse2/story.rb', line 140 def task(**args); tasks(args).first; end |
#tasks(**args) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/clubhouse2/story.rb', line 77 def tasks(**args) @tasks ||= @task_ids.collect do |this_task_id| task_data = JSON.parse(@client.api_request(:get, @client.url("#{api_url}/tasks/#{this_task_id}"))) Task.new(client: @client, object: task_data) end @tasks.reject { |s| args.collect { |k,v| s.send(k) != v }.reduce(:|) } end |
#to_h ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/clubhouse2/story.rb', line 98 def to_h super.merge({ comments: [ *comments ].collect(&:to_h), tasks: [ *tasks ].collect(&:to_h), files: [ *files ].collect(&:to_h), story_links: [ *story_links ].collect(&:to_h), labels: [ *labels ].collect(&:to_h), branches: [ *branches ].collect(&:to_h), commits: [ *commits ].collect(&:to_h), }) end |
#update(**args) ⇒ Object
46 47 48 49 50 |
# File 'lib/clubhouse2/story.rb', line 46 def update(**args) # The API won't let us try to update the project ID without changing it args.delete(:project_id) if args[:project_id] == @project_id super end |
#validate(**args) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/clubhouse2/story.rb', line 16 def validate(**args) raise NoSuchEpic.new(args[:epic_id]) unless @client.epic(id: args[:epic_id]) if args[:epic_id] raise NoSuchProject.new(args[:project_id]) unless @client.project(id: args[:project_id]) if args[:project_id] raise NoSuchMember.new(args[:requested_by_id]) unless @client.member(id: args[:requested_by_id]) if args[:requested_by_id] (args[:follower_ids] || []).each do |this_member| raise NoSuchMember.new(this_member) unless @client.member(id: this_member) end (args[:owner_ids] || []).each do |this_member| raise NoSuchMember.new(this_member) unless @client.member(id: this_member) end (args[:file_ids] || []).each do |this_file| raise NoSuchFile.new(this_file) unless @client.file(id: this_file) end (args[:linked_file_ids] || []).each do |this_linked_file| raise NoSuchLinkedFile.new(this_linked_file) unless @client.linked_file(id: this_linked_file) end (args[:story_links] || []).each do |this_linked_story| raise NoSuchLinkedStory.new(this_linked_story) unless @client.story(id: this_linked_story['subject_id']) end (args[:labels] || []).collect! do |this_label| this_label.is_a? Label ? this_label : @client.label(id: this_label['name']) end end |