inforouter 0.1.0 → 0.2.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 (55) hide show
  1. checksums.yaml +8 -8
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +1 -1
  4. data/.travis.yml +5 -0
  5. data/Gemfile +0 -3
  6. data/README.md +102 -2
  7. data/Rakefile +20 -1
  8. data/inforouter.gemspec +12 -8
  9. data/lib/config/locales/en.yml +34 -0
  10. data/lib/inforouter.rb +26 -7
  11. data/lib/inforouter/access_list.rb +25 -27
  12. data/lib/inforouter/access_list_domain_members_item.rb +11 -0
  13. data/lib/inforouter/access_list_user_group_item.rb +17 -0
  14. data/lib/inforouter/access_list_user_item.rb +17 -0
  15. data/lib/inforouter/client.rb +19 -16
  16. data/lib/inforouter/configuration.rb +10 -4
  17. data/lib/inforouter/document.rb +64 -0
  18. data/lib/inforouter/errors.rb +2 -0
  19. data/lib/inforouter/errors/api_error.rb +17 -0
  20. data/lib/inforouter/errors/inforouter_error.rb +77 -1
  21. data/lib/inforouter/errors/missing_config_error.rb +1 -1
  22. data/lib/inforouter/errors/missing_config_option_error.rb +1 -1
  23. data/lib/inforouter/errors/soap_error.rb +2 -1
  24. data/lib/inforouter/errors/unexpected_soap_response_error.rb +18 -0
  25. data/lib/inforouter/folder.rb +139 -0
  26. data/lib/inforouter/record.rb +13 -0
  27. data/lib/inforouter/responses.rb +14 -0
  28. data/lib/inforouter/responses/base.rb +78 -0
  29. data/lib/inforouter/responses/create_folder.rb +10 -0
  30. data/lib/inforouter/responses/delete_folder.rb +10 -0
  31. data/lib/inforouter/responses/document.rb +48 -0
  32. data/lib/inforouter/responses/document_exists.rb +10 -0
  33. data/lib/inforouter/responses/folder.rb +33 -0
  34. data/lib/inforouter/responses/folder_exists.rb +10 -0
  35. data/lib/inforouter/responses/generic.rb +28 -0
  36. data/lib/inforouter/responses/set_access_list.rb +10 -0
  37. data/lib/inforouter/responses/set_folder_rules.rb +10 -0
  38. data/lib/inforouter/responses/update_folder_properties.rb +10 -0
  39. data/lib/inforouter/responses/update_property_set_definition.rb +10 -0
  40. data/lib/inforouter/responses/update_property_set_row.rb +10 -0
  41. data/lib/inforouter/responses/users.rb +38 -0
  42. data/lib/inforouter/rights.rb +18 -0
  43. data/lib/inforouter/rule_item.rb +25 -0
  44. data/lib/inforouter/rules.rb +51 -0
  45. data/lib/inforouter/user.rb +39 -0
  46. data/lib/inforouter/users.rb +25 -0
  47. data/lib/inforouter/version.rb +1 -1
  48. data/test/helper.rb +3 -0
  49. data/test/test_client.rb +4 -0
  50. data/test/test_configuration.rb +31 -0
  51. data/test/test_setup.rb +18 -0
  52. metadata +96 -6
  53. data/.rspec +0 -2
  54. data/lib/inforouter/folder_rule.rb +0 -50
  55. data/spec/spec_helper.rb +0 -29
@@ -1,13 +1,19 @@
1
1
  module Inforouter #:nodoc:
2
- # Inforouter gem configuration.
2
+ # infoRouter gem configuration.
3
3
  class Configuration
4
- # Inforouter host.
4
+ # infoRouter WSDL.
5
+ attr_accessor :wsdl
6
+ # infoRouter host.
5
7
  attr_accessor :host
6
- # Inforouter username.
8
+ # infoRouter username.
7
9
  attr_accessor :username
8
- # Inforouter password.
10
+ # infoRouter password.
9
11
  attr_accessor :password
10
12
 
