mxhero-api 0.1.6 → 0.1.7
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 +42 -0
- data/mxhero-api.gemspec +4 -4
- data/test/fixtures/api/account_properties.yml +42 -0
- data/test/fixtures/api/account_properties_not_found.yml +39 -0
- data/test/fixtures/api/update_account_properties.yml +115 -0
- data/test/test_mxhero_api.rb +44 -0
- metadata +9 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
data/lib/mxhero-api.rb
CHANGED
@@ -196,8 +196,46 @@ module MxHero
|
|
196
196
|
return false
|
197
197
|
end
|
198
198
|
|
199
|
+
# @param [String] domain
|
200
|
+
# @param [String] account Ex.: test or mxhero (the user name)
|
201
|
+
# @return [MxHero::API::Response] reponse
|
202
|
+
# the key :msg contains a Hash with the key, value of any property.
|
203
|
+
# Example:
|
204
|
+
#
|
205
|
+
# { 'email': 'test@mxhero.com', 'name': 'John', 'lastname': 'Doe', ... }
|
206
|
+
#
|
207
|
+
def account_properties(domain, account)
|
208
|
+
url = account_properties_url(domain, account)
|
209
|
+
response = call(:get, url)
|
210
|
+
if response.status == 200
|
211
|
+
props = {}
|
212
|
+
json_parse(response.content).each { |property| props[property[:name]] = property[:value] }
|
213
|
+
return Response.new(response.code, props)
|
214
|
+
end
|
215
|
+
parse_response(response)
|
216
|
+
end
|
217
|
+
|
218
|
+
# @param [String] domain
|
219
|
+
# @param [String] account
|
220
|
+
# @param [Hash] properties The properties of the account. Ex.: { 'email': 'test@mxhero.com', 'name': 'John', 'lastname': 'Doe', ... }
|
221
|
+
#
|
222
|
+
# @return [MxHero::API::Response]. On success not return msg.
|
223
|
+
def update_account_properties(domain, account, properties)
|
224
|
+
url = account_properties_url(domain, account)
|
225
|
+
response = call(:put, url, account_properties_to_json(properties))
|
226
|
+
parse_response(response)
|
227
|
+
end
|
228
|
+
|
199
229
|
private
|
200
230
|
|
231
|
+
def account_properties_to_json(properties)
|
232
|
+
out = []
|
233
|
+
properties.each do |key, value|
|
234
|
+
out << { name: key, value: value }
|
235
|
+
end
|
236
|
+
out.to_json
|
237
|
+
end
|
238
|
+
|
201
239
|
# @return [MxHero::API::Response] a response object
|
202
240
|
def parse_response(response, opts = { on_empty: nil })
|
203
241
|
json = response.content
|
@@ -255,6 +293,10 @@ module MxHero
|
|
255
293
|
rules_for_domain_url(domain) + "/#{id}"
|
256
294
|
end
|
257
295
|
|
296
|
+
def account_properties_url(domain, account)
|
297
|
+
accounts_by_domain_url(domain) + "/#{account}/properties"
|
298
|
+
end
|
299
|
+
|
258
300
|
def service_url
|
259
301
|
@service_url
|
260
302
|
end
|
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.7"
|
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-14"
|
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/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_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/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/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_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/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,42 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://admin:password@localhost:8080/webapi/api/v1/domains/tesla.com/accounts/test/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 "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
|
+
RnJpLCAwOSBBdWcgMjAxMyAxNjoyMjo1MCBHTVQ=
|
34
|
+
body:
|
35
|
+
encoding: US-ASCII
|
36
|
+
string: ! '[{"name":"email","value":"test@tesla.com"},{"name":"fax","value":""},{"name":"lastname","value":"The
|
37
|
+
user test lastname"},{"name":"mobile","value":""},{"name":"name","value":"The
|
38
|
+
user test name"},{"name":"opt1","value":""},{"name":"opt2","value":"option
|
39
|
+
2"},{"name":"opt3","value":""},{"name":"telephone","value":"3333-3333"}]'
|
40
|
+
http_version:
|
41
|
+
recorded_at: Wed, 14 Aug 2013 18:23:18 GMT
|
42
|
+
recorded_with: VCR 2.5.0
|
@@ -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/xxxxx/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: 404
|
19
|
+
message: !binary |-
|
20
|
+
Tm90IEZvdW5k
|
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
|
+
RnJpLCAwOSBBdWcgMjAxMyAxNjo0NzoxMyBHTVQ=
|
34
|
+
body:
|
35
|
+
encoding: US-ASCII
|
36
|
+
string: ! '{"status":404,"code":404,"message":"domain.account.not.found","developerMessage":"domain.account.not.found","moreInfoUrl":"mailto:support@mxhero.com"}'
|
37
|
+
http_version:
|
38
|
+
recorded_at: Wed, 14 Aug 2013 18:47:40 GMT
|
39
|
+
recorded_with: VCR 2.5.0
|
@@ -0,0 +1,115 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://admin:password@localhost:8080/webapi/api/v1/domains/tesla.com/accounts/test/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 "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
|
+
RnJpLCAwOSBBdWcgMjAxMyAxNzozNTo1MCBHTVQ=
|
34
|
+
body:
|
35
|
+
encoding: US-ASCII
|
36
|
+
string: ! '[{"name":"email","value":"test@tesla.com"},{"name":"fax","value":""},{"name":"lastname","value":"The
|
37
|
+
user test lastname"},{"name":"mobile","value":""},{"name":"name","value":"The
|
38
|
+
user test name"},{"name":"opt1","value":""},{"name":"opt2","value":"option
|
39
|
+
2"},{"name":"opt3","value":""},{"name":"telephone","value":"3333-3333"}]'
|
40
|
+
http_version:
|
41
|
+
recorded_at: Wed, 14 Aug 2013 19:36:16 GMT
|
42
|
+
- request:
|
43
|
+
method: put
|
44
|
+
uri: http://admin:password@localhost:8080/webapi/api/v1/domains/tesla.com/accounts/test/properties
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: ! '[{"name":"email","value":"test@tesla.com"},{"name":"fax","value":null},{"name":"lastname","value":"The
|
48
|
+
user test lastname CHANGED"},{"name":"name","value":"The user test name CHANGED"},{"name":"opt1","value":""},{"name":"opt2","value":"option
|
49
|
+
2"},{"name":"opt3","value":""},{"name":"telephone","value":"3333-3333"}]'
|
50
|
+
headers:
|
51
|
+
Accept:
|
52
|
+
- application/json
|
53
|
+
Content-Type:
|
54
|
+
- application/json
|
55
|
+
Authorization:
|
56
|
+
- Basic YWRtaW46cGFzc3dvcmQ=
|
57
|
+
response:
|
58
|
+
status:
|
59
|
+
code: 200
|
60
|
+
message: !binary |-
|
61
|
+
T0s=
|
62
|
+
headers:
|
63
|
+
!binary "U2VydmVy":
|
64
|
+
- !binary |-
|
65
|
+
QXBhY2hlLUNveW90ZS8xLjE=
|
66
|
+
!binary "Q29udGVudC1MZW5ndGg=":
|
67
|
+
- !binary |-
|
68
|
+
MA==
|
69
|
+
!binary "RGF0ZQ==":
|
70
|
+
- !binary |-
|
71
|
+
RnJpLCAwOSBBdWcgMjAxMyAxNzozNTo1MCBHTVQ=
|
72
|
+
body:
|
73
|
+
encoding: US-ASCII
|
74
|
+
string: ''
|
75
|
+
http_version:
|
76
|
+
recorded_at: Wed, 14 Aug 2013 19:36:16 GMT
|
77
|
+
- request:
|
78
|
+
method: get
|
79
|
+
uri: http://admin:password@localhost:8080/webapi/api/v1/domains/tesla.com/accounts/test/properties
|
80
|
+
body:
|
81
|
+
encoding: US-ASCII
|
82
|
+
string: ''
|
83
|
+
headers:
|
84
|
+
Accept:
|
85
|
+
- application/json
|
86
|
+
Content-Type:
|
87
|
+
- application/json
|
88
|
+
Authorization:
|
89
|
+
- Basic YWRtaW46cGFzc3dvcmQ=
|
90
|
+
response:
|
91
|
+
status:
|
92
|
+
code: 200
|
93
|
+
message: !binary |-
|
94
|
+
T0s=
|
95
|
+
headers:
|
96
|
+
!binary "U2VydmVy":
|
97
|
+
- !binary |-
|
98
|
+
QXBhY2hlLUNveW90ZS8xLjE=
|
99
|
+
!binary "Q29udGVudC1UeXBl":
|
100
|
+
- !binary |-
|
101
|
+
YXBwbGljYXRpb24vanNvbg==
|
102
|
+
!binary "VHJhbnNmZXItRW5jb2Rpbmc=":
|
103
|
+
- !binary |-
|
104
|
+
Y2h1bmtlZA==
|
105
|
+
!binary "RGF0ZQ==":
|
106
|
+
- !binary |-
|
107
|
+
RnJpLCAwOSBBdWcgMjAxMyAxNzozNTo1MCBHTVQ=
|
108
|
+
body:
|
109
|
+
encoding: US-ASCII
|
110
|
+
string: ! '[{"name":"email","value":"test@tesla.com"},{"name":"fax","value":null},{"name":"lastname","value":"The
|
111
|
+
user test lastname CHANGED"},{"name":"name","value":"The user test name CHANGED"},{"name":"opt1","value":""},{"name":"opt2","value":"option
|
112
|
+
2"},{"name":"opt3","value":""},{"name":"telephone","value":"3333-3333"}]'
|
113
|
+
http_version:
|
114
|
+
recorded_at: Wed, 14 Aug 2013 19:36:16 GMT
|
115
|
+
recorded_with: VCR 2.5.0
|
data/test/test_mxhero_api.rb
CHANGED
@@ -129,6 +129,50 @@ class MxHeroAPITest < MiniTest::Unit::TestCase
|
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
+
def test_account_properties
|
133
|
+
VCR.use_cassette('account_properties') do
|
134
|
+
account = 'test'
|
135
|
+
response = @api.account_properties(domain, account)
|
136
|
+
assert_equal 200, response.code
|
137
|
+
assert response.is_a? MxHero::API::Response
|
138
|
+
properties = response.msg
|
139
|
+
%w( email fax lastname mobile name opt1 opt2 opt3 telephone ).each do |property|
|
140
|
+
assert properties.key? property
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_account_propertes_not_found
|
146
|
+
VCR.use_cassette('account_properties_not_found') do
|
147
|
+
begin
|
148
|
+
account = 'xxxxx'
|
149
|
+
response = @api.account_properties(domain, account)
|
150
|
+
assert_equal 404, response.code
|
151
|
+
assert response.is_a? MxHero::API::Response
|
152
|
+
rescue
|
153
|
+
flunk 'error!'
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_update_account_properties
|
159
|
+
VCR.use_cassette('update_account_properties') do
|
160
|
+
account = 'test'
|
161
|
+
response = @api.account_properties(domain, account)
|
162
|
+
properties = response.msg
|
163
|
+
properties['lastname'] = properties['lastname'] + ' CHANGED'
|
164
|
+
properties['name'] = properties['name'] + ' CHANGED'
|
165
|
+
properties['fax'] = nil
|
166
|
+
response = @api.update_account_properties(domain, account, properties)
|
167
|
+
assert_equal 200, response.code
|
168
|
+
|
169
|
+
response = @api.account_properties(domain, account)
|
170
|
+
assert_equal properties['lastname'], response.msg['lastname']
|
171
|
+
assert_equal properties['name'], response.msg['name']
|
172
|
+
assert_equal properties['fax'], response.msg['fax']
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
132
176
|
private
|
133
177
|
|
134
178
|
def 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.7
|
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-14 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: vcr
|
@@ -79,6 +79,8 @@ files:
|
|
79
79
|
- VERSION
|
80
80
|
- lib/mxhero-api.rb
|
81
81
|
- mxhero-api.gemspec
|
82
|
+
- test/fixtures/api/account_properties.yml
|
83
|
+
- test/fixtures/api/account_properties_not_found.yml
|
82
84
|
- test/fixtures/api/accounts_from_domain.yml
|
83
85
|
- test/fixtures/api/create_rule_alredy_exist.yml
|
84
86
|
- test/fixtures/api/create_rule_for_domain.yml
|
@@ -89,6 +91,7 @@ files:
|
|
89
91
|
- test/fixtures/api/domain_rule.yml
|
90
92
|
- test/fixtures/api/domains.yml
|
91
93
|
- test/fixtures/api/rules_for_domain.yml
|
94
|
+
- test/fixtures/api/update_account_properties.yml
|
92
95
|
- test/fixtures/api/update_rule.yml
|
93
96
|
- test/helper.rb
|
94
97
|
- test/test_mxhero_api.rb
|
@@ -108,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
111
|
version: '0'
|
109
112
|
segments:
|
110
113
|
- 0
|
111
|
-
hash:
|
114
|
+
hash: -69256700798046253
|
112
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
116
|
none: false
|
114
117
|
requirements:
|
@@ -122,6 +125,8 @@ signing_key:
|
|
122
125
|
specification_version: 3
|
123
126
|
summary: A MxHero API client for ruby
|
124
127
|
test_files:
|
128
|
+
- test/fixtures/api/account_properties.yml
|
129
|
+
- test/fixtures/api/account_properties_not_found.yml
|
125
130
|
- test/fixtures/api/accounts_from_domain.yml
|
126
131
|
- test/fixtures/api/create_rule_alredy_exist.yml
|
127
132
|
- test/fixtures/api/create_rule_for_domain.yml
|
@@ -132,6 +137,7 @@ test_files:
|
|
132
137
|
- test/fixtures/api/domain_rule.yml
|
133
138
|
- test/fixtures/api/domains.yml
|
134
139
|
- test/fixtures/api/rules_for_domain.yml
|
140
|
+
- test/fixtures/api/update_account_properties.yml
|
135
141
|
- test/fixtures/api/update_rule.yml
|
136
142
|
- test/helper.rb
|
137
143
|
- test/test_mxhero_api.rb
|