mxhero-api 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/dto.rb +32 -0
- data/lib/mxhero-api.rb +63 -1
- data/mxhero-api.gemspec +4 -4
- data/test/fixtures/api/update_accounts_group_scope.yml +75 -0
- data/test/fixtures/api/update_accounts_properties_scope.yml +111 -0
- data/test/test_dto.rb +28 -0
- data/test/test_mxhero_api.rb +27 -0
- metadata +10 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.14
|
data/lib/dto.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# DTO class allows to create a structure that support
|
2
|
+
# export to json and construct with a hash.
|
3
|
+
#
|
4
|
+
# Example of use:
|
5
|
+
#
|
6
|
+
# class User < DTO.new(:first_name, :last_name, :birthday)
|
7
|
+
#
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# or
|
11
|
+
#
|
12
|
+
# User = Class.new(DTO.new :first_name, :last_name, :birthday)
|
13
|
+
#
|
14
|
+
class DTO < Struct
|
15
|
+
|
16
|
+
def initialize(attrs = {})
|
17
|
+
members.each do |member|
|
18
|
+
send("#{member}=", attrs[member])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_json
|
23
|
+
attrs = {}
|
24
|
+
members.each { |attr| attrs[attr] = send(attr) }
|
25
|
+
attrs.to_json
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
members.map { |attr| "#{attr}: #{send(attr)}" }.join(", ")
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/lib/mxhero-api.rb
CHANGED
@@ -5,6 +5,7 @@ require 'json'
|
|
5
5
|
require_relative 'communication'
|
6
6
|
require_relative 'urls'
|
7
7
|
require_relative 'groups'
|
8
|
+
require_relative 'dto'
|
8
9
|
|
9
10
|
module MxHero::API
|
10
11
|
# The class that contains the response information
|
@@ -28,6 +29,41 @@ module MxHero::API
|
|
28
29
|
alias_method :content=, :msg=
|
29
30
|
end
|
30
31
|
|
32
|
+
|
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
|
65
|
+
|
66
|
+
|
31
67
|
# A client to interact with mxhero engine API
|
32
68
|
class Client
|
33
69
|
include Communication
|
@@ -159,7 +195,7 @@ module MxHero::API
|
|
159
195
|
def accounts_without_group_url(domain, filter_account)
|
160
196
|
domain_by_id_url(domain) + "/groups/accounts/available?account=#{filter_account}"
|
161
197
|
end
|
162
|
-
|
198
|
+
|
163
199
|
def verbose?
|
164
200
|
@verbose
|
165
201
|
end
|
@@ -258,8 +294,34 @@ module MxHero::API
|
|
258
294
|
parse_response(response)
|
259
295
|
end
|
260
296
|
|
297
|
+
#
|
298
|
+
# @param [String] domain
|
299
|
+
# @param [Array<Hash>] accounts. An array of hash with :account and :properties. The :properties
|
300
|
+
# contains a Hash with the equivalent of name and value.
|
301
|
+
# @param [String] scope :groups, :properties or :both (default: properties)
|
302
|
+
#
|
303
|
+
def update_accounts(domain, accounts, scope = :properties)
|
304
|
+
scope_param = scope == :both ? 'groups,properties' : scope.to_s
|
305
|
+
#url = "/domains/#{domain}/accounts/upload?scope=#{scope_param}"
|
306
|
+
url = accounts_by_domain_url(domain) + "/upload?scope=#{scope_param}"
|
307
|
+
|
308
|
+
message = []
|
309
|
+
accounts.each do |account|
|
310
|
+
properties = remap_properties(account[:properties])
|
311
|
+
#message << { account: account[:account], properties: properties, group: account[:group], domain: domain }
|
312
|
+
message << { account: account[:account], properties: properties, group: account[:group] }
|
313
|
+
end
|
314
|
+
response = call(:put, url, message.to_json) # accounts to json
|
315
|
+
parse_response(response)
|
316
|
+
end
|
317
|
+
|
318
|
+
# --------------------------------------------------------------------------------------------------------------------------------
|
261
319
|
private
|
262
320
|
|
321
|
+
def remap_properties(properties)
|
322
|
+
return nil if properties.nil?
|
323
|
+
properties.keys.map { |name| { name: name, value: properties[name] } }
|
324
|
+
end
|
263
325
|
|
264
326
|
# Complete the URL with the pagination info (:limit and :offset)
|
265
327
|
# @param [String] original URL. Ex.: http://www.example.com/api/accounts
|
data/mxhero-api.gemspec
CHANGED
@@ -2,20 +2,20 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "mxhero-api"
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.14"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Maximiliano Dello Russo", "Juan Pablo Royo", "mxHero"]
|
9
|
-
s.date = "2013-09-
|
9
|
+
s.date = "2013-09-30"
|
10
10
|
s.description = "A gem to provide easy access to the API of MxHero platform (http://www.mxhero.com/)"
|
11
11
|
s.email = ["maxidr@mxhero.com", "juanpablo.royo@gmail.com", "mxhero@mxhero.com"]
|
12
|
-
s.files = [".gitignore", ".rvmrc", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "VERSION", "lib/communication.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/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/update_account_properties.yml", "test/fixtures/api/update_rule.yml", "test/helper.rb", "test/test_groups.rb", "test/test_mxhero_api.rb", "test/test_mxhero_api_response.rb"]
|
12
|
+
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/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/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
13
|
s.homepage = "http://github.com/mxhero/mxhero-api"
|
14
14
|
s.licenses = ["GPL-3"]
|
15
15
|
s.require_paths = ["lib"]
|
16
16
|
s.rubygems_version = "1.8.25"
|
17
17
|
s.summary = "A MxHero API client for ruby"
|
18
|
-
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/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/update_account_properties.yml", "test/fixtures/api/update_rule.yml", "test/helper.rb", "test/test_groups.rb", "test/test_mxhero_api.rb", "test/test_mxhero_api_response.rb"]
|
18
|
+
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/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/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
19
|
|
20
20
|
if s.respond_to? :specification_version then
|
21
21
|
s.specification_version = 3
|
@@ -0,0 +1,75 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: put
|
5
|
+
uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/tesla.com/accounts/upload?scope=groups
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: ! '[{"account":"john.doe","properties":null,"group":"development"}]'
|
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
|
+
TW9uLCAzMCBTZXAgMjAxMyAxNDoxMDoyMyBHTVQ=
|
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: ! '[{"account":"john.doe","domain":null,"createdDate":null,"updatedDate":null,"group":"development","aliases":null,"dataSource":null,"properties":null}]'
|
37
|
+
http_version:
|
38
|
+
recorded_at: Mon, 30 Sep 2013 14:10:23 GMT
|
39
|
+
- request:
|
40
|
+
method: get
|
41
|
+
uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/tesla.com/accounts?account=john.doe&limit=&offset=
|
42
|
+
body:
|
43
|
+
encoding: US-ASCII
|
44
|
+
string: ''
|
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
|
+
TW9uLCAzMCBTZXAgMjAxMyAxNDoxMDoyMyBHTVQ=
|
61
|
+
!binary "U2VydmVy":
|
62
|
+
- !binary |-
|
63
|
+
QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
|
64
|
+
!binary "VHJhbnNmZXItRW5jb2Rpbmc=":
|
65
|
+
- !binary |-
|
66
|
+
Y2h1bmtlZA==
|
67
|
+
!binary "Q29udGVudC1UeXBl":
|
68
|
+
- !binary |-
|
69
|
+
YXBwbGljYXRpb24vanNvbg==
|
70
|
+
body:
|
71
|
+
encoding: US-ASCII
|
72
|
+
string: ! '{"elements":[{"account":"john.doe","domain":"tesla.com","createdDate":1378759081000,"updatedDate":1380550173000,"group":"development","aliases":[{"name":"john.doe","domain":"tesla.com","dataSource":"manual"}],"dataSource":"manual","properties":null}],"totalElements":1,"totalPages":1,"actualPage":1}'
|
73
|
+
http_version:
|
74
|
+
recorded_at: Mon, 30 Sep 2013 14:10:23 GMT
|
75
|
+
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/tesla.com/accounts/john.doe/properties
|
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
|
+
RnJpLCAyNyBTZXAgMjAxMyAxOTo1MjozNyBHTVQ=
|
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: ! '[{"name":"email","value":""},{"name":"fax","value":""},{"name":"lastname","value":""},{"name":"mobile","value":"011212011011"},{"name":"name","value":""},{"name":"opt1","value":""},{"name":"opt2","value":""},{"name":"opt3","value":""},{"name":"telephone","value":""}]'
|
37
|
+
http_version:
|
38
|
+
recorded_at: Fri, 27 Sep 2013 19:52:37 GMT
|
39
|
+
- request:
|
40
|
+
method: put
|
41
|
+
uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/tesla.com/accounts/upload?scope=properties
|
42
|
+
body:
|
43
|
+
encoding: UTF-8
|
44
|
+
string: ! '[{"account":"john.doe","properties":[{"name":"email","value":""},{"name":"fax","value":""},{"name":"lastname","value":""},{"name":"mobile","value":"011212011011011"},{"name":"name","value":""},{"name":"opt1","value":""},{"name":"opt2","value":""},{"name":"opt3","value":""},{"name":"telephone","value":""}]}]'
|
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
|
+
RnJpLCAyNyBTZXAgMjAxMyAxOTo1MjozOCBHTVQ=
|
61
|
+
!binary "U2VydmVy":
|
62
|
+
- !binary |-
|
63
|
+
QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
|
64
|
+
!binary "VHJhbnNmZXItRW5jb2Rpbmc=":
|
65
|
+
- !binary |-
|
66
|
+
Y2h1bmtlZA==
|
67
|
+
!binary "Q29udGVudC1UeXBl":
|
68
|
+
- !binary |-
|
69
|
+
YXBwbGljYXRpb24vanNvbg==
|
70
|
+
body:
|
71
|
+
encoding: US-ASCII
|
72
|
+
string: ! '[]'
|
73
|
+
http_version:
|
74
|
+
recorded_at: Fri, 27 Sep 2013 19:52:38 GMT
|
75
|
+
- request:
|
76
|
+
method: get
|
77
|
+
uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/tesla.com/accounts/john.doe/properties
|
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
|
+
RnJpLCAyNyBTZXAgMjAxMyAxOTo1MjozOCBHTVQ=
|
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: ! '[{"name":"email","value":""},{"name":"fax","value":""},{"name":"lastname","value":""},{"name":"mobile","value":"011212011011011"},{"name":"name","value":""},{"name":"opt1","value":""},{"name":"opt2","value":""},{"name":"opt3","value":""},{"name":"telephone","value":""}]'
|
109
|
+
http_version:
|
110
|
+
recorded_at: Fri, 27 Sep 2013 19:52:38 GMT
|
111
|
+
recorded_with: VCR 2.5.0
|
data/test/test_dto.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class User < DTO.new(:first_name, :last_name)
|
4
|
+
end
|
5
|
+
|
6
|
+
class DTOTest < MiniTest::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@user = User.new(first_name: 'John', last_name: 'Doe', another: 'Yeah!')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_accessors
|
12
|
+
assert_equal 'John', @user.first_name
|
13
|
+
assert_equal 'Doe', @user.last_name
|
14
|
+
refute @user.respond_to? :another
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_to_json
|
18
|
+
assert_equal({ first_name: 'John', last_name: 'Doe' }.to_json, @user.to_json)
|
19
|
+
another = Class.new(DTO.new :first_name, :childs )
|
20
|
+
with_childs = another.new(first_name: 'Jess', childs: [ 'Albert', 'Margo' ])
|
21
|
+
assert_equal({ first_name: 'Jess', childs: ['Albert', 'Margo']}.to_json, with_childs.to_json)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_to_s
|
25
|
+
expected = "first_name: John, last_name: Doe"
|
26
|
+
assert_equal expected, @user.to_s
|
27
|
+
end
|
28
|
+
end
|
data/test/test_mxhero_api.rb
CHANGED
@@ -219,6 +219,33 @@ class MxHeroAPITest < MiniTest::Unit::TestCase
|
|
219
219
|
assert_equal properties['fax'], response.msg['fax']
|
220
220
|
end
|
221
221
|
end
|
222
|
+
|
223
|
+
def test_update_accounts_group_scope
|
224
|
+
VCR.use_cassette('update_accounts_group_scope') do
|
225
|
+
|
226
|
+
accounts = [ { account: 'john.doe', group: 'development' } ]
|
227
|
+
response = @api.update_accounts(domain, accounts, :groups)
|
228
|
+
account = @api.accounts_by_domain(domain, account: 'john.doe')[:elements].first
|
229
|
+
assert_equal 'development', account[:group]
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_update_accounts_properties_scope
|
234
|
+
VCR.use_cassette('update_accounts_properties_scope') do
|
235
|
+
props = @api.account_properties(domain, 'john.doe').msg
|
236
|
+
changed = props.clone
|
237
|
+
original = changed['mobile']
|
238
|
+
changed['mobile'] = original + '011'
|
239
|
+
|
240
|
+
accounts = [ { account: 'john.doe', properties: changed } ]
|
241
|
+
|
242
|
+
@api.update_accounts(domain, accounts, :properties)
|
243
|
+
|
244
|
+
properties = @api.account_properties(domain, 'john.doe').msg
|
245
|
+
assert_equal original + '011', properties['mobile']
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
222
249
|
|
223
250
|
private
|
224
251
|
|
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.
|
4
|
+
version: 0.1.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-09-
|
14
|
+
date: 2013-09-30 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: vcr
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- Rakefile
|
79
79
|
- VERSION
|
80
80
|
- lib/communication.rb
|
81
|
+
- lib/dto.rb
|
81
82
|
- lib/groups.rb
|
82
83
|
- lib/mxhero-api.rb
|
83
84
|
- lib/urls.rb
|
@@ -105,8 +106,11 @@ files:
|
|
105
106
|
- test/fixtures/api/rules_for_domain_by_component.yml
|
106
107
|
- test/fixtures/api/save_group.yml
|
107
108
|
- test/fixtures/api/update_account_properties.yml
|
109
|
+
- test/fixtures/api/update_accounts_group_scope.yml
|
110
|
+
- test/fixtures/api/update_accounts_properties_scope.yml
|
108
111
|
- test/fixtures/api/update_rule.yml
|
109
112
|
- test/helper.rb
|
113
|
+
- test/test_dto.rb
|
110
114
|
- test/test_groups.rb
|
111
115
|
- test/test_mxhero_api.rb
|
112
116
|
- test/test_mxhero_api_response.rb
|
@@ -125,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
129
|
version: '0'
|
126
130
|
segments:
|
127
131
|
- 0
|
128
|
-
hash:
|
132
|
+
hash: -22379060016314683
|
129
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
134
|
none: false
|
131
135
|
requirements:
|
@@ -162,8 +166,11 @@ test_files:
|
|
162
166
|
- test/fixtures/api/rules_for_domain_by_component.yml
|
163
167
|
- test/fixtures/api/save_group.yml
|
164
168
|
- test/fixtures/api/update_account_properties.yml
|
169
|
+
- test/fixtures/api/update_accounts_group_scope.yml
|
170
|
+
- test/fixtures/api/update_accounts_properties_scope.yml
|
165
171
|
- test/fixtures/api/update_rule.yml
|
166
172
|
- test/helper.rb
|
173
|
+
- test/test_dto.rb
|
167
174
|
- test/test_groups.rb
|
168
175
|
- test/test_mxhero_api.rb
|
169
176
|
- test/test_mxhero_api_response.rb
|