mux-rails 0.2.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -8
- 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 +57 -6
- data/lib/mux/notifications.rb +2 -0
- data/lib/mux/rails/version.rb +3 -1
- data/lib/mux/rails.rb +12 -2
- metadata +47 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8eed39bcc85b931de2c1fc0c0fccc991e6c9b4805f17c2ab9d96cd2b27f499f
|
4
|
+
data.tar.gz: a6a72d700e704f56da45e85bc4abde6d2cf31a410cecd14e2f96c67883cdadd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fb4bde3eb8575396f39ffd03b017702391928b937e3adf1fb8c46a3f499660e0af3196d00420f13bb64a57c5f2184f9df5cfd8f10f151241ac30225ef0865e6
|
7
|
+
data.tar.gz: 7e4ab93b4e0211599cb3c57d70f65e9f7c87787816081e4b1080c3a1d6c4a4f431e5fd3eb87c17bf0c190699413394ac727cf888389d6a01ab76c0f797480744
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Mux::Rails
|
2
2
|
|
3
|
+
![Gem Version](https://badge.fury.io/rb/mux-rails.svg)
|
3
4
|
![Ruby](https://github.com/asgerb/mux-rails/workflows/Ruby/badge.svg)
|
4
5
|
|
5
6
|
A Rails Engine for working with [Mux](https://mux.com/).
|
@@ -8,17 +9,30 @@ Use `Mux::Client` to create assets and `Mux::Notifications` (built on the
|
|
8
9
|
`ActiveSupport::Notifications` API) to handle incoming webhook requests.
|
9
10
|
|
10
11
|
## Installation
|
11
|
-
|
12
|
+
|
13
|
+
Run
|
14
|
+
|
15
|
+
```bash
|
16
|
+
bundle add mux-rails
|
17
|
+
```
|
18
|
+
|
19
|
+
or add this line to your application's Gemfile:
|
12
20
|
|
13
21
|
```ruby
|
14
22
|
gem 'mux-rails'
|
15
23
|
```
|
16
24
|
|
25
|
+
and run `bundle install`.
|
26
|
+
|
27
|
+
Then mount the engine in your routes:
|
28
|
+
|
17
29
|
```ruby
|
18
30
|
# config/routes.rb
|
19
31
|
mount Mux::Engine, at: "/mux" # provide a custom path
|
20
32
|
```
|
21
33
|
|
34
|
+
Remember to configure the webhooks at mux.com to point to `https://yourwebsite.com/mux/events`.
|
35
|
+
|
22
36
|
## Usage
|
23
37
|
|
24
38
|
### Setup Mux tokens
|
@@ -71,25 +85,23 @@ Using a subscriber with a block we can listen to incoming events from Mux and do
|
|
71
85
|
|
72
86
|
Mux::Notifications.subscribe "video.asset.created" do |event|
|
73
87
|
# handle asset created
|
74
|
-
# event.
|
75
|
-
# event.data.playback_ids.first.id
|
88
|
+
# event.id == mux_asset_id
|
76
89
|
end
|
77
90
|
|
78
91
|
Mux::Notifications.subscribe "video.asset.ready" do |event|
|
79
92
|
# handle asset ready
|
80
|
-
# event.
|
81
|
-
# event.data.playback_ids.first.id
|
93
|
+
# event.id == mux_asset_id
|
82
94
|
end
|
83
95
|
|
84
96
|
Mux::Notifications.subscribe "video.asset.deleted" do |event|
|
85
97
|
# handle asset deleted
|
86
|
-
# event.
|
87
|
-
# event.data.playback_ids.first.id
|
98
|
+
# event.id == mux_asset_id
|
88
99
|
end
|
89
100
|
```
|
90
101
|
|
91
102
|
The block is passed an event which is simply the incoming JSON (take a peek
|
92
|
-
in [fixtures](test/fixtures) for examples) wrapped in
|
103
|
+
in [fixtures](test/fixtures) for examples) wrapped in [`Mux::Event`](lib/mux/event.rb) class based on
|
104
|
+
`Dry::Struct`.
|
93
105
|
|
94
106
|
## License
|
95
107
|
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,63 @@
|
|
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? :stream_key, Types::Coercible::String
|
38
|
+
attribute? :reconnect_window, Types::Coercible::Integer
|
39
|
+
attribute? :latency_mode, Types::Coercible::String
|
40
|
+
|
41
|
+
attribute? :playback_ids, Types::Array do
|
42
|
+
attribute :id, Types::Coercible::String
|
43
|
+
attribute :policy, Types::Coercible::String
|
44
|
+
end
|
45
|
+
|
46
|
+
attribute? :tracks, Types::Array do
|
47
|
+
attribute? :id, Types::Coercible::String
|
48
|
+
attribute? :type, Types::Coercible::String
|
49
|
+
|
50
|
+
attribute? :duration, Types::Coercible::Float
|
51
|
+
|
52
|
+
# when type = "video"
|
53
|
+
attribute? :max_width, Types::Coercible::Integer
|
54
|
+
attribute? :max_height, Types::Coercible::Integer
|
55
|
+
attribute? :max_frame_rate, Types::Coercible::Float
|
56
|
+
|
57
|
+
# when type = "audio"
|
58
|
+
attribute? :max_channels, Types::Coercible::Integer
|
59
|
+
attribute? :max_channel_layout, Types::Coercible::String
|
60
|
+
end
|
10
61
|
end
|
11
62
|
end
|
12
63
|
end
|
data/lib/mux/notifications.rb
CHANGED
data/lib/mux/rails/version.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"
|
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: 1.0.2
|
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:
|
11
|
+
date: 2022-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,20 +24,48 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dry-struct
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dry-types
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: mux_ruby
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
59
|
- - "~>"
|
32
60
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
61
|
+
version: '3.0'
|
34
62
|
type: :runtime
|
35
63
|
prerelease: false
|
36
64
|
version_requirements: !ruby/object:Gem::Requirement
|
37
65
|
requirements:
|
38
66
|
- - "~>"
|
39
67
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
68
|
+
version: '3.0'
|
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
|
@@ -118,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
160
|
- !ruby/object:Gem::Version
|
119
161
|
version: '0'
|
120
162
|
requirements: []
|
121
|
-
rubygems_version: 3.1.
|
163
|
+
rubygems_version: 3.1.4
|
122
164
|
signing_key:
|
123
165
|
specification_version: 4
|
124
166
|
summary: A Rails Engine for integrating with Mux.
|