naranya_ecm-sdk 0.0.34 → 0.0.35
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 +3 -1
- data/lib/naranya_ecm-sdk/version.rb +1 -1
- data/lib/naranya_ecm/behaviors/media_methods.rb +50 -23
- data/lib/naranya_ecm/models/media_process.rb +3 -0
- data/lib/naranya_ecm/models/media_profile.rb +2 -10
- data/lib/naranya_ecm/models/media_resource.rb +29 -0
- data/lib/naranya_ecm/models/notification.rb +31 -0
- data/lib/naranya_ecm/rest/client.rb +7 -1
- data/lib/naranya_ecm/rest/model.rb +0 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb9d2934d262d1b2756004bb52d806d06ba23cbe
|
4
|
+
data.tar.gz: 685cc13008257d3a91cae01515b58428dfe7d3e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c85654045b5dc54105ef010f5c0f1c729a47a8b3832ffed1e782efa3b8d463e3a1bf3885aea1d058197358ab7c5e1112454d225b02fd38290dddffc24563a1eb
|
7
|
+
data.tar.gz: dd3b862753366e2fb7d45f6be2b39c5fe2d412b6a84c226cd97ea01b0d66f66f4251103c8d6f7f613c4430552d301b1f27849f21400da8f5dcbdfab71b164b86
|
data/lib/naranya_ecm-sdk.rb
CHANGED
@@ -41,6 +41,7 @@ module NaranyaEcm
|
|
41
41
|
autoload :MediaProfile
|
42
42
|
autoload :MediaProcess
|
43
43
|
autoload :MediaResource
|
44
|
+
autoload :Notification
|
44
45
|
end
|
45
46
|
|
46
47
|
module Behaviors
|
@@ -69,7 +70,8 @@ module NaranyaEcm
|
|
69
70
|
|
70
71
|
DEFAULT_CONFIG = {
|
71
72
|
site: "http://ecm.naranya.net:5000",
|
72
|
-
|
73
|
+
client_notify_url: "http://www.example.com/naranya_ecm/notifications",
|
74
|
+
notification_processing_modules: []
|
73
75
|
}.freeze
|
74
76
|
|
75
77
|
class << self
|
@@ -22,37 +22,64 @@ module NaranyaEcm::Behaviors
|
|
22
22
|
mr.flatten.uniq
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
# Returns an Array of MediaResource objects which match the given options in their role list.
|
26
|
+
#
|
27
|
+
# ==== Attributes
|
28
|
+
#
|
29
|
+
# * +options+ - The given options to select the MediaResource objects
|
30
|
+
#
|
31
|
+
# ==== Options
|
32
|
+
#
|
33
|
+
# You may which to break out options as a separate item since there maybe
|
34
|
+
# multiple items. Note options are prefixed with a colon, denoting them
|
35
|
+
# as a
|
36
|
+
#
|
37
|
+
# * +:match+ - An Array of roles that *must* exist in matching MediaResource objects.
|
38
|
+
# * +:prefer+ - An Array of values consisting of:
|
39
|
+
# * A String indicating a desired role
|
40
|
+
# * A Hash containing the desired role as key, and an Array of fallback roles as value.
|
41
|
+
#
|
42
|
+
# ==== Examples
|
43
|
+
#
|
44
|
+
# Illustrate the behaviour of the method using examples. Indent examples:
|
45
|
+
#
|
46
|
+
# base = Base.new("Example String")
|
47
|
+
# base.method_name("Example", "more")
|
48
|
+
def select_media_by_roles(options)
|
49
|
+
|
50
|
+
options = options.with_indifferent_access if options.is_a?(Hash) && !options.is_a?(ActiveSupport::HashWithIndifferentAccess)
|
51
|
+
|
52
|
+
match = options.is_a?(Hash) ? options[:match] : options
|
53
|
+
match = [match.to_s] if match.is_a?(String) || match.is_a?(Symbol)
|
54
|
+
|
55
|
+
raise ArgumentError, "No match options given" if match.blank?
|
56
|
+
|
57
|
+
except = options.is_a?(Hash) ? options[:except] : []
|
58
|
+
except = [except.to_s] if except.is_a?(String) || except.is_a?(Symbol)
|
59
|
+
except = [] if except.blank?
|
60
|
+
|
61
|
+
filtered_media = self.media_resources.select do |mr|
|
62
|
+
((mr.roles & match).count == match.count) && ((mr.roles & except).count < 1)
|
32
63
|
end
|
33
|
-
detected_media
|
34
|
-
end
|
35
64
|
|
36
|
-
|
37
|
-
|
38
|
-
|
65
|
+
prefer = options.is_a?(Hash) ? options[:prefer] : nil
|
66
|
+
prefer = [prefer.to_s] if prefer.is_a?(String) || prefer.is_a?(Symbol)
|
67
|
+
|
68
|
+
filtered_media
|
39
69
|
end
|
40
70
|
|
41
|
-
def
|
42
|
-
|
43
|
-
current_roles = given_roles.dup
|
44
|
-
selected_media = nil
|
45
|
-
until selected_media.present? || current_roles.count < 1 do
|
46
|
-
selected_media = self.media_resources.select { |mr| (mr.roles & current_roles).count == current_roles.count }
|
47
|
-
current_roles.pop
|
48
|
-
end
|
49
|
-
selected_media
|
71
|
+
def detect_media_by_roles(options)
|
72
|
+
select_media_by_roles(options).first
|
50
73
|
end
|
51
74
|
|
52
|
-
def select_media_urls_by_roles(
|
53
|
-
selected_media = select_media_by_roles(
|
75
|
+
def select_media_urls_by_roles(options)
|
76
|
+
selected_media = select_media_by_roles(options)
|
54
77
|
selected_media.present? ? selected_media.map(&:downloadable_url) : nil
|
55
78
|
end
|
56
79
|
|
80
|
+
def detect_media_url_by_roles(options)
|
81
|
+
select_media_urls_by_roles(options).first
|
82
|
+
end
|
83
|
+
|
57
84
|
end
|
58
85
|
end
|
@@ -15,16 +15,8 @@ module NaranyaEcm
|
|
15
15
|
field :preset_id, type: String
|
16
16
|
|
17
17
|
# Template content
|
18
|
-
field :template, type:
|
19
|
-
|
20
|
-
def template_hash
|
21
|
-
ActiveSupport::JSON.decode template
|
22
|
-
end
|
23
|
-
|
24
|
-
def template_hash=(hash = {})
|
25
|
-
self.template = ActiveSupport::JSON.encode hash
|
26
|
-
end
|
27
|
-
|
18
|
+
field :template, type: Hash
|
19
|
+
|
28
20
|
end
|
29
21
|
|
30
22
|
end
|
@@ -69,6 +69,35 @@ module NaranyaEcm
|
|
69
69
|
NaranyaEcm.root_directory
|
70
70
|
end
|
71
71
|
|
72
|
+
def move_downloadable_to(path, force_move=false)
|
73
|
+
|
74
|
+
raise ArgumentError, "Given path is empty" unless path.present?
|
75
|
+
path = path[1..-1] if path.present? && path[0] == "/"
|
76
|
+
raise ArgumentError, "Can't use root (/) as target path" unless path.present?
|
77
|
+
|
78
|
+
path_exists = root_directory.files.head(path).present?
|
79
|
+
|
80
|
+
if !path_exists || (path_exists && force_move)
|
81
|
+
old_file = root_directory.files.get downloadable_resource_key
|
82
|
+
|
83
|
+
new_file = root_directory.files.create(
|
84
|
+
key: path,
|
85
|
+
body: old_file.body,
|
86
|
+
content_type: old_file.content_type,
|
87
|
+
last_modified: old_file.last_modified,
|
88
|
+
:public => public?
|
89
|
+
)
|
90
|
+
|
91
|
+
self.downloadable_url = public? ? new_file.public_url : new_file.url(1.minutes.from_now).split("?").first
|
92
|
+
|
93
|
+
old_file.destroy if self.save
|
94
|
+
true
|
95
|
+
else
|
96
|
+
false
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
72
101
|
# Generates a MediaProcess with self as the source MediaResource.
|
73
102
|
def process_with_profile(given_profile, given_options = {})
|
74
103
|
raise ArgumentError, 'Given profile is not a MediaProfile' unless given_profile.is_a? NaranyaEcm::MediaProfile
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module NaranyaEcm
|
2
|
+
|
3
|
+
class Notification
|
4
|
+
|
5
|
+
include ActiveModel::Model
|
6
|
+
include ActiveModel::Serialization
|
7
|
+
|
8
|
+
attr_accessor :media_process_id, :processed_media_resources, :ok
|
9
|
+
|
10
|
+
def attributes
|
11
|
+
{ media_process_id: media_process_id, processed_media_resources: processed_media_resources, ok: ok }
|
12
|
+
end
|
13
|
+
|
14
|
+
def process
|
15
|
+
NaranyaEcm.logger.debug "NaranyaEcm::Notification: #{self.attributes}"
|
16
|
+
NaranyaEcm.logger.debug "NaranyaEcm::Notification: No processing implemented."
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.process(given_attributes)
|
20
|
+
notification = self.new given_attributes
|
21
|
+
notification.process
|
22
|
+
end
|
23
|
+
|
24
|
+
NaranyaEcm.config.notification_processing_modules.each do |module_name|
|
25
|
+
processing_module = module_name.safe_constantize
|
26
|
+
include processing_module if processing_module.present?
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -46,8 +46,14 @@ module NaranyaEcm::Rest
|
|
46
46
|
options[:log_level] = :debug
|
47
47
|
options[:log_format] = :apache
|
48
48
|
|
49
|
-
|
49
|
+
# HTTParty no envía un parametro GET si es un Array vacío.
|
50
|
+
# Convertir los arrays vacíos a [nil] (WTF?)
|
51
|
+
if method == :get && options[:query].is_a?(Hash)
|
52
|
+
options[:query].each { |key, val| options[:query][key] = [nil] if val.is_a?(Array) && val.empty? }
|
53
|
+
end
|
50
54
|
|
55
|
+
response = HTTParty.send method, url, options
|
56
|
+
|
51
57
|
# Retry if response code is 401 and a client token is present:
|
52
58
|
if response.code == 401 && authorization_header.present?
|
53
59
|
options[:headers]['Authorization'] = authorization_header(true)
|
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.35
|
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-07-
|
11
|
+
date: 2014-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -210,6 +210,7 @@ files:
|
|
210
210
|
- lib/naranya_ecm/models/media_process.rb
|
211
211
|
- lib/naranya_ecm/models/media_profile.rb
|
212
212
|
- lib/naranya_ecm/models/media_resource.rb
|
213
|
+
- lib/naranya_ecm/models/notification.rb
|
213
214
|
- lib/naranya_ecm/rest/association_relation.rb
|
214
215
|
- lib/naranya_ecm/rest/associations.rb
|
215
216
|
- lib/naranya_ecm/rest/client.rb
|