13
+ def initialize(options = {})
14
+ @wsdl = options[:wsdl] || File.dirname(__FILE__) + '/../../resources/inforouter.wsdl'
15
+ end
16
+
11
17
  # Check the configuration.
12
18
  #
13
19
  # Will raise a Inforouter::Errors::MissingConfigOption if any of the host or
@@ -0,0 +1,64 @@
1
+ module Inforouter #:nodoc
2
+ class Document < Record
3
+ # Document ID.
4
+ attr_accessor :document_id
5
+ # Document name.
6
+ attr_accessor :name
7
+ # Document path.
8
+ attr_accessor :path
9
+ # Document description.
10
+ attr_accessor :description
11
+ # Document update instructions.
12
+ attr_accessor :update_instructions
13
+ # Document creation date.
14
+ attr_accessor :creation_date
15
+ # Document modification date.
16
+ attr_accessor :modification_date
17
+ # Document checkout date.
18
+ attr_accessor :checkout_date
19
+ # Document checkout by.
20
+ attr_accessor :checkout_by
21
+ # Document checkout by user name.
22
+ attr_accessor :checkout_by_user_name
23
+ # Document size.
24
+ attr_accessor :size
25
+ # Document type.
26
+ attr_accessor :type
27
+ # Document percent complete.
28
+ attr_accessor :percent_complete
29
+ # Document completion date.
30
+ attr_accessor :completion_date
31
+ # Document importance.
32
+ attr_accessor :importance
33
+ # Document retention date.
34
+ attr_accessor :retention_date
35
+ # Document disposition date.
36
+ attr_accessor :disposition_date
37
+ # Document expiration date.
38
+ attr_accessor :expiration_date
39
+ # Document register date.
40
+ attr_accessor :register_date
41
+ # Document registered by.
42
+ attr_accessor :registered_by
43
+ # Document doc type ID.
44
+ attr_accessor :doc_type_id
45
+ # Document doc type name.
46
+ attr_accessor :doc_type_name
47
+ # Document version number.
48
+ attr_accessor :version_number
49
+
50
+ # @return [Boolean]
51
+ def exists?
52
+ response = Inforouter.client.request :document_exists, path_params
53
+ result = Inforouter::Responses::DocumentExists.parse response
54
+ result[:@success] == 'true'
55
+ end
56
+
57
+ private
58
+
59
+ # @return [Hash]
60
+ def path_params
61
+ { :path => path }
62
+ end
63
+ end
64
+ end
@@ -2,3 +2,5 @@ require 'inforouter/errors/inforouter_error'
2
2
  require 'inforouter/errors/missing_config_error'
3
3
  require 'inforouter/errors/missing_config_option_error'
4
4
  require 'inforouter/errors/soap_error'
5
+ require 'inforouter/errors/unexpected_soap_response_error.rb'
6
+ require 'inforouter/errors/api_error'
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ module Inforouter #:nodoc:
3
+ module Errors #:nodoc:
4
+ # This error is raised when the infoRouter service
5
+ # returns an error from an API.
6
+ class ApiError < InforouterError
7
+ # @param message [String] Error message.
8
+ # @param raw [String] Raw data from the SOAP response.
9
+ def initialize(message, raw)
10
+ super(compose_message('api_error',
11
+ :message => message,
12
+ :raw => raw
13
+ ))
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,8 +1,84 @@
1
1
  # encoding: utf-8
2
2
  module Inforouter #:nodoc:
3
3
  module Errors #:nodoc:
4
- # Default parent Inforouter error for all custom errors.
4
+ # Default parent infoRouter error for all custom errors. This handles the
5
+ # base key for the translations and provides the convenience method for
6
+ # translating the messages.
7
+ #
8
+ # Generously borrowed from Mongoid[https://github.com/mongoid/mongoid/blob/master/lib/mongoid/errors/mongoid_error.rb].
5
9
  class InforouterError < StandardError
