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,59 @@
1
+ require 'thron/gateway/session'
2
+
3
+ module Thron
4
+ module Gateway
5
+ class Client < Session
6
+
7
+ PACKAGE = Package.new(:xcontents, :resources, self.service_name)
8
+
9
+ def self.routes
10
+ @routes ||= {
11
+ client_detail: Route::factory(name: 'detailClient', package: PACKAGE, verb: Route::Verbs::GET),
12
+ update_audit_duration_days: Route::factory(name: 'updateAuditDurationDays', package: PACKAGE),
13
+ enable_secure_connection: Route::factory(name: 'updateSecureConnectionEnabled', package: PACKAGE),
14
+ trash_properties_older_than: Route::factory(name: 'updateTrashProperties', package: PACKAGE)
15
+ }
16
+ end
17
+
18
+ def client_detail
19
+ query = {
20
+ clientId: client_id,
21
+ }
22
+ route(to: __callee__, query: query, token_id: token_id) do |response|
23
+ name = response.body.delete('name')
24
+ name_hash = name ? { name: name } : {}
25
+ response.body = Entity::Base::factory(response.body.fetch('properties') { {} }.merge!(name_hash))
26
+ end
27
+ end
28
+
29
+ def update_audit_duration_days(options = {})
30
+ days = options[:days]
31
+ body = {
32
+ clientId: client_id,
33
+ auditDurationDays: days.to_i
34
+ }
35
+ route(to: __callee__, body: body, token_id: token_id)
36
+ end
37
+
38
+ def enable_secure_connection(options = {})
39
+ enabled = options[:enabled]
40
+ body = {
41
+ clientId: client_id,
42
+ secureConnectionEnabled: !!enabled
43
+ }
44
+ route(to: __callee__, body: body, token_id: token_id)
45
+ end
46
+
47
+ def trash_properties_older_than(options = {})
48
+ days = options[:days]
49
+ body = {
50
+ clientId: client_id,
51
+ properties: {
52
+ removeContentsOlderThan: days.to_i
53
+ }
54
+ }
55
+ route(to: __callee__, body: body, token_id: token_id)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,76 @@
1
+ require 'thron/gateway/session'
2
+
3
+ module Thron
4
+ module Gateway
5
+ class Comment < Session
6
+
7
+ PACKAGE = Package.new(:xcontents, :resources, self.service_name)
8
+
9
+ paginate :list_comments
10
+
11
+ def self.routes
12
+ @routes ||= {
13
+ comment_detail: Route::factory(name: 'detail', package: PACKAGE, verb: Route::Verbs::GET),
14
+ list_comments: Route::factory(name: 'getComments', package: PACKAGE, verb: Route::Verbs::GET),
15
+ insert_comment: Route::factory(name: 'insertComment', package: PACKAGE),
16
+ report_comment_abuse: Route::factory(name: 'reportAbuse', package: PACKAGE)
17
+ }
18
+ end
19
+
20
+ def comment_detail(options = {})
21
+ comment_id = options[:comment_id]
22
+ query = {
23
+ clientId: client_id,
24
+ commentId: comment_id
25
+ }
26
+ route(to: __callee__, query: query, token_id: token_id) do |response|
27
+ response.body = Entity::Base::factory(response.body.fetch('comment') { {} })
28
+ end
29
+ end
30
+
31
+ def list_comments(options = {})
32
+ criteria = options.fetch(:criteria) { {} }
33
+ locale = options[:locale]
34
+ order_by = options[:order_by]
35
+ offset = options[:offset].to_i
36
+ limit = options[:limit].to_i
37
+ order_by = order_by ? { orderBy: order_by } : {}
38
+ query = {
39
+ clientId: client_id,
40
+ locale: locale,
41
+ offset: offset,
42
+ numberOfResults: limit
43
+ }.merge(criteria).merge(order_by)
44
+ route(to: __callee__, query: query, token_id: token_id) do |response|
45
+ response.body = Entity::Base::factory(response.body.fetch('comments') { [] })
46
+ end
47
+ end
48
+
49
+ def insert_comment(options = {})
50
+ content_id = options[:content_id]
51
+ data = options[:data]
52
+ category_id = options[:category_id]
53
+ body = {
54
+ clientId: client_id,
55
+ contentId: content_id,
56
+ comment: data,
57
+ categoryIdForAcl: category_id
58
+ }
59
+ route(to: __callee__, body: body, token_id: token_id) do |response|
60
+ response.body = Entity::Base::factory(response.body.fetch('comment') { {} })
61
+ end
62
+ end
63
+
64
+ def report_comment_abuse(options = {})
65
+ comment_id = options[:comment_id]
66
+ user_id = options[:user_id]
67
+ query = {
68
+ clientId: client_id,
69
+ commentId: comment_id,
70
+ userId: user_id
71
+ }
72
+ route(to: __callee__, query: query, token_id: token_id)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,120 @@
1
+ require 'thron/gateway/session'
2
+
3
+ module Thron
4
+ module Gateway
5
+ class Contact < Session
6
+
7
+ base_uri "#{Config::thron::protocol}://#{Config::thron::client_id}-view.thron.com/contactunit"
8
+
9
+ PACKAGE = Package.new(:xcontact, :resources, self.service_name)
10
+
11
+ paginate :list_contacts, :list_contact_keys
12
+
13
+ def self.routes
14
+ @routes ||= {
15
+ add_contact_key: Route::factory(name: 'addKey', package: PACKAGE, params: [client_id]),
16
+ contact_detail: Route::factory(name: 'detail', package: PACKAGE, verb: Route::Verbs::GET, params: [client_id]),
17
+ insert_contact: Route::factory(name: 'insert', package: PACKAGE, params: [client_id]),
18
+ list_contacts: Route::factory(name: 'list', package: PACKAGE, params: [client_id]),
19
+ list_contact_keys: Route::factory(name: 'listKey', package: PACKAGE, params: [client_id]),
20
+ remove_contact_key: Route::factory(name: 'removeKey', package: PACKAGE, params: [client_id]),
21
+ update_contact: Route::factory(name: 'update', package: PACKAGE, params: [client_id])
22
+ }
23
+ end
24
+
25
+ def add_contact_key(options = {})
26
+ contact_id = options[:contact_id]
27
+ ik = options[:ik]
28
+ body = {
29
+ contactId: contact_id,
30
+ ik: ik
31
+ }
32
+ route(to: __callee__, body: body, token_id: token_id) do |response|
33
+ response.body = Entity::Base::factory(response.body.fetch('item') { {} })
34
+ end
35
+ end
36
+
37
+ def contact_detail(options = {})
38
+ contact_id = options[:contact_id]
39
+ query = {
40
+ contactId: contact_id,
41
+ }
42
+ route(to: __callee__, query: query, token_id: token_id) do |response|
43
+ response.body = Entity::Base::factory(response.body.fetch('item') { {} })
44
+ end
45
+ end
46
+
47
+ def insert_contact(options = {})
48
+ name = options[:name]
49
+ ik = options[:ik]
50
+ body = {
51
+ value: {
52
+ ik: ik,
53
+ name: name
54
+ }
55
+ }
56
+ route(to: __callee__, body: body, token_id: token_id) do |response|
57
+ response.body = Entity::Base::factory(response.body.fetch('item') { {} })
58
+ end
59
+ end
60
+
61
+ def list_contacts(options = {})
62
+ criteria = options.fetch(:criteria) { {} }
63
+ option = options.fetch(:option) { {} }
64
+ offset = options[:offset].to_i
65
+ limit = options[:limit].to_i
66
+ body = {
67
+ criteria: criteria,
68
+ option: option,
69
+ offset: offset,
70
+ limit: limit
71
+ }
72
+ route(to: __callee__, body: body, token_id: token_id) do |response|
73
+ response.body = Entity::Base::factory(response.body.fetch('items') { [] })
74
+ end
75
+ end
76
+
77
+ def list_contact_keys(options = {})
78
+ search_key = options[:search_key]
79
+ offset = options[:offset].to_i
80
+ limit = options[:limit].to_i
81
+ body = {
82
+ criteria: {
83
+ searchKey: search_key
84
+ },
85
+ offset: offset,
86
+ limit: limit
87
+ }
88
+ route(to: __callee__, body: body, token_id: token_id) do |response|
89
+ response.body = response.body.fetch('items') { [] }
90
+ end
91
+ end
92
+
93
+ def remove_contact_key(options = {})
94
+ contact_id = options[:contact_id]
95
+ key = options[:key]
96
+ body = {
97
+ contactId: contact_id,
98
+ key: key
99
+ }
100
+ route(to: __callee__, body: body, token_id: token_id) do |response|
101
+ response.body = Entity::Base::factory(response.body.fetch('item') { {} })
102
+ end
103
+ end
104
+
105
+ def update_contact(options = {})
106
+ contact_id = options[:contact_id]
107
+ name = options[:name]
108
+ body = {
109
+ contactId: contact_id,
110
+ update: {
111
+ name: name
112
+ }
113
+ }
114
+ route(to: __callee__, body: body, token_id: token_id) do |response|
115
+ response.body = Entity::Base::factory(response.body.fetch('item') { {} })
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,267 @@
1
+ require 'thron/gateway/session'
2
+
3
+ module Thron
4
+ module Gateway
5
+ class Content < Session
6
+
7
+ PACKAGE = Package.new(:xcontents, :resources, self.service_name)
8
+
9
+ paginate :find_contents
10
+
11
+ def self.routes
12
+ @routes ||= {
13
+ add_content_for_locale: Route::factory(name: 'addContent4Locale', package: PACKAGE),
14
+ add_content_pretty_id: Route::factory(name: 'addContentPrettyId', package: PACKAGE),
15
+ add_player_embed_code: Route::factory(name: 'addPlayerEmbedCode', package: PACKAGE),
16
+ add_linked_content: Route::factory(name: 'addLinkedContent', package: PACKAGE),
17
+ add_linked_contents: Route::factory(name: 'addLinkedContents', package: PACKAGE),
18
+ content_detail: Route::factory(name: 'detail', package: PACKAGE, verb: Route::Verbs::GET),
19
+ find_contents: Route::factory(name: 'findByProperties', package: PACKAGE),
20
+ move_linked_content: Route::factory(name: 'moveLinkedContent', package: PACKAGE),
21
+ remove_content_for_locale: Route::factory(name: 'removeContent4Locale', package: PACKAGE),
22
+ remove_content_pretty_id: Route::factory(name: 'removeContentPrettyId', package: PACKAGE),
23
+ remove_linked_contents: Route::factory(name: 'removeLinkedContents', package: PACKAGE),
24
+ remove_player_embed_code: Route::factory(name: 'removePlayerEmbedCode', package: PACKAGE),
25
+ update_available_solutions: Route::factory(name: 'updateAvailableSolutions', package: PACKAGE),
26
+ update_content: Route::factory(name: 'updateContent', package: PACKAGE),
27
+ update_content_for_locale: Route::factory(name: 'updateContent4Locale', package: PACKAGE),
28
+ update_content_pretty_id: Route::factory(name: 'updateContentPrettyId', package: PACKAGE),
29
+ update_player_embed_code: Route::factory(name: 'updatePlayerEmbedCode', package: PACKAGE),
30
+ update_player_embed_codes: Route::factory(name: 'updatePlayerEmbedCodes', package: PACKAGE),
31
+ update_user_specific_values: Route::factory(name: 'updateUserSpecificValues', package: PACKAGE)
32
+ }
33
+ end
34
+
35
+ %w[add update].each do |action|
36
+ define_method("#{action}_content_for_locale") do |options|
37
+ content_id = options[:content_id]
38
+ locale = options[:locale]
39
+ category_id = options[:category_id]
40
+ body = {
41
+ client: {
42
+ clientId: client_id
43
+ },
44
+ contentId: content_id,
45
+ detail: locale,
46
+ categoryIdForAcl: category_id
47
+ }
48
+ route(to: __callee__, body: body, token_id: token_id)
49
+ end
50
+
51
+ define_method("#{action}_content_pretty_id") do |options|
52
+ content_id = options[:content_id]
53
+ pretty_id = options[:pretty_id]
54
+ category_id = options[:category_id]
55
+ body = {
56
+ clientId: client_id,
57
+ contentId: content_id,
58
+ prettyId: pretty_id,
59
+ categoryIdForAcl: category_id
60
+ }
61
+ route(to: __callee__, body: body, token_id: token_id)
62
+ end
63
+
64
+ define_method("#{action}_player_embed_code") do |options|
65
+ content_id = options[:content_id]
66
+ data = options[:data]
67
+ body = {
68
+ clientId: client_id,
69
+ contentId: content_id,
70
+ embedCode: data
71
+ }
72
+ route(to: __callee__, body: body, token_id: token_id)
73
+ end
74
+ end
75
+
76
+ def add_linked_content(options = {})
77
+ content_id = options[:content_id]
78
+ data = options[:data]
79
+ category_id = options[:category_id]
80
+ body = {
81
+ clientId: client_id,
82
+ contentId: content_id,
83
+ linkedContent: data,
84
+ categoryIdForAcl: category_id
85
+ }
86
+ route(to: __callee__, body: body, token_id: token_id)
87
+ end
88
+
89
+ def add_linked_contents(options = {})
90
+ content_id = options[:content_id]
91
+ contents = options[:contents]
92
+ category_id = options[:category_id]
93
+ body = {
94
+ clientId: client_id,
95
+ contentId: content_id,
96
+ linkedContents: {
97
+ contents: contents
98
+ },
99
+ categoryIdForAcl: category_id
100
+ }
101
+ route(to: __callee__, body: body, token_id: token_id)
102
+ end
103
+
104
+ def content_detail(options = {})
105
+ content_id = options[:content_id]
106
+ extra = options.fetch(:extra) { {} }
107
+ locale = options[:locale]
108
+ access_key = options[:access_key]
109
+ query = {
110
+ clientId: client_id,
111
+ contentId: content_id,
112
+ locale: locale,
113
+ pkey: access_key
114
+ }.merge(extra)
115
+ route(to: __callee__, query: query, token_id: token_id) do |response|
116
+ response.body = Entity::Base::factory(response.body)
117
+ end
118
+ end
119
+
120
+ def find_contents(options = {})
121
+ criteria = options.fetch(:criteria) { {} }
122
+ field_option = options.fetch(:field_option) { {} }
123
+ locale = options[:locale]
124
+ div_area = options[:div_area]
125
+ order_by = options[:order_by]
126
+ offset = options[:offset].to_i
127
+ limit = options[:limit].to_i
128
+ body = {
129
+ client: {
130
+ clientId: client_id
131
+ },
132
+ criteria: criteria,
133
+ contentFieldOption: field_option,
134
+ locale: locale,
135
+ divArea: div_area,
136
+ orderBy: order_by,
137
+ offset: offset.to_i,
138
+ numberOfresults: limit.to_i
139
+ }
140
+ route(to: __callee__, body: body, token_id: token_id) do |response|
141
+ response.body = Entity::Base::factory(response.body.fetch('contents') { [] })
142
+ end
143
+ end
144
+
145
+ def move_linked_content(options = {})
146
+ content_id = options[:content_id]
147
+ from = options[:from].to_i
148
+ to = options[:to].to_i
149
+ link_type = options[:link_type]
150
+ body = {
151
+ clientId: client_id,
152
+ xcontentId: content_id,
153
+ oldPosition: from.to_i,
154
+ newPosition: to.to_i,
155
+ linkType: link_type
156
+ }
157
+ route(to: __callee__, body: body, token_id: token_id)
158
+ end
159
+
160
+ def remove_content_for_locale(options = {})
161
+ content_id = options[:content_id]
162
+ locale = options[:locale]
163
+ query = {
164
+ clientId: client_id,
165
+ contentId: content_id,
166
+ locale: locale
167
+ }
168
+ route(to: __callee__, query: query, token_id: token_id)
169
+ end
170
+
171
+ def remove_content_pretty_id(options = {})
172
+ content_id = options[:content_id]
173
+ locale = options[:locale]
174
+ category_id = options[:category_id]
175
+ body = {
176
+ clientId: client_id,
177
+ contentId: content_id,
178
+ locale: locale,
179
+ categoryIdForAcl: category_id
180
+ }
181
+ route(to: __callee__, body: body, token_id: token_id)
182
+ end
183
+
184
+ def remove_linked_contents(options = {})
185
+ content_id = options[:content_id]
186
+ criteria = options.fetch(:criteria) { {} }
187
+ category_id = options[:category_id]
188
+ body = {
189
+ clientId: client_id,
190
+ contentId: content_id,
191
+ criteria: criteria,
192
+ categoryIdForAcl: category_id
193
+ }
194
+ route(to: __callee__, body: body, token_id: token_id)
195
+ end
196
+
197
+ def remove_player_embed_code(options = {})
198
+ content_id = options[:content_id]
199
+ player_id = options[:player_id]
200
+ body = {
201
+ clientId: client_id,
202
+ contentId: content_id,
203
+ embedCodeId: player_id
204
+ }
205
+ route(to: __callee__, body: body, token_id: token_id)
206
+ end
207
+
208
+ def update_available_solutions(options = {})
209
+ content_id = options[:content_id]
210
+ solutions = options[:solutions].to_a
211
+ category_id = options[:category_id]
212
+ body = {
213
+ clientId: client_id,
214
+ contentId: content_id,
215
+ contentValues: {
216
+ availableInSolutions: solutions
217
+ },
218
+ categoryIdForAcl: category_id
219
+ }
220
+ route(to: __callee__, body: body, token_id: token_id)
221
+ end
222
+
223
+ def update_content(options = {})
224
+ content_id = options[:content_id]
225
+ data = options[:data]
226
+ category_id = options[:category_id]
227
+ body = {
228
+ clientId: client_id,
229
+ contentId: content_id,
230
+ contentValues: data,
231
+ categoryIdForAcl: category_id
232
+ }
233
+ route(to: __callee__, body: body, token_id: token_id)
234
+ end
235
+
236
+ def update_player_embed_codes(options = {})
237
+ content_id = options[:content_id]
238
+ players = options[:players]
239
+ category_id = options[:category_id]
240
+ body = {
241
+ clientId: client_id,
242
+ contentId: content_id,
243
+ embedCodes: {
244
+ embedCodes: players
245
+ },
246
+ categoryIdForAcl: category_id
247
+ }
248
+ route(to: __callee__, body: body, token_id: token_id)
249
+ end
250
+
251
+ def update_user_specific_values(options = {})
252
+ username = options[:username]
253
+ content_id = options[:content_id]
254
+ data = options[:data]
255
+ category_id = options[:category_id]
256
+ body = {
257
+ clientId: client_id,
258
+ username: username,
259
+ contentId: content_id,
260
+ contentParams: data,
261
+ categoryIdForAcl: category_id
262
+ }
263
+ route(to: __callee__, body: body, token_id: token_id)
264
+ end
265
+ end
266
+ end
267
+ end