mxhero-api 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mxhero-api.rb +17 -8
- data/mxhero-api.gemspec +4 -4
- data/test/fixtures/api/accounts_filtered.yml +96 -0
- data/test/test_mxhero_api.rb +13 -0
- metadata +5 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.11
|
data/lib/mxhero-api.rb
CHANGED
@@ -169,9 +169,12 @@ module MxHero
|
|
169
169
|
# Retrive all the account from one domain
|
170
170
|
#
|
171
171
|
# @params [String] domain
|
172
|
-
# @
|
173
|
-
# @
|
174
|
-
# @option
|
172
|
+
# @params [String] filter_account the account to filter in the list. This can be a part of an account.
|
173
|
+
# @param [Hash] refinement
|
174
|
+
# @option refinement [Fixnum] :limit of elements per page
|
175
|
+
# @option refinement [Fixnum] :offset number of page (start in 1)
|
176
|
+
# @option refinement [String] :account filter accounts that start with this value
|
177
|
+
#
|
175
178
|
#
|
176
179
|
# @return [Hash] with the following elements:
|
177
180
|
# * :elements [Array<Hash>] the list of accounts as a Hash, when any element contains:
|
@@ -190,8 +193,12 @@ module MxHero
|
|
190
193
|
# * :actualPage [Fixnum]
|
191
194
|
#
|
192
195
|
# @raise an exception when the status code isn't 200
|
193
|
-
def accounts_by_domain(domain, pagination = {})
|
194
|
-
|
196
|
+
def accounts_by_domain(domain, refinement = {}) #filter_account = nil, pagination = {})
|
197
|
+
params = refinement.dup
|
198
|
+
filter_account = params.delete(:account)
|
199
|
+
limit, offset = params.values_at(:limit, :offset)
|
200
|
+
|
201
|
+
url = paginate accounts_by_domain_url(domain, filter_account), { limit: limit, offset: offset }
|
195
202
|
response = call(:get, url)
|
196
203
|
json_parse(response.content)
|
197
204
|
end
|
@@ -252,7 +259,7 @@ module MxHero
|
|
252
259
|
paginated = url.dup
|
253
260
|
connector = url.include?('?') ? '&' : '?'
|
254
261
|
[ :limit, :offset ].map do |elem|
|
255
|
-
if pagination
|
262
|
+
if pagination[elem]
|
256
263
|
paginated << "#{connector}#{elem.to_s}=#{pagination[elem]}"
|
257
264
|
connector = '&'
|
258
265
|
end
|
@@ -293,6 +300,7 @@ module MxHero
|
|
293
300
|
unless more_options[:throw_exception] == false
|
294
301
|
raise "An error ocurred when try to communicate with the API\nError: #{response}" if (500..600).include?(response.status)
|
295
302
|
end
|
303
|
+
|
296
304
|
response
|
297
305
|
end
|
298
306
|
|
@@ -313,8 +321,9 @@ module MxHero
|
|
313
321
|
service_url + '/domains'
|
314
322
|
end
|
315
323
|
|
316
|
-
def accounts_by_domain_url(domain)
|
317
|
-
|
324
|
+
def accounts_by_domain_url(domain, filter_account = nil)
|
325
|
+
filter = filter_account ? "?account=#{filter_account}" : ''
|
326
|
+
domain_by_id_url(domain) + 'accounts' + filter
|
318
327
|
end
|
319
328
|
|
320
329
|
def domain_by_id_url(domain)
|
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.11"
|
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-
|
9
|
+
s.date = "2013-09-10"
|
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/mxhero-api.rb", "mxhero-api.gemspec", "test/fixtures/api/account_properties.yml", "test/fixtures/api/account_properties_not_found.yml", "test/fixtures/api/accounts_from_domain.yml", "test/fixtures/api/accounts_from_domain_paginated.yml", "test/fixtures/api/create_rule_alredy_exist.yml", "test/fixtures/api/create_rule_for_domain.yml", "test/fixtures/api/create_rule_success.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/rules_for_domain.yml", "test/fixtures/api/rules_for_domain_by_component.yml", "test/fixtures/api/update_account_properties.yml", "test/fixtures/api/update_rule.yml", "test/helper.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/mxhero-api.rb", "mxhero-api.gemspec", "test/fixtures/api/account_properties.yml", "test/fixtures/api/account_properties_not_found.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/create_rule_alredy_exist.yml", "test/fixtures/api/create_rule_for_domain.yml", "test/fixtures/api/create_rule_success.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/rules_for_domain.yml", "test/fixtures/api/rules_for_domain_by_component.yml", "test/fixtures/api/update_account_properties.yml", "test/fixtures/api/update_rule.yml", "test/helper.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_from_domain.yml", "test/fixtures/api/accounts_from_domain_paginated.yml", "test/fixtures/api/create_rule_alredy_exist.yml", "test/fixtures/api/create_rule_for_domain.yml", "test/fixtures/api/create_rule_success.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/rules_for_domain.yml", "test/fixtures/api/rules_for_domain_by_component.yml", "test/fixtures/api/update_account_properties.yml", "test/fixtures/api/update_rule.yml", "test/helper.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_filtered.yml", "test/fixtures/api/accounts_from_domain.yml", "test/fixtures/api/accounts_from_domain_paginated.yml", "test/fixtures/api/create_rule_alredy_exist.yml", "test/fixtures/api/create_rule_for_domain.yml", "test/fixtures/api/create_rule_success.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/rules_for_domain.yml", "test/fixtures/api/rules_for_domain_by_component.yml", "test/fixtures/api/update_account_properties.yml", "test/fixtures/api/update_rule.yml", "test/helper.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,96 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://admin:password@localhost:8080/webapi/api/v1/domains/tesla.com/accounts?account=user
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
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: OK
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- Apache-Coyote/1.1
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
Transfer-Encoding:
|
26
|
+
- chunked
|
27
|
+
Date:
|
28
|
+
- Sat, 10 Aug 2013 21:24:29 GMT
|
29
|
+
body:
|
30
|
+
encoding: UTF-8
|
31
|
+
string: '{"elements":[{"account":"user_1","domain":"tesla.com","createdDate":1376105684000,"updatedDate":1376105684000,"group":null,"aliases":[{"name":"user_1","domain":"tesla.com","dataSource":"manual"}],"dataSource":"manual"},{"account":"user_2","domain":"tesla.com","createdDate":1376105691000,"updatedDate":1376105691000,"group":null,"aliases":[{"name":"user_2","domain":"tesla.com","dataSource":"manual"}],"dataSource":"manual"},{"account":"user_3","domain":"tesla.com","createdDate":1376105698000,"updatedDate":1376105698000,"group":null,"aliases":[{"name":"user_3","domain":"tesla.com","dataSource":"manual"}],"dataSource":"manual"}],"totalElements":3,"totalPages":1,"actualPage":1}'
|
32
|
+
http_version:
|
33
|
+
recorded_at: Tue, 10 Sep 2013 15:07:05 GMT
|
34
|
+
- request:
|
35
|
+
method: get
|
36
|
+
uri: http://admin:password@localhost:8080/webapi/api/v1/domains/tesla.com/accounts?account=test
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: ''
|
40
|
+
headers:
|
41
|
+
Accept:
|
42
|
+
- application/json
|
43
|
+
Content-Type:
|
44
|
+
- application/json
|
45
|
+
Authorization:
|
46
|
+
- Basic YWRtaW46cGFzc3dvcmQ=
|
47
|
+
response:
|
48
|
+
status:
|
49
|
+
code: 200
|
50
|
+
message: OK
|
51
|
+
headers:
|
52
|
+
Server:
|
53
|
+
- Apache-Coyote/1.1
|
54
|
+
Content-Type:
|
55
|
+
- application/json
|
56
|
+
Transfer-Encoding:
|
57
|
+
- chunked
|
58
|
+
Date:
|
59
|
+
- Sat, 10 Aug 2013 21:24:29 GMT
|
60
|
+
body:
|
61
|
+
encoding: UTF-8
|
62
|
+
string: '{"elements":[{"account":"test","domain":"tesla.com","createdDate":1376065216000,"updatedDate":1376069631000,"group":null,"aliases":[{"name":"test","domain":"tesla.com","dataSource":"manual"}],"dataSource":"manual"}],"totalElements":1,"totalPages":1,"actualPage":1}'
|
63
|
+
http_version:
|
64
|
+
recorded_at: Tue, 10 Sep 2013 15:07:05 GMT
|
65
|
+
- request:
|
66
|
+
method: get
|
67
|
+
uri: http://admin:password@localhost:8080/webapi/api/v1/domains/tesla.com/accounts?account=user_2
|
68
|
+
body:
|
69
|
+
encoding: UTF-8
|
70
|
+
string: ''
|
71
|
+
headers:
|
72
|
+
Accept:
|
73
|
+
- application/json
|
74
|
+
Content-Type:
|
75
|
+
- application/json
|
76
|
+
Authorization:
|
77
|
+
- Basic YWRtaW46cGFzc3dvcmQ=
|
78
|
+
response:
|
79
|
+
status:
|
80
|
+
code: 200
|
81
|
+
message: OK
|
82
|
+
headers:
|
83
|
+
Server:
|
84
|
+
- Apache-Coyote/1.1
|
85
|
+
Content-Type:
|
86
|
+
- application/json
|
87
|
+
Transfer-Encoding:
|
88
|
+
- chunked
|
89
|
+
Date:
|
90
|
+
- Sat, 10 Aug 2013 21:24:29 GMT
|
91
|
+
body:
|
92
|
+
encoding: UTF-8
|
93
|
+
string: '{"elements":[{"account":"user_2","domain":"tesla.com","createdDate":1376105691000,"updatedDate":1376105691000,"group":null,"aliases":[{"name":"user_2","domain":"tesla.com","dataSource":"manual"}],"dataSource":"manual"}],"totalElements":1,"totalPages":1,"actualPage":1}'
|
94
|
+
http_version:
|
95
|
+
recorded_at: Tue, 10 Sep 2013 15:07:05 GMT
|
96
|
+
recorded_with: VCR 2.5.0
|
data/test/test_mxhero_api.rb
CHANGED
@@ -110,6 +110,19 @@ class MxHeroAPITest < MiniTest::Unit::TestCase
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
+
def test_accounts_by_domain_filtered
|
114
|
+
VCR.use_cassette('accounts_filtered') do
|
115
|
+
# The test environment have 4 accounts:
|
116
|
+
# user_1, user_2, user_3 and test
|
117
|
+
response = @api.accounts_by_domain(domain, account: 'user')
|
118
|
+
assert_equal 3, response[:elements].count
|
119
|
+
response = @api.accounts_by_domain(domain, account: 'test')
|
120
|
+
assert_equal 1, response[:elements].count
|
121
|
+
response = @api.accounts_by_domain(domain, account: 'user_2')
|
122
|
+
assert_equal 1, response[:elements].count
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
113
126
|
def test_accounts_by_domain_paginated
|
114
127
|
VCR.use_cassette('accounts_from_domain_paginated') do
|
115
128
|
response = @api.accounts_by_domain(domain, limit: 4, offset: 1)
|
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.11
|
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-
|
14
|
+
date: 2013-09-10 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: vcr
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- mxhero-api.gemspec
|
82
82
|
- test/fixtures/api/account_properties.yml
|
83
83
|
- test/fixtures/api/account_properties_not_found.yml
|
84
|
+
- test/fixtures/api/accounts_filtered.yml
|
84
85
|
- test/fixtures/api/accounts_from_domain.yml
|
85
86
|
- test/fixtures/api/accounts_from_domain_paginated.yml
|
86
87
|
- test/fixtures/api/create_rule_alredy_exist.yml
|
@@ -113,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
114
|
version: '0'
|
114
115
|
segments:
|
115
116
|
- 0
|
116
|
-
hash:
|
117
|
+
hash: 1574735906110401669
|
117
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
119
|
none: false
|
119
120
|
requirements:
|
@@ -129,6 +130,7 @@ summary: A MxHero API client for ruby
|
|
129
130
|
test_files:
|
130
131
|
- test/fixtures/api/account_properties.yml
|
131
132
|
- test/fixtures/api/account_properties_not_found.yml
|
133
|
+
- test/fixtures/api/accounts_filtered.yml
|
132
134
|
- test/fixtures/api/accounts_from_domain.yml
|
133
135
|
- test/fixtures/api/accounts_from_domain_paginated.yml
|
134
136
|
- test/fixtures/api/create_rule_alredy_exist.yml
|