mxhero-api 0.1.16 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTkxYTllMDVlMDk4ZjdiZmFjMGY3N2E4Y2FmMTUwYTI2NTFjMzhmMA==
4
+ ODVkZTY0MWUwYTYzNWJkMTIyNmEyM2YzNDk1OGVjYThmMTM0Y2MwZQ==
5
5
  data.tar.gz: !binary |-
6
- YTNlM2I1MmVmMzViMjJiMjZmZThjMjg1YmEzNmEwZmVlYzllYjQyZg==
6
+ MDY5ZTg5ZWU0ZDZiNjA1M2ZhMDIwZTBhMjQwYTRlMjY1ODA0OWIyNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjU2M2MzYTAwZDViODMwZGYzYjJiMjY4MWE4NTQyN2NmM2E0N2IzN2UwNzEy
10
- NjQ4YWQ2YjAyYjA3OGI3NzMyODA1NzlmYmEwZmVkMDZhNWY5YzQ3YzdmMDU4
11
- OWU0MmU4YjY2NDVlMTAzMGUxMjc4NWRiNTQxZTRlOTI2NWJjNjA=
9
+ NTg3MjBiYWNhNDY0NWE3YTI5MDVlNmYzYWNkNzQ4NGJlMmVlOTYyMjUwYmNl
10
+ OTJmZjFmYWQzYjdhNGExNWM4ZGY5MDljYzk2Mjk0NjNlNjgxNTU2ZjMzM2Iw
11
+ NTRhNWE3NWVkY2M1YjhhMTYyYTFkYjg4YTdlMWVlMTM4NjdmY2U=
12
12
  data.tar.gz: !binary |-
13
- YmFjOTBmZmU0Yjk2NmI0ZDYwMjA0ZTE5NmM0OWRjOTdhMGU0ODI2NGE3MThl
14
- YjFjZGJjM2IzNGYxYmViYzYxZjJlN2U3NTg2MWUyZjVlMWU4N2MyY2ZkMzA4
15
- YjkxMDc3MDZhNTRkYmI2NmRkZjMyMjliNTlhMTg1Yjc2ODkzYjg=
13
+ ZDRkN2YyNzRkNjdiN2ZhZTlmNGJiNDFhMWQxMzJjMmMyMThlYjRiYmUzNTg3
14
+ YjBlYmEyNjljZTZjNjc3MTU4NDhlNDNiYTRmZDUzYmQ5MGFmNmIwM2E5ZWZk
15
+ YzA1NmNjMmM3YjY0N2ZlMjc3ODdlZmQxMjk5MjNhMjllOWE2ZTg=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.16
1
+ 0.1.17
@@ -0,0 +1,148 @@
1
+ module MxHero::API
2
+
3
+ class Directory
4
+ attr_accessor :domain, :type, :address, :port, :ssl,
5
+ :user, :password, :filter, :base, :next_update,
6
+ :last_update, :error, :override, :dn_authenticate,
7
+ :properties
8
+
9
+ def initialize(data = {})
10
+ return if data.empty?
11
+ [
12
+ :domain, [:type, :directoryType], [:address, :addres], :port,
13
+ [:ssl, :sslFlag], :user, :password, :filter, :base,
14
+ [:next_update, :nextUpdate],
15
+ [:last_update, :lastUpdate],
16
+ :error, [:override, :overrideFlag],
17
+ [:dn_authenticate, :dnAuthenticate],
18
+ :properties
19
+ ].each do |property|
20
+ case property
21
+ when Symbol
22
+ send "#{property}=", data[property]
23
+ when Array
24
+ send "#{property.first}=", data[property.first] || data[property.last]
25
+ end
26
+ end
27
+ end
28
+
29
+ def last_update=(date)
30
+ parse_update_dates(:last_update, date)
31
+ end
32
+
33
+ def next_update=(date)
34
+ parse_update_dates(:next_update, date)
35
+ end
36
+
37
+ def to_json
38
+ {
39
+ domain: domain,
40
+ directoryType: type,
41
+ addres: address,
42
+ port: port,
43
+ sslFlag: ssl, # || false,
44
+ user: user, password: password,
45
+ filter: filter, base: base,
46
+ nextUpdate: next_update, # || DateTime.now.strftime('%Q'),
47
+ lastUpdate: last_update, # || DateTime.now.strftime('%Q'),
48
+ error: error,
49
+ overrideFlag: override, #override.nil? ? true : override,
50
+ dnAuthenticate: dn_authenticate,
51
+ properties: properties || []
52
+ }.to_json
53
+ end
54
+
55
+ private
56
+
57
+ def parse_update_dates(property, date)
58
+ if date.is_a? Fixnum or date.is_a? String
59
+ instance_variable_set "@#{property}", DateTime.strptime(date.to_s, '%Q')
60
+ else
61
+ instance_variable_set "@#{property}", date
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ class Directories
68
+ include Communication
69
+ include Urls
70
+
71
+ attr_reader :domain
72
+
73
+ def initialize(domain, config = {})
74
+ @domain = domain
75
+ @service_url = config[:api_url]
76
+ @username = config[:username]
77
+ @password = config[:password]
78
+ @verbose = config[:verbose] || false
79
+ end
80
+
81
+
82
+ # Fetch the directory information
83
+ #
84
+ # @return [MxHero::API::Directory | nil] the directory or nil when not exist.
85
+ def fetch
86
+ response = call(:get, directories_url)
87
+ if (200..299).include? response.code
88
+ hash = json_parse response.content
89
+ return Directory.new hash
90
+ end
91
+ nil
92
+ end
93
+
94
+ # Create a directory configuration
95
+ #
96
+ # @return [MxHero::API::Response] that Directory created
97
+ # In case on error, may be one of the following:
98
+ # + domain.ldap.alredy.exists
99
+ #
100
+ def create(directory)
101
+ directory.domain = domain
102
+ response = call(:post, directories_url, directory.to_json, throw_exception: false)
103
+ wrap_response_from response
104
+ end
105
+
106
+ # Update the directory configuration
107
+ #
108
+ # @return [MxHero::API::Response] that Directory updated
109
+ # In case on error, may be one of the following:
110
+ # + domain.ldap.not.found
111
+ #
112
+ def update(directory)
113
+ directory.domain = domain
114
+ response = call(:put, directories_url, directory.to_json, throw_exception: false)
115
+ wrap_response_from response
116
+ end
117
+
118
+ # Delete the directory configuration
119
+ #
120
+ # @return [MxHero::API::Response] with content empty.
121
+ # In case on error, may be one of the following:
122
+ # + domain.ldap.not.found : Inexistent group
123
+ def delete
124
+ response = call(:delete, directories_url, throw_exception: false)
125
+ wrap_response_from response
126
+ end
127
+
128
+
129
+ # -------------------------------------------------------------------------
130
+ private
131
+
132
+ def wrap_response_from(response)
133
+ content = (200..299).include?(response.code) ? directory_from(response) : json_parse(response.content)
134
+ Response.new(response.status, content)
135
+ end
136
+
137
+ def directory_from(response)
138
+ return nil if response.content.nil? || response.content.empty?
139
+ hash = json_parse response.content
140
+ Directory.new hash
141
+ end
142
+
143
+ def directories_url
144
+ "http://test.mxhero.com/webapi/api/v1/domains/#{domain}/adldap"
145
+ end
146
+ end
147
+
148
+ end
data/lib/mxhero-api.rb CHANGED
@@ -6,6 +6,7 @@ require_relative 'communication'
6
6
  require_relative 'urls'
