uiza_framgia_test 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) 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 +29 -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 +181 -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 +289 -0
  20. data/doc/EMBED_METADATA.md +4 -0
  21. data/doc/ENTITY.md +486 -0
  22. data/doc/ERRORS_CODE.md +60 -0
  23. data/doc/LIVE_STREAMING.md +6 -0
  24. data/doc/STORAGE.md +195 -0
  25. data/lib/uiza.rb +42 -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/api_resource/category_resource.rb +33 -0
  34. data/lib/uiza/api_resource/entity_resource.rb +41 -0
  35. data/lib/uiza/api_resource/storage_resource.rb +21 -0
  36. data/lib/uiza/category.rb +44 -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/storage.rb +17 -0
  48. data/lib/uiza/uiza_client.rb +82 -0
  49. data/lib/uiza/version.rb +3 -0
  50. data/uiza.gemspec +36 -0
  51. metadata +137 -0
@@ -0,0 +1,41 @@
1
+ module Uiza
2
+ module APIResource
3
+ module EntityResource
4
+ def create_entity params
5
+ Uiza::Entity.create params
6
+ end
7
+
8
+ def retrieve_entity id
9
+ Uiza::Entity.retrieve id
10
+ end
11
+
12
+ def list_entity params = {}
13
+ Uiza::Entity.list params
14
+ end
15
+
16
+ def update_entity params
17
+ Uiza::Entity.update params
18
+ end
19
+
20
+ def delete_entity id
21
+ Uiza::Entity.delete id
22
+ end
23
+
24
+ def search_entity keyword
25
+ Uiza::Entity.search keyword
26
+ end
27
+
28
+ def publish_entity id
29
+ Uiza::Entity.publish id
30
+ end
31
+
32
+ def get_status_publish_entity id
33
+ Uiza::Entity.get_status_publish id
34
+ end
35
+
36
+ def get_aws_upload_key_entity
37
+ Uiza::Entity.get_aws_upload_key
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ module Uiza
2
+ module APIResource
3
+ module StorageResource
4
+ def add_storage params
5
+ Uiza::Storage.add params
6
+ end
7
+
8
+ def retrieve_storage id
9
+ Uiza::Storage.retrieve id
10
+ end
11
+
12
+ def update_storage params
13
+ Uiza::Storage.update params
14
+ end
15
+
16
+ def remove_storage id
17
+ Uiza::Storage.remove id
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,44 @@
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 entity_id, metadata_ids
22
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/media/entity/related/metadata"
23
+ method = :post
24
+ headers = {"Authorization" => Uiza.authorization}
25
+ params = {entityId: entity_id, metadataIds: metadata_ids}
26
+ description_link = OBJECT_API_DESCRIPTION_LINK[:create_relation]
27
+
28
+ uiza_client = UizaClient.new url, method, headers, params, description_link
29
+ uiza_client.execute_request
30
+ end
31
+
32
+ def delete_relation entity_id, metadata_ids
33
+ url = "https://#{Uiza.workspace_api_domain}/api/public/v3/media/entity/related/metadata"
34
+ method = :post
35
+ headers = {"Authorization" => Uiza.authorization}
36
+ params = {entityId: entity_id, metadataIds: metadata_ids}
37
+ description_link = OBJECT_API_DESCRIPTION_LINK[:delete_relation]
38
+
39
+ uiza_client = UizaClient.new url, method, headers, params, description_link
40
+ uiza_client.execute_request
41
+ end
42
+ end
43
+ end
44
+ 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, code = nil, message = nil
12
+ @description_link = description_link
13
+ @code = (code.nil? ? nil : code.to_i) || self.class::DEFAULT_CODE
14
+ @message = message || self.class::DEFAULT_MESSAGE
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,82 @@
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
+ check_and_raise_error code
35
+
36
+ data = @response["data"]
37
+ JSON.parse(data.to_json, object_class: OpenStruct)
38
+ end
39
+
40
+ private
41
+
42
+ def check_and_raise_error code
43
+ reg_2xx = /^2\d\d$/
44
+ reg_4xx = /^4\d\d$/
45
+ reg_5xx = /^5\d\d$/
46
+
47
+ return if code.to_s =~ reg_2xx
48
+
49
+ case code.to_s
50
+ when "400"
51
+ error = Uiza::Error::BadRequestError.new @description_link
52
+ message = Uiza::Error::BadRequestError::DEFAULT_MESSAGE
53
+ when "401"
54
+ error = Uiza::Error::UnauthorizedError.new @description_link
55
+ message = Uiza::Error::UnauthorizedError::DEFAULT_MESSAGE
56
+ when "404"
57
+ error = Uiza::Error::NotFoundError.new @description_link
58
+ message = Uiza::Error::NotFoundError::DEFAULT_MESSAGE
59
+ when "422"
60
+ error = Uiza::Error::UnprocessableError.new @description_link
61
+ message = Uiza::Error::UnprocessableError::DEFAULT_MESSAGE
62
+ when "500"
63
+ error = Uiza::Error::InternalServerError.new @description_link
64
+ message = Uiza::Error::InternalServerError::DEFAULT_MESSAGE
65
+ when "503"
66
+ error = Uiza::Error::ServiceUnavailableError.new @description_link
67
+ message = Uiza::Error::ServiceUnavailableError::DEFAULT_MESSAGE
68
+ when reg_4xx
69
+ error = Uiza::Error::ClientError.new @description_link, code
70
+ message = Uiza::Error::ClientError::DEFAULT_MESSAGE
71
+ when reg_5xx
72
+ error = Uiza::Error::ServerError.new @description_link, code
73
+ message = Uiza::Error::ServerError::DEFAULT_MESSAGE
74
+ else
75
+ error = Uiza::Error::UizaError.new @description_link, code
76
+ message = Uiza::Error::UizaError::DEFAULT_MESSAGE
77
+ end
78
+
79
+ raise error, message
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,3 @@
1
+ module Uiza
2
+ VERSION = "0.1.0".freeze
3
+ end
data/uiza.gemspec ADDED
@@ -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_framgia_test"
7
+ spec.version = "0.1.1"
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,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uiza_framgia_test
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Vo Khanh Toan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-19 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/api_resource/category_resource.rb
94
+ - lib/uiza/api_resource/entity_resource.rb
95
+ - lib/uiza/api_resource/storage_resource.rb
96
+ - lib/uiza/category.rb
97
+ - lib/uiza/entity.rb
98
+ - lib/uiza/error/bad_request_error.rb
99
+ - lib/uiza/error/client_error.rb
100
+ - lib/uiza/error/internal_server_error.rb
101
+ - lib/uiza/error/not_found_error.rb
102
+ - lib/uiza/error/server_error.rb
103
+ - lib/uiza/error/service_unavailable_error.rb
104
+ - lib/uiza/error/uiza_error.rb
105
+ - lib/uiza/error/unauthorized_error.rb
106
+ - lib/uiza/error/unprocessable_error.rb
107
+ - lib/uiza/storage.rb
108
+ - lib/uiza/uiza_client.rb
109
+ - lib/uiza/version.rb
110
+ - uiza.gemspec
111
+ homepage: https://docs.uiza.io
112
+ licenses:
113
+ - MIT
114
+ metadata:
115
+ allowed_push_host: https://rubygems.org
116
+ homepage_uri: https://docs.uiza.io
117
+ source_code_uri: https://github.com/uizaio/api-wrapper-ruby
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: 2.0.0
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubygems_version: 3.0.2
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: Ruby wrapper library for Uiza API
137
+ test_files: []