10
+ BASE_KEY = 'inforouter.errors.messages' #:nodoc:
11
+
12
+ # Compose the message.
13
+ #
14
+ # @example Create the message.
15
+ # error.compose_message
16
+ #
17
+ # @return [String] The composed message.
18
+ def compose_message(key, attributes = {})
19
+ @problem = problem(key, attributes)
20
+ @summary = summary(key, attributes)
21
+ @resolution = resolution(key, attributes)
22
+
23
+ "\nProblem:\n #{@problem}" +
24
+ "\nSummary:\n #{@summary}" +
25
+ "\nResolution:\n #{@resolution}"
26
+ end
27
+
28
+ private
29
+
30
+ # Given the key of the specific error and the options hash, translate the
31
+ # message.
32
+ #
33
+ # @example Translate the message.
34
+ # error.translate("errors", :key => value)
35
+ #
36
+ # @param key [String] The key of the error in the locales.
37
+ # @param options [Hash] The objects to pass to create the message.
38
+ #
39
+ # @return [String] A localized error message string.
40
+ def translate(key, options)
41
+ ::I18n.translate("#{BASE_KEY}.#{key}", options)
42
+ end
43
+
44
+ # Create the problem.
45
+ #
46
+ # @example Create the problem.
47
+ # error.problem("error", {})
48
+ #
49
+ # @param key [String, Symbol] The error key.
50
+ # @param attributes [Hash] The attributes to interpolate.
51
+ #
52
+ # @return [String] The problem.
53
+ def problem(key, attributes)
54
+ translate("#{key}.message", attributes)
55
+ end
56
+
57
+ # Create the summary.
58
+ #
59
+ # @example Create the summary.
60
+ # error.summary("error", {})
61
+ #
62
+ # @param key [String, Symbol] The error key.
63
+ # @param attributes [Hash] The attributes to interpolate.
64
+ #
65
+ # @return [String] The summary.
66
+ def summary(key, attributes)
67
+ translate("#{key}.summary", attributes)
68
+ end
69
+
70
+ # Create the resolution.
71
+ #
72
+ # @example Create the resolution
73
+ # error.resolution("error", {})
74
+ #
75
+ # @param key [String, Symbol] The error key.
76
+ # @param attributes [Hash] The attributes to interpolate.
77
+ #
78
+ # @return [String] The resolution.
79
+ def resolution(key, attributes)
80
+ translate("#{key}.resolution", attributes)
81
+ end
6
82
  end
7
83
  end
8
84
  end
@@ -2,7 +2,7 @@
2
2
  module Inforouter #:nodoc:
3
3
  module Errors #:nodoc:
4
4
  # This error is raised when attempting to create a new client without
5
- # configuring Inforouter.
5
+ # configuring infoRouter.
6
6
  class MissingConfigError < InforouterError
7
7
  # Create a new error.
8
8
  def initialize
@@ -3,7 +3,7 @@ module Inforouter #:nodoc:
3
3
  module Errors #:nodoc:
4
4
  # This error is raised when a configuration option is missing.
5
5
  class MissingConfigOption < InforouterError
6
- # @params name [String]
6
+ # @param name [String]
7
7
  def initialize(name)
8
8
  super(compose_message('missing_config_option', :name => name))
9
9
  end
@@ -20,7 +20,8 @@ module Inforouter #:nodoc:
20
20
 
21
21
  private
22
22
 
23
- # @params fault_string [String]
23
+ # @param fault_string [String]
24
+ #
24
25
  # @return [String]
25
26
  def parse_fault(fault_string)
26
27
  fault_string.lines.first.strip