7
7
  require_relative 'groups'
8
8
  require_relative 'dto'
9
+ require_relative 'directories'
9
10
 
10
11
  module MxHero::API
11
12
  # The class that contains the response information
@@ -25,43 +26,48 @@ module MxHero::API
25
26
  code.to_i == 200 || code.to_i == 201
26
27
  end
27
28
 
29
+ # @return [String] the error message
30
+ def error
31
+ content[:developerMessage] if content.is_a? Hash
32
+ end
33
+
28
34
  alias_method :content, :msg
29
35
  alias_method :content=, :msg=
30
36
  end
31
37
 
32
38
 
33
- class Account
34
- attr_accessor :account, :domain, :created_date, :updated_date, :group, :properties
35
-
36
- def initialize(props = {})
37
- @account = props[:account]
38
- @domain = props[:domain]
39
- @created_date = props[:created_date] || props[:createdDate]
40
- @updated_date = props[:updated_date] || props[:updatedDate]
41
- @group = props[:group]
42
- @properties = props[:properties] || []
43
- end
44
-
45
- def to_json
46
- { account: account, domain: domain,
47
- createdDate: created_date,
48
- updatedDate: updated_date,
49
- group: group,
50
- properties: properties }.to_json
51
- end
52
-
53
- def to_s
54
- """
55
- account: #{account}
56
- domain: #{domain}
57
- updated_date: #{updated_date}
58
- created_date: #{created_date}
59
- group: #{group}
60
- properties: #{properties}
61
- """
62
- end
63
-
64
- end
39
+ #class Account
40
+ # attr_accessor :account, :domain, :created_date, :updated_date, :group, :properties
41
+ #
42
+ # def initialize(props = {})
43
+ # @account = props[:account]
44
+ # @domain = props[:domain]
45
+ # @created_date = props[:created_date] || props[:createdDate]
46
+ # @updated_date = props[:updated_date] || props[:updatedDate]
47
+ # @group = props[:group]
48
+ # @properties = props[:properties] || []
49
+ # end
50
+
51
+ # def to_json
52
+ # { account: account, domain: domain,
53
+ # createdDate: created_date,
54
+ # updatedDate: updated_date,
55
+ # group: group,
56
+ # properties: properties }.to_json
57
+ # end
58
+
59
+ # def to_s
60
+ # """
61
+ # account: #{account}
62
+ # domain: #{domain}
63
+ # updated_date: #{updated_date}
64
+ # created_date: #{created_date}
65
+ # group: #{group}
66
+ # properties: #{properties}
67
+ # """
68
+ # end
69
+
70
+ #end
65
71
 
