Module: UiDelta::Utils
- Defined in:
- lib/ui_delta/utils.rb
Class Method Summary collapse
-
.connection ⇒ Object
http connection that will be used for uploading images.
- .get_presigned_url(run_id, identifier) ⇒ Object
- .image_file(identifier) ⇒ Object
- .images_dir ⇒ Object
- .upload_image(run_id, identifier, browser, device, os, browser_version, device_name, os_version, image_width, image_height) ⇒ Object
Class Method Details
.connection ⇒ Object
http connection that will be used for uploading images
4 5 6 7 8 9 10 11 12 |
# File 'lib/ui_delta/utils.rb', line 4 def self.connection base_uri = UiDelta.base_uri Faraday.new(base_uri, request: { timeout: 120, open_timeout: 120 }) do |f| f.request :authorization, :basic, UiDelta.api_key, 'X' f.request :multipart f.request :url_encoded f.adapter :net_http end end |
.get_presigned_url(run_id, identifier) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/ui_delta/utils.rb', line 41 def self.get_presigned_url(run_id, identifier) resp = connection.post( "/api/v1/runs/#{run_id}/run_images/presigned-url", filename: "#{identifier}.png" ) JSON.parse resp.body end |
.image_file(identifier) ⇒ Object
37 38 39 |
# File 'lib/ui_delta/utils.rb', line 37 def self.image_file(identifier) "#{Dir.pwd}/#{images_dir}/#{identifier}.png" end |
.images_dir ⇒ Object
14 15 16 |
# File 'lib/ui_delta/utils.rb', line 14 def self.images_dir 'tmp/ui_delta'.freeze end |
.upload_image(run_id, identifier, browser, device, os, browser_version, device_name, os_version, image_width, image_height) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ui_delta/utils.rb', line 18 def self.upload_image(run_id, identifier, browser, device, os, browser_version, device_name, os_version, image_width, image_height) image_content = File.open(image_file(identifier), 'rb').read data = get_presigned_url(run_id, identifier) # upload to S3 directly resp = Faraday.put(data["presign_url"], image_content) unless resp.status == 200 raise "Failed to complete UiDelta image [#{identifier}.png] upload" end # create the run image on UiDelta connection.post("/api/v1/runs/#{run_id}/run_images", image: data["image_url"], image_width: image_width, image_height: image_height, identifier: identifier, browser: browser, device: device, os: os, browser_version: browser_version, device_name: device_name, os_version: os_version) end |