uiza 1.0.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.
Files changed (48) 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 +41 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/CONTRIBUTORS.txt +3 -0
  8. data/Gemfile +6 -0
  9. data/Gemfile.lock +65 -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 +179 -0
  14. data/Rakefile +6 -0
  15. data/bin/console +14 -0
  16. data/bin/setup +8 -0
  17. data/doc/ANALYTIC.md +5 -0
  18. data/doc/CALLBACK.md +4 -0
  19. data/doc/CATEGORY.md +282 -0
  20. data/doc/EMBED_METADATA.md +4 -0
  21. data/doc/ENTITY.md +466 -0
  22. data/doc/ERRORS_CODE.md +60 -0
  23. data/doc/LIVE_STREAMING.md +6 -0
  24. data/doc/STORAGE.md +189 -0
  25. data/lib/uiza.rb +34 -0
  26. data/lib/uiza/api_operation/add.rb +16 -0
  27. data/lib/uiza/api_operation/create.rb +16 -0
  28. data/lib/uiza/api_operation/delete.rb +15 -0
  29. data/lib/uiza/api_operation/list.rb +14 -0
  30. data/lib/uiza/api_operation/remove.rb +15 -0
  31. data/lib/uiza/api_operation/retrieve.rb +15 -0
  32. data/lib/uiza/api_operation/update.rb +16 -0
  33. data/lib/uiza/category.rb +42 -0
  34. data/lib/uiza/entity.rb +68 -0
  35. data/lib/uiza/error/bad_request_error.rb +8 -0
  36. data/lib/uiza/error/client_error.rb +8 -0
  37. data/lib/uiza/error/internal_server_error.rb +8 -0
  38. data/lib/uiza/error/not_found_error.rb +8 -0
  39. data/lib/uiza/error/server_error.rb +8 -0
  40. data/lib/uiza/error/service_unavailable_error.rb +8 -0
  41. data/lib/uiza/error/uiza_error.rb +18 -0
  42. data/lib/uiza/error/unauthorized_error.rb +8 -0
  43. data/lib/uiza/error/unprocessable_error.rb +8 -0
  44. data/lib/uiza/storage.rb +17 -0
  45. data/lib/uiza/uiza_client.rb +74 -0
  46. data/lib/uiza/version.rb +3 -0
  47. data/uiza.gemspec +36 -0
  48. metadata +134 -0
