openvidu-ruby-client 0.2.0 → 0.4.0

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
  SHA1:
3
- metadata.gz: 6816d2ce00a5d853de33612fca8b893d9d4f76d2
4
- data.tar.gz: 417436d1f059a6688a7ee77355c8c73b89156e57
3
+ metadata.gz: 5f5a0eb2dc94b5816ee311555d3739ba1fc64a9a
4
+ data.tar.gz: 7071c1d9e02b6f3ac9d80d12376fd628d9c8e6fc
5
5
  SHA512:
6
- metadata.gz: b51fcf9e220816e1ee32a7b0fce6147f0c96a9ab5286a9560f5b05c68ef0144c472900696d278efb27b8134f3af01f7df3543cb8446c2b3831fd23233e47eb49
7
- data.tar.gz: c41aa3bcc46633072358561daf62080a1794f833aa5ed6409a04446b29a5d542848bc8a0d7e03af4ba88a54d65f3e4a2bd986dda1b1a5a62bba7101976e06414
6
+ metadata.gz: a226c1b45b92dbd419e771f108a02b802af82500453b6bcaf7e84d21b013f1a9a960824a7b4251331d9bf857105e14753082ba690a596490808bfe8d8c0f48e3
7
+ data.tar.gz: 02ca643fad82e6b2c809fe2122dd708273e13813f548144d4426bf2a0acf26b3b1b9db709d0590d656d0f45188d1b7c315b2b7888f2730b4b4f34ed64517b894
@@ -0,0 +1,4 @@
1
+ OPENVIDU_URL=https://localhost:4443
2
+ OPENVIDU_USERNAME=openviduapp
3
+ OPENVIDU_PASSWORD=MY_SECRET
4
+ OPENVIDU_VERIFY_PEER=false
data/.gitignore CHANGED
@@ -9,3 +9,7 @@
9
9
  /spec/reports/
10
10
  /tmp/
11
11
  /vendor/
12
+ .DS_Store
13
+ \.idea
14
+ \.rakeTasks
15
+ Gemfile.lock
@@ -3,11 +3,16 @@ sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm: 2.4.5
6
+ dist: bionic
6
7
 
7
8
  services:
8
9
  - docker
9
10
 
11
+ env:
12
+ OPENVIDU_VERIFY_PEER: false
13
+
10
14
  before_install:
11
15
  - gem install bundler -v 1.17.3
12
16
  - docker pull openvidu/openvidu-server-kms
13
- - docker run -p 4443:4443 -d --rm -e openvidu.secret=MY_SECRET openvidu/openvidu-server-kms
17
+ - docker run -p 4443:4443 -d --rm -e openvidu.secret=MY_SECRET -e openvidu.recording.path=/recordings -e openvidu.recording=true -v /var/run/docker.sock:/var/run/docker.sock openvidu/openvidu-server-kms
18
+ - while [[ "$(curl -k -uOPENVIDUAPP:MY_SECRET -s -o /dev/null -w ''%{http_code}'' https://localhost:4443)" != "200" ]]; do echo "Waiting for Openvidu..."; sleep 5; done
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # OpenVidu Ruby Client
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/open_vidu`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ ![Build Status](https://travis-ci.org/BryanSaxon/openvidu-ruby-client.svg?branch=master)
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,12 +20,33 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ To get started locally, first pull the OpenVidu Docker image and start a container:
26
24
 
27
25
  ```bash
