mxhero-api 0.1.7 → 0.1.8
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 +31 -3
- data/mxhero-api.gemspec +4 -4
- data/test/fixtures/api/accounts_from_domain_paginated.yml +39 -0
- data/test/test_mxhero_api.rb +9 -0
- metadata +5 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.8
|
data/lib/mxhero-api.rb
CHANGED
@@ -161,9 +161,13 @@ module MxHero
|
|
161
161
|
parse_response(response, on_empty: [])
|
162
162
|
end
|
163
163
|
|
164
|
+
#
|
164
165
|
# Retrive all the account from one domain
|
165
166
|
#
|
166
|
-
#
|
167
|
+
# @params [String] domain
|
168
|
+
# @param [Hash] pagination
|
169
|
+
# @option pagination [Fixnum] :limit of elements per page
|
170
|
+
# @option pagination [Fixnum] :offset number of page (start in 1)
|
167
171
|
#
|
168
172
|
# @return [Hash] with the following elements:
|
169
173
|
# * :elements [Array<Hash>] the list of accounts as a Hash, when any element contains:
|
@@ -182,12 +186,13 @@ module MxHero
|
|
182
186
|
# * :actualPage [Fixnum]
|
183
187
|
#
|
184
188
|
# @raise an exception when the status code isn't 200
|
185
|
-
def accounts_by_domain(domain)
|
186
|
-
url = accounts_by_domain_url(domain)
|
189
|
+
def accounts_by_domain(domain, pagination = {})
|
190
|
+
url = paginate accounts_by_domain_url(domain), pagination
|
187
191
|
response = call(:get, url)
|
188
192
|
json_parse(response.content)
|
189
193
|
end
|
190
194
|
|
195
|
+
|
191
196
|
# @return [Boolean] true when operation it's ok
|
192
197
|
def delete_rule(domain, id)
|
193
198
|
url = domain_rule_url(domain, id)
|
@@ -227,6 +232,29 @@ module MxHero
|
|
227
232
|
end
|
228
233
|
|
229
234
|
private
|
235
|
+
|
236
|
+
|
237
|
+
# Complete the URL with the pagination info (:limit and :offset)
|
238
|
+
# @param [String] original URL. Ex.: http://www.example.com/api/accounts
|
239
|
+
# @param [Hash] pagination
|
240
|
+
# @option pagination [Fixnum] :limit of elements per page
|
241
|
+
# @option pagination [Fixnum] :offset number of page (start in 1)
|
242
|
+
#
|
243
|
+
# @return [String] the URL with the pagination parameters.
|
244
|
+
# Ex.: url: http://www.example.com/api/accounts
|
245
|
+
# pagination: { limit: 4, offset: 2 }
|
246
|
+
# return > http://www.example.com/api/accounts?limit=4&offset=2
|
247
|
+
def paginate(url, pagination)
|
248
|
+
paginated = url.dup
|
249
|
+
connector = url.include?('?') ? '&' : '?'
|
250
|
+
[ :limit, :offset ].map do |elem|
|
251
|
+
if pagination.key? elem
|
252
|
+
paginated << "#{connector}#{elem.to_s}=#{pagination[elem]}"
|
253
|
+
connector = '&'
|
254
|
+
end
|
255
|
+
end
|
256
|
+
paginated
|
257
|
+
end
|
230
258
|
|
231
259
|
def account_properties_to_json(properties)
|
232
260
|
out = []
|
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.8"
|
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-08-
|
9
|
+
s.date = "2013-08-15"
|
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/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/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_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/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/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/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_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/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,39 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://admin:password@localhost:8080/webapi/api/v1/domains/tesla.com/accounts?limit=4&offset=1
|
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 "U2VydmVy":
|
23
|
+
- !binary |-
|
24
|
+
QXBhY2hlLUNveW90ZS8xLjE=
|
25
|
+
!binary "Q29udGVudC1UeXBl":
|
26
|
+
- !binary |-
|
27
|
+
YXBwbGljYXRpb24vanNvbg==
|
28
|
+
!binary "VHJhbnNmZXItRW5jb2Rpbmc=":
|
29
|
+
- !binary |-
|
30
|
+
Y2h1bmtlZA==
|
31
|
+
!binary "RGF0ZQ==":
|
32
|
+
- !binary |-
|
33
|
+
U2F0LCAxMCBBdWcgMjAxMyAwMzozNToxNSBHTVQ=
|
34
|
+
body:
|
35
|
+
encoding: US-ASCII
|
36
|
+
string: ! '{"elements":[{"account":"test","domain":"tesla.com","createdDate":1376065216000,"updatedDate":1376069631000,"group":null,"aliases":[{"name":"test","domain":"tesla.com","dataSource":"manual"}],"dataSource":"manual"},{"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":6,"totalPages":2,"actualPage":1}'
|
37
|
+
http_version:
|
38
|
+
recorded_at: Thu, 15 Aug 2013 21:29:19 GMT
|
39
|
+
recorded_with: VCR 2.5.0
|
data/test/test_mxhero_api.rb
CHANGED
@@ -92,6 +92,15 @@ class MxHeroAPITest < MiniTest::Unit::TestCase
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
+
def test_accounts_by_domain_paginated
|
96
|
+
VCR.use_cassette('accounts_from_domain_paginated') do
|
97
|
+
response = @api.accounts_by_domain(domain, limit: 4, offset: 1)
|
98
|
+
must_have_the_keys(response, %w( elements totalElements totalPages actualPage ))
|
99
|
+
assert_equal 4, response[:elements].count
|
100
|
+
assert_equal 1, response[:actualPage]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
95
104
|
def test_delete_rule
|
96
105
|
VCR.use_cassette('delete_rule') do
|
97
106
|
rules = obtain_rules(domain)
|
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.8
|
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-08-
|
14
|
+
date: 2013-08-15 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: vcr
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- test/fixtures/api/account_properties.yml
|
83
83
|
- test/fixtures/api/account_properties_not_found.yml
|
84
84
|
- test/fixtures/api/accounts_from_domain.yml
|
85
|
+
- test/fixtures/api/accounts_from_domain_paginated.yml
|
85
86
|
- test/fixtures/api/create_rule_alredy_exist.yml
|
86
87
|
- test/fixtures/api/create_rule_for_domain.yml
|
87
88
|
- test/fixtures/api/create_rule_success.yml
|
@@ -111,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
112
|
version: '0'
|
112
113
|
segments:
|
113
114
|
- 0
|
114
|
-
hash: -
|
115
|
+
hash: -3291556788727679228
|
115
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
117
|
none: false
|
117
118
|
requirements:
|
@@ -128,6 +129,7 @@ test_files:
|
|
128
129
|
- test/fixtures/api/account_properties.yml
|
129
130
|
- test/fixtures/api/account_properties_not_found.yml
|
130
131
|
- test/fixtures/api/accounts_from_domain.yml
|
132
|
+
- test/fixtures/api/accounts_from_domain_paginated.yml
|
131
133
|
- test/fixtures/api/create_rule_alredy_exist.yml
|
132
134
|
- test/fixtures/api/create_rule_for_domain.yml
|
133
135
|
- test/fixtures/api/create_rule_success.yml
|