openvidu-ruby-client 0.2.3 → 0.3.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: 59a8122f21134fc2603ab6a8ee13db1688c30e8c
4
- data.tar.gz: 822010be06300ead388a01be303fdd8a54a7fdb1
3
+ metadata.gz: 92a0236b9a03c43f0e291d64f90afe17c0b7df22
4
+ data.tar.gz: 349f451e07e134e94e1fa51b496ef4058595e67f
5
5
  SHA512:
6
- metadata.gz: 5526e8ef1d05d2942df8bea05184452041502440b230652d36955fdc88519d19590df1abe5bd1b1aca557b5c0c22151902a4e0feaa2e7d0df08c94eb539cfe33
7
- data.tar.gz: 1057d5c72a526ada260bbd5327641e6ee8198924ba04e301c9ec15a17f00f334ba4d17ac79cacef9a9c4a11dfbcfaf81aebaf17c3c9cb8afacf8583b8887e421
6
+ metadata.gz: 547c143edba3b07a2bc0bad6fa41b7dd0ddd8663f9f25b37f9ec7992652377547da6284164ea06ad55de2eb74d68188d9e4ff53525ebbab025b3676326b83cbc
7
+ data.tar.gz: 5bcbfcb21c66f75c8b11df8c9a44992bbb8087a64d1e37ac52998baf4052d29754564346833202a16a8bf51db0d517c2a7667452a04ee76e83b6654922125602
data/.gitignore CHANGED
@@ -11,3 +11,5 @@
11
11
  /vendor/
12
12
  .DS_Store
13
13
  \.idea
14
+ \.rakeTasks
15
+ Gemfile.lock
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'
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,11 +8,14 @@ module OpenVidu
7
8
  GENERATED_PARAMS = %w[].freeze
8
9
  ALL_PARAMS = (ASSIGNABLE_PARAMS + GENERATED_PARAMS).freeze
9
10
 
11
+ attr_reader :server
12
+
10
13
  def self.content_key
11
14
  'content'
12
15
  end
13
16
 
14
- def initialize(params = {})
17
+ def initialize(uri, params = {})
18
+ @server = Server.new(uri).freeze
15
19
  self.class::ALL_PARAMS.each do |param|
16
20
  instance_variable_set("@#{param}", params[param.to_sym])
17
21
  self.class.send(:attr_accessor, param.to_sym)
@@ -5,19 +5,23 @@ require 'open_vidu/exceptions'
5
5
  module OpenVidu
6
6
  # Command
7
7
  class Command
8
- attr_reader :object, :method, :endpoint, :params
8
+ attr_reader :object, :method, :endpoint, :params, :requestor, :responder, :server
9
9
 
10
- def initialize(object, method, endpoint, params = {})
10
+ def initialize(object, method, endpoint, params = {}, options: {})
11
11
  @object = object
12
12
  @method = method
13
13
  @endpoint = endpoint
14
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
15
19
  end
16
20
 
17
21
  def execute
18
- response = OpenVidu::Requestor.new(method, endpoint, params).execute
22
+ response = requestor.execute
19
23
  raise OpenVidu::ResponseError.new(response) unless valid?(response)
20
- OpenVidu::Responder.new(object, response.parsed_response).execute
24
+ responder.execute(server, object, response.parsed_response)
21
25
  end
22
26
 
23
27
  private
@@ -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
@@ -14,19 +14,19 @@ module OpenVidu
14
14
  'items'
15
15
  end
16
16
 
17
- def self.all
17
+ def all
18
18
  OpenVidu::Command.new(
19
- :recording, :get, 'api/recordings'
19
+ :recording,
20
+ :get,
21
+ 'api/recordings',
22
+ { options: { server: server } }
20
23
  ).execute
21
24
  end
22
25
 
23
- def self.create(params)
24
- new(params).create
25
- end
26
-
27
- def self.find(id)
26
+ def find(id)
28
27
  OpenVidu::Command.new(
29
- :recording, :get, "api/recordings/#{id}"
28
+ :recording, :get, "api/recordings/#{id}",
29
+ { options: { server: server } }
30
30
  ).execute
31
31
  end
32
32
 
@@ -34,7 +34,8 @@ module OpenVidu
34
34
  OpenVidu::Command.new(
35
35
  :recording,
36
36
  :post,
37
- "api/recordings/stop/#{id}"
37
+ "api/recordings/stop/#{id}",
38
+ { options: { server: server } }
38
39
  ).execute
39
40
  end
40
41
 
@@ -42,13 +43,18 @@ module OpenVidu
42
43
  OpenVidu::Command.new(
43
44
  :recording,
44
45
  :delete,
45
- "api/recordings/#{id}"
46
+ "api/recordings/#{id}",
47
+ { options: { server: server } }
46
48
  ).execute
47
49
  end
48
50
 
49
51
  def create
50
52
  OpenVidu::Command.new(
51
- :recording, :post, 'api/recordings/start', create_params
53
+ :recording,
54
+ :post,
55
+ 'api/recordings/start',
56
+ create_params,
57
+ { options: { server: server } }
52
58
  ).execute
53
59
  end
54
60
 
@@ -4,13 +4,10 @@ require 'json'
4
4
  module OpenVidu
5
5
  # Requestor
6
6
  class Requestor
7
- attr_reader :method, :endpoint, :params
7
+ attr_reader :server, :method, :endpoint, :params
8
8
 
9
- BASE_URL = ENV['OPENVIDU_URL']
10
- TOKEN = "#{ENV['OPENVIDU_USERNAME']}:#{ENV['OPENVIDU_PASSWORD']}".freeze
11
- VERIFY_PEER = ENV['OPENVIDU_VERIFY_PEER']
12
-
13
- def initialize(method, endpoint, params = {})
9
+ def initialize(server, method, endpoint, params = {})
10
+ @server = server
14
11
  @method = method
