Class: BugsnagSourcemapUploader::UploadTask

Inherits:
Object
  • Object
show all
Defined in:
lib/bugsnag_sourcemap_uploader/upload_task.rb

Overview

The unit of work to send a sourcemap with its associated minified javascript file to Bugsnag.

Defined Under Namespace

Classes: ExecutionErrorResult, Result

Constant Summary collapse

UPLOAD_URL =

Bugsnag upload URL

'https://upload.bugsnag.com/'

Instance Method Summary collapse

Constructor Details

#initialize(asset_metadata:, bugsnag_api_key:) ⇒ UploadTask

Returns a new instance of UploadTask.



11
12
13
14
# File 'lib/bugsnag_sourcemap_uploader/upload_task.rb', line 11

def initialize(asset_metadata:, bugsnag_api_key:)
  @asset_metadata = 
  @bugsnag_api_key = bugsnag_api_key
end

Instance Method Details

#run(http_options: {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bugsnag_sourcemap_uploader/upload_task.rb', line 16

def run(http_options: {})
  body_payload = {
    'apiKey' => @bugsnag_api_key,
    'minifiedUrl' => @asset_metadata.cdn_url,
    'sourceMap' => source_map_contents,
    'minifiedFile' => script_contents,
    'overwrite' => true
  }

  payload = http_options.merge(body: body_payload)

  Result.new(
    @asset_metadata,
    HTTParty.post(UPLOAD_URL, payload)
  )
rescue StandardError => e
  ExecutionErrorResult.new(@asset_metadata, e)
end