class TicketAbstractorClient::Jira::Attachment

Attributes

endpoint[RW]
project[RW]
ticket_id[RW]

Public Class Methods

fetch(ticket_id, endpoint)
Alias for: fetch_by_ticket_id
fetch_by_id_and_name(id, name, endpoint) click to toggle source
# 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) click to toggle source
# 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
Also aliased as: fetch
new(opts) click to toggle source
# 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

Protected Class Methods

download_attachment(id, name, endpoint) click to toggle source
# File lib/ticket_abstractor_client/jira/attachment.rb, line 25
def download_attachment(id, name, endpoint)
  file_content = Client.new(endpoint).get_attachment(id: id, name: name)
  save_content(file_content, "#{id}_#{name}")
end

Public Instance Methods

sync!() click to toggle source
# 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