Class: Marlens::JiraApi::RemoteImageAttachmentUploader
- Inherits:
-
Object
- Object
- Marlens::JiraApi::RemoteImageAttachmentUploader
- Defined in:
- lib/marlens/jira_api/remote_image_attachment_uploader.rb
Constant Summary collapse
- MAX_REDIRECTS =
5
Instance Method Summary collapse
-
#initialize(client:, issue_key:, allowed_hosts:, strict: false, failures: nil) ⇒ RemoteImageAttachmentUploader
constructor
A new instance of RemoteImageAttachmentUploader.
- #media_node_for(image) ⇒ Object
Constructor Details
#initialize(client:, issue_key:, allowed_hosts:, strict: false, failures: nil) ⇒ RemoteImageAttachmentUploader
Returns a new instance of RemoteImageAttachmentUploader.
22 23 24 25 26 27 28 |
# File 'lib/marlens/jira_api/remote_image_attachment_uploader.rb', line 22 def initialize(client:, issue_key:, allowed_hosts:, strict: false, failures: nil) @allowed_hosts = allowed_hosts @client = client @failures = failures @issue_key = issue_key @strict = strict end |
Instance Method Details
#media_node_for(image) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/marlens/jira_api/remote_image_attachment_uploader.rb', line 30 def media_node_for(image) = (image.fetch(:url)) dimensions = .fetch("dimensions") MarkdownToAdf.external_media_single( url: .fetch("content"), alt: image[:alt].to_s.strip.empty? ? .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 failure = { url: image[:url], alt: image[:alt], error_class: error.class.name, error_message: error. } @failures << failure if @failures raise ImageUploadError.new(failure) if @strict warn "Failed to upload image #{image[:url]}: #{error.class}: #{error.}" MarkdownToAdf.paragraph("#{image[:alt] || "Image"}: #{image[:url]}") end |