@@ -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
@@ -0,0 +1,17 @@
1
+ module Uiza
2
+ class Storage
3
+ extend Uiza::APIOperation::Add
4
+ extend Uiza::APIOperation::Retrieve
5
+ extend Uiza::APIOperation::Update
6
+ extend Uiza::APIOperation::Remove
7
+
8
+ OBJECT_API_PATH = "media/storage".freeze
9
+
10
+ OBJECT_API_DESCRIPTION_LINK = {
11
+ add: "https://docs.uiza.io/#add-a-storage",
12
+ retrieve: "https://docs.uiza.io/#retrieve-a-storage",
13
+ update: "https://docs.uiza.io/#update-storage",
14
+ remove: "https://docs.uiza.io/#remove-storage"
15
+ }.freeze
16
+ end
17
+ end
@@ -0,0 +1,74 @@
1
+ module Uiza
2
+ class UizaClient
3
+ def initialize url, method, headers, params, description_link
4
+ @uri = URI.parse url
5
+ @description_link = description_link
6
+
7
+ case method.to_s.downcase
8
+ when "get"
9
+ @uri.query = URI.encode_www_form params
10
+ @request = Net::HTTP::Get.new @uri
11
+ when "post"
12
+ @request = Net::HTTP::Post.new @uri
13
+ @request.body = JSON.dump params
14
+ when "put"
15
+ @request = Net::HTTP::Put.new @uri
16
+ @request.body = JSON.dump params
17
+ when "delete"
18
+ @request = Net::HTTP::Delete.new @uri
19
+ @request.body = JSON.dump params
20
+ end
21
+
22
+ @request.content_type = "application/json"
23
+ headers.each do |key, value|
24
+ @request[key] = value
25
+ end
26
+ end
27
+
28
+ def execute_request
29
+ @http = Net::HTTP.start @uri.host, @uri.port, use_ssl: true
30
+ @response = @http.request @request
31
+ @response = JSON.parse @response.body
32
+
33
+ code = @response["code"]
34
+ message = @response["message"]
35
+ check_and_raise_error code, message
36
+
37
+ data = @response["data"]
38
+ JSON.parse(data.to_json, object_class: OpenStruct)
39
+ end
40
+
41
+ private
42
+
43
+ def check_and_raise_error code, message
44
+ reg_2xx = /^2\d\d$/
45
+ reg_4xx = /^4\d\d$/
46
+ reg_5xx = /^5\d\d$/
47
+
48
+ return if code.to_s =~ reg_2xx
49
+
50
+ case code.to_s
51
+ when "400"
52
+ error = Uiza::Error::BadRequestError.new @description_link, message
53
+ when "401"
54
+ error = Uiza::Error::UnauthorizedError.new @description_link, message
55
+ when "404"
56
+ error = Uiza::Error::NotFoundError.new @description_link, message
57
+ when "422"
58
+ error = Uiza::Error::UnprocessableError.new @description_link, message
59
+ when "500"
60
+ error = Uiza::Error::InternalServerError.new @description_link, message
61
+ when "503"
62
+ error = Uiza::Error::ServiceUnavailableError.new @description_link, message
63
+ when reg_4xx
64
+ error = Uiza::Error::ClientError.new @description_link, message, code
65
+ when reg_5xx
66
+ error = Uiza::Error::ServerError.new @description_link, message, code
67
+ else
68
+ error = Uiza::Error::UizaError.new @description_link, message, code
69
+ end
70
+
71
+ raise error, message
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ module Uiza
2
+ VERSION = "0.1.0".freeze
3
+ end
@@ -0,0 +1,36 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "uiza/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "uiza"
7
+ spec.version = "1.0.0"
8
+ spec.required_ruby_version = ">= 2.0.0"
9
+ spec.authors = ["Vo Khanh Toan"]
10
+ spec.email = ["toanvk@uiza.io"]
11
+
12
+ spec.summary = "Ruby wrapper library for Uiza API"
13
+ spec.description = "See https://docs.uiza.io for details"
14
+ spec.homepage = "https://docs.uiza.io"
15
+ spec.license = "MIT"
16
+
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/uizaio/api-wrapper-ruby"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 2.0"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uiza
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Vo Khanh Toan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-25 00:00:00.000000000 Z
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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: See https://docs.uiza.io for details
56
+ email:
57
+ - toanvk@uiza.io
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".rubocop.yml"
63
+ - ".rubocop_disable.yml"
64
+ - ".rubocop_enable.yml"
65
+ - CHANGELOG.md
66
+ - CODE_OF_CONDUCT.md
67
+ - CONTRIBUTORS.txt
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - History.txt
71
+ - LICENSE.txt
72
+ - PULL_REQUEST_TEMPLATE.md
73
+ - README.md
74
+ - Rakefile
75
+ - bin/console
76
+ - bin/setup
77
+ - doc/ANALYTIC.md
78
+ - doc/CALLBACK.md
79
+ - doc/CATEGORY.md
80
+ - doc/EMBED_METADATA.md
81
+ - doc/ENTITY.md
82
+ - doc/ERRORS_CODE.md
83
+ - doc/LIVE_STREAMING.md
84
+ - doc/STORAGE.md
85
+ - lib/uiza.rb
86
+ - lib/uiza/api_operation/add.rb
87
+ - lib/uiza/api_operation/create.rb
88
+ - lib/uiza/api_operation/delete.rb
89
+ - lib/uiza/api_operation/list.rb
90
+ - lib/uiza/api_operation/remove.rb
91
+ - lib/uiza/api_operation/retrieve.rb
92
+ - lib/uiza/api_operation/update.rb
93
+ - lib/uiza/category.rb
94
+ - lib/uiza/entity.rb
95
+ - lib/uiza/error/bad_request_error.rb
96
+ - lib/uiza/error/client_error.rb
97
+ - lib/uiza/error/internal_server_error.rb
98
+ - lib/uiza/error/not_found_error.rb
99
+ - lib/uiza/error/server_error.rb
100
+ - lib/uiza/error/service_unavailable_error.rb
101
+ - lib/uiza/error/uiza_error.rb
102
+ - lib/uiza/error/unauthorized_error.rb
103
+ - lib/uiza/error/unprocessable_error.rb
104
+ - lib/uiza/storage.rb
105
+ - lib/uiza/uiza_client.rb
106
+ - lib/uiza/version.rb
107
+ - uiza.gemspec
108
+ homepage: https://docs.uiza.io
109
+ licenses:
110
+ - MIT
111
+ metadata:
112
+ allowed_push_host: https://rubygems.org
113
+ homepage_uri: https://docs.uiza.io
114
+ source_code_uri: https://github.com/uizaio/api-wrapper-ruby
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: 2.0.0
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubygems_version: 3.0.2
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Ruby wrapper library for Uiza API
134
+ test_files: []