28
- OPENVIDU_URL = 'https://localhost:4443'
29
- OPENVIDU_USERNAME = 'OPENVIDUAPP'
30
- OPENVIDU_PASSWORD = 'MY_SECRET'
26
+ docker pull openvidu/openvidu-server-kms
27
+ docker run -p 4443:4443 -d --rm -e openvidu.secret=MY_SECRET -e openvidu.recording.path=/recordings -e openvidu.recording=true -v /var/run/docker.sock:/var/run/docker.sock openvidu/openvidu-server-kms
28
+ ```
29
+
30
+ Set the following environment variables in your Ruby application:
31
+
32
+ To start a OpenVidu session:
33
+
34
+ ```ruby
35
+ server = 'https://127.0.0.1:4443?token=MY_SECRET&timeout=5'
36
+
37
+ OpenVidu::Session.new(server,
38
+ customSessionId: 'your-custom-session-id',
39
+ defaultOutputMode: 'INDIVIDUAL',
40
+ recordingMode: 'ALWAYS').create
41
+
42
+ # Create a token to publish video
43
+ token = OpenVidu::Token.new(server, session: 'your-custom-session-id,
44
+ role: "PUBLISHER",
45
+ data: {
46
+ "full_name": "John Smith" # Custom data can be supplied here
47
+ }
48
+ )
49
+
31
50
  ```
32
51
 
33
52
  ## Development
@@ -1,6 +1,7 @@
1
1
  require "open_vidu/version"
2
+ require "open_vidu/base"
2
3
 
3
4
  module OpenVidu
4
5
  class Error < StandardError; end
5
- # Your code goes here...
6
+
6
7
  end
@@ -1,4 +1,5 @@
1
1
  require 'open_vidu/command'
2
+ require 'open_vidu/server'
2
3
 
3
4
  module OpenVidu
4
5
  # Base
@@ -7,7 +8,14 @@ module OpenVidu
7
8
  GENERATED_PARAMS = %w[].freeze
8
9
  ALL_PARAMS = (ASSIGNABLE_PARAMS + GENERATED_PARAMS).freeze
9
10
 
10
- def initialize(params = {})
11
+ attr_reader :server
12
+
13
+ def self.content_key
14
+ 'content'
15
+ end
16
+
17
+ def initialize(uri, params = {})
18
+ @server = Server.new(uri).freeze
11
19
  self.class::ALL_PARAMS.each do |param|
12
20
  instance_variable_set("@#{param}", params[param.to_sym])
13
21
  self.class.send(:attr_accessor, param.to_sym)
@@ -1,28 +1,33 @@
1
1
  require 'open_vidu/requestor'
2
2
  require 'open_vidu/responder'
3
+ require 'open_vidu/exceptions'
3
4
 
4
5
  module OpenVidu
5
6
  # Command
6
7
  class Command
7
- attr_reader :object, :method, :endpoint, :params
8
+ attr_reader :object, :method, :endpoint, :params, :requestor, :responder, :server
8
9
 
9
- def initialize(object, method, endpoint, params = {})
10
+ def initialize(object, method, endpoint, params = {}, options: {})
10
11
  @object = object
11
12
  @method = method
12
13
  @endpoint = endpoint
13
14
  @params = params
15
+
16
+ @server = options.fetch(:server)
17
+ @requestor = options[:requestor] || OpenVidu::Requestor.new(server, method, endpoint, params)
18
+ @responder = options[:responder] || OpenVidu::Responder.new
14
19
  end
15
20
 
16
21
  def execute
17
- response = OpenVidu::Requestor.new(method, endpoint, params).execute
18
- OpenVidu::Responder.new(object, response).execute if valid?(response)
22
+ response = requestor.execute
23
+ raise OpenVidu::ResponseError.new(response) unless valid?(response)
24
+ responder.execute(server, object, response.parsed_response)
19
25
  end
20
26
 
21
27
  private
22
28
 
23
- # TODO: Implement.
24
29
  def valid?(response)
25
- true
30
+ response.success?
26
31
  end
27
32
  end
28
33
  end
@@ -12,8 +12,8 @@ module OpenVidu
12
12
  ].freeze
13
13
  ALL_PARAMS = (ASSIGNABLE_PARAMS + GENERATED_PARAMS).freeze
14
14
 
15
- def self.config
16
- OpenVidu::Command.new(:config, :get, 'config').execute
15
+ def config
16
+ OpenVidu::Command.new(:config, :get, 'config', { options: {server: server } }).execute
17
17
  end
18
18
  end
19
19
  end
@@ -0,0 +1,9 @@
1
+ module OpenVidu
2
+ class ResponseError < StandardError
3
+ attr_reader :response
4
+ def initialize(response)
5
+ @response = response
6
+ super("OpenVidu Response error code: #{response.code}")
7
+ end
8
+ end
9
+ end
@@ -10,19 +10,32 @@ module OpenVidu
10
10
  ].freeze
11
11
  ALL_PARAMS = (ASSIGNABLE_PARAMS + GENERATED_PARAMS).freeze
12
12
 
13
- def self.all
13
+ def self.content_key
14
+ 'items'
15
+ end
16
+
17
+ def all
14
18
  OpenVidu::Command.new(
15
- :recording, :get, 'api/recordings'
19
+ :recording,
20
+ :get,
21
+ 'api/recordings',
22
+ { options: { server: server } }
16
23
  ).execute
17
24
  end
18
25
 
19
- def self.create(params)
20
- new(params).create
26
+ def find(id)
27
+ OpenVidu::Command.new(
28
+ :recording, :get, "api/recordings/#{id}",
29
+ { options: { server: server } }
30
+ ).execute
21
31
  end
22
32
 
23
- def self.find(id)
33
+ def stop
24
34
  OpenVidu::Command.new(
25
- :recording, :get, "api/recordings/#{id}"
35
+ :recording,
36
+ :post,
37
+ "api/recordings/stop/#{id}",
38
+ { options: { server: server } }
26
39
  ).execute
27
40
  end
28
41
 
@@ -30,15 +43,18 @@ module OpenVidu
30
43
  OpenVidu::Command.new(
31
44
  :recording,
32
45
  :delete,
33
- "api/recordings/stop/#{id}"
46
+ "api/recordings/#{id}",
47
+ { options: { server: server } }
34
48
  ).execute
35
49
  end
36
50
 
37
- alias_method :stop, :delete
38
-
39
51
  def create
40
52
  OpenVidu::Command.new(
41
- :recording, :post, 'api/recordings/start', create_params
53
+ :recording,
54
+ :post,
55
+ 'api/recordings/start',
56
+ create_params,
57
+ { options: { server: server } }
42
58
  ).execute
43
59
  end
44
60
 
@@ -1,39 +1,36 @@
1
- require 'dotenv/load'
2
1
  require 'httparty'
3
2
  require 'json'
4
3
 
5
4
  module OpenVidu
6
5
  # Requestor
7
6
  class Requestor
8
- attr_reader :method, :endpoint, :params
7
+ attr_reader :server, :method, :endpoint, :params
9
8
 
10
- BASE_URL = ENV['OPENVIDU_URL']
11
- TOKEN = "#{ENV['OPENVIDU_USERNAME']}:#{ENV['OPENVIDU_PASSWORD']}".freeze
12
- MODE = ENV['MODE']
13
-
14
- def initialize(method, endpoint, params = {})
9
+ def initialize(server, method, endpoint, params = {})
10
+ @server = server
15
11
  @method = method
16
12
  @endpoint = endpoint
17
13
  @params = params
18
14
  end
19
15
 
20
16
  def execute
21
- HTTParty.send(method, url, options)&.parsed_response
17
+ HTTParty.send(method, url, options)
22
18
  end
23
19
 
24
20
  private
25
21
 
26
22
  def url
27
- "#{BASE_URL}/#{endpoint}"
23
+ "#{server.scheme}://#{server.host}:#{server.port || 4443}/#{endpoint}"
28
24
  end
29
25
 
30
26
  def options
31
27
  {
32
28
  headers: {
33
- 'Authorization' => "Basic #{Base64.strict_encode64(TOKEN)}",
29
+ 'Authorization' => "Basic #{Base64.strict_encode64(server.token)}",
34
30
  'Content-Type' => 'application/json'
35
31
  },
36
- verify: MODE != 'DEV',
32
+ verify: server.verify_peer?,
33
+ timeout: server.timeout,
37
34
  body: params.to_json
38
35
  }
39
36
  end
@@ -1,27 +1,30 @@
1
- require 'byebug'
2
-
3
1
  module OpenVidu
4
2
  # Responder
5
3
  class Responder
6
4
  attr_reader :object, :response
7
5
 
8
- def initialize(object, response)
6
+ def execute(server, object, response)
9
7
  @object = object
10
8
  @response = response
11
- end
12
-
13
- def execute
14
9
  klass = Object.const_get(klass_name)
15
10
 
16
11
  return true if record_destroyed?
17
- return klass.new(mapped_params(response)) if complete_record?
18
- return klass.find(response['id']) if record_lookup?
12
+ return klass.new(server, mapped_params(response)) if complete_record?
13
+ return klass.new(server).find(response['id']) if record_lookup?
19
14
 
20
- response['content'].map { |hash| klass.new(mapped_params(hash)) }
15
+ response[content_key].map { |hash| klass.new(server, mapped_params(hash)) }
21
16
  end
22
17
 
23
18
  private
24
19
 
20
+ def klass
21
+ Object.const_get(klass_name)
22
+ end
23
+
24
+ def content_key
25
+ klass.content_key
26
+ end
27
+
25
28
  def klass_name
26
29
  "OpenVidu::#{object.to_s.split('_').map(&:capitalize).join('')}"
27
30
  end
@@ -0,0 +1,49 @@
1
+ require 'addressable'
2
+ require 'forwardable'
3
+
4
+ module OpenVidu
5
+ # Endpoint configuration
6
+ class Server
7
+ extend Forwardable
8
+
9
+ InvalidURI = Class.new(StandardError)
10
+
11
+ DEFAULT_TIMEOUT = 10 # seconds
12
+
13
+ def_delegators :@uri, :host, :port, :scheme, :query_values, :to_s
14
+
15
+ # `uri` should take the form of scheme://some-openvidu-host-or-ip:port?token=<your-secret-here>
16
+ # e.g. https://1.2.3.4?token=abcdefghijklmnop
17
+ def initialize(uri)
18
+ @uri = Addressable::URI.parse(uri.to_s)
19
+ raise InvalidURI if @uri.empty?
20
+ end
21
+
22
+ def token
23
+ "OPENVIDUAPP:#{query_values.fetch('token')}"
24
+ end
25
+
26
+ def host_and_port
27
+ "#{host}:#{port}"
28
+ end
29
+
30
+ def verify_peer?
31
+ return false if query_values['verify_peer'].to_s.downcase == 'false'
32
+
33
+ true
34
+ end
35
+
36
+ def timeout
37
+ if query_values['timeout'].to_i > 0
38
+ query_values['timeout'].to_i
39
+ else
40
+ DEFAULT_TIMEOUT
41
+ end
42
+ end
43
+
44
+ def ==(other)
45
+ other.to_s == self.to_s
46
+ end
47
+ end
48
+ end
49
+
@@ -8,31 +8,39 @@ module OpenVidu
8
8
  GENERATED_PARAMS = %w[sessionId createdAt connections recording].freeze
9
9
  ALL_PARAMS = (ASSIGNABLE_PARAMS + GENERATED_PARAMS).freeze
10
10
 
11
- def self.all
11
+ def all
12
12
  OpenVidu::Command.new(
13
- :session, :get, 'api/sessions'
13
+ :session, :get, 'api/sessions', { options: { server: server } }
14
14
  ).execute
15
15
  end
16
16
 
17
- def self.create(params)
18
- new(params).create
19
- end
20
-
21
- def self.find(id)
17
+ def find(id)
22
18
  OpenVidu::Command.new(
23
- :session, :get, "api/sessions/#{id}"
19
+ :session, :get, "api/sessions/#{id}", { options: { server: server } }
24
20
  ).execute
25
21
  end
26
22
 
23
+ def exists?(id)
24
+ begin
25
+ OpenVidu::Command.new(
26
+ :session, :get, "api/sessions/#{id}", { options: { server: server } }
27
+ ).execute
28
+ true
29
+ rescue OpenVidu::ResponseError => e
30
+ raise e unless e.response.code == 404
31
+ false
32
+ end
33
+ end
34
+
27
35
  def create
28
36
  OpenVidu::Command.new(
29
- :session, :post, 'api/sessions', create_params
37
+ :session, :post, 'api/sessions', create_params, { options: { server: server } }
30
38
  ).execute
31
39
  end
32
40
 
33
41
  def delete
34
42
  OpenVidu::Command.new(
35
- :session, :delete, "api/sessions/#{sessionId}"
43
+ :session, :delete, "api/sessions/#{customSessionId}", { options: { server: server } }
36
44
  ).execute
37
45
  end
38
46
  end
@@ -5,13 +5,9 @@ module OpenVidu
5
5
  GENERATED_PARAMS = %w[id token].freeze
6
6
  ALL_PARAMS = (ASSIGNABLE_PARAMS + GENERATED_PARAMS).freeze
7
7
 
8
- def self.create(params)
9
- new(params).create
10
- end
11
-
12
8
  def create
13
9
  OpenVidu::Command.new(
14
- :token, :post, 'api/tokens', create_params
10
+ :token, :post, 'api/tokens', create_params, options: { server: server }
15
11
  ).execute
16
12
  end
17
13
  end
@@ -1,3 +1,3 @@
1
1
  module OpenVidu
2
- VERSION = "0.2.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -32,12 +32,14 @@ Gem::Specification.new do |spec|
32
32
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
33
  spec.require_paths = ['lib']
34
34
 
35
- spec.add_development_dependency 'bundler', '~> 1.16'
36
35
  spec.add_development_dependency 'byebug', '~> 9.0', '>= 9.0.6'
37
36
  spec.add_development_dependency 'minitest', '~> 5.0'
38
37
  spec.add_development_dependency 'rake', '~> 10.0'
39
38
  spec.add_development_dependency 'test-unit', '~> 3.3', '>= 3.3.4'
39
+ spec.add_development_dependency 'openssl', '>= 2.1.2' # Fix for Travis CI
40
+ spec.add_development_dependency 'webmock', '~> 3.7'
41
+ spec.add_development_dependency 'simplecov', '~> 0.17'
40
42
 
41
- spec.add_runtime_dependency 'dotenv', '~> 2.7', '>= 2.7.5'
42
- spec.add_runtime_dependency 'httparty', '~> 0.13.7'
43
+ spec.add_runtime_dependency 'addressable', '>= 2.5.0'
44
+ spec.add_runtime_dependency 'httparty', '>= 0.13'
43
45
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openvidu-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Saxon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-09 00:00:00.000000000 Z
11
+ date: 2020-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.16'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.16'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: byebug
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -93,39 +79,75 @@ dependencies:
93
79
  - !ruby/object:Gem::Version
94
80
  version: 3.3.4
95
81
  - !ruby/object:Gem::Dependency
96
- name: dotenv
82
+ name: openssl
97
83
  requirement: !ruby/object:Gem::Requirement
98
84
  requirements:
99
- - - "~>"
85
+ - - ">="
100
86
  - !ruby/object:Gem::Version
101
- version: '2.7'
87
+ version: 2.1.2
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
102
92
  - - ">="
103
93
  - !ruby/object:Gem::Version
104
- version: 2.7.5
105
- type: :runtime
94
+ version: 2.1.2
95
+ - !ruby/object:Gem::Dependency
96
+ name: webmock
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '3.7'
102
+ type: :development
106
103
  prerelease: false
107
104
  version_requirements: !ruby/object:Gem::Requirement
108
105
  requirements:
109
106
  - - "~>"
110
107
  - !ruby/object:Gem::Version
111
- version: '2.7'
108
+ version: '3.7'
109
+ - !ruby/object:Gem::Dependency
110
+ name: simplecov
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '0.17'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '0.17'
123
+ - !ruby/object:Gem::Dependency
124
+ name: addressable
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: 2.5.0
130
+ type: :runtime
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
112
134
  - - ">="
113
135
  - !ruby/object:Gem::Version
114
- version: 2.7.5
136
+ version: 2.5.0
115
137
  - !ruby/object:Gem::Dependency
116
138
  name: httparty
117
139
  requirement: !ruby/object:Gem::Requirement
118
140
  requirements:
119
- - - "~>"
141
+ - - ">="
120
142
  - !ruby/object:Gem::Version
121
- version: 0.13.7
143
+ version: '0.13'
122
144
  type: :runtime
123
145
  prerelease: false
124
146
  version_requirements: !ruby/object:Gem::Requirement
125
147
  requirements:
126
- - - "~>"
148
+ - - ">="
127
149
  - !ruby/object:Gem::Version
128
- version: 0.13.7
150
+ version: '0.13'
129
151
  description: Ruby client built around OpenVidu's REST API.
130
152
  email:
131
153
  - emailBryanSaxon@gmail.com
@@ -133,7 +155,7 @@ executables: []
133
155
  extensions: []
134
156
  extra_rdoc_files: []
135
157
  files:
136
- - ".DS_Store"
158
+ - ".env.sample"
137
159
  - ".gitignore"
138
160
  - ".travis.yml"
139
161
  - CODE_OF_CONDUCT.md
@@ -143,15 +165,15 @@ files:
143
165
  - Rakefile
144
166
  - bin/console
145
167
  - bin/setup
146
- - lib/.DS_Store
147
168
  - lib/open_vidu.rb
148
- - lib/open_vidu/.DS_Store
149
169
  - lib/open_vidu/base.rb
150
170
  - lib/open_vidu/command.rb
151
171
  - lib/open_vidu/config.rb
172
+ - lib/open_vidu/exceptions.rb
152
173
  - lib/open_vidu/recording.rb
153
174
  - lib/open_vidu/requestor.rb
154
175
  - lib/open_vidu/responder.rb
176
+ - lib/open_vidu/server.rb
155
177
  - lib/open_vidu/session.rb
156
178
  - lib/open_vidu/token.rb
157
179
  - lib/open_vidu/version.rb
@@ -179,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
201
  version: '0'
180
202
  requirements: []
181
203
  rubyforge_project:
182
- rubygems_version: 2.6.14.3
204
+ rubygems_version: 2.5.2.2
183
205
  signing_key:
184
206
  specification_version: 4
185
207
  summary: OpenVidu Ruby client.
data/.DS_Store DELETED
Binary file
Binary file
Binary file