@@ -0,0 +1,18 @@
1
+ # encoding utf-8
2
+ module Inforouter #:nodoc:
3
+ module Errors #:nodoc:
4
+ # This error is raised when infoRouter returns an unexpected SOAP response.
5
+ class UnexpectedSOAPResponse < InforouterError
6
+ # @param raw [String] Raw data from the SOAP response.
7
+ # @param key [String] Expected key in the SOAP response.
8
+ # @param chain [String] Complete SOAP response chain in which the key could not be found.
9
+ def initialize(raw, key, chain)
10
+ super(compose_message('unexpected_soap_response',
11
+ :key => key,
12
+ :raw => raw,
13
+ :chain => chain
14
+ ))
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,139 @@
1
+ module Inforouter #:nodoc:
2
+ # A <tt>Folder</tt> defines an infoRouter folder.
3
+ class Folder < Record
4
+ # Folder ID.
5
+ attr_accessor :folder_id
6
+ # Folder parent ID.
7
+ attr_accessor :parent_id
8
+ # Folder name.
9
+ attr_accessor :name
10
+ # Folder path.
11
+ attr_accessor :path
12
+ # Folder description.
13
+ attr_accessor :description
14
+ # Folder creation date.
15
+ attr_accessor :creation_date
16
+ # Folder owner name.
17
+ attr_accessor :owner_name
18
+ # Folder domain ID.
19
+ attr_accessor :domain_id
20
+ # Folder access list.
21
+ attr_accessor :access_list
22
+ # Folder rules.
23
+ attr_accessor :rules
24
+ # Folder folders. Array of <tt>Inforouter::Folder</tt>s.
25
+ attr_accessor :folders
26
+ # Folder documents. Array of <tt>Inforouter::Document</tt>s.
27
+ attr_accessor :documents
28
+
29
+ def initialize(params = {})
30
+ params = {
31
+ :folders = [],
32
+ :documents = []
33
+ }.merge(params)
34
+ super params
35
+ end
36
+
37
+ # @return [String]
38
+ def description
39
+ @description ||= begin
40
+ response = Inforouter.client.request :get_folder, folder_params
41
+ folder = Inforouter::Responses::Folder.parse response
42
+ @description = folder.description
43
+ end
44
+ end
45
+
46
+ # Setting the path also sets the name if not already set.
47
+ def path=(path)
48
+ @name ||= path.split('/').last
49
+ @path = path
50
+ end
51
+
52
+ # @return [Boolean]
53
+ def create
54
+ response = Inforouter.client.request :create_folder, path_params
55
+ result = Inforouter::Responses::CreateFolder.parse response
56
+ result[:@success] == 'true'
57
+ end
58
+
59
+ # @return [Boolean]
60
+ def exists?
61
+ response = Inforouter.client.request :folder_exists, path_params
62
+ result = Inforouter::Responses::FolderExists.parse response
63
+ result[:@success] == 'true'
64
+ end
65
+
66
+ # @return [Array<Inforouter::Folder>]
67
+ def folders
68
+ @folders ||= begin
69
+ response = Inforouter.client.request :get_folders_and_documents, folders_and_documents_params
70
+ @folders, @documents = Inforouter::Responses::FoldersDocuments.parse response
71
+ @folders
72
+ end
73
+ end
74
+
75
+ # @return [Array<Inforouter::Document>]
76
+ def documents
77
+ @documents ||= begin
78
+ response = Inforouter.client.request :get_folders_and_documents, folders_and_documents_params
79
+ @folders, @documents = Inforouter::Responses::FoldersDocuments.parse response
80
+ @documents
81
+ end
82
+ end
83
+
84
+ # @return [Boolean]
85
+ def update_properties
86
+ request_params = {
87
+ :path => path,
88
+ :new_folder_name => name,
89
+ :description => description
90
+ }
91
+ response = Inforouter.client.request :update_folder_properties, request_params
92
+ result = Inforouter::Responses::UpdateFolderProperties.parse response
93
+ result[:@success] == 'true'
94
+ end
95
+
96
+ # @return [Boolean]
97
+ def update_rules(options = {})
98
+ options = { :apply_to_tree => false }.merge(options)
99
+ request_params = {
100
+ :path => path,
101
+ 'xmlRules' => rules.to_xml,
102
+ :apply_to_tree => options[:apply_to_tree] ? 1 : 0
103
+ }
104
+ response = Inforouter.client.request :set_folder_rules, request_params
105
+ result = Inforouter::Responses::SetFolderRules.parse response
106
+ result[:@success] == 'true'
107
+ end
108
+
109
+ private
110
+
111
+ # @return [Hash]
112
+ def path_params
113
+ { :path => path }
114
+ end
115
+
116
+ # @return [Hash]
117
+ def folder_params
118
+ {
119
+ :path => path,
120
+ :with_rules => 0,
121
+ 'withPropertySets' => 0,
122
+ 'withSecurity' => 0,
123
+ 'withOwner' => 0
124
+ }
125
+ end
126
+
127
+ # @return [Hash]
128
+ def folders_and_documents_params
129
+ {
130
+ :path => path,
131
+ 'withrules' => 0,
132
+ 'withPropertySets' => 0,
133
+ 'withSecurity' => 0,
134
+ 'withOwner' => 0,
135
+ 'withVersions' => 0
136
+ }
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,13 @@
1
+ module Inforouter #:nodoc:
2
+ # A generic infoRouter record.
3
+ class Record
4
+ # Initialize the record.
5
+ #
6
+ # @param attrs [Hash] Attributes defined for this record.
7
+ def initialize(attrs = {})
8
+ attrs.each do |sym, val|
9
+ send "#{sym}=", val
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ require 'inforouter/responses/base'
2
+ require 'inforouter/responses/generic'
3
+ require 'inforouter/responses/create_folder'
4
+ require 'inforouter/responses/delete_folder'
5
+ require 'inforouter/responses/document'
6
+ require 'inforouter/responses/document_exists'
7
+ require 'inforouter/responses/folder'
8
+ require 'inforouter/responses/folder_exists'
9
+ require 'inforouter/responses/set_access_list'
10
+ require 'inforouter/responses/set_folder_rules'
11
+ require 'inforouter/responses/update_folder_properties'
12
+ require 'inforouter/responses/update_property_set_definition'
13
+ require 'inforouter/responses/update_property_set_row'
14
+ require 'inforouter/responses/users'
@@ -0,0 +1,78 @@
1
+ module Inforouter #:nodoc:
2
+ module Responses #:nodoc:
3
+ # A base infoRouter SOAP response.
4
+ class Base
5
+ # Raw response.
6
+ attr_accessor :raw
7
+
8
+ # @param savon_response [Savon::Response]
9
+ def initialize(savon_response)
10
+ @raw = savon_response.to_hash
11
+ parse!
12
+ end
13
+
14
+ class << self
15
+ # Location of the response in the SOAP XML.
16
+ def response_success(value)
17
+ set_dsl(:response_success, value)
18
+ end
19
+
20
+ # Location of the error message in the SOAP XML.
21
+ def error_message(value)
22
+ set_dsl(:error_message, value)
23
+ end
24
+
25
+ # Parse a SOAP response.
26
+ #
27
+ # @param savon_response [Savon::Response]
28
+ def parse(savon_response)
29
+ new(savon_response)
30
+ end
31
+ end
32
+
33
+ # Match an element in the SOAP response
34
+ #
35
+ # @param match [String] XML path to match.
36
+ def match(chain)
37
+ current_value = raw
38
+ chain.split('/').each do |key|
39
+ current_value = current_value[key.to_sym]
40
+ next if current_value
41
+ fail Inforouter::Errors::UnexpectedSOAPResponse.new(raw, key, chain)
42
+ end
43
+ current_value
44
+ end
45
+
46
+ private
47
+
48
+ class_attribute :dsl
49
+
50
+ class << self
51
+ def set_dsl(key, value)
52
+ self.dsl ||= {}
53
+ self.dsl[key] = value
54
+ self.dsl
55
+ end
56
+
57
+ # @param date [String]
58
+ #
59
+ # @return [DateTime]
60
+ def parse_datetime(date)
61
+ DateTime.strptime(date, '%Y-%m-%d %H:%M:%S')
62
+ rescue ArgumentError
63
+ nil
64
+ end
65
+ end
66
+
67
+ def parse!
68
+ if self.dsl[:response_success]
69
+ return true if match(self.dsl[:response_success]) == 'true'
70
+ end
71
+ if self.dsl[:error_message]
72
+ return true if match(self.dsl[:error_message]) == ''
73
+ # TODO
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end