uiza_minh_phong 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +535 -0
  3. data/.rubocop_disable.yml +78 -0
  4. data/.rubocop_enable.yml +786 -0
  5. data/CHANGELOG.md +50 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/CONTRIBUTORS.txt +3 -0
  8. data/Gemfile +7 -0
  9. data/Gemfile.lock +73 -0
  10. data/History.txt +1 -0
  11. data/LICENSE.txt +21 -0
  12. data/PULL_REQUEST_TEMPLATE.md +44 -0
  13. data/README.md +248 -0
  14. data/Rakefile +6 -0
  15. data/bin/console +14 -0
  16. data/bin/setup +8 -0
  17. data/doc/ANALYTIC.md +143 -0
  18. data/doc/CALLBACK.md +161 -0
  19. data/doc/CATEGORY.md +312 -0
  20. data/doc/EMBED_METADATA.md +4 -0
  21. data/doc/ENTITY.md +470 -0
  22. data/doc/ERRORS_CODE.md +60 -0
  23. data/doc/LIVE_STREAMING.md +452 -0
  24. data/doc/STORAGE.md +188 -0
  25. data/doc/USER.md +286 -0
  26. data/lib/uiza.rb +39 -0
  27. data/lib/uiza/analytic.rb +42 -0
  28. data/lib/uiza/api_operation/add.rb +16 -0
  29. data/lib/uiza/api_operation/create.rb +16 -0
  30. data/lib/uiza/api_operation/delete.rb +15 -0
  31. data/lib/uiza/api_operation/list.rb +14 -0
  32. data/lib/uiza/api_operation/remove.rb +15 -0
  33. data/lib/uiza/api_operation/retrieve.rb +15 -0
  34. data/lib/uiza/api_operation/update.rb +16 -0
  35. data/lib/uiza/callback.rb +16 -0
  36. data/lib/uiza/category.rb +42 -0
  37. data/lib/uiza/entity.rb +68 -0
  38. data/lib/uiza/error/bad_request_error.rb +8 -0
  39. data/lib/uiza/error/client_error.rb +8 -0
  40. data/lib/uiza/error/internal_server_error.rb +8 -0
  41. data/lib/uiza/error/not_found_error.rb +8 -0
  42. data/lib/uiza/error/server_error.rb +8 -0
  43. data/lib/uiza/error/service_unavailable_error.rb +8 -0
  44. data/lib/uiza/error/uiza_error.rb +18 -0
  45. data/lib/uiza/error/unauthorized_error.rb +8 -0
  46. data/lib/uiza/error/unprocessable_error.rb +8 -0
  47. data/lib/uiza/live.rb +86 -0
  48. data/lib/uiza/storage.rb +17 -0
  49. data/lib/uiza/uiza_client.rb +86 -0
  50. data/lib/uiza/uiza_open_struct.rb +18 -0
  51. data/lib/uiza/user.rb +41 -0
  52. data/lib/uiza/version.rb +3 -0
  53. data/uiza.gemspec +36 -0
  54. metadata +141 -0
