eivid 1.0.5 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b16e547e53edc9be84a3a08ed34040e9eb00995f0e28d5a7b724d038d905204
4
- data.tar.gz: d6925d650bee18147b71f2f919f416a03807292cf0b528d2a22905bad33c144b
3
+ metadata.gz: b995a651b9c7d8ae829041db1b2dcb8bd272ff646687db1b714d4c71f01f4892
4
+ data.tar.gz: e9142b432d08eb85f21217965af5ddca7a5ba4962401a219e0c4f236980072a4
5
5
  SHA512:
6
- metadata.gz: b49a8b85807843736d3a2617ed1134b414fbfe1dd68aeed7172f59d2105c0b8c213b0ee6d3736ee29ce2787d7e1d11bcef0b037445d7f84062d724d5926852ae
7
- data.tar.gz: c8830d684823a77d6023168a51a6ea43101f81e4489be674f7195867b0f17c6ba06c81b9f3903f06e7db38c5ee3e9754eef5f213106fb1e5e3afba98f81247d8
6
+ metadata.gz: 9b48dadeee80c0bee563b30e5852016b7e23184d08a494ceca635aa3f160721c5ba8b0e41e9d32bb9be7a0eafc9c61273d1bc1c8a07b89985b8a5f96de4b40c4
7
+ data.tar.gz: 67500bcd2c6723eaa6900aaef6a6b31786c0adb64b6fcd12ccdf11962d77f8d388058dc170957ef68020d89f448c1a20f9dbdb8cef4f7236dfb1270fd5a186d3
@@ -0,0 +1,4 @@
1
+ module Eivid
2
+ class VideoUnavailableAllAttemptsFailedError < StandardError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Eivid
2
+ class VideoUrlsAllAttemptsFailedError < StandardError
3
+ end
4
+ end
@@ -1,7 +1,12 @@
1
1
  module Eivid
2
2
  class CheckVimeoStatusJob < ApplicationJob
3
3
 
4
- retry_on VideoUnavailableError, wait: 10.seconds, attempts: 50
4
+ retry_on(VideoUnavailableError, wait: 10.seconds, attempts: 50) do |job, error|
5
+ raise Eivid::VideoUnavailableAllAttemptsFailedError, "failed after the set max attempts (#{job.executions} times)"
6
+ end
7
+
8
+ discard_on ActiveJob::DeserializationError
9
+
5
10
  after_perform :poll_vimeo_urls
6
11
 
7
12
  def perform(video_record:)
@@ -0,0 +1,24 @@
1
+ module Eivid
2
+ class GetVimeoHdUrlJob < ApplicationJob
3
+
4
+ include Eivid::GetVimeoUrlsMixin
5
+
6
+ def perform(video_record:, vimeo_id:)
7
+ @video_record = video_record
8
+ @vimeo_id = vimeo_id
9
+
10
+ set_response
11
+ set_url_hd
12
+
13
+ return unless @url_hd
14
+ update_record
15
+ end
16
+
17
+ private
18
+
19
+ def update_record
20
+ @video_record.update(url_hd: @url_hd)
21
+ end
22
+
23
+ end
24
+ end
@@ -1,7 +1,13 @@
1
1
  module Eivid
2
2
  class GetVimeoUrlsJob < ApplicationJob
3
3
 
4
- retry_on VideoUrlsUnavailableError, wait: 10.seconds, attempts: 50
4
+ include Eivid::GetVimeoUrlsMixin
5
+
6
+ retry_on(VideoUrlsUnavailableError, wait: 10.seconds, attempts: 50) do |job, error|
7
+ raise Eivid::VideoUrlsAllAttemptsFailedError, "failed after the set max attempts (#{job.executions} times)"
8
+ end
9
+
10
+ discard_on ActiveJob::DeserializationError
5
11
 
6
12
  def perform(video_record:, vimeo_id:)
7
13
  @video_record = video_record
@@ -16,55 +22,33 @@ module Eivid
16
22
  validate_url_thumbnail
17
23
 
18
24
  update_record
25
+ schedule_hd_url_job
19
26
  notify_front
20
27
  end
21
28
 
22
29
  private
23
30
 
24
- def set_response
25
- @response = Eivid::RequestService.get_video @vimeo_id
26
- end
27
-
28
- def set_url_sd
29
- @url_sd = dig_video_url :sd
30
- end
31
-
32
- def set_url_hd
33
- @url_hd = dig_video_url :hd
34
- end
35
-
36
- def dig_video_url(definition)
37
- @response[:files]&.find { |video| video[:quality] == definition.to_s }&.dig(:link)
31
+ def notify_front
32
+ data = { video: @video_record.slice(:id, :user_id), progress: { percentage: 100, step: "All video versions are available on Vimeo." } }
33
+ NotifyFrontService.progress('notify_method_on_versions_available', data)
38
34
  end