66
72
 
67
73
  # A client to interact with mxhero engine API
data/mxhero-api.gemspec CHANGED
@@ -1,22 +1,22 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: mxhero-api 0.1.16 ruby lib
2
+ # stub: mxhero-api 0.1.17 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "mxhero-api"
6
- s.version = "0.1.16"
6
+ s.version = "0.1.17"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.authors = ["Maximiliano Dello Russo", "Juan Pablo Royo", "mxHero"]
10
- s.date = "2013-10-21"
10
+ s.date = "2013-11-19"
11
11
  s.description = "A gem to provide easy access to the API of MxHero platform (http://www.mxhero.com/)"
12
12
  s.email = ["maxidr@mxhero.com", "juanpablo.royo@gmail.com", "mxhero@mxhero.com"]
13
- s.files = [".gitignore", ".rvmrc", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "VERSION", "lib/communication.rb", "lib/dto.rb", "lib/groups.rb", "lib/mxhero-api.rb", "lib/urls.rb", "mxhero-api.gemspec", "test/fixtures/api/account_properties.yml", "test/fixtures/api/account_properties_not_found.yml", "test/fixtures/api/accounts.yml", "test/fixtures/api/accounts_filtered.yml", "test/fixtures/api/accounts_from_domain.yml", "test/fixtures/api/accounts_from_domain_paginated.yml", "test/fixtures/api/accounts_without_group.yml", "test/fixtures/api/add_an_inexistent_account_to_group.yml", "test/fixtures/api/add_and_remove_account.yml", "test/fixtures/api/all_groups.yml", "test/fixtures/api/create_rule_for_domain.yml", "test/fixtures/api/delete_group.yml", "test/fixtures/api/delete_rule.yml", "test/fixtures/api/domain_by_id.yml", "test/fixtures/api/domain_by_id_not_found.yml", "test/fixtures/api/domain_rule.yml", "test/fixtures/api/domains.yml", "test/fixtures/api/ldap_info.yml", "test/fixtures/api/remove_account_from_group_twice.yml", "test/fixtures/api/remove_inexistente_account_from_group.yml", "test/fixtures/api/rules_for_domain.yml", "test/fixtures/api/rules_for_domain_by_component.yml", "test/fixtures/api/save_group.yml", "test/fixtures/api/test_domain.yml", "test/fixtures/api/update_account_properties.yml", "test/fixtures/api/update_accounts_group_scope.yml", "test/fixtures/api/update_accounts_properties_scope.yml", "test/fixtures/api/update_rule.yml", "test/helper.rb", "test/test_dto.rb", "test/test_groups.rb", "test/test_mxhero_api.rb", "test/test_mxhero_api_response.rb"]
13
+ s.files = [".gitignore", ".rvmrc", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "VERSION", "lib/communication.rb", "lib/directories.rb", "lib/dto.rb", "lib/groups.rb", "lib/mxhero-api.rb", "lib/urls.rb", "mxhero-api.gemspec", "test/fixtures/api/account_properties.yml", "test/fixtures/api/account_properties_not_found.yml", "test/fixtures/api/accounts.yml", "test/fixtures/api/accounts_filtered.yml", "test/fixtures/api/accounts_from_domain.yml", "test/fixtures/api/accounts_from_domain_paginated.yml", "test/fixtures/api/accounts_without_group.yml", "test/fixtures/api/add_an_inexistent_account_to_group.yml", "test/fixtures/api/add_and_remove_account.yml", "test/fixtures/api/all_groups.yml", "test/fixtures/api/create_directory.yml", "test/fixtures/api/create_rule_for_domain.yml", "test/fixtures/api/delete_directory.yml", "test/fixtures/api/delete_group.yml", "test/fixtures/api/delete_rule.yml", "test/fixtures/api/domain_by_id.yml", "test/fixtures/api/domain_by_id_not_found.yml", "test/fixtures/api/domain_rule.yml", "test/fixtures/api/domains.yml", "test/fixtures/api/fetch_directory.yml", "test/fixtures/api/ldap_info.yml", "test/fixtures/api/remove_account_from_group_twice.yml", "test/fixtures/api/remove_inexistente_account_from_group.yml", "test/fixtures/api/rules_for_domain.yml", "test/fixtures/api/rules_for_domain_by_component.yml", "test/fixtures/api/save_group.yml", "test/fixtures/api/test_domain.yml", "test/fixtures/api/update_account_properties.yml", "test/fixtures/api/update_accounts_group_scope.yml", "test/fixtures/api/update_accounts_properties_scope.yml", "test/fixtures/api/update_directory.yml", "test/fixtures/api/update_rule.yml", "test/helper.rb", "test/test_directories.rb", "test/test_dto.rb", "test/test_groups.rb", "test/test_mxhero_api.rb", "test/test_mxhero_api_response.rb"]
14
14
  s.homepage = "http://github.com/mxhero/mxhero-api"
