naranya_ecm-sdk 0.0.27 → 0.0.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/naranya_ecm-sdk.rb +7 -0
- data/lib/naranya_ecm-sdk/version.rb +1 -1
- data/lib/naranya_ecm/models/content.rb +209 -34
- data/lib/naranya_ecm/rest/client.rb +1 -1
- data/lib/naranya_ecm/rest/errors.rb +20 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe024c1fb8de7856dc1c7fc5890f5194046059b8
|
4
|
+
data.tar.gz: eae615e6dc5b250134ac204e936a7509b019f4d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e1ed60fa76e8b03a7f20e2a4c7995b16e147d234ca671c93319ae62ccfa740920238f7baa17f387fbfcac35b9be253b44d34ed772b912013d69e9bee3b2d177
|
7
|
+
data.tar.gz: dcf357e123ab07edd39cc5adf3df13ffbb36416d2bc45076e83593775781ec7bffd1182ffcd64d3103a4c45d50aad6ea6abbbe952397dd35fdc171fed8c4748e
|
data/lib/naranya_ecm-sdk.rb
CHANGED
@@ -17,6 +17,10 @@ module NaranyaEcm
|
|
17
17
|
autoload :Client
|
18
18
|
end
|
19
19
|
|
20
|
+
# == NaranyaEcm \Rest Module
|
21
|
+
#
|
22
|
+
# <tt>NaranyaEcm::Rest</tt> provides the REST persistance and querying layer
|
23
|
+
# that connects the NaranyaEcm models with the Naranya CaaS REST services.
|
20
24
|
module Rest
|
21
25
|
extend ActiveSupport::Autoload
|
22
26
|
autoload :Client
|
@@ -47,6 +51,9 @@ module NaranyaEcm
|
|
47
51
|
autoload :ContentLifecycle
|
48
52
|
end
|
49
53
|
|
54
|
+
# == NaranyaEcm \Search Module
|
55
|
+
#
|
56
|
+
# <tt>NaranyaEcm::Search</tt> implements classes and methods for querying the Naranya CaaS Search engine.
|
50
57
|
module Search
|
51
58
|
extend ActiveSupport::Autoload
|
52
59
|
autoload :Hit
|
@@ -1,84 +1,241 @@
|
|
1
|
-
|
2
1
|
module NaranyaEcm
|
2
|
+
|
3
|
+
##
|
4
|
+
# Represents a Content unit in the Naranya CaaS Service
|
5
|
+
#
|
6
|
+
# A content unit is made of by a list of some required attributes,
|
7
|
+
# along with any non-required attributes.
|
8
|
+
#
|
9
|
+
# == Attributes List
|
10
|
+
#
|
11
|
+
# === Required Attributes
|
12
|
+
#
|
13
|
+
# In order to create a Content Unit, the Content Object should contain at least the following attributes:
|
14
|
+
# * <tt>lifecycle_name:</tt> Indicates whether the Content object follows a <tt>simple</tt> lifecycle, a <tt>validatable</tt> lifecycle (can't publish without some sort of editorial validation first), or any other significant lifecycle.
|
15
|
+
# * <tt>title_translations:</tt> At least one localized title is required. This attribute is a Hash-like object, requiring the locale name as a key, and the localized string as value.
|
16
|
+
# * <tt>author:</tt> This string represents the name of the author of the content.
|
17
|
+
#
|
18
|
+
# === Other significant attributes
|
19
|
+
#
|
20
|
+
# The Naranya CaaS Service is prepared to manage and gives meaning to the following attributes:
|
21
|
+
# * <tt>type:</tt> The type of content. Aids the client application in determining how to display and manage the content.
|
22
|
+
# * <tt>description_translations:</tt> Localizable descriptions of the Content.
|
23
|
+
# * <tt>content_rating:</tt>
|
24
|
+
# * <tt>keywords:</tt> Array containing a list of keywords
|
25
|
+
# * <tt>main_url:</tt> The main URL pointing to the content AS DISPLAYED BY THE CLIENT APP.
|
26
|
+
#
|
27
|
+
# == Associations
|
28
|
+
#
|
29
|
+
# * <tt>category:</tt>
|
30
|
+
# * <tt>versions:</tt>
|
31
|
+
# * <tt>current_version:</tt>
|
32
|
+
# * <tt>latest_version:</tt>
|
33
|
+
# * <tt>media_resources:</tt>
|
3
34
|
class Content
|
4
35
|
|
36
|
+
# Include the REST persistance methods:
|
5
37
|
include NaranyaEcm.document_module
|
38
|
+
|
39
|
+
# Include the timestamping methods:
|
6
40
|
include NaranyaEcm::Behaviors::Timestampable
|
41
|
+
|
42
|
+
# Include the search methods:
|
7
43
|
include NaranyaEcm::Search::Methods
|
44
|
+
|
45
|
+
# Include the media list methods:
|
8
46
|
include NaranyaEcm::Behaviors::MediaMethods
|
9
47
|
|
10
|
-
|
48
|
+
##
|
49
|
+
# :attr: type
|
50
|
+
#
|
11
51
|
# Describes the main type of the content - App, Note, etc.
|
12
52
|
field :type, type: String
|
13
53
|
|
14
|
-
|
54
|
+
##
|
55
|
+
# :attr: lifecycle_name
|
56
|
+
#
|
15
57
|
# Determines the lifecycle for the specific content:
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
58
|
+
# * <tt>simple:</tt> draft -> published -> deactivated
|
59
|
+
# * <tt>validatable:</tt> draft -> awaiting_acceptance -> accepted -> published -> deactivated
|
60
|
+
# * <tt>expirable:</tt> draft -> published -> expired/inactive
|
19
61
|
field :lifecycle_name, type: String, default: -> { 'simple' }
|
20
62
|
validates :lifecycle_name, presence: true
|
21
63
|
|
22
|
-
|
64
|
+
##
|
65
|
+
# :attr: lifecycle_state
|
66
|
+
#
|
23
67
|
# A managed string that describes the current state of this particular content.
|
24
68
|
# Depending on the Content's lifecycle, it changes upon several events.
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
69
|
+
# * <tt>draft:</tt>
|
70
|
+
# * <tt>awaiting_acceptance:</tt>
|
71
|
+
# * <tt>accepted:</tt>
|
72
|
+
# * <tt>rejected:</tt>
|
73
|
+
# * <tt>published:</tt>
|
74
|
+
# * <tt>deactivated:</tt>
|
30
75
|
field :lifecycle_state, type: String, default: -> { :draft }
|
31
76
|
validates :lifecycle_state, presence: true
|
32
77
|
|
33
|
-
|
78
|
+
##
|
79
|
+
# :attr: title
|
80
|
+
#
|
34
81
|
# The content title that can be displayed as header, result, etc.
|
35
82
|
field :title, type: String, localize: true
|
36
83
|
validate :at_least_one_title_translation_must_exist
|
37
84
|
|
38
|
-
|
39
|
-
#
|
85
|
+
##
|
86
|
+
# :attr: title_translations
|
87
|
+
#
|
88
|
+
# Hash-like containing all the title translations.
|
89
|
+
|
90
|
+
##
|
91
|
+
# :attr: description
|
92
|
+
#
|
93
|
+
# The localized content description that can be displayed as header, result, etc.
|
40
94
|
field :description, type: String, localize: true
|
95
|
+
|
96
|
+
##
|
97
|
+
# :attr: description_translations
|
98
|
+
#
|
99
|
+
# Hash-like containing all the description translations.
|
41
100
|
|
42
|
-
|
101
|
+
##
|
102
|
+
# :attr: content_rating
|
103
|
+
#
|
104
|
+
# Hash-like object containing all the localized content ratings, with the rating system as a Key, and the corresponding ratin object as value.
|
43
105
|
field :content_rating, type: Hash
|
44
106
|
|
45
|
-
|
107
|
+
##
|
108
|
+
# :attr: keywords
|
109
|
+
#
|
110
|
+
# Array containing a list of keywords
|
46
111
|
field :keywords, type: Array
|
47
112
|
|
113
|
+
##
|
114
|
+
# :attr: author
|
115
|
+
#
|
48
116
|
# Author:
|
49
117
|
# The name of the user who created this content.
|
50
118
|
field :author, type: String
|
51
|
-
validates :author,
|
52
|
-
presence: true
|
119
|
+
validates :author, presence: true
|
53
120
|
|
121
|
+
##
|
122
|
+
# :attr: main_url
|
123
|
+
#
|
54
124
|
# Main URL:
|
55
125
|
# The URL that should be used to render or display the content.
|
56
126
|
field :main_url, type: String
|
57
|
-
validates :main_url,
|
58
|
-
format: { with: URI.regexp },
|
59
|
-
allow_nil: true,
|
60
|
-
allow_blank: true
|
127
|
+
validates :main_url, format: { with: URI.regexp }, allow_nil: true, allow_blank: true
|
61
128
|
|
129
|
+
##
|
130
|
+
# :attr: category
|
131
|
+
# :category: Associations
|
132
|
+
#
|
133
|
+
# The category to which the Content belongs.
|
62
134
|
belongs_to :category
|
63
135
|
|
64
|
-
|
65
|
-
|
136
|
+
##
|
137
|
+
# :attr: versions
|
138
|
+
# :category: Associations
|
139
|
+
#
|
140
|
+
# A list of ContentVersion objects corresponding to changes in a versionable content.
|
141
|
+
has_many :versions, class_name: :ContentVersion
|
66
142
|
|
67
|
-
|
68
|
-
|
143
|
+
##
|
144
|
+
# :attr: current_version
|
145
|
+
# :category: Associations
|
146
|
+
#
|
147
|
+
# The ContentVersion object marked as current. It must be published.
|
148
|
+
belongs_to :current_version, class_name: :ContentVersion
|
69
149
|
|
70
|
-
|
71
|
-
|
150
|
+
##
|
151
|
+
# :attr: latest_version
|
152
|
+
# :category: Associations
|
153
|
+
#
|
154
|
+
# The ContentVersion object marked as latest.
|
155
|
+
belongs_to :latest_version, class_name: :ContentVersion
|
72
156
|
|
73
|
-
|
74
|
-
|
75
|
-
|
157
|
+
##
|
158
|
+
# :attr: media_resources
|
159
|
+
# :category: Associations
|
160
|
+
#
|
161
|
+
# A list of MediaResource objects associated directly to the Content.
|
162
|
+
has_many :media_resources, class_name: :MediaResource, inverse_of: :content
|
76
163
|
|
77
164
|
###############################################################
|
78
165
|
# StateMachine:
|
79
166
|
include AASM
|
80
167
|
include AASM::Persistence::RestPersistence
|
81
168
|
|
169
|
+
##
|
170
|
+
# :method: request_an_acceptance_review
|
171
|
+
# :call-seq:
|
172
|
+
# request_an_acceptance_review => true or false
|
173
|
+
#
|
174
|
+
# Triggers the <tt>request_an_acceptance_review</tt> event, and starts the Content transition to an :awaiting_acceptance state.
|
175
|
+
|
176
|
+
##
|
177
|
+
# :method: request_an_acceptance_review!
|
178
|
+
# :call-seq:
|
179
|
+
# request_an_acceptance_review => true or Error
|
180
|
+
#
|
181
|
+
# Same as #request_an_acceptance_review, but raises an error if the transition halted.
|
182
|
+
|
183
|
+
##
|
184
|
+
# :method: accept
|
185
|
+
# :call-seq:
|
186
|
+
# accept => true or false
|
187
|
+
#
|
188
|
+
# Triggers the <tt>accept</tt> event.
|
189
|
+
|
190
|
+
##
|
191
|
+
# :method: accept!
|
192
|
+
# :call-seq:
|
193
|
+
# accept! => true or Error
|
194
|
+
#
|
195
|
+
# Same as #accept, but raises an error if the transition halted.
|
196
|
+
|
197
|
+
##
|
198
|
+
# :method: reject
|
199
|
+
# :call-seq:
|
200
|
+
# reject => true or false
|
201
|
+
#
|
202
|
+
# Triggers the <tt>reject</tt> event, which starts the Content transition to an <tt>:rejected</tt> state.
|
203
|
+
|
204
|
+
##
|
205
|
+
# :method: reject!
|
206
|
+
# :call-seq:
|
207
|
+
# reject! => true or Error
|
208
|
+
#
|
209
|
+
# Same as #reject, but raises an error if the transition did not complete.
|
210
|
+
|
211
|
+
##
|
212
|
+
# :method: publish
|
213
|
+
# :call-seq:
|
214
|
+
# publish => true or false
|
215
|
+
#
|
216
|
+
# Triggers the <tt>publish</tt> event, which starts the Content transition to a <tt>:published</tt> state.
|
217
|
+
|
218
|
+
##
|
219
|
+
# :method: publish!
|
220
|
+
# :call-seq:
|
221
|
+
# publish! => true or Error
|
222
|
+
#
|
223
|
+
# Same as #publish, but raises an error if the transition did not complete.
|
224
|
+
|
225
|
+
##
|
226
|
+
# :method: deactivate
|
227
|
+
# :call-seq:
|
228
|
+
# deactivate => true or false
|
229
|
+
#
|
230
|
+
# Triggers the <tt>deactivate</tt> event, which starts the Content transition to a <tt>:deactivated</tt> state.
|
231
|
+
|
232
|
+
##
|
233
|
+
# :method: deactivate!
|
234
|
+
# :call-seq:
|
235
|
+
# deactivate! => true or Error
|
236
|
+
#
|
237
|
+
# Same as #deactivate, but raises an error if the transition did not complete.
|
238
|
+
|
82
239
|
aasm column: :lifecycle_state do
|
83
240
|
|
84
241
|
state :draft, initial: true
|
@@ -119,11 +276,29 @@ module NaranyaEcm
|
|
119
276
|
end
|
120
277
|
end
|
121
278
|
|
122
|
-
|
123
|
-
|
279
|
+
##
|
280
|
+
# :method: simple_lifecycle?
|
281
|
+
# :call-seq:
|
282
|
+
# simple_lifecycle? => true or false
|
283
|
+
#
|
284
|
+
# Shows whether the Content object has a simple lifecycle.
|
285
|
+
def simple_lifecycle?
|
286
|
+
self.lifecycle_name == 'simple'
|
287
|
+
end
|
288
|
+
|
289
|
+
##
|
290
|
+
# :method: validatable_lifecycle?
|
291
|
+
# :call-seq:
|
292
|
+
# validatable_lifecycle? => true or false
|
293
|
+
#
|
294
|
+
# Shows whether the Content object has a validatable lifecycle.
|
295
|
+
def validatable_lifecycle?
|
296
|
+
self.lifecycle_name == 'validatable'
|
297
|
+
end
|
124
298
|
|
125
299
|
private
|
126
300
|
|
301
|
+
# Validates that at least one title translation exists.
|
127
302
|
def at_least_one_title_translation_must_exist
|
128
303
|
errors.add :title_translations, "must have at least one translation" unless title_translations.keys.any?
|
129
304
|
end
|
@@ -74,7 +74,7 @@ module NaranyaEcm::Rest
|
|
74
74
|
log_level: :debug,
|
75
75
|
log_format: :curl
|
76
76
|
|
77
|
-
::NaranyaEcm::Rest::RestError.
|
77
|
+
::NaranyaEcm::Rest::RestError.raise_by_failed_response(token_response.code) unless token_response.success?
|
78
78
|
|
79
79
|
"Bearer #{token_response['access_token']}"
|
80
80
|
end
|
@@ -11,6 +11,8 @@ module NaranyaEcm::Rest
|
|
11
11
|
super(msg)
|
12
12
|
end
|
13
13
|
|
14
|
+
##
|
15
|
+
# Captura un response y genera + avienta una excepción.
|
14
16
|
def self.raise_by_failed_response(response, message = "")
|
15
17
|
klass = case response.code
|
16
18
|
when 401 then AuthorizationRequired
|
@@ -54,22 +56,32 @@ module NaranyaEcm::Rest
|
|
54
56
|
|
55
57
|
# Raised when connection to the database could not been established (for example when <tt>connection=</tt>
|
56
58
|
# is given a nil object).
|
57
|
-
class ConnectionNotEstablished < RestError
|
59
|
+
class ConnectionNotEstablished < RestError
|
60
|
+
end
|
58
61
|
|
59
62
|
# Raised when REST cannot find record by given id or set of ids.
|
60
|
-
class ResourceNotFound < RestError
|
63
|
+
class ResourceNotFound < RestError
|
64
|
+
end
|
61
65
|
|
62
66
|
# Raised by ActiveRecord::Base.save! and ActiveRecord::Base.create! methods when record cannot be
|
63
67
|
# saved because record is invalid.
|
64
|
-
class ResourceNotSaved < RestError
|
68
|
+
class ResourceNotSaved < RestError
|
69
|
+
end
|
65
70
|
|
66
71
|
# Raised by ActiveRecord::Base.destroy! when a call to destroy would return false.
|
67
|
-
class ResourceNotDestroyed < RestError
|
72
|
+
class ResourceNotDestroyed < RestError
|
73
|
+
end
|
74
|
+
|
75
|
+
class AuthorizationRequired < RestError
|
76
|
+
end
|
68
77
|
|
69
|
-
class
|
78
|
+
class Forbidden < RestError
|
79
|
+
end
|
70
80
|
|
71
|
-
class
|
72
|
-
|
73
|
-
|
81
|
+
class UnprocessableEntity < RestError
|
82
|
+
end
|
83
|
+
|
84
|
+
class RemoteFailed < RestError
|
85
|
+
end
|
74
86
|
|
75
87
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: naranya_ecm-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Quintanilla
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|