Class: TicketAbstractorClient::Jira::Attachment

Inherits:
Base::Attachment show all
Defined in:
lib/ticket_abstractor_client/jira/attachment.rb

Constant Summary

Constants inherited from Base::Attachment

Base::Attachment::SANITIZE_REGEXP

Instance Attribute Summary collapse

Attributes inherited from Base::Attachment

#communications_stack, #data_hash, #external_created_at, #file_path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base::Attachment

#set_data_hash!, #to_hash, #to_json

Constructor Details

#initialize(opts) ⇒ Attachment

Returns a new instance of Attachment.



31
32
33
34
# File 'lib/ticket_abstractor_client/jira/attachment.rb', line 31

def initialize(opts)
  super(opts)
  @ticket_id, @endpoint, @project = opts.values_at(:ticket_id, :endpoint, :project)
end

Instance Attribute Details

#endpointObject

Returns the value of attribute endpoint.



4
5
6
# File 'lib/ticket_abstractor_client/jira/attachment.rb', line 4

def endpoint
  @endpoint
end

#projectObject

Returns the value of attribute project.



4
5
6
# File 'lib/ticket_abstractor_client/jira/attachment.rb', line 4

def project
  @project
end

#ticket_idObject

Returns the value of attribute ticket_id.



4
5
6
# File 'lib/ticket_abstractor_client/jira/attachment.rb', line 4

def ticket_id
  @ticket_id
end

Class Method Details

.fetch_by_id_and_name(id, name, endpoint) ⇒ Object



7
8
9
10
# File 'lib/ticket_abstractor_client/jira/attachment.rb', line 7

def fetch_by_id_and_name(id, name, endpoint)
  file_path = download_attachment(id, name, endpoint)
  new(file_path: file_path, endpoint: endpoint)
end

.fetch_by_ticket_id(ticket_id, endpoint) ⇒ Object Also known as: fetch



12
13
14
15
16
17
18
19
20
# File 'lib/ticket_abstractor_client/jira/attachment.rb', line 12

def fetch_by_ticket_id(ticket_id, endpoint)
  ticket = Client.new(endpoint).get_ticket_by_id(ticket_id: ticket_id, fields: :attachment)

  ticket['fields']['attachment'].each_with_object([]) do |hash, attachments|
    attachment = fetch_by_id_and_name(hash['id'], hash['filename'], endpoint)
    attachment.ticket_id = ticket_id
    attachments << attachment
  end
end

Instance Method Details

#sync!Object



36
37
38
39
# File 'lib/ticket_abstractor_client/jira/attachment.rb', line 36

def sync!
  response = Client.new(@endpoint).create_attachment(self)
  @external_created_at = response.first['created']
end