Class: Marlens::JiraApi::RemoteImageAttachmentUploader

Inherits:
Object
  • Object
show all
Defined in:
lib/marlens/jira_api/remote_image_attachment_uploader.rb

Constant Summary collapse

MAX_REDIRECTS =
5

Instance Method Summary collapse

Constructor Details

#initialize(client:, issue_key:, allowed_hosts:) ⇒ RemoteImageAttachmentUploader

Returns a new instance of RemoteImageAttachmentUploader.



13
14
15
16
17
# File 'lib/marlens/jira_api/remote_image_attachment_uploader.rb', line 13

def initialize(client:, issue_key:, allowed_hosts:)
  @allowed_hosts = allowed_hosts
  @client = client
  @issue_key = issue_key
end

Instance Method Details

#media_node_for(image) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/marlens/jira_api/remote_image_attachment_uploader.rb', line 19

def media_node_for(image)
  attachment = upload_image_attachment(image.fetch(:url))
  dimensions = attachment.fetch("dimensions")

  MarkdownToAdf.media_single(
    id: attachment.fetch("id"),
    alt: image[:alt].to_s.strip.empty? ? attachment.fetch("filename") : image[:alt],
    width: image_dimension_value(image[:width], dimensions.fetch("width")),
    height: image_dimension_value(image[:height], dimensions.fetch("height"))
  )
rescue StandardError => error
  warn "Failed to upload image #{image[:url]}: #{error.class}: #{error.message}"
  MarkdownToAdf.paragraph("#{image[:alt] || "Image"}: #{image[:url]}")
end