Class: YandexTracker::Collections::Attachments

Inherits:
Base
  • Object
show all
Defined in:
lib/yandex_tracker/collections/attachments.rb

Overview

Collections::Attachments

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#inspect

Constructor Details

#initialize(client, issue_id = nil, comment_id = nil) ⇒ Attachments

Returns a new instance of Attachments.



9
10
11
12
13
14
# File 'lib/yandex_tracker/collections/attachments.rb', line 9

def initialize(client, issue_id = nil, comment_id = nil)
  super(client)
  @resource = Resources::Attachment.new(client)
  @issue_id = issue_id
  @comment_id = comment_id
end

Instance Method Details

#create(file, **attributes) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/yandex_tracker/collections/attachments.rb', line 16

def create(file, **attributes)
  response = if comment_id
               resource.create_for_comment(issue_id, comment_id, file, **attributes)
             elsif issue_id
               resource.create_for_issue(issue_id, file, **attributes)
             else
               resource.create(file, **attributes) # Create unattached file
             end
  build_object(Objects::Attachment, response, { issue_id: issue_id })
end

#find(id) ⇒ Object



27
28
29
30
# File 'lib/yandex_tracker/collections/attachments.rb', line 27

def find(id)
  response = resource.find(id)
  build_object(Objects::Attachment, response, { issue_id: issue_id })
end

#list(**params) ⇒ Object



32
33
34
35
36
# File 'lib/yandex_tracker/collections/attachments.rb', line 32

def list(**params)
  params = params.merge(issue: issue_id) if issue_id
  response = resource.list(issue_id, **params)
  build_objects(Objects::Attachment, response, { issue_id: issue_id })
end