15
12
  @endpoint = endpoint
16
13
  @params = params
@@ -23,16 +20,16 @@ module OpenVidu
23
20
  private
24
21
 
25
22
  def url
26
- "#{BASE_URL}/#{endpoint}"
23
+ "#{server.scheme}://#{server.host}:#{server.port || 4443}/#{endpoint}"
27
24
  end
28
25
 
29
26
  def options
30
27
  {
31
28
  headers: {
32
- 'Authorization' => "Basic #{Base64.strict_encode64(TOKEN)}",
29
+ 'Authorization' => "Basic #{Base64.strict_encode64(server.token)}",
33
30
  'Content-Type' => 'application/json'
34
31
  },
35
- verify: VERIFY_PEER != 'false',
32
+ verify: server.verify_peer?,
36
33
  body: params.to_json
37
34
  }
38
35
  end
@@ -3,19 +3,16 @@ module OpenVidu
3
3
  class Responder
4
4
  attr_reader :object, :response
5
5
 
6
- def initialize(object, response)
6
+ def execute(server, object, response)
7
7
  @object = object
8
8
  @response = response
9
- end
10
-
11
- def execute
12
9
  klass = Object.const_get(klass_name)
13
10
 
14
11
  return true if record_destroyed?
15
- return klass.new(mapped_params(response)) if complete_record?
16
- 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?
17
14
 
18
- response[content_key].map { |hash| klass.new(mapped_params(hash)) }
15
+ response[content_key].map { |hash| klass.new(server, mapped_params(hash)) }
19
16
  end
20
17
 
21
18
  private
@@ -0,0 +1,39 @@
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
+ def_delegators :@uri, :host, :port, :scheme, :query_values, :to_s
12
+
13
+ # `uri` should take the form of scheme://some-openvidu-host-or-ip:port?token=<your-secret-here>
14
+ # e.g. https://1.2.3.4?token=abcdefghijklmnop
15
+ def initialize(uri)
16
+ @uri = Addressable::URI.parse(uri.to_s)
17
+ raise InvalidURI if @uri.empty?
18
+ end
19
+
20
+ def token
21
+ "OPENVIDUAPP:#{query_values.fetch('token')}"
22
+ end
23
+
24
+ def host_and_port
25
+ "#{host}:#{port}"
26
+ end
27
+
28
+ def verify_peer?
29
+ return false if query_values['verify_peer'].to_s.downcase == 'false'
30
+
31
+ true
32
+ end
33
+
34
+ def ==(other)
35
+ other.to_s == self.to_s
36
+ end
37
+ end
38
+ end
39
+
@@ -8,26 +8,22 @@ 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
 
27
- def self.exists?(id)
23
+ def exists?(id)
28
24
  begin
29
25
  OpenVidu::Command.new(
30
- :session, :get, "api/sessions/#{id}"
26
+ :session, :get, "api/sessions/#{id}", { options: { server: server } }
31
27
  ).execute
32
28
  true
33
29
  rescue OpenVidu::ResponseError => e
@@ -38,13 +34,13 @@ module OpenVidu
38
34
 
39
35
  def create
40
36
  OpenVidu::Command.new(
41
- :session, :post, 'api/sessions', create_params
37
+ :session, :post, 'api/sessions', create_params, { options: { server: server } }
42
38
  ).execute
43
39
  end
44
40
 
45
41
  def delete
46
42
  OpenVidu::Command.new(
47
- :session, :delete, "api/sessions/#{sessionId}"
43
+ :session, :delete, "api/sessions/#{customSessionId}", { options: { server: server } }
48
44
  ).execute
49
45
  end
50
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.3"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -37,7 +37,9 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency 'rake', '~> 10.0'
38
38
  spec.add_development_dependency 'test-unit', '~> 3.3', '>= 3.3.4'
39
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_development_dependency 'dotenv', '~> 2.7', '>= 2.7.5'
43
+ spec.add_runtime_dependency 'addressable', '>= 2.5.0'
42
44
  spec.add_runtime_dependency 'httparty', '>= 0.13'
43
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openvidu-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.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-30 00:00:00.000000000 Z
11
+ date: 2019-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -93,25 +93,47 @@ dependencies:
93
93
  - !ruby/object:Gem::Version
94
94
  version: 2.1.2
95
95
  - !ruby/object:Gem::Dependency
96
- name: dotenv
96
+ name: webmock
97
97
  requirement: !ruby/object:Gem::Requirement
98
98
  requirements:
99
99
  - - "~>"
100
100
  - !ruby/object:Gem::Version
101
- version: '2.7'
102
- - - ">="
101
+ version: '3.7'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '3.7'
109
+ - !ruby/object:Gem::Dependency
110
+ name: simplecov
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
103
114
  - !ruby/object:Gem::Version
104
- version: 2.7.5
115
+ version: '0.17'
105
116
  type: :development
106
117
  prerelease: false
107
118
  version_requirements: !ruby/object:Gem::Requirement
108
119
  requirements:
109
120
  - - "~>"
110
121
  - !ruby/object:Gem::Version
111
- version: '2.7'
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
@@ -151,6 +173,7 @@ files:
151
173
  - lib/open_vidu/recording.rb
152
174
  - lib/open_vidu/requestor.rb
153
175
  - lib/open_vidu/responder.rb
176
+ - lib/open_vidu/server.rb
154
177
  - lib/open_vidu/session.rb
155
178
  - lib/open_vidu/token.rb
156
179
  - lib/open_vidu/version.rb