naranya_ecm-sdk 0.0.34 → 0.0.35

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebafc5d4f40d88b45a99cea2b04dd3a1b6731194
4
- data.tar.gz: 435aac8f54e0dbd45e673af840a108e70c0853af
3
+ metadata.gz: fb9d2934d262d1b2756004bb52d806d06ba23cbe
4
+ data.tar.gz: 685cc13008257d3a91cae01515b58428dfe7d3e8
5
5
  SHA512:
6
- metadata.gz: e8d58cc2b57220b85d98bf859be73771c0c630489c03daa5be6abd35629aa212d03b867606d756cbe116e3d663bb6c5d755fbe07a59e9254b17171753c3fdbd9
7
- data.tar.gz: ac438bcbfe33d990f3ae4152a48c1db0e33c468d34190ef5bf8ad3cb758af6660a47140134ea6eb5489e2164e68affa972829645dfe136570ee57acade41bf35
6
+ metadata.gz: c85654045b5dc54105ef010f5c0f1c729a47a8b3832ffed1e782efa3b8d463e3a1bf3885aea1d058197358ab7c5e1112454d225b02fd38290dddffc24563a1eb
7
+ data.tar.gz: dd3b862753366e2fb7d45f6be2b39c5fe2d412b6a84c226cd97ea01b0d66f66f4251103c8d6f7f613c4430552d301b1f27849f21400da8f5dcbdfab71b164b86
@@ -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
- cache_store: []
73
+ client_notify_url: "http://www.example.com/naranya_ecm/notifications",
74
+ notification_processing_modules: []
73
75
  }.freeze
74
76
 
75
77
  class << self
@@ -1,3 +1,3 @@
1
1
  module NaranyaEcm
2
- VERSION = "0.0.34"
2
+ VERSION = "0.0.35"
3
3
  end
@@ -22,37 +22,64 @@ module NaranyaEcm::Behaviors
22
22
  mr.flatten.uniq
23
23
  end
24
24
 
25
- def detect_media_by_roles(*given_roles)
26
- raise ArgumentError, "Given role list is blank" if given_roles.blank?
27
- current_roles = given_roles.dup
28
- detected_media = nil
29
- until detected_media.present? || current_roles.count < 1 do
30
- detected_media = self.media_resources.detect { |mr| (mr.roles & current_roles).count == current_roles.count }
31
- current_roles.pop
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
- def detect_media_url_by_roles(*given_roles)
37
- detected_media = detect_media_by_roles(*given_roles)
38
- detected_media.present? ? detected_media.downloadable_url : nil
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 select_media_by_roles(*given_roles)
42
- raise ArgumentError, "Given role list is blank" if given_roles.blank?
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(*given_roles)
53
- selected_media = select_media_by_roles(*given_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
@@ -12,6 +12,9 @@ module NaranyaEcm
12
12
  # Source Media Resource:
13
13
  belongs_to :media_resource
14
14
 
15
+ # Profile used as base:
16
+ belongs_to :media_profile
17
+
15
18
  field :notify_url, type: String
16
19
 
17
20
  field :append_media_roles, type: Array, default: -> { [] }
@@ -15,16 +15,8 @@ module NaranyaEcm
15
15
  field :preset_id, type: String
16
16
 
17
17
  # Template content
18
- field :template, type: String
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
- response = HTTParty.send method, url, options
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)
@@ -1,4 +1,3 @@
1
- require 'httparty'
2
1
  require 'active_model'
3
2
 
4
3
  module NaranyaEcm::Rest
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.34
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-02 00:00:00.000000000 Z
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