eivid 1.1.4 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84e784e3dbec889dae0b8fd97deade4b7dfb158845015783c1f3bc4bf7ff1f5f
4
- data.tar.gz: d804c9c9c80d164bcfcf07046d880f3359e7e1c6f030d038039c43e711689941
3
+ metadata.gz: 24ee978f547944d6c9468eeebfe0d4a8e196c2dc273118139255b30349487e4e
4
+ data.tar.gz: b619bca48a02939b349535d99e273eff04731ecf5efcdfebf9c2364cec9d172f
5
5
  SHA512:
6
- metadata.gz: ade10d5df13c9d5bd79ce6c1c0e12a8ac470feca13d0cc7c0611a51d632dd01fb344afe54a4163a0a781238b8c9f63f3ceb6726a71aa17c93160eb4ef76bda75
7
- data.tar.gz: e6df28555d25e1d259546285924e5fd237383bebfb9ce98b7856c3b2618428ca31245a07b67cc5f37396aa1aefb89cf6c863e232e820aba97bb3104774339586
6
+ metadata.gz: 53d3bf0598eb180fb6e0c11087de04db614da1f9ab9bab9fe37cb9ca96c192936854960a1e1713fae9bdad8f0c7df6ed7e4deb398a5da216886dcf592f288faa
7
+ data.tar.gz: 72fd598c3d9f2e89c378eaff5e37ab91899ac453bbd3435dfdc2cd9599d0fbf1532a47f5194c4661766ea1a119b25cdff93934333f4623349099f0088fff3cbf
@@ -2,54 +2,20 @@ module Eivid
2
2
  class UploadVimeoJob < ApplicationJob
3
3
 
4
4
  def perform(video_record:, video_path:)
5
- @video_record = video_record
6
- @video_path = video_path
7
- @video_file = File.open(video_path).read
5
+ # Upload video
6
+ uploaded_data = Eivid::RequestService.upload_video(video_path:)
7
+ vimeo_id, vimeo_url = uploaded_data.values_at(:vimeo_id, :vimeo_url)
8
8
 
9
- upload_to_vimeo
10
- set_attributes
11
- update_record
12
- add_to_folder
13
-
14
- notify_front
15
- check_status
16
- end
17
-
18
- private
9
+ # Update records
10
+ video_record.update(url_embedded: vimeo_url, vimeo_id:)
11
+ Eivid::RequestService.add_video_to_folder(video_record:)
19
12
 
20
- def upload_to_vimeo
21
- @response = Eivid::RequestService.upload_video(video_path: @video_path)
22
- end
23
-
24
- def set_attributes
25
- set_vimeo_url
26
- set_vimeo_id
27
- end
28
-
29
- def set_vimeo_url
30
- @vimeo_url = @response.dig(:link)
31
- end
32
-
33
- def set_vimeo_id
34
- @vimeo_id = @vimeo_url.split('/').last
35
- end
36
-
37
- def update_record
38
- @video_record.update(url_embedded: @vimeo_url, vimeo_id: @vimeo_id)
39
- end
40
-
41
- def add_to_folder
42
- Eivid::RequestService.add_video_to_folder(video_record: @video_record)
43
- end
44
-
45
- def check_status
46
- CheckVimeoStatusJob.perform_later(video_record: @video_record)
47
- end
48
-
49
- def notify_front
50
- data = { video: @video_record.slice(:id, :user_id), progress: { percentage: 33, step: "The video has been uploaded to Vimeo." } }
13
+ # Communicate status to the front-end
14
+ data = { video: video_record.slice(:id, :user_id), progress: { percentage: 33, step: "The video has been uploaded to Vimeo." } }
51
15
  NotifyFrontService.progress('notify_method_on_upload', data)
16
+ CheckVimeoStatusJob.perform_later(video_record:)
52
17
  end
53
18
 
19
+
54
20
  end
55
21
  end
@@ -2,38 +2,43 @@ module Eivid::Concerns::RequestService::UploadVideo
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  def upload_video(video_path:)
5
- @file = File.open(video_path)
6
- retrieve_upload_link
7
- tus_upload_to_vimeo
8
- @response
5
+ file = File.open(video_path)
6
+ data = retrieve_upload_link(file: file)
7
+ upload_link, response = data.values_at(:upload_link, :response)
8
+ vimeo_url = response.dig(:link)
9
+ vimeo_id = vimeo_url.split('/').last
10
+
11
+ tus_upload_to_vimeo(file:, upload_link:)
12
+ {vimeo_id:, vimeo_url:}
9
13
  end
10
14
 
11
15
  private
12
16
 
13
- def retrieve_upload_link
17
+ def retrieve_upload_link(file:)
14
18
  efforts = 0
15
19
  max_efforts = 180
16
20
  sleep_time = 1
21
+ upload_link = nil
17
22
 
18
- while @upload_link.blank? && efforts < max_efforts do
23
+ while upload_link.blank? && efforts < max_efforts do
19
24
 
20
25
  puts "Trying to retrieve upload link from Vimeo... try #{efforts}/#{max_efforts} with #{sleep_time} seconds sleep in between..."
21
26
 
22
- @request = HTTParty.post Eivid::RequestService::VIDEOS_URL, **upload_params
23
- @response = JSON.parse(@request).deep_symbolize_keys
24
- @upload_link = @response.dig(:upload, :upload_link)
27
+ request = HTTParty.post Eivid::RequestService::VIDEOS_URL, **upload_params(file)
28
+ response = JSON.parse(request).deep_symbolize_keys
29
+ upload_link = response.dig(:upload, :upload_link)
25
30
 
26
- if @upload_link.blank?
31
+ if upload_link.blank?
27
32
  sleep sleep_time
28
33
  efforts += 1
29
-
30
34
  else
31
35
  puts "successfully retrieved the Vimeo upload link!"
36
+ return {response: response, upload_link: upload_link}
32
37
  end
33
38
  end
34
39
  end
35
40
 
36
- def tus_upload_to_vimeo
41
+ def tus_upload_to_vimeo(file:, upload_link:)
37
42
  efforts = 0
38
43
  max_efforts = 10
39
44
  sleep_time = 30
@@ -42,7 +47,7 @@ module Eivid::Concerns::RequestService::UploadVideo
42
47
  while !successful && efforts < max_efforts
43
48
 
44
49
  puts "Trying to upload the video to Vimeo... try #{efforts}/#{max_efforts} with #{sleep_time} seconds sleep in between..."
45
- response = HTTParty.patch @upload_link, body: @file.read, headers: tus_headers
50
+ response = HTTParty.patch upload_link, body: file.read, headers: tus_headers
46
51
 
47
52
  if response.code >= 500
48
53
  sleep sleep_time
@@ -54,11 +59,11 @@ module Eivid::Concerns::RequestService::UploadVideo
54
59
  end
55
60
  end
56
61
 
57
- def upload_params
62
+ def upload_params(file)
58
63
  body = {
59
64
  "upload" => {
60
65
  "approach" => "tus",
61
- "size" => @file.size.to_s,
66
+ "size" => file.size.to_s,
62
67
  }
63
68
  }
64
69
 
data/lib/eivid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eivid
2
- VERSION = '1.1.4'
2
+ VERSION = '1.1.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eivid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurriaan Schrofer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-14 00:00:00.000000000 Z
11
+ date: 2024-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubygems_version: 3.2.22
146
+ rubygems_version: 3.5.9
147
147
  signing_key:
148
148
  specification_version: 4
149
149
  summary: Eivid because we can.