39
35
 
40
- def set_url_thumbnail
41
- @url_thumbnail = find_high_res_thumbnail || find_low_res_thumbnail
36
+ def update_record
37
+ @video_record.update(uploaded: true, url_sd: @url_sd, url_hd: @url_hd, url_thumbnail: @url_thumbnail)
42
38
  end
43
39
 
44
- def find_high_res_thumbnail
45
- @response&.dig(:pictures, :sizes)&.find { |url| url[:width] == 960 && url[:height] == 540 }&.dig(:link_with_play_button)
40
+ def schedule_hd_url_job
41
+ Eivid::GetVimeoHdUrlJob.set(wait: 5.minutes).perform_later(video_record: @video_record, vimeo_id: @vimeo_id)
46
42
  end
47
43
 
48
- def find_low_res_thumbnail
49
- @response&.dig(:pictures, :sizes)&.find { |url| url[:width] == 640 && url[:height] == 360 }&.dig(:link_with_play_button)
50
- end
51
44
 
52
45
  def validate_url_presence
53
- raise Eivid::VideoUrlsUnavailableError unless @url_thumbnail
46
+ raise Eivid::VideoUrlsUnavailableError unless @url_thumbnail && @url_sd
54
47
  end
55
48
 
56
49
  def validate_url_thumbnail
57
50
  raise Eivid::VideoUrlsUnavailableError if @url_thumbnail.include? 'video%2Fdefault'
58
51
  end
59
52
 
60
- def update_record
61
- @video_record.update(uploaded: true, url_sd: @url_sd, url_hd: @url_hd, url_thumbnail: @url_thumbnail)
62
- end
63
-
64
- def notify_front
65
- data = { video: @video_record.slice(:id, :user_id), progress: { percentage: 100, step: "All video versions are available on Vimeo." } }
66
- NotifyFrontService.progress('notify_method_on_versions_available', data)
67
- end
68
-
69
53
  end
70
54
  end
@@ -0,0 +1,36 @@
1
+ module Eivid::GetVimeoUrlsMixin
2
+ extend ActiveSupport::Concern
3
+ included do
4
+
5
+ private
6
+
7
+ def set_response
8
+ @response = Eivid::RequestService.get_video @vimeo_id
9
+ end
10
+
11
+ def set_url_sd
12
+ @url_sd = dig_video_url :sd
13
+ end
14
+
15
+ def set_url_hd
16
+ @url_hd = dig_video_url :hd
17
+ end
18
+
19
+ def dig_video_url(definition)
20
+ @response[:files]&.find { |video| video[:quality] == definition.to_s }&.dig(:link)
21
+ end
22
+
23
+ def set_url_thumbnail
24
+ @url_thumbnail = find_high_res_thumbnail || find_low_res_thumbnail
25
+ end
26
+
27
+ def find_high_res_thumbnail
28
+ @response&.dig(:pictures, :sizes)&.find { |url| url[:width] == 960 && url[:height] == 540 }&.dig(:link_with_play_button)
29
+ end
30
+
31
+ def find_low_res_thumbnail
32
+ @response&.dig(:pictures, :sizes)&.find { |url| url[:width] == 640 && url[:height] == 360 }&.dig(:link_with_play_button)
33
+ end
34
+
35
+ end
36
+ end
data/lib/eivid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eivid
2
- VERSION = '1.0.5'
2
+ VERSION = '1.0.7'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eivid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurriaan Schrofer
@@ -71,11 +71,15 @@ files:
71
71
  - app/errors/eivid/maximum_vimeo_poll_reached_error.rb
72
72
  - app/errors/eivid/video_file_not_present_error.rb
73
73
  - app/errors/eivid/video_file_size_too_big_error.rb
74
+ - app/errors/eivid/video_unavailable_all_attempts_failed_error.rb
74
75
  - app/errors/eivid/video_unavailable_error.rb
76
+ - app/errors/eivid/video_urls_all_attempts_failed_error.rb
75
77
  - app/errors/eivid/video_urls_unavailable_error.rb
76
78
  - app/jobs/eivid/application_job.rb
77
79
  - app/jobs/eivid/check_vimeo_status_job.rb
80
+ - app/jobs/eivid/get_vimeo_hd_url_job.rb
78
81
  - app/jobs/eivid/get_vimeo_urls_job.rb
82
+ - app/jobs/eivid/get_vimeo_urls_mixin.rb
79
83
  - app/jobs/eivid/upload_vimeo_job.rb
80
84
  - app/mailers/eivid/application_mailer.rb
81
85
  - app/models/eivid/application_record.rb