15
15
  s.licenses = ["GPL-3"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubygems_version = "2.1.9"
18
18
  s.summary = "A MxHero API client for ruby"
19
- s.test_files = ["test/fixtures/api/account_properties.yml", "test/fixtures/api/account_properties_not_found.yml", "test/fixtures/api/accounts.yml", "test/fixtures/api/accounts_filtered.yml", "test/fixtures/api/accounts_from_domain.yml", "test/fixtures/api/accounts_from_domain_paginated.yml", "test/fixtures/api/accounts_without_group.yml", "test/fixtures/api/add_an_inexistent_account_to_group.yml", "test/fixtures/api/add_and_remove_account.yml", "test/fixtures/api/all_groups.yml", "test/fixtures/api/create_rule_for_domain.yml", "test/fixtures/api/delete_group.yml", "test/fixtures/api/delete_rule.yml", "test/fixtures/api/domain_by_id.yml", "test/fixtures/api/domain_by_id_not_found.yml", "test/fixtures/api/domain_rule.yml", "test/fixtures/api/domains.yml", "test/fixtures/api/ldap_info.yml", "test/fixtures/api/remove_account_from_group_twice.yml", "test/fixtures/api/remove_inexistente_account_from_group.yml", "test/fixtures/api/rules_for_domain.yml", "test/fixtures/api/rules_for_domain_by_component.yml", "test/fixtures/api/save_group.yml", "test/fixtures/api/test_domain.yml", "test/fixtures/api/update_account_properties.yml", "test/fixtures/api/update_accounts_group_scope.yml", "test/fixtures/api/update_accounts_properties_scope.yml", "test/fixtures/api/update_rule.yml", "test/helper.rb", "test/test_dto.rb", "test/test_groups.rb", "test/test_mxhero_api.rb", "test/test_mxhero_api_response.rb"]
19
+ s.test_files = ["test/fixtures/api/account_properties.yml", "test/fixtures/api/account_properties_not_found.yml", "test/fixtures/api/accounts.yml", "test/fixtures/api/accounts_filtered.yml", "test/fixtures/api/accounts_from_domain.yml", "test/fixtures/api/accounts_from_domain_paginated.yml", "test/fixtures/api/accounts_without_group.yml", "test/fixtures/api/add_an_inexistent_account_to_group.yml", "test/fixtures/api/add_and_remove_account.yml", "test/fixtures/api/all_groups.yml", "test/fixtures/api/create_directory.yml", "test/fixtures/api/create_rule_for_domain.yml", "test/fixtures/api/delete_directory.yml", "test/fixtures/api/delete_group.yml", "test/fixtures/api/delete_rule.yml", "test/fixtures/api/domain_by_id.yml", "test/fixtures/api/domain_by_id_not_found.yml", "test/fixtures/api/domain_rule.yml", "test/fixtures/api/domains.yml", "test/fixtures/api/fetch_directory.yml", "test/fixtures/api/ldap_info.yml", "test/fixtures/api/remove_account_from_group_twice.yml", "test/fixtures/api/remove_inexistente_account_from_group.yml", "test/fixtures/api/rules_for_domain.yml", "test/fixtures/api/rules_for_domain_by_component.yml", "test/fixtures/api/save_group.yml", "test/fixtures/api/test_domain.yml", "test/fixtures/api/update_account_properties.yml", "test/fixtures/api/update_accounts_group_scope.yml", "test/fixtures/api/update_accounts_properties_scope.yml", "test/fixtures/api/update_directory.yml", "test/fixtures/api/update_rule.yml", "test/helper.rb", "test/test_directories.rb", "test/test_dto.rb", "test/test_groups.rb", "test/test_mxhero_api.rb", "test/test_mxhero_api_response.rb"]
20
20
 
21
21
  if s.respond_to? :specification_version then
22
22
  s.specification_version = 4
@@ -0,0 +1,78 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/test.com/adldap
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"domain":"test.com","directoryType":"gapps","addres":null,"port":null,"sslFlag":null,"user":"user","password":"password","filter":null,"base":null,"nextUpdate":null,"lastUpdate":null,"error":null,"overrideFlag":null,"dnAuthenticate":null,"properties":[]}'
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Content-Type:
13
+ - application/json
14
+ Authorization:
15
+ - Basic YWRtaW46cGFzc3dvcmQ=
16
+ response:
17
+ status:
18
+ code: 201
19
+ message: !binary |-
20
+ Q3JlYXRlZA==
21
+ headers:
22
+ !binary "RGF0ZQ==":
23
+ - !binary |-
24
+ TW9uLCAxOCBOb3YgMjAxMyAyMTo0MzoxMCBHTVQ=
25
+ !binary "U2VydmVy":
26
+ - !binary |-
27
+ QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
28
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
29
+ - !binary |-
30
+ Y2h1bmtlZA==
31
+ !binary "Q29udGVudC1UeXBl":
32
+ - !binary |-
33
+ YXBwbGljYXRpb24vanNvbg==
34
+ body:
35
+ encoding: US-ASCII
36
+ string: ! '{"domain":"test.com","directoryType":"gapps","addres":null,"port":null,"sslFlag":false,"user":"user","password":"password","filter":null,"base":null,"nextUpdate":1384810990000,"lastUpdate":null,"error":null,"overrideFlag":false,"dnAuthenticate":null,"properties":[]}'
37
+ http_version:
38
+ recorded_at: Mon, 18 Nov 2013 21:43:10 GMT
39
+ - request:
40
+ method: post
41
+ uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/test.com/adldap
42
+ body:
43
+ encoding: UTF-8
44
+ string: ! '{"domain":"test.com","directoryType":"gapps","addres":null,"port":null,"sslFlag":null,"user":"user","password":"password","filter":null,"base":null,"nextUpdate":null,"lastUpdate":null,"error":null,"overrideFlag":null,"dnAuthenticate":null,"properties":[]}'
45
+ headers:
46
+ Accept:
47
+ - application/json
48
+ Content-Type:
49
+ - application/json
50
+ Authorization:
51
+ - Basic YWRtaW46cGFzc3dvcmQ=
52
+ response:
53
+ status:
54
+ code: 500
55
+ message: !binary |-
56
+ SW50ZXJuYWwgU2VydmVyIEVycm9y
57
+ headers:
58
+ !binary "RGF0ZQ==":
59
+ - !binary |-
60
+ TW9uLCAxOCBOb3YgMjAxMyAyMTo0MzoxMCBHTVQ=
61
+ !binary "U2VydmVy":
62
+ - !binary |-
63
+ QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
64
+ !binary "Q29ubmVjdGlvbg==":
65
+ - !binary |-
66
+ Y2xvc2U=
67
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
68
+ - !binary |-
69
+ Y2h1bmtlZA==
70
+ !binary "Q29udGVudC1UeXBl":
71
+ - !binary |-
72
+ YXBwbGljYXRpb24vanNvbg==
73
+ body:
74
+ encoding: US-ASCII
75
+ string: ! '{"status":500,"code":500,"developerMessage":"domain.ldap.already.exists","moreInfoUrl":"mailto:support@mxhero.com"}'
76
+ http_version:
77
+ recorded_at: Mon, 18 Nov 2013 21:43:10 GMT
78
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,113 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: delete
5
+ uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/test.com/adldap
6
+ body:
7
+ encoding: ASCII-8BIT
8
+ string: !binary |-
9
+ dGhyb3dfZXhjZXB0aW9uPWZhbHNl
10
+ headers:
11
+ Accept:
12
+ - application/json
13
+ Content-Type:
14
+ - application/json
15
+ Authorization:
16
+ - Basic YWRtaW46cGFzc3dvcmQ=
17
+ response:
18
+ status:
19
+ code: 200
20
+ message: !binary |-
21
+ T0s=
22
+ headers:
23
+ !binary "RGF0ZQ==":
24
+ - !binary |-
25
+ TW9uLCAxOCBOb3YgMjAxMyAyMTo0Mzo1MyBHTVQ=
26
+ !binary "U2VydmVy":
27
+ - !binary |-
28
+ QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
29
+ !binary "Q29udGVudC1MZW5ndGg=":
30
+ - !binary |-
31
+ MA==
32
+ !binary "Q29udGVudC1UeXBl":
33
+ - !binary |-
34
+ dGV4dC9wbGFpbg==
35
+ body:
36
+ encoding: US-ASCII
37
+ string: ''
38
+ http_version:
39
+ recorded_at: Mon, 18 Nov 2013 21:43:52 GMT
40
+ - request:
41
+ method: get
42
+ uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/test.com/adldap
43
+ body:
44
+ encoding: US-ASCII
45
+ string: ''
46
+ headers:
47
+ Accept:
48
+ - application/json
49
+ Content-Type:
50
+ - application/json
51
+ Authorization:
52
+ - Basic YWRtaW46cGFzc3dvcmQ=
53
+ response:
54
+ status:
55
+ code: 404
56
+ message: !binary |-
57
+ Tm90IEZvdW5k
58
+ headers:
59
+ !binary "RGF0ZQ==":
60
+ - !binary |-
61
+ TW9uLCAxOCBOb3YgMjAxMyAyMTo0Mzo1MyBHTVQ=
62
+ !binary "U2VydmVy":
63
+ - !binary |-
64
+ QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
65
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
66
+ - !binary |-
67
+ Y2h1bmtlZA==
68
+ !binary "Q29udGVudC1UeXBl":
69
+ - !binary |-
70
+ YXBwbGljYXRpb24vanNvbg==
71
+ body:
72
+ encoding: US-ASCII
73
+ string: ! '{"status":404,"code":404,"message":"domain.ldap.not.found","developerMessage":"domain.ldap.not.found","moreInfoUrl":"mailto:support@mxhero.com"}'
74
+ http_version:
75
+ recorded_at: Mon, 18 Nov 2013 21:43:53 GMT
76
+ - request:
77
+ method: delete
78
+ uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/test.com/adldap
79
+ body:
80
+ encoding: ASCII-8BIT
81
+ string: !binary |-
82
+ dGhyb3dfZXhjZXB0aW9uPWZhbHNl
83
+ headers:
84
+ Accept:
85
+ - application/json
86
+ Content-Type:
87
+ - application/json
88
+ Authorization:
89
+ - Basic YWRtaW46cGFzc3dvcmQ=
90
+ response:
91
+ status:
92
+ code: 404
93
+ message: !binary |-
94
+ Tm90IEZvdW5k
95
+ headers:
96
+ !binary "RGF0ZQ==":
97
+ - !binary |-
98
+ TW9uLCAxOCBOb3YgMjAxMyAyMTo0Mzo1MyBHTVQ=
99
+ !binary "U2VydmVy":
100
+ - !binary |-
101
+ QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
102
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
103
+ - !binary |-
104
+ Y2h1bmtlZA==
105
+ !binary "Q29udGVudC1UeXBl":
106
+ - !binary |-
107
+ YXBwbGljYXRpb24vanNvbg==
108
+ body:
109
+ encoding: US-ASCII
110
+ string: ! '{"status":404,"code":404,"message":"domain.ldap.not.found","developerMessage":"domain.ldap.not.found","moreInfoUrl":"mailto:support@mxhero.com"}'
111
+ http_version:
112
+ recorded_at: Mon, 18 Nov 2013 21:43:53 GMT
113
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,39 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/test.com/adldap
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Content-Type:
13
+ - application/json
14
+ Authorization:
15
+ - Basic YWRtaW46cGFzc3dvcmQ=
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: !binary |-
20
+ T0s=
21
+ headers:
22
+ !binary "RGF0ZQ==":
23
+ - !binary |-
24
+ TW9uLCAxOCBOb3YgMjAxMyAyMTo0MjowMCBHTVQ=
25
+ !binary "U2VydmVy":
26
+ - !binary |-
27
+ QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
28
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
29
+ - !binary |-
30
+ Y2h1bmtlZA==
31
+ !binary "Q29udGVudC1UeXBl":
32
+ - !binary |-
33
+ YXBwbGljYXRpb24vanNvbg==
34
+ body:
35
+ encoding: US-ASCII
36
+ string: ! '{"domain":"test.com","directoryType":"gapps","addres":null,"port":null,"sslFlag":false,"user":"user","password":"password","filter":null,"base":null,"nextUpdate":1384810741000,"lastUpdate":null,"error":null,"overrideFlag":false,"dnAuthenticate":null,"properties":[]}'
37
+ http_version:
38
+ recorded_at: Mon, 18 Nov 2013 21:42:00 GMT
39
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,111 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/test.com/adldap
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Content-Type:
13
+ - application/json
14
+ Authorization:
15
+ - Basic YWRtaW46cGFzc3dvcmQ=
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: !binary |-
20
+ T0s=
21
+ headers:
22
+ !binary "RGF0ZQ==":
23
+ - !binary |-
24
+ TW9uLCAxOCBOb3YgMjAxMyAyMTo0MzozNiBHTVQ=
25
+ !binary "U2VydmVy":
26
+ - !binary |-
27
+ QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
28
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
29
+ - !binary |-
30
+ Y2h1bmtlZA==
31
+ !binary "Q29udGVudC1UeXBl":
32
+ - !binary |-
33
+ YXBwbGljYXRpb24vanNvbg==
34
+ body:
35
+ encoding: US-ASCII
36
+ string: ! '{"domain":"test.com","directoryType":"gapps","addres":null,"port":null,"sslFlag":false,"user":"user","password":"password","filter":null,"base":null,"nextUpdate":1384810990000,"lastUpdate":null,"error":null,"overrideFlag":false,"dnAuthenticate":null,"properties":[]}'
37
+ http_version:
38
+ recorded_at: Mon, 18 Nov 2013 21:43:36 GMT
39
+ - request:
40
+ method: put
41
+ uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/test.com/adldap
42
+ body:
43
+ encoding: UTF-8
44
+ string: ! '{"domain":"test.com","directoryType":"zimbra","addres":"zertifikate.telekom.de","port":"389","sslFlag":true,"user":"user","password":"password","filter":null,"base":"cn","nextUpdate":"2013-11-18T21:43:10+00:00","lastUpdate":null,"error":null,"overrideFlag":false,"dnAuthenticate":null,"properties":[]}'
45
+ headers:
46
+ Accept:
47
+ - application/json
48
+ Content-Type:
49
+ - application/json
50
+ Authorization:
51
+ - Basic YWRtaW46cGFzc3dvcmQ=
52
+ response:
53
+ status:
54
+ code: 200
55
+ message: !binary |-
56
+ T0s=
57
+ headers:
58
+ !binary "RGF0ZQ==":
59
+ - !binary |-
60
+ TW9uLCAxOCBOb3YgMjAxMyAyMTo0MzozNiBHTVQ=
61
+ !binary "U2VydmVy":
62
+ - !binary |-
63
+ QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
64
+ !binary "Q29udGVudC1MZW5ndGg=":
65
+ - !binary |-
66
+ MA==
67
+ !binary "Q29udGVudC1UeXBl":
68
+ - !binary |-
69
+ dGV4dC9wbGFpbg==
70
+ body:
71
+ encoding: US-ASCII
72
+ string: ''
73
+ http_version:
74
+ recorded_at: Mon, 18 Nov 2013 21:43:36 GMT
75
+ - request:
76
+ method: get
77
+ uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/test.com/adldap
78
+ body:
79
+ encoding: US-ASCII
80
+ string: ''
81
+ headers:
82
+ Accept:
83
+ - application/json
84
+ Content-Type:
85
+ - application/json
86
+ Authorization:
87
+ - Basic YWRtaW46cGFzc3dvcmQ=
88
+ response:
89
+ status:
90
+ code: 200
91
+ message: !binary |-
92
+ T0s=
93
+ headers:
94
+ !binary "RGF0ZQ==":
95
+ - !binary |-
96
+ TW9uLCAxOCBOb3YgMjAxMyAyMTo0MzozNyBHTVQ=
97
+ !binary "U2VydmVy":
98
+ - !binary |-
99
+ QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
100
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
101
+ - !binary |-
102
+ Y2h1bmtlZA==
103
+ !binary "Q29udGVudC1UeXBl":
104
+ - !binary |-
105
+ YXBwbGljYXRpb24vanNvbg==
106
+ body:
107
+ encoding: US-ASCII
108
+ string: ! '{"domain":"test.com","directoryType":"zimbra","addres":"zertifikate.telekom.de","port":"389","sslFlag":true,"user":"user","password":"password","filter":null,"base":"cn","nextUpdate":1384810990000,"lastUpdate":null,"error":null,"overrideFlag":false,"dnAuthenticate":null,"properties":[]}'
109
+ http_version:
110
+ recorded_at: Mon, 18 Nov 2013 21:43:36 GMT
111
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,85 @@
1
+ require_relative 'helper'
2
+
3
+ class DirectoriesTest < MiniTest::Unit::TestCase
4
+ def setup
5
+ @dirs = MxHero::API::Directories.new(domain,
6
+ username: TEST_API_USER,
7
+ password: TEST_API_PASSWORD,
8
+ verbose: false, api_url: TEST_API_URL)
9
+ end
10
+
11
+ def domain
12
+ 'test.com'
13
+ end
14
+
15
+ def test_fetch
16
+ VCR.use_cassette('fetch_directory') do
17
+ directory = @dirs.fetch
18
+ assert_equal domain, directory.domain
19
+ assert_equal 'gapps', directory.type
20
+ end
21
+ end
22
+
23
+ def test_create
24
+ directory = MxHero::API::Directory.new(domain: 'test.com', type: 'gapps',
25
+ user: 'user', password: 'password')
26
+
27
+ VCR.use_cassette('create_directory') do
28
+ response = @dirs.create directory
29
+ assert response.success?
30
+
31
+ # try to create again
32
+ response = @dirs.create directory
33
+ assert ! response.success?
34
+ assert_equal 'domain.ldap.already.exists', response.error
35
+ end
36
+ end
37
+
38
+ def test_update
39
+ VCR.use_cassette('update_directory') do
40
+ directory = @dirs.fetch
41
+ directory.ssl = true
42
+ directory.base = 'cn'
43
+ directory.type = 'zimbra'
44
+ directory.address = 'zertifikate.telekom.de'
45
+ directory.port = '389'
46
+ directory.user = 'user'
47
+ directory.password = 'password'
48
+
49
+ assert @dirs.update(directory).success?
50
+
51
+ updated = @dirs.fetch
52
+
53
+ assert_equal directory.ssl, updated.ssl
54
+ assert_equal directory.base, updated.base
55
+ assert_equal directory.type, updated.type
56
+ assert_equal directory.address, updated.address
57
+ assert_equal directory.port, updated.port
58
+ assert_equal directory.user, updated.user
59
+ assert_equal directory.password, updated.password
60
+ end
61
+ end
62
+
63
+ def test_delete
64
+ VCR.use_cassette('delete_directory') do
65
+ deleted = @dirs.delete
66
+ assert deleted.success?
67
+ assert_nil @dirs.fetch
68
+
69
+ # try to remove inexistent directory
70
+ deleted = @dirs.delete
71
+ assert ! deleted.success?
72
+ assert_equal 'domain.ldap.not.found', deleted.error
73
+ end
74
+ end
75
+
76
+ def test_updates_dates
77
+ directory = MxHero::API::Directory.new
78
+ directory.next_update = 1379949740000
79
+ directory.last_update = '1379949740000'
80
+ expected = "2013-09-23T15:22:20+00:00"
81
+ assert_equal expected, directory.next_update.to_s #23-09-2013 12:22
82
+ assert_equal expected, directory.last_update.to_s #23-09-2013 12:22
83
+ end
84
+ end
85
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mxhero-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maximiliano Dello Russo
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-10-21 00:00:00.000000000 Z
13
+ date: 2013-11-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: vcr
@@ -71,6 +71,7 @@ files:
71
71
  - Rakefile
