mxhero-api 0.1.1 → 0.1.2
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/.gitignore +3 -0
- data/.rvmrc +1 -0
- data/Gemfile +5 -0
- data/Rakefile +31 -0
- data/VERSION +1 -0
- data/lib/mxhero-api.rb +25 -1
- data/mxhero-api.gemspec +31 -15
- data/test/fixtures/api/domain_by_id.yml +36 -0
- data/test/fixtures/api/domain_by_id_not_found.yml +36 -0
- data/test/helper.rb +6 -0
- data/test/test_mxhero_api.rb +25 -1
- metadata +17 -5
- data/Gemfile.lock +0 -26
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --create 1.9.3@mxhero-api
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,8 +1,39 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rake/testtask'
|
3
|
+
require 'rake/version_task'
|
3
4
|
|
4
5
|
Rake::TestTask.new do |t|
|
5
6
|
t.libs << 'test'
|
6
7
|
end
|
7
8
|
|
8
9
|
task :default => :test
|
10
|
+
|
11
|
+
|
12
|
+
# -*- encoding: utf-8 -*-
|
13
|
+
lib = File.expand_path('./lib', __FILE__)
|
14
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
15
|
+
|
16
|
+
spec = Gem::Specification.new do |gem|
|
17
|
+
gem.name = 'mxhero-api'
|
18
|
+
gem.authors = ['Maximiliano Dello Russo', 'Juan Pablo Royo', 'mxHero']
|
19
|
+
gem.email = ['maxidr@mxhero.com','juanpablo.royo@gmail.com', 'mxhero@mxhero.com']
|
20
|
+
gem.summary = %q{A MxHero API client for ruby}
|
21
|
+
gem.description = %q{A gem to provide easy access to the API of MxHero platform (http://www.mxhero.com/)}
|
22
|
+
gem.homepage = 'http://github.com/mxhero/mxhero-api'
|
23
|
+
|
24
|
+
gem.files = `git ls-files`.split($\)
|
25
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
26
|
+
gem.require_paths = ["lib"]
|
27
|
+
|
28
|
+
gem.add_development_dependency('vcr', '2.5.0')
|
29
|
+
gem.add_development_dependency('webmock', '1.11.0')
|
30
|
+
|
31
|
+
gem.add_dependency('httpclient', '2.3.3')
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
Rake::VersionTask.new do |task|
|
36
|
+
task.with_git_tag = true
|
37
|
+
task.with_gemspec = spec
|
38
|
+
end
|
39
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.2
|
data/lib/mxhero-api.rb
CHANGED
@@ -85,6 +85,24 @@ module MxHero
|
|
85
85
|
response_as_a_hash
|
86
86
|
end
|
87
87
|
|
88
|
+
# Retrive the domain by id according to the parameter if exist
|
89
|
+
#
|
90
|
+
# @param id The domain name or id. For example: 'mydomain.com'
|
91
|
+
# @return [Hash] with the domain attributes if exist
|
92
|
+
# * :domain [String]
|
93
|
+
# * :server [String]
|
94
|
+
# * :creationDate [Fixnum]
|
95
|
+
# * :updateDate [Fixnum]
|
96
|
+
# * :aliases
|
97
|
+
# * :ldap
|
98
|
+
# @raise an exception when the status code isn't 200
|
99
|
+
def domain_by_id(id = nil)
|
100
|
+
raise 'Id domain could not be nil' if id.nil?
|
101
|
+
response = call(:get, domain_by_id_url(id))
|
102
|
+
response_as_a_hash = json_parse(response.content)
|
103
|
+
response_as_a_hash
|
104
|
+
end
|
105
|
+
|
88
106
|
|
89
107
|
def verbose?
|
90
108
|
@verbose
|
@@ -164,7 +182,9 @@ module MxHero
|
|
164
182
|
def call(method, url, body = nil)
|
165
183
|
client = HTTPClient.new
|
166
184
|
client.set_auth(url, @username, @password)
|
167
|
-
client.request(method, url, nil, body, headers)
|
185
|
+
response = client.request(method, url, nil, body, headers)
|
186
|
+
raise 'an error ocurred when try to communicate with the API' if 500..600.include?(response.status)
|
187
|
+
response
|
168
188
|
end
|
169
189
|
|
170
190
|
# Default headers
|
@@ -184,6 +204,10 @@ module MxHero
|
|
184
204
|
service_url + '/domains'
|
185
205
|
end
|
186
206
|
|
207
|
+
def domain_by_id_url(domain)
|
208
|
+
domains_url + "/#{domain}/"
|
209
|
+
end
|
210
|
+
|
187
211
|
def domain_rule_url(domain, id)
|
188
212
|
rules_for_domain_url(domain) + "/#{id}"
|
189
213
|
end
|
data/mxhero-api.gemspec
CHANGED
@@ -1,20 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
|
2
|
-
Gem::Specification.new do |
|
3
|
-
|
4
|
-
|
5
|
-
gem.authors = ['Maximiliano Dello Russo']
|
6
|
-
gem.email = ['maxidr@mxhero.com']
|
7
|
-
gem.summary = %q{A MxHero API client for ruby}
|
8
|
-
gem.description = %q{A gem to provide easy access to the API of MxHero platform (http://www.mxhero.com/)}
|
9
|
-
gem.homepage = 'http://github.com/mxhero/mxhero-api'
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "mxhero-api"
|
5
|
+
s.version = "0.1.2"
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Maximiliano Dello Russo", "Juan Pablo Royo", "mxHero"]
|
9
|
+
s.date = "2013-08-07"
|
10
|
+
s.description = "A gem to provide easy access to the API of MxHero platform (http://www.mxhero.com/)"
|
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"]
|
13
|
+
s.homepage = "http://github.com/mxhero/mxhero-api"
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
s.rubygems_version = "1.8.25"
|
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"]
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
gem.add_dependency('httpclient', '2.3.3')
|
19
|
+
if s.respond_to? :specification_version then
|
20
|
+
s.specification_version = 3
|
19
21
|
|
22
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
23
|
+
s.add_development_dependency(%q<vcr>, ["= 2.5.0"])
|
24
|
+
s.add_development_dependency(%q<webmock>, ["= 1.11.0"])
|
25
|
+
s.add_runtime_dependency(%q<httpclient>, ["= 2.3.3"])
|
26
|
+
else
|
27
|
+
s.add_dependency(%q<vcr>, ["= 2.5.0"])
|
28
|
+
s.add_dependency(%q<webmock>, ["= 1.11.0"])
|
29
|
+
s.add_dependency(%q<httpclient>, ["= 2.3.3"])
|
30
|
+
end
|
31
|
+
else
|
32
|
+
s.add_dependency(%q<vcr>, ["= 2.5.0"])
|
33
|
+
s.add_dependency(%q<webmock>, ["= 1.11.0"])
|
34
|
+
s.add_dependency(%q<httpclient>, ["= 2.3.3"])
|
35
|
+
end
|
20
36
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://admin:password@localhost:8080/webapi/api/v1/domains/test.com/
|
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 "Q29udGVudC1UeXBl":
|
23
|
+
- !binary |-
|
24
|
+
YXBwbGljYXRpb24vanNvbg==
|
25
|
+
!binary "VHJhbnNmZXItRW5jb2Rpbmc=":
|
26
|
+
- !binary |-
|
27
|
+
Y2h1bmtlZA==
|
28
|
+
!binary "U2VydmVy":
|
29
|
+
- !binary |-
|
30
|
+
SmV0dHkoNi4xLjEwKQ==
|
31
|
+
body:
|
32
|
+
encoding: US-ASCII
|
33
|
+
string: ! '{"domain":"test.com","server":"smtp.server","creationDate":1360096371000,"updatedDate":1360096371000,"aliases":["test.com"],"ldap":null}'
|
34
|
+
http_version:
|
35
|
+
recorded_at: Wed, 07 Aug 2013 17:55:32 GMT
|
36
|
+
recorded_with: VCR 2.5.0
|
@@ -0,0 +1,36 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://admin:password@localhost:8080/webapi/api/v1/domains/test.notfound.com/
|
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: 404
|
19
|
+
message: !binary |-
|
20
|
+
Tm90IEZvdW5k
|
21
|
+
headers:
|
22
|
+
!binary "Q29udGVudC1UeXBl":
|
23
|
+
- !binary |-
|
24
|
+
YXBwbGljYXRpb24vanNvbg==
|
25
|
+
!binary "VHJhbnNmZXItRW5jb2Rpbmc=":
|
26
|
+
- !binary |-
|
27
|
+
Y2h1bmtlZA==
|
28
|
+
!binary "U2VydmVy":
|
29
|
+
- !binary |-
|
30
|
+
SmV0dHkoNi4xLjEwKQ==
|
31
|
+
body:
|
32
|
+
encoding: US-ASCII
|
33
|
+
string: ! '{"status":404,"code":404,"message":"domain.not.found","developerMessage":"domain.not.found","moreInfoUrl":"mailto:support@mxhero.com"}'
|
34
|
+
http_version:
|
35
|
+
recorded_at: Wed, 07 Aug 2013 18:00:41 GMT
|
36
|
+
recorded_with: VCR 2.5.0
|
data/test/helper.rb
CHANGED
data/test/test_mxhero_api.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative 'helper'
|
1
|
+
require_relative 'helper'
|
2
2
|
|
3
3
|
class MxHeroAPITest < MiniTest::Unit::TestCase
|
4
4
|
|
@@ -46,6 +46,30 @@ class MxHeroAPITest < MiniTest::Unit::TestCase
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
def test_domain_by_id
|
50
|
+
VCR.use_cassette('domain_by_id') do
|
51
|
+
id = "test.com"
|
52
|
+
tesla_domain = @api.domain_by_id(id)
|
53
|
+
assert tesla_domain.key?(:domain)
|
54
|
+
assert tesla_domain.key?(:server)
|
55
|
+
assert tesla_domain.key?(:creationDate)
|
56
|
+
assert tesla_domain.key?(:aliases)
|
57
|
+
assert tesla_domain.key?(:ldap)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_domain_by_id_not_found
|
62
|
+
VCR.use_cassette('domain_by_id_not_found') do
|
63
|
+
id = "test.notfound.com"
|
64
|
+
tesla_domain = @api.domain_by_id(id)
|
65
|
+
assert tesla_domain[:status] == 404
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_domain_by_id_param_could_not_be_nil
|
70
|
+
assert_raises(RuntimeError) { @api.domain_by_id }
|
71
|
+
end
|
72
|
+
|
49
73
|
def rule_msg_with_domain(domain)
|
50
74
|
msg = create_rule_msg
|
51
75
|
msg[:domain] = domain
|
metadata
CHANGED
@@ -1,15 +1,17 @@
|
|
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Maximiliano Dello Russo
|
9
|
+
- Juan Pablo Royo
|
10
|
+
- mxHero
|
9
11
|
autorequire:
|
10
12
|
bindir: bin
|
11
13
|
cert_chain: []
|
12
|
-
date: 2013-07
|
14
|
+
date: 2013-08-07 00:00:00.000000000 Z
|
13
15
|
dependencies:
|
14
16
|
- !ruby/object:Gem::Dependency
|
15
17
|
name: vcr
|
@@ -62,19 +64,25 @@ dependencies:
|
|
62
64
|
description: A gem to provide easy access to the API of MxHero platform (http://www.mxhero.com/)
|
63
65
|
email:
|
64
66
|
- maxidr@mxhero.com
|
67
|
+
- juanpablo.royo@gmail.com
|
68
|
+
- mxhero@mxhero.com
|
65
69
|
executables: []
|
66
70
|
extensions: []
|
67
71
|
extra_rdoc_files: []
|
68
72
|
files:
|
73
|
+
- .gitignore
|
74
|
+
- .rvmrc
|
69
75
|
- Gemfile
|
70
|
-
- Gemfile.lock
|
71
76
|
- README.md
|
72
77
|
- Rakefile
|
78
|
+
- VERSION
|
73
79
|
- lib/mxhero-api.rb
|
74
80
|
- mxhero-api.gemspec
|
75
81
|
- test/fixtures/api/create_rule_alredy_exist.yml
|
76
82
|
- test/fixtures/api/create_rule_for_domain.yml
|
77
83
|
- test/fixtures/api/create_rule_success.yml
|
84
|
+
- test/fixtures/api/domain_by_id.yml
|
85
|
+
- test/fixtures/api/domain_by_id_not_found.yml
|
78
86
|
- test/fixtures/api/domain_rule.yml
|
79
87
|
- test/fixtures/api/domains.yml
|
80
88
|
- test/fixtures/api/rules_for_domain.yml
|
@@ -96,6 +104,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
104
|
- - ! '>='
|
97
105
|
- !ruby/object:Gem::Version
|
98
106
|
version: '0'
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
hash: -1666481203265487076
|
99
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
111
|
none: false
|
101
112
|
requirements:
|
@@ -104,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
115
|
version: '0'
|
105
116
|
requirements: []
|
106
117
|
rubyforge_project:
|
107
|
-
rubygems_version: 1.8.
|
118
|
+
rubygems_version: 1.8.25
|
108
119
|
signing_key:
|
109
120
|
specification_version: 3
|
110
121
|
summary: A MxHero API client for ruby
|
@@ -112,6 +123,8 @@ test_files:
|
|
112
123
|
- test/fixtures/api/create_rule_alredy_exist.yml
|
113
124
|
- test/fixtures/api/create_rule_for_domain.yml
|
114
125
|
- test/fixtures/api/create_rule_success.yml
|
126
|
+
- test/fixtures/api/domain_by_id.yml
|
127
|
+
- test/fixtures/api/domain_by_id_not_found.yml
|
115
128
|
- test/fixtures/api/domain_rule.yml
|
116
129
|
- test/fixtures/api/domains.yml
|
117
130
|
- test/fixtures/api/rules_for_domain.yml
|
@@ -121,4 +134,3 @@ test_files:
|
|
121
134
|
- test/helper.rb
|
122
135
|
- test/test_mxhero_api.rb
|
123
136
|
- test/test_mxhero_api_response.rb
|
124
|
-
has_rdoc:
|
data/Gemfile.lock
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
mxhero-api (0.1.1)
|
5
|
-
httpclient (= 2.3.3)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
addressable (2.3.4)
|
11
|
-
crack (0.3.2)
|
12
|
-
httpclient (2.3.3)
|
13
|
-
rake (10.1.0)
|
14
|
-
vcr (2.5.0)
|
15
|
-
webmock (1.11.0)
|
16
|
-
addressable (>= 2.2.7)
|
17
|
-
crack (>= 0.3.2)
|
18
|
-
|
19
|
-
PLATFORMS
|
20
|
-
ruby
|
21
|
-
|
22
|
-
DEPENDENCIES
|
23
|
-
mxhero-api!
|
24
|
-
rake (= 10.1.0)
|
25
|
-
vcr (= 2.5.0)
|
26
|
-
webmock (= 1.11.0)
|