class JIRA::Resource::Attachment

Public Class Methods

endpoint_name() click to toggle source
# File lib/jira/resource/attachment.rb, line 13
def self.endpoint_name
  'attachments'
end
meta(client) click to toggle source
# File lib/jira/resource/attachment.rb, line 17
def self.meta(client)
  response = client.get(client.options[:rest_base_path] + '/attachment/meta')
  parse_json(response.body)
end

Public Instance Methods

save!(attrs, path = url) click to toggle source
# File lib/jira/resource/attachment.rb, line 22
def save!(attrs, path = url)
  file = attrs['file'] || attrs[:file] # Keep supporting 'file' parameter as a string for backward compatibility
  mime_type = attrs[:mimeType] || 'application/binary'

  headers = { 'X-Atlassian-Token' => 'nocheck' }
  data = { 'file' => UploadIO.new(file, mime_type, file) }

  response = client.post_multipart(path, data , headers)

  set_attributes(attrs, response)

  @expanded = false
  true
end

Private Instance Methods

set_attributes(attributes, response) click to toggle source
# File lib/jira/resource/attachment.rb, line 39
def set_attributes(attributes, response)
  set_attrs(attributes, false)
  return if response.body.nil? || response.body.length < 2

  json = self.class.parse_json(response.body)
  attachment = json[0]

  set_attrs(attachment)
end