72
72
  - VERSION
73
73
  - lib/communication.rb
74
+ - lib/directories.rb
74
75
  - lib/dto.rb
75
76
  - lib/groups.rb
76
77
  - lib/mxhero-api.rb
@@ -86,13 +87,16 @@ files:
86
87
  - test/fixtures/api/add_an_inexistent_account_to_group.yml
87
88
  - test/fixtures/api/add_and_remove_account.yml
88
89
  - test/fixtures/api/all_groups.yml
90
+ - test/fixtures/api/create_directory.yml
89
91
  - test/fixtures/api/create_rule_for_domain.yml
92
+ - test/fixtures/api/delete_directory.yml
90
93
  - test/fixtures/api/delete_group.yml
91
94
  - test/fixtures/api/delete_rule.yml
92
95
  - test/fixtures/api/domain_by_id.yml
93
96
  - test/fixtures/api/domain_by_id_not_found.yml
94
97
  - test/fixtures/api/domain_rule.yml
95
98
  - test/fixtures/api/domains.yml
99
+ - test/fixtures/api/fetch_directory.yml
96
100
  - test/fixtures/api/ldap_info.yml
97
101
  - test/fixtures/api/remove_account_from_group_twice.yml
98
102
  - test/fixtures/api/remove_inexistente_account_from_group.yml
