true-conf 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f29978dc3d4c91a159b066f4987ab87345847cbaa132ad58961800ff9d07ce0d
4
- data.tar.gz: 68b055e0881cbcccdb388c92fbaa3e49c69ea2ba47046a0972f13fdfb461d931
3
+ metadata.gz: 00ff9c51d74805eb57bf177b08b9e1756aebe22657f63b305d8367496e7e2bfa
4
+ data.tar.gz: e1593f9f88add18b5603ca84c0e5d7006c6f4f585195cd787e7ef20e711f036e
5
5
  SHA512:
6
- metadata.gz: 9443f207e49049cbec6d61fca3bfda2b23f0b790afd057d38346caaff610cec72c2dc2a68cc4e5fd40b33d9bf9ef9429b87122b259d015afc1b764a147ab4b3e
7
- data.tar.gz: 10cfaf7451a53c10e3d1f790bb02046215c7ae36ba5a1965ce2e65c6cf38b9b75ac41532b141a95cc5032094d62a28b2bc66bbb96c05518792c3d43067f443bd
6
+ metadata.gz: d495a41c2efbf4383833006ae42ac12c766f50f40d21e529fc377d5bb2d23caa930d6c1b43103cf43b0673500ded6e91821e1a911a9cfaade5bd395fe709b8b8
7
+ data.tar.gz: e28f7951f0fe8f1b84d2e6d796af1ed290d2a6e3dabfac2063159187abb4cd929881d3225bb2cff23435f15f81ab82e6dc5e4c5e9498cb55bbec23db7783ef95
data/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # TrueConf Server API Client
2
2
 
