mxhero-api 0.1.22 → 0.1.23

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
- YTU2MzgzYTcyNzVhODRmOTM5MGU5MDZkN2Y0ZmVjM2JhYjg0YjA2Mg==
4
+ YjA2M2I2OTM1ZjljNWM0ZTQ0Mjk5ZGQzN2JlM2IwZjI0M2ZlZmVmMA==
5
5
  data.tar.gz: !binary |-
6
- NjQ5MDE2MmNlYjE2YjJhOGY3ZDQ4NmMxMjhjMjk5MWRhYzMzNjY4MQ==
6
+ M2ViZWM4NWVlN2M1YTg0Yzg4NGVhNTBiZTBkOGRhZjQzMjE5YjRhMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzJlZGNjZTUzZmZkNGViY2VkY2Q2ZjA5ZjkwYzE5MGRhY2VlMDE4Yzk2OWM1
10
- N2RlMmJhMjA1YzI1MzczMzQwMzY3OWJiZjdjYWFjMDllNDE1YzJmMjVhN2Vl
11
- ZjFlNDkzMDEwZDc2ZDY2YmNhNmIzZDYyZDQzNGNhNThiN2E4OTE=
9
+ M2QzN2EzMWQxYmE0YzA2NTgzMWYzYmE3YWYwMDFlZGYxZmFhMjNjN2Y3ZjNi
10
+ ZDVmMDE4MmFhMTdjYjI1MjhmNjYzMzM3NmRkZDgyMDg0ZTdmYmJlZWIzZjY1
11
+ ZGViMmJlYjVhZTIwMjg1NjA5YWVlZjA5ZmEzMDY4OGM2NWZkMjc=
12
12
  data.tar.gz: !binary |-
13
- NGY4NjVjOWUzYTI1ZDQ1OWExZDZiOWJiNzU3ZmQ4NmU1M2ZjOTkzN2Y5ZDY3
14
- NzUzZTM0M2UzMjMxNjcwN2M4MjI0NTFjNjVlNjM3MTNiNmUyOGIyYzQyM2Mz
15
- ZDgzNjllMzMwZGM2ZTI2NjJkNDVjNjk5ZjkwYzRhYTdiMWNmMzM=
13
+ OTEwY2EwYTk3NDU1YjdmMDgxYTNlZjNkNDU1YzU3M2IyNWI2OThlOWVlZGEy
14
+ ZTQ3ZWE3MjAxOTkwMzdlODkxNmY2NTc2ZTcxN2EyMGNjMWExOGFkZjEzMjEy
15
+ MWJlNGI2OTc4ZDBhN2NlMzQzN2Q1ZDFjN2JjZDYzNzJiZTIwYjE=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.22
1
+ 0.1.23
data/lib/directories.rb CHANGED
@@ -14,8 +14,7 @@ module MxHero::API
14
14
  [:next_update, :nextUpdate],
15
15
  [:last_update, :lastUpdate],
16
16
  :error, [:override, :overrideFlag],
17
- [:dn_authenticate, :dnAuthenticate],
18
- :properties
17
+ [:dn_authenticate, :dnAuthenticate]
19
18
  ].each do |property|
20
19
  case property
21
20
  when Symbol
@@ -24,8 +23,10 @@ module MxHero::API
24
23
  send "#{property.first}=", data[property.first] || data[property.last]
25
24
  end
26
25
  end
26
+ load_properties(data)
27
27
  end
28
28
 
29
+
29
30
  def last_update=(date)
30
31
  parse_update_dates(:last_update, date)
31
32
  end
@@ -38,7 +39,7 @@ module MxHero::API
38
39
  properties.each { |prop, value| send("#{prop}=", value) if respond_to?("#{prop}=") }
39
40
  end
40
41
 
41
- def to_json
42
+ def to_hash
42
43
  {
43
44
  domain: domain,
44
45
  directoryType: type,
@@ -52,12 +53,33 @@ module MxHero::API
52
53
  error: error,
53
54
  overrideFlag: override, #override.nil? ? true : override,
54
55
  dnAuthenticate: dn_authenticate,
55
- properties: properties || []
56
- }.to_json
56
+ properties: properties_field_to_hash
57
+ }
58
+ end
59
+
60
+ def to_json
61
+ to_hash.to_json
57
62
  end
58
63
 
59
64
  private
60
65
 
66
+ def load_properties(data)
67
+ @properties ||= {}
68
+ props = data[:properties]
69
+ case props
70
+ when Array then (props || []).each { |property| @properties[property[:name].to_sym] = property[:key] }
71
+ when Hash then @properties = props
72
+ end
73
+ end
74
+
75
+ def properties_field_to_hash
76
+ values = []
77
+ (properties || []).each do |name, value|
78
+ values << { name: name, key: value }
79
+ end
80
+ values
81
+ end
82
+
61
83
  def parse_update_dates(property, date)
62
84
  if date.is_a? Integer or date.is_a? String
63
85
  instance_variable_set "@#{property}", DateTime.strptime(date.to_s, '%Q')
data/mxhero-api.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: mxhero-api 0.1.22 ruby lib
2
+ # stub: mxhero-api 0.1.23 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "mxhero-api"
6
- s.version = "0.1.22"
6
+ s.version = "0.1.23"
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"]
@@ -108,5 +108,39 @@ class DirectoriesTest < MiniTest::Unit::TestCase
108
108
  directory.update_properties changes
109
109
  changes.keys.each { |prop| assert_equal changes[prop], directory.send(prop) }
110
110
  end
111
+
112
+ def test_initialize_properties
113
+ directory = MxHero::API::Directory.new domain: domain,
114
+ properties: [ {name: 'email', key: 'ldap.email'}, {name: 'name', key: 'user.name'} ]
115
+
116
+ assert_equal({ email: 'ldap.email', name: 'user.name' }, directory.properties)
117
+
118
+ directory = MxHero::API::Directory.new domain: domain,
119
+ properties: { email: 'ldap.email', name: 'user.name' }
120
+
121
+ assert_equal({ email: 'ldap.email', name: 'user.name' }, directory.properties)
122
+ end
123
+
124
+ def test_properties_to_json
125
+ directory = MxHero::API::Directory.new domain: domain,
126
+ properties: { email: 'ldap.email', name: 'user.name' }
127
+
128
+ expected = {
129
+ domain: directory.domain, directoryType: directory.type,
130
+ addres: directory.address, port: directory.port, sslFlag: directory.ssl,
131
+ user: directory.user, password: directory.password, filter: directory.filter,
132
+ base: directory.base, nextUpdate: directory.next_update,
133
+ lastUpdate: directory.last_update, error: directory.error,
134
+ overrideFlag: directory.override, dnAuthenticate: directory.dn_authenticate,
135
+ properties: [ { name: 'email', key:'ldap.email' }, { name: 'name', key: 'user.name' } ]
136
+ }
137
+
138
+ assert_equal expected.to_json, directory.to_json
139
+
140
+ directory = MxHero::API::Directory.new domain: domain
141
+ expected[:properties] = []
142
+ assert_equal expected.to_json, directory.to_json
143
+ end
144
+
111
145
  end
112
146
 
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.22
4
+ version: 0.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maximiliano Dello Russo