@@ -103,8 +107,10 @@ files:
103
107
  - test/fixtures/api/update_account_properties.yml
104
108
  - test/fixtures/api/update_accounts_group_scope.yml
105
109
  - test/fixtures/api/update_accounts_properties_scope.yml
110
+ - test/fixtures/api/update_directory.yml
106
111
  - test/fixtures/api/update_rule.yml
107
112
  - test/helper.rb
113
+ - test/test_directories.rb
108
114
  - test/test_dto.rb
109
115
  - test/test_groups.rb
110
116
  - test/test_mxhero_api.rb
@@ -144,13 +150,16 @@ test_files:
144
150
  - test/fixtures/api/add_an_inexistent_account_to_group.yml
145
151
  - test/fixtures/api/add_and_remove_account.yml
146
152
  - test/fixtures/api/all_groups.yml
153
+ - test/fixtures/api/create_directory.yml
147
154
  - test/fixtures/api/create_rule_for_domain.yml
155
+ - test/fixtures/api/delete_directory.yml
148
156
  - test/fixtures/api/delete_group.yml
149
157
  - test/fixtures/api/delete_rule.yml
150
158
  - test/fixtures/api/domain_by_id.yml
151
159
  - test/fixtures/api/domain_by_id_not_found.yml
152
160
  - test/fixtures/api/domain_rule.yml
153
161
  - test/fixtures/api/domains.yml
162
+ - test/fixtures/api/fetch_directory.yml
154
163
  - test/fixtures/api/ldap_info.yml
155
164
  - test/fixtures/api/remove_account_from_group_twice.yml
156
165
  - test/fixtures/api/remove_inexistente_account_from_group.yml
@@ -161,9 +170,12 @@ test_files:
161
170
  - test/fixtures/api/update_account_properties.yml
162
171
  - test/fixtures/api/update_accounts_group_scope.yml
163
172
  - test/fixtures/api/update_accounts_properties_scope.yml
173
+ - test/fixtures/api/update_directory.yml
164
174
  - test/fixtures/api/update_rule.yml
165
175
  - test/helper.rb
176
+ - test/test_directories.rb
166
177
  - test/test_dto.rb
167
178
  - test/test_groups.rb
168
179
  - test/test_mxhero_api.rb
169
180
  - test/test_mxhero_api_response.rb
181
+ has_rdoc: