eivid 1.0.5 → 1.0.10

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: 5d4c04b8322a6feab4b5a6329e564f1687cf6e71d7db09538101a38233aa9263
4
+ data.tar.gz: df5e24bb82fdb4f5e45e9eefc57fdababf0ff623efd29d0f9a32d0c4ab0cf5e1
5
5
  SHA512:
6
- metadata.gz: b49a8b85807843736d3a2617ed1134b414fbfe1dd68aeed7172f59d2105c0b8c213b0ee6d3736ee29ce2787d7e1d11bcef0b037445d7f84062d724d5926852ae
7
- data.tar.gz: c8830d684823a77d6023168a51a6ea43101f81e4489be674f7195867b0f17c6ba06c81b9f3903f06e7db38c5ee3e9754eef5f213106fb1e5e3afba98f81247d8
6
+ metadata.gz: 970e33e8efb6f0a3d15c2af957fee892edd48b67fac09fa72d295a82ffeef0da6bfbb9497554688a04344d71720873274ea7c11d6a207951556b79f67ec43fb1
7
+ data.tar.gz: e955eea3a14e70a13135d3a231307259a82bf0f7b22415551adddec3c7994cf3428b3be422dad2adff2806d90e443ddb247020a62397dd57634e667222f92787
@@ -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
@@ -0,0 +1,16 @@
1
+ module Eivid
2
+ class RequestFolderIdJob < ApplicationJob
3
+
4
+ def perform(eivid_owner_id)
5
+
6
+ owner = Owner.find(eivid_owner_id)
7
+ folder_id = RequestService.create_folder(namespace: Eivid.owner_model, id: owner.id)
8
+
9
+ # binding.pry
10
+
11
+ owner.update!(folder_id: folder_id)
12
+
13
+ end
14
+
15
+ end
16
+ end
@@ -12,5 +12,7 @@ module Eivid::Concerns::MainApp::VideoConcerns
12
12
  scope :has_processed_video, -> { joins(:videos).where('eivid_videos.uploaded': true).distinct }
13
13
  scope :has_unprocessed_video, -> { joins(:videos).where('eivid_videos.uploaded' => false).distinct }
14
14
 
15
+ scope :has_video_from_user, -> (user_id) { joins(:videos).where('eivid_videos.user_id = ?', user_id) }
16
+
15
17
  end
16
18
  end
@@ -6,7 +6,7 @@ module Eivid::Concerns::RequestService::ManageFolder
6
6
  end
7
7
 
8
8
  def create_folder(namespace:, id:)
9
- body = { "name" => "#{Rails.env}_#{namespace}_#{id}" }
9
+ body = { "name" => "#{rails_environment}_#{namespace}_#{id}" }
10
10
 
11
11
  @response = HTTParty.post Eivid::RequestService::FOLDER_URL, body: body.to_json, headers: default_headers
12
12
  get_folder_id
@@ -20,6 +20,11 @@ module Eivid::Concerns::RequestService::ManageFolder
20
20
  HTTParty.put endpoint, headers: default_headers
21
21
  end
22
22
 
23
+ def rails_environment
24
+ return "test" if Figaro.env.IS_TEST_SERVER
25
+ Rails.env
26
+ end
27
+
23
28
  private
24
29
 
25
30
  def get_folder_id
@@ -5,16 +5,16 @@ module Eivid
5
5
 
6
6
  validates :external_id, presence: true, uniqueness: true
7
7
 
8
- before_create :get_folder_id
8
+ after_create :get_folder_id
9
9
 
10
- belongs_to :"#{Eivid.owner_model}", foreign_key: "external_id"
10
+ belongs_to :"#{Eivid.owner_model}", foreign_key: "external_id", optional: true
11
11
 
12
12
  def external_owner
13
13
  send Eivid.owner_model
14
14
  end
15
15
 
16
16
  def get_folder_id
17
- self.folder_id = RequestService.create_folder(namespace: Eivid.owner_model, id: self.external_id)
17
+ RequestFolderIdJob.perform_later(self.id)
18
18
  end
19
19
 
20
20
  end
data/lib/eivid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eivid
2
- VERSION = '1.0.5'
2
+ VERSION = '1.0.10'
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.0.5
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurriaan Schrofer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-19 00:00:00.000000000 Z
11
+ date: 2021-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -71,11 +71,16 @@ 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
83
+ - app/jobs/eivid/request_folder_id_job.rb
79
84
  - app/jobs/eivid/upload_vimeo_job.rb
80
85
  - app/mailers/eivid/application_mailer.rb
81
86
  - app/models/eivid/application_record.rb