mxhero-api 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/mxhero-api.rb +40 -5
- data/mxhero-api.gemspec +3 -3
- data/test/fixtures/api/accounts_from_domain.yml +39 -0
- data/test/helper.rb +1 -1
- data/test/test_mxhero_api.rb +19 -1
- metadata +4 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/mxhero-api.rb
CHANGED
@@ -95,7 +95,8 @@ module MxHero
|
|
95
95
|
# * :updateDate [Fixnum]
|
96
96
|
# * :aliases
|
97
97
|
# * :ldap
|
98
|
-
# @raise an exception when the status code
|
98
|
+
# @raise an exception when the status code is one of the 5xx status error
|
99
|
+
# @raise an exception if @param id is nil
|
99
100
|
def domain_by_id(id = nil)
|
100
101
|
raise 'Id domain could not be nil' if id.nil?
|
101
102
|
response = call(:get, domain_by_id_url(id))
|
@@ -133,7 +134,6 @@ module MxHero
|
|
133
134
|
|
134
135
|
# Create a rule
|
135
136
|
#
|
136
|
-
# @param domain [String]
|
137
137
|
# @param [Hash] msg
|
138
138
|
# @option msg [String] :domain
|
139
139
|
# @option msg [Boolean] :twoWays
|
@@ -147,7 +147,7 @@ module MxHero
|
|
147
147
|
#
|
148
148
|
# @return [MxHero::API::Response]
|
149
149
|
def create_rule(msg)
|
150
|
-
response = call(:post, rules_url, msg.to_json)
|
150
|
+
response = call(:post, rules_url, msg.to_json, throw_exception: false)
|
151
151
|
parse_response(response)
|
152
152
|
end
|
153
153
|
|
@@ -161,6 +161,33 @@ module MxHero
|
|
161
161
|
parse_response(response, on_empty: [])
|
162
162
|
end
|
163
163
|
|
164
|
+
# Retrive all the account from one domain
|
165
|
+
#
|
166
|
+
# TODO: Improve the response. We really need manage pagination here?
|
167
|
+
#
|
168
|
+
# @return [Hash] with the following elements:
|
169
|
+
# * :elements [Array<Hash>] the list of accounts as a Hash, when any element contains:
|
170
|
+
# * :account [String] example: alex
|
171
|
+
# * :domain [String] example: mxhero.com
|
172
|
+
# * :createdDate [Fixnum] example: 1375909565000 (epoch format)
|
173
|
+
# * :updatedDate [Fixnum]
|
174
|
+
# * :group [String]
|
175
|
+
# * :aliases [Array<Hash>] the list of aliases of one account
|
176
|
+
# * :name [String]
|
177
|
+
# * :domain [String]
|
178
|
+
# * :dataSource [String]
|
179
|
+
# * :dataSource [String]
|
180
|
+
# * :totalElements [Fixnum]
|
181
|
+
# * :totalPages [Fixnum]
|
182
|
+
# * :actualPage [Fixnum]
|
183
|
+
#
|
184
|
+
# @raise an exception when the status code isn't 200
|
185
|
+
def accounts_by_domain(domain)
|
186
|
+
url = accounts_by_domain_url(domain)
|
187
|
+
response = call(:get, url)
|
188
|
+
json_parse(response.content)
|
189
|
+
end
|
190
|
+
|
164
191
|
private
|
165
192
|
|
166
193
|
# @return [MxHero::API::Response] a response object
|
@@ -179,11 +206,15 @@ module MxHero
|
|
179
206
|
# @param method [Symbol] indicate the HTTP verb (:get, :post, :put, etc)
|
180
207
|
# @param url [String]
|
181
208
|
# @param body [String] (default: nil)
|
182
|
-
|
209
|
+
# @param [Hash] more_options
|
210
|
+
# @option more_options [Boolean] :throw_exception (default: true) throw exception if the response status are between 500 and 600
|
211
|
+
def call(method, url, body = nil, more_options = {})
|
183
212
|
client = HTTPClient.new
|
184
213
|
client.set_auth(url, @username, @password)
|
185
214
|
response = client.request(method, url, nil, body, headers)
|
186
|
-
|
215
|
+
unless more_options[:throw_exception] == false
|
216
|
+
raise 'an error ocurred when try to communicate with the API' if (500..600).include?(response.status)
|
217
|
+
end
|
187
218
|
response
|
188
219
|
end
|
189
220
|
|
@@ -204,6 +235,10 @@ module MxHero
|
|
204
235
|
service_url + '/domains'
|
205
236
|
end
|
206
237
|
|
238
|
+
def accounts_by_domain_url(domain)
|
239
|
+
domain_by_id_url(domain) + 'accounts'
|
240
|
+
end
|
241
|
+
|
207
242
|
def domain_by_id_url(domain)
|
208
243
|
domains_url + "/#{domain}/"
|
209
244
|
end
|
data/mxhero-api.gemspec
CHANGED
@@ -2,19 +2,19 @@
|
|
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.3"
|
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
9
|
s.date = "2013-08-07"
|
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", "README.md", "Rakefile", "VERSION", "lib/mxhero-api.rb", "mxhero-api.gemspec", "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/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/service_create_footer.yml", "test/fixtures/api/service_footer_for_domain.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", "README.md", "Rakefile", "VERSION", "lib/mxhero-api.rb", "mxhero-api.gemspec", "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/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/service_create_footer.yml", "test/fixtures/api/service_footer_for_domain.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.require_paths = ["lib"]
|
15
15
|
s.rubygems_version = "1.8.25"
|
16
16
|
s.summary = "A MxHero API client for ruby"
|
17
|
-
s.test_files = ["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/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/service_create_footer.yml", "test/fixtures/api/service_footer_for_domain.yml", "test/fixtures/api/update_rule.yml", "test/helper.rb", "test/test_mxhero_api.rb", "test/test_mxhero_api_response.rb"]
|
17
|
+
s.test_files = ["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/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/service_create_footer.yml", "test/fixtures/api/service_footer_for_domain.yml", "test/fixtures/api/update_rule.yml", "test/helper.rb", "test/test_mxhero_api.rb", "test/test_mxhero_api_response.rb"]
|
18
18
|
|
19
19
|
if s.respond_to? :specification_version then
|
20
20
|
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/mxhero.com/accounts
|
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
|
+
V2VkLCAwNyBBdWcgMjAxMyAyMTo0MjoyMyBHTVQ=
|
25
|
+
!binary "U2VydmVy":
|
26
|
+
- !binary |-
|
27
|
+
QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
|
28
|
+
!binary "Q29udGVudC1MZW5ndGg=":
|
29
|
+
- !binary |-
|
30
|
+
MjkwMg==
|
31
|
+
!binary "Q29udGVudC1UeXBl":
|
32
|
+
- !binary |-
|
33
|
+
YXBwbGljYXRpb24vanNvbg==
|
34
|
+
body:
|
35
|
+
encoding: US-ASCII
|
36
|
+
string: ! '{"elements":[{"account":"alex","domain":"mxhero.com","createdDate":1375909565000,"updatedDate":1375909565000,"group":null,"aliases":[{"name":"alex","domain":"hero.mx","dataSource":"manual"},{"name":"alex","domain":"mxhero.com","dataSource":"manual"},{"name":"alex","domain":"mxhero.net","dataSource":"manual"},{"name":"alex","domain":"mxhero.org","dataSource":"manual"}],"dataSource":"manual"},{"account":"bruno","domain":"mxhero.com","createdDate":1375909591000,"updatedDate":1375909591000,"group":null,"aliases":[{"name":"bcsantos","domain":"hero.mx","dataSource":"manual"},{"name":"bcsantos","domain":"mxhero.com","dataSource":"manual"},{"name":"bcsantos","domain":"mxhero.net","dataSource":"manual"},{"name":"bcsantos","domain":"mxhero.org","dataSource":"manual"},{"name":"bruno","domain":"mxhero.com","dataSource":"manual"}],"dataSource":"manual"},{"account":"gussoler","domain":"mxhero.com","createdDate":1375909608000,"updatedDate":1375909608000,"group":null,"aliases":[{"name":"gussoler","domain":"hero.mx","dataSource":"manual"},{"name":"gussoler","domain":"mxhero.com","dataSource":"manual"},{"name":"gussoler","domain":"mxhero.net","dataSource":"manual"},{"name":"gussoler","domain":"mxhero.org","dataSource":"manual"}],"dataSource":"manual"},{"account":"jproyo","domain":"mxhero.com","createdDate":1375909608000,"updatedDate":1375909608000,"group":null,"aliases":[{"name":"jproyo","domain":"hero.mx","dataSource":"manual"},{"name":"jproyo","domain":"mxhero.com","dataSource":"manual"},{"name":"jproyo","domain":"mxhero.net","dataSource":"manual"}],"dataSource":"manual"},{"account":"martinm","domain":"mxhero.com","createdDate":1375909591000,"updatedDate":1375909591000,"group":null,"aliases":[{"name":"martinm","domain":"hero.mx","dataSource":"manual"},{"name":"martinm","domain":"mxhero.com","dataSource":"manual"},{"name":"martinm","domain":"mxhero.net","dataSource":"manual"}],"dataSource":"manual"},{"account":"maxidr","domain":"mxhero.com","createdDate":1375909624000,"updatedDate":1375909624000,"group":null,"aliases":[{"name":"maxidr","domain":"hero.mx","dataSource":"manual"},{"name":"maxidr","domain":"mxhero.com","dataSource":"manual"},{"name":"maxidr","domain":"mxhero.net","dataSource":"manual"},{"name":"maxidr","domain":"mxhero.org","dataSource":"manual"}],"dataSource":"manual"},{"account":"mmarmol","domain":"mxhero.com","createdDate":1375909565000,"updatedDate":1375909565000,"group":null,"aliases":[{"name":"mmarmol","domain":"hero.mx","dataSource":"manual"},{"name":"mmarmol","domain":"mxhero.com","dataSource":"manual"},{"name":"mmarmol","domain":"mxhero.net","dataSource":"manual"}],"dataSource":"manual"},{"account":"test","domain":"mxhero.com","createdDate":1375741652000,"updatedDate":1375741652000,"group":"development","aliases":[{"name":"test","domain":"mxhero.com","dataSource":"manual"}],"dataSource":"manual"}],"totalElements":8,"totalPages":1,"actualPage":1}'
|
37
|
+
http_version:
|
38
|
+
recorded_at: Wed, 07 Aug 2013 21:42:22 GMT
|
39
|
+
recorded_with: VCR 2.5.0
|
data/test/helper.rb
CHANGED
@@ -10,7 +10,7 @@ require 'minitest/pride'
|
|
10
10
|
Dir['./lib/**/*.rb'].each { |rb| require rb }
|
11
11
|
|
12
12
|
TEST_API_DOMAIN = 'tesla.com'
|
13
|
-
TEST_API_URL = 'http://localhost:8080/webapi/api/v1'
|
13
|
+
TEST_API_URL = ENV['TEST_API_URL'] || 'http://localhost:8080/webapi/api/v1'
|
14
14
|
TEST_API_USER = 'admin'
|
15
15
|
TEST_API_PASSWORD = 'password'
|
16
16
|
|
data/test/test_mxhero_api.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'helper'
|
2
2
|
|
3
3
|
class MxHeroAPITest < MiniTest::Unit::TestCase
|
4
4
|
|
@@ -70,6 +70,24 @@ class MxHeroAPITest < MiniTest::Unit::TestCase
|
|
70
70
|
assert_raises(RuntimeError) { @api.domain_by_id }
|
71
71
|
end
|
72
72
|
|
73
|
+
def test_accounts_by_domain
|
74
|
+
VCR.use_cassette('accounts_from_domain') do
|
75
|
+
domain = 'mxhero.com'
|
76
|
+
response = @api.accounts_by_domain(domain)
|
77
|
+
must_have_the_keys(response, %w( elements totalElements totalPages actualPage ))
|
78
|
+
response[:elements].each do |account|
|
79
|
+
must_have_the_keys(account, %w( account domain createdDate updatedDate group aliases dataSource ) )
|
80
|
+
account[:aliases].each { |t_alias| must_have_the_keys(t_alias, %w( name domain dataSource )) }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def must_have_the_keys(hash, keys)
|
86
|
+
keys.each do |key|
|
87
|
+
assert hash.key?(key.to_sym), "must have the key #{key}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
73
91
|
def rule_msg_with_domain(domain)
|
74
92
|
msg = create_rule_msg
|
75
93
|
msg[:domain] = 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.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- VERSION
|
79
79
|
- lib/mxhero-api.rb
|
80
80
|
- mxhero-api.gemspec
|
81
|
+
- test/fixtures/api/accounts_from_domain.yml
|
81
82
|
- test/fixtures/api/create_rule_alredy_exist.yml
|
82
83
|
- test/fixtures/api/create_rule_for_domain.yml
|
83
84
|
- test/fixtures/api/create_rule_success.yml
|
@@ -106,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
107
|
version: '0'
|
107
108
|
segments:
|
108
109
|
- 0
|
109
|
-
hash:
|
110
|
+
hash: 2775185487953988515
|
110
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
112
|
none: false
|
112
113
|
requirements:
|
@@ -120,6 +121,7 @@ signing_key:
|
|
120
121
|
specification_version: 3
|
121
122
|
summary: A MxHero API client for ruby
|
122
123
|
test_files:
|
124
|
+
- test/fixtures/api/accounts_from_domain.yml
|
123
125
|
- test/fixtures/api/create_rule_alredy_exist.yml
|
124
126
|
- test/fixtures/api/create_rule_for_domain.yml
|
125
127
|
- test/fixtures/api/create_rule_success.yml
|