thron 0.7.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 (50) hide show
  1. checksums.yaml +7 -0
  2. data/.env.example +4 -0
  3. data/.gitignore +13 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +4 -0
  6. data/README.md +182 -0
  7. data/Rakefile +10 -0
  8. data/Vagrantfile +80 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +7 -0
  11. data/config/thron.yml +10 -0
  12. data/lib/thron.rb +3 -0
  13. data/lib/thron/circuit_breaker.rb +46 -0
  14. data/lib/thron/config.rb +35 -0
  15. data/lib/thron/entity/base.rb +78 -0
  16. data/lib/thron/entity/image.rb +30 -0
  17. data/lib/thron/gateway/access_manager.rb +69 -0
  18. data/lib/thron/gateway/apps.rb +91 -0
  19. data/lib/thron/gateway/apps_admin.rb +153 -0
  20. data/lib/thron/gateway/base.rb +41 -0
  21. data/lib/thron/gateway/category.rb +210 -0
  22. data/lib/thron/gateway/client.rb +59 -0
  23. data/lib/thron/gateway/comment.rb +76 -0
  24. data/lib/thron/gateway/contact.rb +120 -0
  25. data/lib/thron/gateway/content.rb +267 -0
  26. data/lib/thron/gateway/content_category.rb +32 -0
  27. data/lib/thron/gateway/content_list.rb +40 -0
  28. data/lib/thron/gateway/dashboard.rb +120 -0
  29. data/lib/thron/gateway/delivery.rb +122 -0
  30. data/lib/thron/gateway/device.rb +58 -0
  31. data/lib/thron/gateway/metadata.rb +68 -0
  32. data/lib/thron/gateway/publish_in_weebo_express.rb +39 -0
  33. data/lib/thron/gateway/publishing_process.rb +141 -0
  34. data/lib/thron/gateway/repository.rb +111 -0
  35. data/lib/thron/gateway/session.rb +15 -0
  36. data/lib/thron/gateway/users_group_manager.rb +117 -0
  37. data/lib/thron/gateway/v_user_manager.rb +195 -0
  38. data/lib/thron/logger.rb +25 -0
  39. data/lib/thron/pageable.rb +26 -0
  40. data/lib/thron/paginator.rb +82 -0
  41. data/lib/thron/response.rb +48 -0
  42. data/lib/thron/root.rb +9 -0
  43. data/lib/thron/routable.rb +80 -0
  44. data/lib/thron/route.rb +102 -0
  45. data/lib/thron/string_extensions.rb +23 -0
  46. data/lib/thron/user.rb +77 -0
  47. data/lib/thron/version.rb +3 -0
  48. data/log/.gitignore +4 -0
  49. data/thron.gemspec +26 -0
  50. metadata +176 -0
@@ -0,0 +1,32 @@
1
+ require 'thron/gateway/session'
2
+
3
+ module Thron
4
+ module Gateway
5
+ class ContentCategory < Session
6
+
7
+ PACKAGE = Package.new(:xcontents, :resources, self.service_name)
8
+
9
+ def self.routes
10
+ @routes ||= {
11
+ link_category_to_content: Route::factory(name: 'linkCategoryToContent', package: PACKAGE),
12
+ remove_category_from_content: Route::factory(name: 'removeCategoryToContent', package: PACKAGE)
13
+ }
14
+ end
15
+
16
+ self.routes.keys.each do |message|
17
+ define_method(message) do |options|
18
+ category_id = options[:category_id]
19
+ content_id = options[:content_id]
20
+ apply_acl = options.fetch(:apply_acl) { false }
21
+ query = {
22
+ clientId: client_id,
23
+ categoryId: category_id,
24
+ contentId: content_id,
25
+ applyAcl: apply_acl
26
+ }
27
+ route(to: __callee__, query: query, token_id: token_id)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,40 @@
1
+ require 'thron/gateway/session'
2
+
3
+ module Thron
4
+ module Gateway
5
+ class ContentList < Session
6
+
7
+ PACKAGE = Package.new(:xcontents, :resources, self.service_name)
8
+
9
+ paginate :show_contents
10
+
11
+ def self.routes
12
+ @routes ||= {
13
+ show_contents: Route::factory(name: 'showContents', package: PACKAGE, verb: Route::Verbs::GET)
14
+ }
15
+ end
16
+
17
+ def show_contents(options = {})
18
+ category_id = options[:category_id]
19
+ locale = options[:locale]
20
+ criteria = options.fetch(:criteria) { {} }
21
+ recursive = options.fetch(:recursive) { true }
22
+ order_by = options.fetch(:order_by) { 'contentName_A' }
23
+ limit = options[:limit].to_i
24
+ offset = options[:offset].to_i
25
+ query = {
26
+ clientId: client_id,
27
+ categoryId: category_id,
28
+ locale: locale,
29
+ searchOnSubCategories: recursive,
30
+ orderBy: order_by,
31
+ numberOfResult: limit,
32
+ offset: offset
33
+ }.merge(criteria)
34
+ route(to: __callee__, query: query, token_id: token_id) do |response|
35
+ response.body = Entity::Base::factory(response.body.fetch('contents') { [] })
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,120 @@
1
+ require 'thron/gateway/session'
2
+
3
+ module Thron
4
+ module Gateway
5
+ class Dashboard < Session
6
+
7
+ PACKAGE = Package.new(:xadmin, :resources, self.service_name)
8
+
9
+ def self.routes
10
+ @routes ||= {
11
+ change_contents_owner: Route::factory(name: 'changeContentsOwner', package: PACKAGE),
12
+ download_source_file: Route::factory(name: 'downloadSourceFile', package: PACKAGE, verb: Route::Verbs::GET),
13
+ migrate_user_stuff: Route::factory(name: 'migrateUserStuff', package: PACKAGE),
14
+ propagate_acl_to_sub_categories: Route::factory(name: 'propagateAclToSubCategories', package: PACKAGE),
15
+ replace_source_files: Route::factory(name: 'replaceSourceFiles', package: PACKAGE),
16
+ reset_content_user_preferences: Route::factory(name: 'resetUserPreferences', package: PACKAGE),
17
+ trash_contents: Route::factory(name: 'trashContent', package: PACKAGE),
18
+ untrash_contents: Route::factory(name: 'untrashContent', package: PACKAGE)
19
+ }
20
+ end
21
+
22
+ def change_contents_owner(options = {})
23
+ contents = options[:contents]
24
+ body = {
25
+ clientId: client_id,
26
+ contents: contents
27
+ }
28
+ route(to: __callee__, body: body, token_id: token_id)
29
+ end
30
+
31
+ def download_source_file(options = {})
32
+ content_id = options[:content_id]
33
+ save_as = options[:save_as]
34
+ query = {
35
+ clientId: client_id,
36
+ tokenId: token_id,
37
+ xcontentId: content_id,
38
+ saveAs: save_as
39
+ }
40
+ route(to: __callee__, query: query, token_id: token_id)
41
+ end
42
+
43
+ def migrate_user_stuff(options = {})
44
+ user_id1 = options[:user_id1]
45
+ user_id2 = options[:user_id2]
46
+ remove_user_id1 = options.fetch(:remove_user_id1) { false }
47
+ body = {
48
+ clientId: client_id,
49
+ userId1: user_id1,
50
+ userId2: user_id2,
51
+ removeUserId1: remove_user_id1
52
+ }
53
+ route(to: __callee__, body: body, token_id: token_id)
54
+ end
55
+
56
+ def propagate_acl_to_sub_categories(options = {})
57
+ category_id = options[:category_id]
58
+ acls = options[:acls]
59
+ force = options.fetch(:force) { false }
60
+ body = {
61
+ clientId: client_id,
62
+ categoryId: category_id,
63
+ acls: acls,
64
+ force: force
65
+ }
66
+ route(to: __callee__, body: body, token_id: token_id)
67
+ end
68
+
69
+ def replace_source_files(options = {})
70
+ media_content_id = options[:media_content_id]
71
+ content_id = options[:content_id]
72
+ file_ids = options[:file_ids]
73
+ remove_original_files = options.fetch(:remove_original_files) { false }
74
+ body = {
75
+ clientId: client_id,
76
+ mediaContentId: media_content_id,
77
+ xcontentId: content_id,
78
+ sourceFiles: { repositoryFileIds: file_ids },
79
+ removeOriginalFiles: remove_original_files
80
+ }
81
+ route(to: __callee__, body: body, token_id: token_id)
82
+ end
83
+
84
+ def reset_content_user_preferences(options = {})
85
+ content_id = options[:content_id]
86
+ body = {
87
+ clientId: client_id,
88
+ xcontentId: content_id
89
+ }
90
+ route(to: __callee__, body: body, token_id: token_id)
91
+ end
92
+
93
+ def trash_contents(options = {})
94
+ contents = options[:contents]
95
+ body = {
96
+ clientId: client_id,
97
+ contentList: { contentsToTrash: contents.map(&:payload) }
98
+ }
99
+ route(to: __callee__, body: body, token_id: token_id) do |response|
100
+ response.extra(attribute: 'contentsInIssue')
101
+ end
102
+ end
103
+
104
+ def untrash_contents(options = {})
105
+ new_user_id = options[:new_user_id]
106
+ content_ids = options[:content_ids]
107
+ body = {
108
+ clientId: client_id,
109
+ contentList: {
110
+ newUserId: new_user_id,
111
+ xcontentIds: content_ids
112
+ }
113
+ }
114
+ route(to: __callee__, body: body, token_id: token_id) do |response|
115
+ response.extra(attribute: 'contentsInIssue')
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,122 @@
1
+ require 'thron/gateway/session'
2
+
3
+ module Thron
4
+ module Gateway
5
+ class Delivery < Session
6
+
7
+ PACKAGE = Package.new(:xcontents, :resources, self.service_name)
8
+
9
+ paginate :content_cuepoints, :downloadable_contents, :playlist_contents, :recommended_contents
10
+
11
+ def self.routes
12
+ @routes ||= {
13
+ content_metadata: Route::factory(name: 'getContentDetail', package: PACKAGE, verb: Route::Verbs::GET),
14
+ content_cuepoints: Route::factory(name: 'getCuePoints', package: PACKAGE, verb: Route::Verbs::GET),
15
+ downloadable_contents: Route::factory(name: 'getDownloadableContents', package: PACKAGE, verb: Route::Verbs::GET),
16
+ playlist_contents: Route::factory(name: 'getPlaylistContents', package: PACKAGE, verb: Route::Verbs::GET),
17
+ recommended_contents: Route::factory(name: 'getRecommendedContents', package: PACKAGE, verb: Route::Verbs::GET),
18
+ content_subtitles: Route::factory(name: 'getSubTitles', package: PACKAGE, verb: Route::Verbs::GET, accept: Route::Types::PLAIN),
19
+ content_thumbnail: Route::lazy_factory(name: 'getThumbnail', package: PACKAGE, verb: Route::Verbs::GET)
20
+ }
21
+ end
22
+
23
+ def content_metadata(options = {})
24
+ content_id = options[:content_id]
25
+ criteria = options.fetch(:criteria) { {} }
26
+ query = {
27
+ clientId: client_id,
28
+ xcontentId: content_id
29
+ }.merge!(criteria)
30
+ route(to: __callee__, query: query, token_id: token_id) do |response|
31
+ response.body = Entity::Base::factory(response.body)
32
+ end
33
+ end
34
+
35
+ def content_cuepoints(options = {})
36
+ content_id = options[:content_id]
37
+ criteria = options.fetch(:criteria) { {} }
38
+ offset = options[:offset].to_i
39
+ limit = options[:limit].to_i
40
+ query = {
41
+ clientId: client_id,
42
+ xcontentId: content_id,
43
+ offset: offset,
44
+ numberOfResult: limit
45
+ }.merge!(criteria)
46
+ route(to: __callee__, query: query, token_id: token_id) do |response|
47
+ response.body = Entity::Base::factory(response.body.fetch('cuePoints') { [] })
48
+ end
49
+ end
50
+
51
+ def downloadable_contents(options = {})
52
+ content_id = options[:content_id]
53
+ criteria = options.fetch(:criteria) { {} }
54
+ offset = options[:offset].to_i
55
+ limit = options[:limit].to_i
56
+ query = {
57
+ clientId: client_id,
58
+ xcontentId: content_id,
59
+ offset: offset,
60
+ numberOfResult: limit
61
+ }.merge!(criteria)
62
+ route(to: __callee__, query: query, token_id: token_id) do |response|
63
+ response.body = Entity::Base::factory(response.body.fetch('contents') { [] })
64
+ end
65
+ end
66
+
67
+ def playlist_contents(options = {})
68
+ content_id = options[:content_id]
69
+ criteria = options.fetch(:criteria) { {} }
70
+ offset = options[:offset].to_i
71
+ limit = options[:limit].to_i
72
+ query = {
73
+ clientId: client_id,
74
+ xcontentId: content_id,
75
+ offset: offset,
76
+ numberOfResult: limit
77
+ }.merge!(criteria)
78
+ route(to: __callee__, query: query, token_id: token_id) do |response|
79
+ response.body = Entity::Base::factory(response.body.fetch('contents') { [] })
80
+ end
81
+ end
82
+
83
+ def recommended_contents(options = {})
84
+ content_id = options[:content_id]
85
+ pkey = options[:pkey]
86
+ criteria = options.fetch(:criteria) { { admin: true } }
87
+ offset = options[:offset].to_i
88
+ limit = options[:limit].to_i
89
+ query = {
90
+ clientId: client_id,
91
+ xcontentId: content_id,
92
+ pkey: pkey,
93
+ offset: offset,
94
+ numberOfResult: limit
95
+ }.merge!(criteria)
96
+ route(to: __callee__, query: query, token_id: token_id) do |response|
97
+ response.body = Entity::Base::factory(response.body.fetch('contents') { [] })
98
+ end
99
+ end
100
+
101
+ def content_subtitles(options = {})
102
+ content_id = options[:content_id]
103
+ locale = options[:locale]
104
+ criteria = options.fetch(:criteria) { {} }
105
+ query = {
106
+ clientId: client_id,
107
+ xcontentId: content_id,
108
+ locale: locale
109
+ }.merge!(criteria)
110
+ route(to: __callee__, query: query, token_id: token_id)
111
+ end
112
+
113
+ def content_thumbnail(options = {})
114
+ content_id = options[:content_id]
115
+ div_area = options[:div_area]
116
+ route(to: __callee__, token_id: token_id, params: [client_id, div_area, content_id]) do |response|
117
+ response.body = Entity::Base::factory(response.body)
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,58 @@
1
+ require 'thron/gateway/session'
2
+
3
+ module Thron
4
+ module Gateway
5
+ class Device < Session
6
+
7
+ base_uri "#{Config::thron::protocol}://#{Config::thron::client_id}-device.thron.com/api"
8
+
9
+ PACKAGE = Package.new(:xdevice, :resources, self.service_name)
10
+
11
+ def self.routes
12
+ @routes ||= {
13
+ connect_device: Route::factory(name: 'connect', package: PACKAGE),
14
+ disconnect_device: Route::factory(name: 'disconnect', package: PACKAGE),
15
+ get_device: Route::factory(name: 'get', package: PACKAGE, verb: Route::Verbs::GET, params: [client_id])
16
+ }
17
+ end
18
+
19
+ def connect_device(options = {})
20
+ device_id = options[:device_id]
21
+ ik = options[:ik]
22
+ contact_name = options[:contact_name]
23
+ body = {
24
+ clientId: client_id,
25
+ deviceId: device_id,
26
+ ik: ik,
27
+ contactName: contact_name
28
+ }
29
+ route(to: __callee__, body: body, token_id: token_id) do |response|
30
+ response.body = Entity::Base::factory(response.body)
31
+ end
32
+ end
33
+
34
+ def disconnect_device(options = {})
35
+ device_id = options[:device_id]
36
+ contact_id = options[:contact_id]
37
+ body = {
38
+ clientId: client_id,
39
+ deviceId: device_id,
40
+ contactId: contact_id
41
+ }
42
+ route(to: __callee__, body: body, token_id: token_id) do |response|
43
+ response.body = Entity::Base::factory(response.body)
44
+ end
45
+ end
46
+
47
+ def get_device(options = {})
48
+ device_id = options[:device_id]
49
+ query = {
50
+ deviceId: device_id,
51
+ }
52
+ route(to: __callee__, query: query, token_id: token_id) do |response|
53
+ response.body = Entity::Base::factory(response.body)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,68 @@
1
+ require 'thron/gateway/session'
2
+
3
+ module Thron
4
+ module Gateway
5
+ class Metadata < Session
6
+
7
+ PACKAGE = Package.new(:xcontents, :resources, self.service_name)
8
+
9
+ def self.routes
10
+ @routes ||= {
11
+ insert_metadata: Route::factory(name: 'insertMetadata', package: PACKAGE),
12
+ remove_all_metadata: Route::factory(name: 'removeAllMetadata', package: PACKAGE),
13
+ remove_metadata: Route::factory(name: 'removeMetadata', package: PACKAGE),
14
+ update_metadata: Route::factory(name: 'updateMetadata', package: PACKAGE),
15
+ update_single_metadata: Route::factory(name: 'updateSingleMetadata', package: PACKAGE)
16
+ }
17
+ end
18
+
19
+ def insert_metadata(options = {})
20
+ content_id = options[:content_id]
21
+ data = options[:data]
22
+ category_id = options[:category_id]
23
+ body = {
24
+ client: { clientId: client_id },
25
+ contentId: content_id,
26
+ metadata: data,
27
+ categoryIdForAcl: category_id
28
+ }
29
+ route(to: __callee__, body: body, token_id: token_id)
30
+ end
31
+
32
+ def remove_all_metadata(options = {})
33
+ content_id = options[:content_id]
34
+ body = {
35
+ clientId: client_id,
36
+ contentId: content_id
37
+ }
38
+ route(to: __callee__, body: body, token_id: token_id)
39
+ end
40
+
41
+ def update_metadata(options = {})
42
+ content_id = options[:content_id]
43
+ data_list = options[:data_list]
44
+ category_id = options[:category_id]
45
+ body = {
46
+ clientId: client_id,
47
+ contentId: content_id,
48
+ metadata: { metadata: data_list },
49
+ categoryIdForAcl: category_id
50
+ }
51
+ route(to: __callee__, body: body, token_id: token_id)
52
+ end
53
+
54
+ %w[remove update_single].each do |action|
55
+ define_method("#{action}_metadata") do |options|
56
+ content_id = options[:content_id]
57
+ data = options[:data]
58
+ body = {
59
+ clientId: client_id,
60
+ contentId: content_id,
61
+ metadata: data
62
+ }
63
+ route(to: __callee__, body: body, token_id: token_id)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,39 @@
1
+ require 'thron/gateway/session'
2
+
3
+ module Thron
4
+ module Gateway
5
+ class PublishInWeeboExpress < Session
6
+
7
+ PACKAGE = Package.new(:xadmin, :resources, self.service_name)
8
+
9
+ def self.routes
10
+ @routes ||= {
11
+ publish_audio: Route::factory(name: 'publishAudio', package: PACKAGE),
12
+ publish_content_in_channels: Route::factory(name: 'publishContentInChannels', package: PACKAGE),
13
+ publish_document: Route::factory(name: 'publishDocument', package: PACKAGE),
14
+ publish_image: Route::factory(name: 'publishImage', package: PACKAGE),
15
+ publish_live_event: Route::factory(name: 'publishLiveEvent', package: PACKAGE),
16
+ publish_pagelet: Route::factory(name: 'publishPagelet', package: PACKAGE),
17
+ publish_playlist: Route::factory(name: 'publishPlayList', package: PACKAGE),
18
+ publish_program: Route::factory(name: 'publishProgram', package: PACKAGE),
19
+ publish_video: Route::factory(name: 'publishVideo', package: PACKAGE),
20
+ upload_and_publish: Route::factory(name: 'uploadAndPublish', package: PACKAGE)
21
+ }
22
+ end
23
+
24
+ self.routes.keys.each do |message|
25
+ define_method(message) do |options|
26
+ data = options[:data]
27
+ body = {
28
+ clientId: client_id,
29
+ param: data
30
+ }
31
+ route(to: message, body: body, token_id: token_id) do |response|
32
+ response.extra(attribute: 'actionsInError')
33
+ response.body = Entity::Base::factory(response.body.fetch('content') { {} })
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end