3
+ [![Gem Version][gem-badger]][gem]
3
4
  [![TrueConf](https://circleci.com/gh/paderinandrey/true-conf.svg?style=svg)](https://circleci.com/gh/paderinandrey/true-conf)
4
5
 
6
+ [gem-badger]: https://img.shields.io/gem/v/true-conf.svg?style=flat&color=blue
7
+ [gem]: https://rubygems.org/gems/true-conf
5
8
  ## Installation
6
9
 
7
10
  Add this line to your application's Gemfile:
@@ -19,13 +22,21 @@ Or install it yourself as:
19
22
  $ gem install true-conf
20
23
 
21
24
  ## Usage
22
- Initialize a client with `client_id` and `client_secret`:
25
+ The TrueConf API uses OAuth2 or Token to authenticate API request. By defaut, a OAuth2 client will be used.
23
26
 
24
27
  ```ruby
25
- client = TrueConf::Client.new client_id: '<client_id>', # required
28
+ # OAuth
29
+ client = TrueConf::Client.new auth_method: 'oauth', # default: oauth
30
+ client_id: '<client_id>', # required
26
31
  client_secret: '<client_secret>', # required
27
32
  api_server: '<server_name>', # required
28
33
  version: '3.2' # optional, default: 3.2
34
+
35
+ # Token
36
+ client = TrueConf::Client.new auth_method: 'token',
37
+ client_token: '<client_token>', # required
38
+ api_server: '<server_name>', # required
39
+ version: '3.2' # optional, default: 3.2
29
40
  ```
30
41
 
31
42
  ```ruby
@@ -161,7 +172,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
161
172
  ## License
162
173
 
163
174
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
164
-
165
- ## Code of Conduct
166
-
167
- Everyone interacting in the True::Conf project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/true-conf/blob/master/CODE_OF_CONDUCT.md).
@@ -1,13 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "evil/client"
4
+ require "oauth2"
4
5
  require "tempfile"
5
6
 
6
7
  require "true-conf/client"
8
+ require "true-conf/types/auth_method_type"
7
9
  require "true-conf/conference"
8
10
  require "true-conf/invitation"
9
11
  require "true-conf/participant"
10
12
  require "true-conf/record"
13
+ require "true-conf/call"
11
14
  require "true-conf/user"
12
15
  require "true-conf/version"
13
16
  require "true-conf/response"
@@ -26,3 +29,8 @@ require "true-conf/entity/invitation_simple"
26
29
  require "true-conf/entity/invitation_list"
27
30
  require "true-conf/entity/record"
28
31
  require "true-conf/entity/record_list"
32
+ require "true-conf/entity/call"
33
+ require "true-conf/entity/call_list"
34
+ require "true-conf/entity/date_time"
35
+ require "true-conf/entity/call_participant_list"
36
+ require "true-conf/entity/call_participant"
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrueConf
4
+ Client.scope :logs do
5
+ path { "/logs" }
6
+ format "json"
7
+
8
+ scope :calls do
9
+ path { "/calls" }
10
+ format "json"
11
+
12
+ operation :all do
13
+ option :timezone, proc(&:to_i), optional: true
14
+ option :page_size, proc(&:to_i), optional: true
15
+ option :page_id, proc(&:to_i), optional: true
16
+ option :sort_field, proc(&:to_s), optional: true
17
+ option :sort_order, proc(&:to_i), optional: true
18
+ option :date_from, proc(&:to_s), optional: true
19
+ option :date_to, proc(&:to_s), optional: true
20
+ option :named_conf_id, proc(&:to_s), optional: true
21
+
22
+ http_method :get
23
+ query do
24
+ options.slice(:timezone, :page_size, :page_id, :sort_field,
25
+ :sort_order, :date_from, :date_to, :named_conf_id)
26
+ end
27
+
28
+ response(200) { |*res| Entity::CallList.build(*res) }
29
+ response(400, 403) { |*res| Error.build(*res) }
30
+ end
31
+ end
32
+
33
+ scope :by_call do
34
+ option :id, proc(&:to_s)
35
+
36
+ path { "/calls/#{id}" }
37
+ format "json"
38
+
39
+ operation :get do
40
+ http_method :get
41
+
42
+ response(200) { |*res| Entity::Call.build(*res) }
43
+ response(403, 404) { |*res| Error.build(*res) }
44
+ end
45
+
46
+ operation :participants do
47
+ option :timezone, proc(&:to_i), optional: true
48
+ option :page_size, proc(&:to_i), optional: true
49
+ option :page_id, proc(&:to_i), optional: true
50
+ option :sort_field, proc(&:to_s), optional: true
51
+ option :sort_order, proc(&:to_i), optional: true
52
+ option :date_from, proc(&:to_s), optional: true
53
+ option :date_to, proc(&:to_s), optional: true
54
+ option :call_id, proc(&:to_s), optional: true
55
+
56
+ query do
57
+ options.slice(:timezone, :page_size, :page_id, :sort_field,
58
+ :sort_order, :date_from, :date_to, :call_id)
59
+ end
60
+ path { "/participants" }
61
+ http_method :get
62
+
63
+ response(200) { |*res| Entity::CallParticipantList.build(*res) }
64
+ response(403, 404) { |*res| Error.build(*res) }
65
+ end
66
+ end
67
+ end
68
+ end
@@ -1,14 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "oauth2"
3
+ require "true-conf/callable"
4
+ require "true-conf/types/auth_method_type"
5
+
6
+ I18n.load_path += [File.expand_path("../config/locales/en.yml", __FILE__)]
7
+
4
8
  module TrueConf
5
9
  class Client < Evil::Client
6
- option :client_id, proc(&:to_s)
7
- option :client_secret, proc(&:to_s)
10
+ option :auth_method, AuthMethodType, default: -> { "oauth" }
11
+ option :client_id, proc(&:to_s), optional: true
12
+ option :client_secret, proc(&:to_s), optional: true
13
+ option :client_token, proc(&:to_s), optional: true
8
14
  option :api_server, proc(&:to_s)
9
15
  option :token_url, proc(&:to_s), default: -> { "/oauth2/v1/token" }
10
16
  option :version, proc(&:to_s), default: -> { "v3.1" }
11
17
 
18
+ validate do
19
+ return if AuthMethodType::METHODS.include?(auth_method)
20
+
21
+ errors.add :invalid_auth_method, field: "auth_method", level: "error"
22
+ end
23
+ validate { errors.add :token_missed if auth_method.token? && client_token.nil? }
24
+ validate { errors.add :client_id_missed if auth_method.oauth? && client_id.nil? }
25
+ validate { errors.add :client_secret_missed if auth_method.oauth? && client_secret.nil? }
26
+ validate { errors.add :unsupported_api_version unless %w[v3.1 v3.2].include?(version) }
27
+
12
28
  format "json"
13
29
  path { "https://#{api_server}/api/#{version}" }
14
30
 
@@ -25,7 +41,8 @@ module TrueConf
25
41
  end
26
42
 
27
43
  security do
28
- token_auth(access_token(client_id, client_secret), inside: :query)
44
+ token = auth_method.oauth? ? access_token(client_id, client_secret) : client_token
45
+ token_auth(token, inside: :query)
29
46
  end
30
47
  end
31
48
  end
@@ -0,0 +1,11 @@
1
+ ---
2
+ en:
3
+ evil:
4
+ client:
5
+ errors:
6
+ true_conf/client:
7
+ invalid_auth_method: "Invalid auth method"
8
+ token_missed: API token missed
9
+ client_id_missed: Client ID missed
10
+ client_secret_missed: Client Secret missed
11
+ unsupported_api_version: Unsupported api version on TrueConf server
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./date_time"
4
+
5
+ module TrueConf
6
+ module Entity
7
+ class Call < TrueConf::Response
8
+ extend TrueConf::Callable
9
+
10
+ option :conference_id, proc(&:to_s)
11
+ option :named_conf_id, proc(&:to_s), optional: true
12
+ option :topic, proc(&:to_s)
13
+ option :class, proc(&:to_i)
14
+ option :type, proc(&:to_i)
15
+ option :subtype, proc(&:to_i)
16
+ option :owner, proc(&:to_s)
17
+ option :participant_count, proc(&:to_i)
18
+ option :start_time, Entity::DateTime, optional: true
19
+ option :duration, proc(&:to_i)
20
+ option :end_time, Entity::DateTime, optional: true
21
+
22
+ class << self
23
+ def build(*res)
24
+ body = res.last
25
+ new JSON.parse(body.first)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrueConf
4
+ module Entity
5
+ class CallList < TrueConf::Response
6
+ option :cnt, proc(&:to_i)
7
+ option :list, [Entity::Call], as: :data
8
+
9
+ class << self
10
+ def build(*res)
11
+ body = res.last
12
+ new JSON.parse(body.first)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./date_time"
4
+
5
+ module TrueConf
6
+ module Entity
7
+ class CallParticipant < TrueConf::Response
8
+ extend TrueConf::Callable
9
+
10
+ option :app_id, proc(&:to_s)
11
+ option :avg_cpu_load, proc(&:to_i)
12
+ option :avg_sent_fps, proc(&:to_i)
13
+ option :bitrate_in, proc(&:to_i)
14
+ option :bitrate_out, proc(&:to_i)
15
+ option :call_id, proc(&:to_s)
16
+ option :display_name, proc(&:to_s)
17
+ option :duration, proc(&:to_i)
18
+ option :join_time, Entity::DateTime, optional: true
19
+ option :leave_reason, proc(&:to_i)
20
+ option :leave_time, Entity::DateTime, optional: true
21
+ option :video_h, proc(&:to_i)
22
+ option :video_w, proc(&:to_i)
23
+
24
+ class << self
25
+ def build(*res)
26
+ body = res.last
27
+ new JSON.parse(body.first)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./call_participant"
4
+
5
+ module TrueConf
6
+ module Entity
7
+ class CallParticipantList < TrueConf::Response
8
+ option :cnt, proc(&:to_i)
9
+ option :list, [Entity::CallParticipant], as: :data
10
+
11
+ class << self
12
+ def build(*res)
13
+ body = res.last
14
+ new JSON.parse(body.first)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrueConf
4
+ module Entity
5
+ class DateTime < TrueConf::Response
6
+ extend TrueConf::Callable
7
+
8
+ option :date, proc(&:to_s)
9
+ option :timezone_type, proc(&:to_i)
10
+ option :timezone, proc(&:to_s)
11
+ end
12
+ end
13
+ end
@@ -12,4 +12,6 @@ module TrueConf
12
12
  option :message, proc(&:to_s)
13
13
  option :errors, [TrueConf::ErrorDetail], optional: true
14
14
  end
15
+
16
+ class ParameterValueNotPermitted < StandardError; end
15
17
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrueConf
4
+ class AuthMethodType < String
5
+ extend TrueConf::Callable
6
+
7
+ METHODS = %w[oauth token].freeze
8
+
9
+ METHODS.each do |method|
10
+ define_method("#{method}?") do
11
+ @auth_method == method
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def initialize(value)
18
+ @auth_method = value.to_s
19
+ super @auth_method
20
+ end
21
+ end
22
+ end
@@ -41,7 +41,7 @@ module TrueConf
41
41
  http_method :post
42
42
  body do
43
43
  options.slice(:login_name, :email, :password, :display_name, :first_name, :last_name,
44
- :company, :mobile_phone, :work_phone, :home_phone, :is_active)
44
+ :company, :mobile_phone, :work_phone, :home_phone, :is_active)
45
45
  end
46
46
 
47
47
  response(200) { |*res| Entity::User.build(*res) }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TrueConf
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: true-conf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Paderin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-09 00:00:00.000000000 Z
11
+ date: 2020-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evil-client
@@ -131,11 +131,18 @@ files:
131
131
  - LICENSE.txt
132
132
  - README.md
133
133
  - lib/true-conf.rb
134
+ - lib/true-conf/call.rb
134
135
  - lib/true-conf/callable.rb
135
136
  - lib/true-conf/client.rb
136
137
  - lib/true-conf/conference.rb
138
+ - lib/true-conf/config/locales/en.yml
139
+ - lib/true-conf/entity/call.rb
140
+ - lib/true-conf/entity/call_list.rb
141
+ - lib/true-conf/entity/call_participant.rb
142
+ - lib/true-conf/entity/call_participant_list.rb
137
143
  - lib/true-conf/entity/conference.rb
138
144
  - lib/true-conf/entity/conference_simple.rb
145
+ - lib/true-conf/entity/date_time.rb
139
146
  - lib/true-conf/entity/invitation.rb
140
147
  - lib/true-conf/entity/invitation_list.rb
141
148
  - lib/true-conf/entity/invitation_simple.rb
@@ -153,6 +160,7 @@ files:
153
160
  - lib/true-conf/participant.rb
154
161
  - lib/true-conf/record.rb
155
162
  - lib/true-conf/response.rb
163
+ - lib/true-conf/types/auth_method_type.rb
156
164
  - lib/true-conf/user.rb
157
165
  - lib/true-conf/version.rb
158
166
  homepage: https://github.com/paderinandrey/true-conf