data/lib/uiza.rb ADDED
@@ -0,0 +1,39 @@
1
+ require "net/http"
2
+ require "net/https"
3
+ require "json"
4
+
5
+ require "uiza/version"
6
+ require "uiza/uiza_client"
7
+ require "uiza/uiza_open_struct"
8
+
9
+ require "uiza/error/uiza_error"
10
+ require "uiza/error/bad_request_error"
11
+ require "uiza/error/unauthorized_error"
12
+ require "uiza/error/not_found_error"
13
+ require "uiza/error/unprocessable_error"
14
+ require "uiza/error/internal_server_error"
15
+ require "uiza/error/service_unavailable_error"
16
+ require "uiza/error/client_error"
17
+ require "uiza/error/server_error"
18
+
19
+ require "uiza/api_operation/create"
20
+ require "uiza/api_operation/add"
21
+ require "uiza/api_operation/retrieve"
22
+ require "uiza/api_operation/list"
23
+ require "uiza/api_operation/update"
24
+ require "uiza/api_operation/delete"
25
+ require "uiza/api_operation/remove"
26
+
27
+ require "uiza/entity"
28
+ require "uiza/storage"
29
+ require "uiza/category"
30
+ require "uiza/live"
31
+ require "uiza/callback"
32
+ require "uiza/user"
33
+ require "uiza/analytic"
34
+
35
+ module Uiza
36
+ class << self
37
+ attr_accessor :workspace_api_domain, :authorization
38
+ end
39
+ end
@@ -0,0 +1,42 @@
1
+ module Uiza
2
+ class Analytic
3
+ OBJECT_API_PATH = "analytic/entity/video-quality".freeze
4
+ OBJECT_API_DESCRIPTION_LINK = {
5
+ get_total_line: "https://docs.uiza.io/#total-line",
6
+ get_type: "https://docs.uiza.io/#type",
7
+ get_line: "https://docs.uiza.io/#line"
8
+ }.freeze
9
+
10
+ class << self
11
+ def get_total_line params
12
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{OBJECT_API_PATH}/total-line-v2"
13
+ method = :get
14
+ headers = {"Authorization" => Uiza.authorization}
15
+ description_link = OBJECT_API_DESCRIPTION_LINK[:get_total_line]
16
+
17
+ uiza_client = UizaClient.new url, method, headers, params, description_link
18
+ uiza_client.execute_request
19
+ end
20
+
21
+ def get_type params
22
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{OBJECT_API_PATH}/type"
23
+ method = :get
24
+ headers = {"Authorization" => Uiza.authorization}
25
+ description_link = OBJECT_API_DESCRIPTION_LINK[:get_type]
26
+
27
+ uiza_client = UizaClient.new url, method, headers, params, description_link
28
+ uiza_client.execute_request
29
+ end
30
+
31
+ def get_line params
32
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{OBJECT_API_PATH}/line"
33
+ method = :get
34
+ headers = {"Authorization" => Uiza.authorization}
35
+ description_link = OBJECT_API_DESCRIPTION_LINK[:get_line]
36
+
37
+ uiza_client = UizaClient.new url, method, headers, params, description_link
38
+ uiza_client.execute_request
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,16 @@
1
+ module Uiza
2
+ module APIOperation
3
+ module Add
4
+ def add params
5
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{self::OBJECT_API_PATH}"
6
+ method = :post
7
+ headers = {"Authorization" => Uiza.authorization}
8
+
9
+ uiza_client = UizaClient.new url, method, headers, params, self::OBJECT_API_DESCRIPTION_LINK[:add]
10
+ response = uiza_client.execute_request
11
+
12
+ retrieve response.id
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Uiza
2
+ module APIOperation
3
+ module Create
4
+ def create params
5
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{self::OBJECT_API_PATH}"
6
+ method = :post
7
+ headers = {"Authorization" => Uiza.authorization}
8
+
9
+ uiza_client = UizaClient.new url, method, headers, params, self::OBJECT_API_DESCRIPTION_LINK[:create]
10
+ response = uiza_client.execute_request
11
+
12
+ retrieve response.id
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ module Uiza
2
+ module APIOperation
3
+ module Delete
4
+ def delete id
5
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{self::OBJECT_API_PATH}"
6
+ method = :delete
7
+ headers = {"Authorization" => Uiza.authorization}
8
+ params = {id: id}
9
+
10
+ uiza_client = UizaClient.new url, method, headers, params, self::OBJECT_API_DESCRIPTION_LINK[:delete]
11
+ uiza_client.execute_request
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module Uiza
2
+ module APIOperation
3
+ module List
4
+ def list params = {}
5
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{self::OBJECT_API_PATH}"
6
+ method = :get
7
+ headers = {"Authorization" => Uiza.authorization}
8
+
9
+ uiza_client = UizaClient.new url, method, headers, params, self::OBJECT_API_DESCRIPTION_LINK[:list]
10
+ uiza_client.execute_request
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module Uiza
2
+ module APIOperation
3
+ module Remove
4
+ def remove id
5
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{self::OBJECT_API_PATH}"
6
+ method = :delete
7
+ headers = {"Authorization" => Uiza.authorization}
8
+ params = {id: id}
9
+
10
+ uiza_client = UizaClient.new url, method, headers, params, self::OBJECT_API_DESCRIPTION_LINK[:remove]
11
+ uiza_client.execute_request
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Uiza
2
+ module APIOperation
3
+ module Retrieve
4
+ def retrieve id
5
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{self::OBJECT_API_PATH}"
6
+ method = :get
7
+ headers = {"Authorization" => Uiza.authorization}
8
+ params = {id: id}
9
+
10
+ uiza_client = UizaClient.new url, method, headers, params, self::OBJECT_API_DESCRIPTION_LINK[:retrieve]
11
+ uiza_client.execute_request
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module Uiza
2
+ module APIOperation
3
+ module Update
4
+ def update params
5
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{self::OBJECT_API_PATH}"
6
+ method = :put
7
+ headers = {"Authorization" => Uiza.authorization}
8
+
9
+ uiza_client = UizaClient.new url, method, headers, params, self::OBJECT_API_DESCRIPTION_LINK[:update]
10
+ response = uiza_client.execute_request
11
+
12
+ retrieve response.id
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Uiza
2
+ class Callback
3
+ extend Uiza::APIOperation::Create
4
+ extend Uiza::APIOperation::Retrieve
5
+ extend Uiza::APIOperation::Update
6
+ extend Uiza::APIOperation::Delete
7
+
8
+ OBJECT_API_PATH = "media/entity/callback".freeze
9
+ OBJECT_API_DESCRIPTION_LINK = {
10
+ create: "https://docs.uiza.io/#create-a-callback",
11
+ retrieve: "https://docs.uiza.io/#retrieve-a-callback",
12
+ update: "https://docs.uiza.io/#update-a-callback",
13
+ delete: "https://docs.uiza.io/#delete-a-callback"
14
+ }.freeze
15
+ end
16
+ end
@@ -0,0 +1,42 @@
1
+ module Uiza
2
+ class Category
3
+ extend Uiza::APIOperation::Create
4
+ extend Uiza::APIOperation::Retrieve
5
+ extend Uiza::APIOperation::Update
6
+ extend Uiza::APIOperation::Delete
7
+ extend Uiza::APIOperation::List
8
+
9
+ OBJECT_API_PATH = "media/metadata".freeze
10
+ OBJECT_API_DESCRIPTION_LINK = {
11
+ create: "https://docs.uiza.io/#create-category",
12
+ retrieve: "https://docs.uiza.io/#retrieve-category",
13
+ list: "https://docs.uiza.io/#retrieve-category-list",
14
+ update: "https://docs.uiza.io/#update-category",
15
+ delete: "https://docs.uiza.io/#delete-category",
16
+ create_relation: "https://docs.uiza.io/#create-category-relation",
17
+ delete_relation: "https://docs.uiza.io/#delete-category-relation"
18
+ }.freeze
19
+
20
+ class << self
21
+ def create_relation params
22
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/media/entity/related/metadata"
23
+ method = :post
24
+ headers = {"Authorization" => Uiza.authorization}
25
+ description_link = OBJECT_API_DESCRIPTION_LINK[:create_relation]
26
+
27
+ uiza_client = UizaClient.new url, method, headers, params, description_link
28
+ uiza_client.execute_request
29
+ end
30
+
31
+ def delete_relation params
32
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/media/entity/related/metadata"
33
+ method = :post
34
+ headers = {"Authorization" => Uiza.authorization}
35
+ description_link = OBJECT_API_DESCRIPTION_LINK[:delete_relation]
36
+
37
+ uiza_client = UizaClient.new url, method, headers, params, description_link
38
+ uiza_client.execute_request
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,68 @@
1
+ module Uiza
2
+ class Entity
3
+ extend Uiza::APIOperation::Create
4
+ extend Uiza::APIOperation::Retrieve
5
+ extend Uiza::APIOperation::List
6
+ extend Uiza::APIOperation::Update
7
+ extend Uiza::APIOperation::Delete
8
+
9
+ OBJECT_API_PATH = "media/entity".freeze
10
+ OBJECT_API_DESCRIPTION_LINK = {
11
+ create: "https://docs.uiza.io/#create-entity",
12
+ retrieve: "https://docs.uiza.io/#retrieve-an-entity",
13
+ list: "https://docs.uiza.io/#list-all-entities",
14
+ update: "https://docs.uiza.io/#update-an-entity",
15
+ delete: "https://docs.uiza.io/#delete-an-entity",
16
+ search: "https://docs.uiza.io/#search-entity",
17
+ publish: "https://docs.uiza.io/#publish-entity-to-cdn",
18
+ get_status_publish: "https://docs.uiza.io/#get-status-publish",
19
+ get_aws_upload_key: "https://docs.uiza.io/#get-aws-upload-key"
20
+ }.freeze
21
+
22
+ class << self
23
+ def search keyword
24
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{OBJECT_API_PATH}/search"
25
+ method = :get
26
+ headers = {"Authorization" => Uiza.authorization}
27
+ params = {keyword: keyword}
28
+ description_link = OBJECT_API_DESCRIPTION_LINK[:search]
29
+
30
+ uiza_client = UizaClient.new url, method, headers, params, description_link
31
+ uiza_client.execute_request
32
+ end
33
+
34
+ def publish id
35
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{OBJECT_API_PATH}/publish"
36
+ method = :post
37
+ headers = {"Authorization" => Uiza.authorization}
38
+ params = {id: id}
39
+ description_link = OBJECT_API_DESCRIPTION_LINK[:publish]
40
+
41
+ uiza_client = UizaClient.new url, method, headers, params, description_link
42
+ uiza_client.execute_request
43
+ end
44
+
45
+ def get_status_publish id
46
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{OBJECT_API_PATH}/publish/status"
47
+ method = :get
48
+ headers = {"Authorization" => Uiza.authorization}
49
+ params = {id: id}
50
+ description_link = OBJECT_API_DESCRIPTION_LINK[:get_status_publish]
51
+
52
+ uiza_client = UizaClient.new url, method, headers, params, description_link
53
+ uiza_client.execute_request
54
+ end
55
+
56
+ def get_aws_upload_key
57
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/admin/app/config/aws"
58
+ method = :get
59
+ headers = {"Authorization" => Uiza.authorization}
60
+ params = {}
61
+ description_link = OBJECT_API_DESCRIPTION_LINK[:get_aws_upload_key]
62
+
63
+ uiza_client = UizaClient.new url, method, headers, params, description_link
64
+ uiza_client.execute_request
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,8 @@
1
+ module Uiza
2
+ module Error
3
+ class BadRequestError < UizaError
4
+ DEFAULT_CODE = 400
5
+ DEFAULT_MESSAGE = "The request was unacceptable, often due to missing a required parameter.".freeze
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Uiza
2
+ module Error
3
+ class ClientError < UizaError
4
+ DEFAULT_CODE = "4xx".freeze
5
+ DEFAULT_MESSAGE = "The error seems to have been caused by the client.".freeze
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Uiza
2
+ module Error
3
+ class InternalServerError < UizaError
4
+ DEFAULT_CODE = 500
5
+ DEFAULT_MESSAGE = "We had a problem with our server. Try again later.".freeze
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Uiza
2
+ module Error
3
+ class NotFoundError < UizaError
4
+ DEFAULT_CODE = 404
5
+ DEFAULT_MESSAGE = "The requested resource doesn't exist.".freeze
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Uiza
2
+ module Error
3
+ class ServerError < UizaError
4
+ DEFAULT_CODE = "5xx".freeze
5
+ DEFAULT_MESSAGE = "The server is aware that it has encountered an error.".freeze
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Uiza
2
+ module Error
3
+ class ServiceUnavailableError < UizaError
4
+ DEFAULT_CODE = 503
5
+ DEFAULT_MESSAGE = "The server is overloaded or down for maintenance.".freeze
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,18 @@
1
+ module Uiza
2
+ module Error
3
+ class UizaError < StandardError
4
+ attr_reader :description_link
5
+ attr_reader :code
6
+ attr_reader :message
7
+
8
+ DEFAULT_CODE = "".freeze
9
+ DEFAULT_MESSAGE = "Unknow Error.".freeze
10
+
11
+ def initialize description_link, message = nil, code = nil
12
+ @description_link = description_link
13
+ @message = (message.to_s.empty? ? nil : message) || self.class::DEFAULT_MESSAGE
14
+ @code = (code.to_s.empty? ? nil : code.to_i) || self.class::DEFAULT_CODE
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ module Uiza
2
+ module Error
3
+ class UnauthorizedError < UizaError
4
+ DEFAULT_CODE = 401
5
+ DEFAULT_MESSAGE = "No valid API key provided.".freeze
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Uiza
2
+ module Error
3
+ class UnprocessableError < UizaError
4
+ DEFAULT_CODE = 422
5
+ DEFAULT_MESSAGE = "The syntax of the request is correct (often cause of wrong parameter).".freeze
6
+ end
7
+ end
8
+ end
data/lib/uiza/live.rb ADDED
@@ -0,0 +1,86 @@
1
+ module Uiza
2
+ class Live
3
+ extend Uiza::APIOperation::Create
4
+ extend Uiza::APIOperation::Retrieve
5
+ extend Uiza::APIOperation::Update
6
+
7
+ OBJECT_API_PATH = "live/entity".freeze
8
+ OBJECT_API_DESCRIPTION_LINK = {
9
+ create: "https://docs.uiza.io/#create-a-live-event",
10
+ retrieve: "https://docs.uiza.io/#retrieve-a-live-event",
11
+ update: "https://docs.uiza.io/#update-a-live-event",
12
+ start_feed: "https://docs.uiza.io/#start-a-live-feed",
13
+ list_recorded: "https://docs.uiza.io/#list-all-recorded-files",
14
+ stop_feed: "https://docs.uiza.io/#stop-a-live-feed",
15
+ get_view: "https://docs.uiza.io/#get-view-of-live-feed",
16
+ delete: "https://docs.uiza.io/#delete-a-record-file",
17
+ convert_to_vod: "https://docs.uiza.io/#convert-into-vod"
18
+ }.freeze
19
+
20
+ class << self
21
+ def start_feed id
22
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{OBJECT_API_PATH}/feed"
23
+ method = :post
24
+ headers = {"Authorization" => Uiza.authorization}
25
+ params = {id: id}
26
+
27
+ uiza_client = UizaClient.new url, method, headers, params, OBJECT_API_DESCRIPTION_LINK[:start_feed]
28
+ response = uiza_client.execute_request
29
+
30
+ retrieve response.entityId
31
+ end
32
+
33
+ def get_view id
34
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{OBJECT_API_PATH}/tracking/current-view"
35
+ method = :get
36
+ headers = {"Authorization" => Uiza.authorization}
37
+ params = {id: id}
38
+ description_link = OBJECT_API_DESCRIPTION_LINK[:get_view]
39
+
40
+ uiza_client = UizaClient.new url, method, headers, params, description_link
41
+ uiza_client.execute_request
42
+ end
43
+
44
+ def stop_feed id
45
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{OBJECT_API_PATH}/feed"
46
+ method = :put
47
+ headers = {"Authorization" => Uiza.authorization}
48
+ params = {id: id}
49
+
50
+ uiza_client = UizaClient.new url, method, headers, params, OBJECT_API_DESCRIPTION_LINK[:stop_feed]
51
+ response = uiza_client.execute_request
52
+
53
+ retrieve response.entityId
54
+ end
55
+
56
+ def list_recorded params = {}
57
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{OBJECT_API_PATH}/dvr"
58
+ method = :get
59
+ headers = {"Authorization" => Uiza.authorization}
60
+
61
+ uiza_client = UizaClient.new url, method, headers, params, OBJECT_API_DESCRIPTION_LINK[:list_recorded]
62
+ uiza_client.execute_request
63
+ end
64
+
65
+ def delete id
66
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{OBJECT_API_PATH}/dvr"
67
+ method = :delete
68
+ headers = {"Authorization" => Uiza.authorization}
69
+ params = {id: id}
70
+
71
+ uiza_client = UizaClient.new url, method, headers, params, OBJECT_API_DESCRIPTION_LINK[:delete]
72
+ uiza_client.execute_request
73
+ end
74
+
75
+ def convert_to_vod id
76
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/#{OBJECT_API_PATH}/dvr/convert-to-vod"
77
+ method = :post
78
+ headers = {"Authorization" => Uiza.authorization}
79
+ params = {id: id}
80
+
81
+ uiza_client = UizaClient.new url, method, headers, params, OBJECT_API_DESCRIPTION_LINK[:convert_to_vod]
82
+ uiza_client.execute_request
83
+ end
84
+ end
85
+ end
86
+ end