mux-rails 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -7
- data/Rakefile +16 -14
- data/app/controllers/mux/application_controller.rb +2 -0
- data/app/controllers/mux/events_controller.rb +7 -5
- data/lib/mux/client.rb +6 -5
- data/lib/mux/engine.rb +2 -0
- data/lib/mux/event.rb +53 -6
- data/lib/mux/notifications.rb +2 -0
- data/lib/mux/rails.rb +12 -2
- data/lib/mux/rails/version.rb +3 -1
- metadata +44 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7322b49a720b1e55df32f6916ae9cdaa626a6fbeb1e93755728d19ce6a8e51df
|
4
|
+
data.tar.gz: 96c0caac8cb6f8f248ef12c8cb13a6e5166c2c9626297677d22e5bdb1ca37fd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e50040a885429872de68f92d0d3045e7bd3fd03dfd9e9a458261df833abca8960557bb22966192341f5ebee8d68bcf67ede5c4bd8a6075eb67d37b7f11491c9
|
7
|
+
data.tar.gz: 2df97d06b227ab78e0e0cc98318a0101abf103f6dd4a030bbb5248d8fd31d534a2246bf22a77f6a6a573aeac5526772e570c0c677a0547ca62b7e84ed2a7d302
|
data/README.md
CHANGED
@@ -19,6 +19,8 @@ gem 'mux-rails'
|
|
19
19
|
mount Mux::Engine, at: "/mux" # provide a custom path
|
20
20
|
```
|
21
21
|
|
22
|
+
Make sure to configure the webhooks at mux.com to point to `https://yourwebsite.com/mux/events`.
|
23
|
+
|
22
24
|
## Usage
|
23
25
|
|
24
26
|
### Setup Mux tokens
|
@@ -71,25 +73,23 @@ Using a subscriber with a block we can listen to incoming events from Mux and do
|
|
71
73
|
|
72
74
|
Mux::Notifications.subscribe "video.asset.created" do |event|
|
73
75
|
# handle asset created
|
74
|
-
# event.
|
75
|
-
# event.data.playback_ids.first.id
|
76
|
+
# event.id == mux_asset_id
|
76
77
|
end
|
77
78
|
|
78
79
|
Mux::Notifications.subscribe "video.asset.ready" do |event|
|
79
80
|
# handle asset ready
|
80
|
-
# event.
|
81
|
-
# event.data.playback_ids.first.id
|
81
|
+
# event.id == mux_asset_id
|
82
82
|
end
|
83
83
|
|
84
84
|
Mux::Notifications.subscribe "video.asset.deleted" do |event|
|
85
85
|
# handle asset deleted
|
86
|
-
# event.
|
87
|
-
# event.data.playback_ids.first.id
|
86
|
+
# event.id == mux_asset_id
|
88
87
|
end
|
89
88
|
```
|
90
89
|
|
91
90
|
The block is passed an event which is simply the incoming JSON (take a peek
|
92
|
-
in [fixtures](test/fixtures) for examples) wrapped in
|
91
|
+
in [fixtures](test/fixtures) for examples) wrapped in [`Mux::Event`](lib/mux/event.rb) class based on
|
92
|
+
`Dry::Struct`.
|
93
93
|
|
94
94
|
## License
|
95
95
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,31 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
begin
|
2
|
-
require
|
4
|
+
require "bundler/setup"
|
3
5
|
rescue LoadError
|
4
|
-
puts
|
6
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
7
|
end
|
6
8
|
|
7
|
-
require
|
9
|
+
require "rdoc/task"
|
8
10
|
|
9
11
|
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
-
rdoc.rdoc_dir =
|
11
|
-
rdoc.title =
|
12
|
-
rdoc.options <<
|
13
|
-
rdoc.rdoc_files.include(
|
14
|
-
rdoc.rdoc_files.include(
|
12
|
+
rdoc.rdoc_dir = "rdoc"
|
13
|
+
rdoc.title = "Mux::Rails"
|
14
|
+
rdoc.options << "--line-numbers"
|
15
|
+
rdoc.rdoc_files.include("README.md")
|
16
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
15
17
|
end
|
16
18
|
|
17
19
|
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
18
|
-
load
|
20
|
+
load "rails/tasks/engine.rake"
|
19
21
|
|
20
|
-
load
|
22
|
+
load "rails/tasks/statistics.rake"
|
21
23
|
|
22
|
-
require
|
24
|
+
require "bundler/gem_tasks"
|
23
25
|
|
24
|
-
require
|
26
|
+
require "rake/testtask"
|
25
27
|
|
26
28
|
Rake::TestTask.new(:test) do |t|
|
27
|
-
t.libs <<
|
28
|
-
t.pattern =
|
29
|
+
t.libs << "test"
|
30
|
+
t.pattern = "test/**/*_test.rb"
|
29
31
|
t.verbose = false
|
30
32
|
end
|
31
33
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Mux
|
2
4
|
class EventsController < ActionController::Base
|
3
5
|
# QUESTION: Is this the right way to handle it?
|
@@ -11,10 +13,10 @@ module Mux
|
|
11
13
|
end
|
12
14
|
|
13
15
|
private
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
def event
|
17
|
+
Mux::Event.new(
|
18
|
+
JSON.parse(request.body.read)
|
19
|
+
)
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
data/lib/mux/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "mux_ruby"
|
2
4
|
|
3
5
|
module Mux
|
@@ -9,7 +11,7 @@ module Mux
|
|
9
11
|
request.input = url
|
10
12
|
request.playback_policy = MuxRuby::PlaybackPolicy.build_from_hash(playback_policy)
|
11
13
|
response = assets_api.create_asset(request)
|
12
|
-
|
14
|
+
response.data.id
|
13
15
|
end
|
14
16
|
|
15
17
|
def destroy_asset(asset_id, options = {})
|
@@ -22,10 +24,9 @@ module Mux
|
|
22
24
|
end
|
23
25
|
|
24
26
|
private
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
27
|
+
def assets_api
|
28
|
+
@assets_api ||= MuxRuby::AssetsApi.new
|
29
|
+
end
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
data/lib/mux/engine.rb
CHANGED
data/lib/mux/event.rb
CHANGED
@@ -1,12 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Mux
|
2
|
-
class Event
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
class Event < Dry::Struct
|
5
|
+
module Types
|
6
|
+
include Dry.Types()
|
7
|
+
end
|
8
|
+
|
9
|
+
transform_keys(&:to_sym)
|
10
|
+
|
11
|
+
attribute :id, Types::String
|
12
|
+
attribute :type, Types::String
|
13
|
+
attribute :created_at, Types::JSON::Time
|
14
|
+
|
15
|
+
attribute :object do
|
16
|
+
attribute :id, Types::Coercible::String
|
17
|
+
attribute :type, Types::Coercible::String
|
18
|
+
end
|
19
|
+
|
20
|
+
attribute :environment do
|
21
|
+
attribute :id, Types::Coercible::String
|
22
|
+
attribute :name, Types::Coercible::String
|
6
23
|
end
|
7
24
|
|
8
|
-
|
9
|
-
|
25
|
+
attribute :data do
|
26
|
+
attribute :id, Types::Coercible::String
|
27
|
+
attribute :status, Types::Coercible::String
|
28
|
+
attribute :created_at, Types::Coercible::Integer
|
29
|
+
|
30
|
+
attribute? :aspect_ratio, Types::Coercible::String
|
31
|
+
attribute? :duration, Types::Coercible::Float
|
32
|
+
attribute? :master_access, Types::Coercible::String
|
33
|
+
attribute? :max_stored_frame_rate, Types::Coercible::Float
|
34
|
+
attribute? :max_stored_resolution, Types::Coercible::String
|
35
|
+
attribute? :mp4_support, Types::Coercible::String
|
36
|
+
|
37
|
+
attribute? :playback_ids, Types::Array do
|
38
|
+
attribute :id, Types::Coercible::String
|
39
|
+
attribute :policy, Types::Coercible::String
|
40
|
+
end
|
41
|
+
|
42
|
+
attribute? :tracks, Types::Array do
|
43
|
+
attribute :id, Types::Coercible::String
|
44
|
+
attribute :type, Types::Coercible::String
|
45
|
+
|
46
|
+
attribute :duration, Types::Coercible::Float
|
47
|
+
|
48
|
+
# when type = "video"
|
49
|
+
attribute? :max_width, Types::Coercible::Integer
|
50
|
+
attribute? :max_height, Types::Coercible::Integer
|
51
|
+
attribute? :max_frame_rate, Types::Coercible::Float
|
52
|
+
|
53
|
+
# when type = "audio"
|
54
|
+
attribute? :max_channels, Types::Coercible::Integer
|
55
|
+
attribute? :max_channel_layout, Types::Coercible::String
|
56
|
+
end
|
10
57
|
end
|
11
58
|
end
|
12
59
|
end
|
data/lib/mux/notifications.rb
CHANGED
data/lib/mux/rails.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry-struct"
|
4
|
+
require "dry-types"
|
5
|
+
require "mux_ruby"
|
6
|
+
|
1
7
|
require "mux/engine"
|
8
|
+
require "mux/rails/version"
|
9
|
+
|
10
|
+
module Mux
|
11
|
+
end
|
2
12
|
|
3
|
-
require "mux/notifications"
|
4
|
-
require "mux/event"
|
5
13
|
require "mux/client"
|
14
|
+
require "mux/event"
|
15
|
+
require "mux/notifications"
|
data/lib/mux/rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mux-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Asger Behncke Jacobsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.8.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dry-struct
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dry-types
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.4'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.4'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: minitest
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +108,20 @@ dependencies:
|
|
80
108
|
- - ">="
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rails_config
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
83
125
|
description: A Rails Engine for integrating with Mux.
|
84
126
|
email:
|
85
127
|
- a@asgerbehnckejacobsen.dk
|