mxhero-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gem 'rake', '10.1.0'
5
+
6
+ # Specify your gem's dependencies in mxhero-api.gemspec
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mxhero-api (0.0.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)
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # MxHero API client
2
+
3
+ A ruby client to interact with the MxHero API
4
+
5
+ ## Instalation
6
+
7
+ gem install mxhero-api
8
+
9
+ or in your Gemfile:
10
+
11
+ gem 'mxhero-api'
12
+
13
+ ## Example of uses
14
+
15
+ Some examples, **complete documentation in the [API client documentation](http://www.rubydoc.info/github/mxhero/mxhero-api/MxHero/API/Client.html)**
16
+
17
+ ### Instanciate a client
18
+
19
+ client = MxHero::API::Client.new(username: 'api username', password: 'api password', api_url: 'http://api-url-example.mxhero.com/api')
20
+
21
+ [See more](http://www.rubydoc.info/github/mxhero/mxhero-api/MxHero/API/Client.html#initialize-instance_method)
22
+
23
+ ### Retrieve all the domains
24
+
25
+ # Retrieve all the domains
26
+ domains = client.domains
27
+
28
+ # Return a hash, example:
29
+ #
30
+ # { :elements => [
31
+ # { :domain=>"tesla.com", :server=>"tesla.com", :creationDate=>1369837819000, :updatedDate=>1369837819000, :aliases=>nil, :ldap=>nil }
32
+ # ],
33
+ # :totalElements=>1,
34
+ # :totalPages=>1,
35
+ # :actualPage=>1
36
+ # }
37
+
38
+ [See more](http://www.rubydoc.info/github/mxhero/mxhero-api/MxHero/API/Client.html#domains-instance_method)
39
+
40
+ ### Retrieve all rules for one domain
41
+
42
+ rules = client.rules_for_domain('tesla.com')
43
+
44
+ [See more](http://www.rubydoc.info/github/mxhero/mxhero-api/MxHero/API/Client.html#rule_for_domain-instance_method)
45
+
46
+ ### Create a rule for one domain
47
+
48
+ # The representation of a rule is a Hash.
49
+ # Example:
50
+ rule = {
51
+ domain: 'test.com',
52
+ twoWays: false,
53
+ enabled: true,
54
+ name: 'Rule name',
55
+ created: DateTime.now.strftime('%Q'), # epoch time for now
56
+ fromDirection: { directionType: 'domain', domain: 'test.com', freeValue: 'test.com' },
57
+ toDirection: { directionType: 'domain', domain: 'test.com', freeValue: 'test.com' },
58
+ properties: [
59
+ { propertyKey: 'return.message', propertyValue: 'footer content' }
60
+ ],
61
+ component: 'org.mxhero.feature.disclaimer'
62
+ }
63
+
64
+ # Create a rule for one domain
65
+ client.create_rule_for_domain('test.com', rule)
66
+
67
+ [See more](http://www.rubydoc.info/github/mxhero/mxhero-api/MxHero/API/Client.html#create_rule_for_domain-instance_method)
68
+
69
+ ### Update a rule
70
+
71
+ client.update_rule(rule)
72
+
73
+ [See more](http://www.rubydoc.info/github/mxhero/mxhero-api/MxHero/API/Client.html#update_rule-instance_method)
74
+
75
+ ### find a rule for one domain
76
+
77
+ client.domain_rule('tesla.com', 12)
78
+
79
+ [See more](http://www.rubydoc.info/github/mxhero/mxhero-api/MxHero/API/Client.html#domain_rule-instance_method)
80
+
81
+ ## Complete documentation
82
+
83
+ Complete documentation in the [API client documentation](http://www.rubydoc.info/github/mxhero/mxhero-api/MxHero/API/Client.html)
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ task :default => :test
data/lib/mxhero_api.rb ADDED
@@ -0,0 +1,197 @@
1
+ require 'httpclient'
2
+ require 'json'
3
+
4
+ module MxHero
5
+
6
+ module API
7
+
8
+ # The class that contains the response information
9
+ #
10
+ # The *code* represent the HTTP code of the response.
11
+ #
12
+ # The *msg* represent a hash with the response information. Example:
13
+ #
14
+ # { status: 500, code: 500, developerMessage: "rules.already.exists.for.component", moreInfoUrl: "mailto:support@mxhero.com" }
15
+ #
16
+ class Response < Struct.new(:code, :msg)
17
+
18
+ # Response is successful? Based in HTTP status code
19
+ def success?
20
+ code.to_i == 200 || code.to_i == 201
21
+ end
22
+ end
23
+
24
+
25
+ # A client to interact with mxhero engine API
26
+ class Client
27
+
28
+ # @param [Hash] config the options of configuration
29
+ # @option config [String] :api_url The URL to consume the API
30
+ # @option config [String] :username The username for access the API
31
+ # @option config [String] :password The password for the user that access the API
32
+ # @option config [Boolean] :verbose (false) If true puts information about http operations
33
+ def initialize(config = {})
34
+ @service_url = config[:api_url]
35
+ @username = config[:username]
36
+ @password = config[:password]
37
+ @verbose = config[:verbose] || false
38
+ end
39
+
40
+ # Find a rule by domain and ID
41
+ #
42
+ # @param domain [String]
43
+ # @param id [Integer] the rule id
44
+ #
45
+ # @return [Hash, nil] the Rule information or nil if not exist
46
+ #
47
+ # @raise an exception when the status code isn't 200
48
+ def domain_rule(domain, id)
49
+ url = domain_rule_url(domain, id)
50
+ response = call(:get, url)
51
+ raise 'an error ocurred when try to communicate with the API' if response.status != 200
52
+ json_parse(response.content)
53
+ end
54
+
55
+ # Update a rule
56
+ # @return [MxHero::API::Response] When the rule is update correctly then return MxHero::API::Response object without msg (msg nil)
57
+ # In case of error, the message is completed with the cause of error
58
+ def update_rule(rule)
59
+ url = domain_rule_url(rule[:domain], rule[:id])
60
+ response = call(:put, url, rule.to_json)
61
+ parse_response(response)
62
+ end
63
+
64
+ # Retrive all the domains
65
+ #
66
+ # TODO: Improve the response. We really need manage pagination here?
67
+ #
68
+ # @return [Hash] with the list of domains
69
+ # * :elements [Array<Hash>] the list of domains as a Hash, when any element contains:
70
+ # * :domain [String]
71
+ # * :server [String]
72
+ # * :creationDate [Fixnum]
73
+ # * :updateDate [Fixnum]
74
+ # * :aliases
75
+ # * :ldap
76
+ # * :totalElements
77
+ # * :totalPages
78
+ # * :actualPage
79
+ #
80
+ # @raise an exception when the status code isn't 200
81
+ def domains
82
+ response = call(:get, domains_url)
83
+ raise 'an error ocurred when try to communicate with the API' if response.status != 200
84
+ response_as_a_hash = json_parse(response.content)
85
+ response_as_a_hash
86
+ end
87
+
88
+
89
+ def verbose?
90
+ @verbose
91
+ end
92
+
93
+ def verbose=(verbose)
94
+ @verbose = verbose
95
+ end
96
+
97
+ # @param domain [String]
98
+ # @param [Hash] msg
99
+ # @option msg [String] :domain
100
+ # @option msg [Boolean] :twoWays
101
+ # @option msg [Boolean] :enabled
102
+ # @option msg [String] :name
103
+ # @option msg [Integer] :created in epoch format
104
+ # @option msg [Hash] :fromDirection
105
+ # @option msg [Hash] :toDirection
106
+ # @option msg [Array<Hash>] :properties
107
+ # @option msg [String] :component
108
+ #
109
+ # @return [MxHero::API::Response]
110
+ def create_rule_for_domain(domain, msg)
111
+ url = rules_for_domain_url(domain)
112
+ response = call(:post, url, msg.to_json)
113
+ parse_response(response)
114
+ end
115
+
116
+ # Create a rule
117
+ #
118
+ # @param domain [String]
119
+ # @param [Hash] msg
120
+ # @option msg [String] :domain
121
+ # @option msg [Boolean] :twoWays
122
+ # @option msg [Boolean] :enabled
123
+ # @option msg [String] :name
124
+ # @option msg [Integer] :created in epoch format
125
+ # @option msg [Hash] :fromDirection
126
+ # @option msg [Hash] :toDirection
127
+ # @option msg [Array<Hash>] :properties
128
+ # @option msg [String] :component
129
+ #
130
+ # @return [MxHero::API::Response]
131
+ def create_rule(msg)
132
+ response = call(:post, rules_url, msg.to_json)
133
+ parse_response(response)
134
+ end
135
+
136
+ # Retrieve all the rules for one domain
137
+ #
138
+ # @return [MxHero::API::Response] reponse
139
+ # the key :msg contains an array of rules for the domain.
140
+ def rules_for_domain(domain)
141
+ url = rules_for_domain_url(domain)
142
+ response = call(:get, url)
143
+ parse_response(response, on_empty: [])
144
+ end
145
+
146
+ private
147
+
148
+ # @return [MxHero::API::Response] a response object
149
+ def parse_response(response, opts = { on_empty: nil })
150
+ json = response.content
151
+ hash = json.nil? || json.empty? ? opts[:on_empty] : json_parse(json)
152
+ Response.new(response.code, hash)
153
+ end
154
+
155
+ # @return [Hash]
156
+ def json_parse(json)
157
+ JSON.parse(json, symbolize_names: true)
158
+ end
159
+
160
+ # Make a HTTP call
161
+ # @param method [Symbol] indicate the HTTP verb (:get, :post, :put, etc)
162
+ # @param url [String]
163
+ # @param body [String] (default: nil)
164
+ def call(method, url, body = nil)
165
+ client = HTTPClient.new
166
+ client.set_auth(url, @username, @password)
167
+ client.request(method, url, nil, body, headers)
168
+ end
169
+
170
+ # Default headers
171
+ def headers
172
+ @headers ||= { 'Accept' => 'application/json', 'Content-Type' => 'application/json' }
173
+ end
174
+
175
+ def rules_for_domain_url(domain)
176
+ service_url + "/domains/#{domain}/rules"
177
+ end
178
+
179
+ def rules_url
180
+ service_url + '/rules'
181
+ end
182
+
183
+ def domains_url
184
+ service_url + '/domains'
185
+ end
186
+
187
+ def domain_rule_url(domain, id)
188
+ rules_for_domain_url(domain) + "/#{id}"
189
+ end
190
+
191
+ def service_url
192
+ @service_url
193
+ end
194
+ end
195
+
196
+ end
197
+ end
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'mxhero-api'
3
+ gem.version = '0.0.1'
4
+ gem.authors = ['Maximiliano Dello Russo']
5
+ gem.email = ['maxidr@mxhero.com']
6
+ gem.summary = %q{A MxHero API client for ruby}
7
+ gem.description = %q{A gem to provide easy access to the API of MxHero platform (http://www.mxhero.com/)}
8
+ gem.homepage = 'http://github.com/mxhero/mxhero-api'
9
+
10
+ gem.files = `git ls-files`.split($\)
11
+
12
+ gem.add_development_dependency('vcr', '2.5.0')
13
+ gem.add_development_dependency('webmock', '1.11.0')
14
+
15
+ gem.add_dependency('httpclient', '2.3.3')
16
+
17
+ end
@@ -0,0 +1,91 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://admin:password@localhost:8080/webapi/api/v1/rules
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"twoWays":false,"enabled":true,"name":"Email footer","created":1369682598000,"fromDirection":{"directionType":"domain","domain":"tesla.com","freeValue":"tesla.com"},"toDirection":{"directionType":"domain","domain":"tesla.com","freeValue":"tesla.com"},"properties":[{"propertyKey":"return.message","propertyValue":"footer
9
+ content"}],"component":"org.mxhero.feature.disclaimer"}'
10
+ headers:
11
+ Accept:
12
+ - application/json
13
+ Content-Type:
14
+ - application/json
15
+ response:
16
+ status:
17
+ code: 201
18
+ message: !binary |-
19
+ Q3JlYXRlZA==
20
+ headers:
21
+ !binary "U2VydmVy":
22
+ - !binary |-
23
+ QXBhY2hlLUNveW90ZS8xLjE=
24
+ !binary "Q29udGVudC1UeXBl":
25
+ - !binary |-
26
+ YXBwbGljYXRpb24vanNvbg==
27
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
28
+ - !binary |-
29
+ Y2h1bmtlZA==
30
+ !binary "RGF0ZQ==":
31
+ - !binary |-
32
+ VHVlLCAyOCBNYXkgMjAxMyAyMDowOTowNCBHTVQ=
33
+ body:
34
+ encoding: ASCII-8BIT
35
+ string: !binary |-
36
+ eyJpZCI6OTEsImRvbWFpbiI6bnVsbCwibmFtZSI6IkVtYWlsIGZvb3RlciIs
37
+ ImNyZWF0ZWQiOjEzNjk3NzE3NDQwMDAsInVwZGF0ZWQiOjEzNjk3NzE3NDQw
38
+ MDAsImVuYWJsZWQiOnRydWUsInR3b1dheXMiOmZhbHNlLCJhZG1pbk9yZGVy
39
+ IjpudWxsLCJjb21wb25lbnQiOiJvcmcubXhoZXJvLmZlYXR1cmUuZGlzY2xh
40
+ aW1lciIsImZyb21EaXJlY3Rpb24iOnsiaWQiOjE4MSwiZGlyZWN0aW9uVHlw
41
+ ZSI6ImRvbWFpbiIsImZyZWVWYWx1ZSI6InRlc2xhLmNvbSIsImRvbWFpbiI6
42
+ InRlc2xhLmNvbSIsImFjY291bnQiOm51bGwsImdyb3VwIjpudWxsfSwidG9E
43
+ aXJlY3Rpb24iOnsiaWQiOjE4MiwiZGlyZWN0aW9uVHlwZSI6ImRvbWFpbiIs
44
+ ImZyZWVWYWx1ZSI6InRlc2xhLmNvbSIsImRvbWFpbiI6InRlc2xhLmNvbSIs
45
+ ImFjY291bnQiOm51bGwsImdyb3VwIjpudWxsfSwicHJvcGVydGllcyI6W3si
46
+ cHJvcGVydHlLZXkiOiJyZXR1cm4ubWVzc2FnZSIsInByb3BlcnR5VmFsdWUi
47
+ OiJmb290ZXIgY29udGVudCJ9XX0=
48
+ http_version:
49
+ recorded_at: Tue, 28 May 2013 20:08:42 GMT
50
+ - request:
51
+ method: post
52
+ uri: http://admin:password@localhost:8080/webapi/api/v1/rules
53
+ body:
54
+ encoding: UTF-8
55
+ string: ! '{"twoWays":false,"enabled":true,"name":"Email footer","created":1369682598000,"fromDirection":{"directionType":"domain","domain":"tesla.com","freeValue":"tesla.com"},"toDirection":{"directionType":"domain","domain":"tesla.com","freeValue":"tesla.com"},"properties":[{"propertyKey":"return.message","propertyValue":"footer
56
+ content"}],"component":"org.mxhero.feature.disclaimer"}'
57
+ headers:
58
+ Accept:
59
+ - application/json
60
+ Content-Type:
61
+ - application/json
62
+ response:
63
+ status:
64
+ code: 500
65
+ message: !binary |-
66
+ SW50ZXJuYWwgU2VydmVyIEVycm9y
67
+ headers:
68
+ !binary "U2VydmVy":
69
+ - !binary |-
70
+ QXBhY2hlLUNveW90ZS8xLjE=
71
+ !binary "Q29udGVudC1UeXBl":
72
+ - !binary |-
73
+ YXBwbGljYXRpb24vanNvbg==
74
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
75
+ - !binary |-
76
+ Y2h1bmtlZA==
77
+ !binary "RGF0ZQ==":
78
+ - !binary |-
79
+ VHVlLCAyOCBNYXkgMjAxMyAyMDowOTowNCBHTVQ=
80
+ !binary "Q29ubmVjdGlvbg==":
81
+ - !binary |-
82
+ Y2xvc2U=
83
+ body:
84
+ encoding: ASCII-8BIT
85
+ string: !binary |-
86
+ eyJzdGF0dXMiOjUwMCwiY29kZSI6NTAwLCJkZXZlbG9wZXJNZXNzYWdlIjoi
87
+ cnVsZXMuYWxyZWFkeS5leGlzdHMuZm9yLmNvbXBvbmVudCIsIm1vcmVJbmZv
88
+ VXJsIjoibWFpbHRvOnN1cHBvcnRAbXhoZXJvLmNvbSJ9
89
+ http_version:
90
+ recorded_at: Tue, 28 May 2013 20:08:42 GMT
91
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,50 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://admin:password@localhost:8080/webapi/api/v1/domains/tesla.com/rules
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"twoWays":false,"enabled":true,"name":"Email footer","created":"1369682598000","fromDirection":{"directionType":"domain","domain":"tesla.com","freeValue":"tesla.com"},"toDirection":{"directionType":"domain","domain":"tesla.com","freeValue":"tesla.com"},"properties":[{"propertyKey":"return.message","propertyValue":"footer
9
+ content"}],"component":"org.mxhero.feature.disclaimer","domain":"tesla.com"}'
10
+ headers:
11
+ Accept:
12
+ - application/json
13
+ Content-Type:
14
+ - application/json
15
+ response:
16
+ status:
17
+ code: 201
18
+ message: !binary |-
19
+ Q3JlYXRlZA==
20
+ headers:
21
+ !binary "U2VydmVy":
22
+ - !binary |-
23
+ QXBhY2hlLUNveW90ZS8xLjE=
24
+ !binary "Q29udGVudC1UeXBl":
25
+ - !binary |-
26
+ YXBwbGljYXRpb24vanNvbg==
27
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
28
+ - !binary |-
29
+ Y2h1bmtlZA==
30
+ !binary "RGF0ZQ==":
31
+ - !binary |-
32
+ VHVlLCAyOCBNYXkgMjAxMyAxNTozNzoyMCBHTVQ=
33
+ body:
34
+ encoding: ASCII-8BIT
35
+ string: !binary |-
36
+ eyJpZCI6ODUsImRvbWFpbiI6InRlc2xhLmNvbSIsIm5hbWUiOiJFbWFpbCBm
37
+ b290ZXIiLCJjcmVhdGVkIjoxMzY5NzU1NDQxMDAwLCJ1cGRhdGVkIjoxMzY5
38
+ NzU1NDQxMDAwLCJlbmFibGVkIjp0cnVlLCJ0d29XYXlzIjpmYWxzZSwiYWRt
39
+ aW5PcmRlciI6bnVsbCwiY29tcG9uZW50Ijoib3JnLm14aGVyby5mZWF0dXJl
40
+ LmRpc2NsYWltZXIiLCJmcm9tRGlyZWN0aW9uIjp7ImlkIjoxNjksImRpcmVj
41
+ dGlvblR5cGUiOiJkb21haW4iLCJmcmVlVmFsdWUiOiJ0ZXNsYS5jb20iLCJk
42
+ b21haW4iOiJ0ZXNsYS5jb20iLCJhY2NvdW50IjpudWxsLCJncm91cCI6bnVs
43
+ bH0sInRvRGlyZWN0aW9uIjp7ImlkIjoxNzAsImRpcmVjdGlvblR5cGUiOiJk
44
+ b21haW4iLCJmcmVlVmFsdWUiOiJ0ZXNsYS5jb20iLCJkb21haW4iOiJ0ZXNs
45
+ YS5jb20iLCJhY2NvdW50IjpudWxsLCJncm91cCI6bnVsbH0sInByb3BlcnRp
46
+ ZXMiOlt7InByb3BlcnR5S2V5IjoicmV0dXJuLm1lc3NhZ2UiLCJwcm9wZXJ0
47
+ eVZhbHVlIjoiZm9vdGVyIGNvbnRlbnQifV19
48
+ http_version:
49
+ recorded_at: Tue, 28 May 2013 15:37:02 GMT
50
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,50 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://admin:password@localhost:8080/webapi/api/v1/rules
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"twoWays":false,"enabled":true,"name":"Email footer","created":"1369682598000","fromDirection":{"directionType":"domain","domain":"tesla.com","freeValue":"tesla.com"},"toDirection":{"directionType":"domain","domain":"tesla.com","freeValue":"tesla.com"},"properties":[{"propertyKey":"return.message","propertyValue":"footer
9
+ content"}],"component":"org.mxhero.feature.disclaimer"}'
10
+ headers:
11
+ Accept:
12
+ - application/json
13
+ Content-Type:
14
+ - application/json
15
+ response:
16
+ status:
17
+ code: 201
18
+ message: !binary |-
19
+ Q3JlYXRlZA==
20
+ headers:
21
+ !binary "U2VydmVy":
22
+ - !binary |-
23
+ QXBhY2hlLUNveW90ZS8xLjE=
24
+ !binary "Q29udGVudC1UeXBl":
25
+ - !binary |-
26
+ YXBwbGljYXRpb24vanNvbg==
27
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
28
+ - !binary |-
29
+ Y2h1bmtlZA==
30
+ !binary "RGF0ZQ==":
31
+ - !binary |-
32
+ VHVlLCAyOCBNYXkgMjAxMyAxMzozNzowOCBHTVQ=
33
+ body:
34
+ encoding: ASCII-8BIT
35
+ string: !binary |-
36
+ eyJpZCI6ODIsImRvbWFpbiI6bnVsbCwibmFtZSI6IkVtYWlsIGZvb3RlciIs
37
+ ImNyZWF0ZWQiOjEzNjk3NDgyMjgwMDAsInVwZGF0ZWQiOjEzNjk3NDgyMjgw
38
+ MDAsImVuYWJsZWQiOnRydWUsInR3b1dheXMiOmZhbHNlLCJhZG1pbk9yZGVy
39
+ IjpudWxsLCJjb21wb25lbnQiOiJvcmcubXhoZXJvLmZlYXR1cmUuZGlzY2xh
40
+ aW1lciIsImZyb21EaXJlY3Rpb24iOnsiaWQiOjE2MywiZGlyZWN0aW9uVHlw
41
+ ZSI6ImRvbWFpbiIsImZyZWVWYWx1ZSI6InRlc2xhLmNvbSIsImRvbWFpbiI6
42
+ InRlc2xhLmNvbSIsImFjY291bnQiOm51bGwsImdyb3VwIjpudWxsfSwidG9E
43
+ aXJlY3Rpb24iOnsiaWQiOjE2NCwiZGlyZWN0aW9uVHlwZSI6ImRvbWFpbiIs
44
+ ImZyZWVWYWx1ZSI6InRlc2xhLmNvbSIsImRvbWFpbiI6InRlc2xhLmNvbSIs
45
+ ImFjY291bnQiOm51bGwsImdyb3VwIjpudWxsfSwicHJvcGVydGllcyI6W3si
46
+ cHJvcGVydHlLZXkiOiJyZXR1cm4ubWVzc2FnZSIsInByb3BlcnR5VmFsdWUi
47
+ OiJmb290ZXIgY29udGVudCJ9XX0=
48
+ http_version:
49
+ recorded_at: Tue, 28 May 2013 13:36:51 GMT
50
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,52 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://admin:password@localhost:8080/webapi/api/v1/domains/tesla.com/rules/97
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Content-Type:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: !binary |-
18
+ T0s=
19
+ headers:
20
+ !binary "U2VydmVy":
21
+ - !binary |-
22
+ QXBhY2hlLUNveW90ZS8xLjE=
23
+ !binary "Q29udGVudC1UeXBl":
24
+ - !binary |-
25
+ YXBwbGljYXRpb24vanNvbg==
26
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
27
+ - !binary |-
28
+ Y2h1bmtlZA==
29
+ !binary "RGF0ZQ==":
30
+ - !binary |-
31
+ V2VkLCAyOSBNYXkgMjAxMyAxOTo0MTozMSBHTVQ=
32
+ body:
33
+ encoding: ASCII-8BIT
34
+ string: !binary |-
35
+ eyJpZCI6OTcsImRvbWFpbiI6InRlc2xhLmNvbSIsIm5hbWUiOiJFbWFpbCBm
36
+ b290ZXIgLSBJbnNpZGUiLCJjcmVhdGVkIjoxMzY5ODM4NTY5MDAwLCJ1cGRh
37
+ dGVkIjoxMzY5ODM4NTY5MDAwLCJlbmFibGVkIjp0cnVlLCJ0d29XYXlzIjpm
38
+ YWxzZSwiYWRtaW5PcmRlciI6bnVsbCwiY29tcG9uZW50Ijoib3JnLm14aGVy
39
+ by5mZWF0dXJlLmRpc2NsYWltZXIiLCJmcm9tRGlyZWN0aW9uIjp7ImlkIjox
40
+ OTMsImRpcmVjdGlvblR5cGUiOiJkb21haW4iLCJmcmVlVmFsdWUiOiJ0ZXNs
41
+ YS5jb20iLCJkb21haW4iOiJ0ZXNsYS5jb20iLCJhY2NvdW50IjpudWxsLCJn
42
+ cm91cCI6bnVsbH0sInRvRGlyZWN0aW9uIjp7ImlkIjoxOTQsImRpcmVjdGlv
43
+ blR5cGUiOiJkb21haW4iLCJmcmVlVmFsdWUiOiJ0ZXNsYS5jb20iLCJkb21h
44
+ aW4iOiJ0ZXNsYS5jb20iLCJhY2NvdW50IjpudWxsLCJncm91cCI6bnVsbH0s
45
+ InByb3BlcnRpZXMiOlt7InByb3BlcnR5S2V5IjoicmV0dXJuLm1lc3NhZ2Ui
46
+ LCJwcm9wZXJ0eVZhbHVlIjoidGVzdCB0aGUmbmJzcDs8Yj50ZW1wbGF0ZSZu
47
+ YnNwOzwvYj5vZiB0aGUmbmJzcDs8aT5mb290ZXI8L2k+PGJyPiJ9LHsicHJv
48
+ cGVydHlLZXkiOiJpbnRlclBhcnNpbmciLCJwcm9wZXJ0eVZhbHVlIjoiZmFs
49
+ c2UifV19
50
+ http_version:
51
+ recorded_at: Wed, 29 May 2013 19:40:50 GMT
52
+ 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
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
+ RnJpLCAwNyBKdW4gMjAxMyAxNTo1MTo0MiBHTVQ=
34
+ body:
35
+ encoding: US-ASCII
36
+ string: ! '{"elements":[{"domain":"tesla.com","server":"tesla.com","creationDate":1369837819000,"updatedDate":1369837819000,"aliases":null,"ldap":null}],"totalElements":1,"totalPages":1,"actualPage":1}'
37
+ http_version:
38
+ recorded_at: Fri, 07 Jun 2013 15:51:41 GMT
39
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,52 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://admin:password@localhost:8080/webapi/api/v1/domains/tesla.com/rules
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Content-Type:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: !binary |-
18
+ T0s=
19
+ headers:
20
+ !binary "U2VydmVy":
21
+ - !binary |-
22
+ QXBhY2hlLUNveW90ZS8xLjE=
23
+ !binary "Q29udGVudC1UeXBl":
24
+ - !binary |-
25
+ YXBwbGljYXRpb24vanNvbg==
26
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
27
+ - !binary |-
28
+ Y2h1bmtlZA==
29
+ !binary "RGF0ZQ==":
30
+ - !binary |-
31
+ V2VkLCAyOSBNYXkgMjAxMyAxNjoxMjoxMiBHTVQ=
32
+ body:
33
+ encoding: ASCII-8BIT
34
+ string: !binary |-
35
+ W3siaWQiOjk3LCJkb21haW4iOiJ0ZXNsYS5jb20iLCJuYW1lIjoiRW1haWwg
36
+ Zm9vdGVyIC0gSW5zaWRlIiwiY3JlYXRlZCI6MTM2OTgzODU2OTAwMCwidXBk
37
+ YXRlZCI6MTM2OTgzODU2OTAwMCwiZW5hYmxlZCI6dHJ1ZSwidHdvV2F5cyI6
38
+ ZmFsc2UsImFkbWluT3JkZXIiOm51bGwsImNvbXBvbmVudCI6Im9yZy5teGhl
39
+ cm8uZmVhdHVyZS5kaXNjbGFpbWVyIiwiZnJvbURpcmVjdGlvbiI6eyJpZCI6
40
+ MTkzLCJkaXJlY3Rpb25UeXBlIjoiZG9tYWluIiwiZnJlZVZhbHVlIjoidGVz
41
+ bGEuY29tIiwiZG9tYWluIjoidGVzbGEuY29tIiwiYWNjb3VudCI6bnVsbCwi
42
+ Z3JvdXAiOm51bGx9LCJ0b0RpcmVjdGlvbiI6eyJpZCI6MTk0LCJkaXJlY3Rp
43
+ b25UeXBlIjoiZG9tYWluIiwiZnJlZVZhbHVlIjoidGVzbGEuY29tIiwiZG9t
44
+ YWluIjoidGVzbGEuY29tIiwiYWNjb3VudCI6bnVsbCwiZ3JvdXAiOm51bGx9
45
+ LCJwcm9wZXJ0aWVzIjpbeyJwcm9wZXJ0eUtleSI6InJldHVybi5tZXNzYWdl
46
+ IiwicHJvcGVydHlWYWx1ZSI6InRlc3QgdGhlJm5ic3A7PGI+dGVtcGxhdGUm
47
+ bmJzcDs8L2I+b2YgdGhlJm5ic3A7PGk+Zm9vdGVyPC9pPjxicj4ifSx7InBy
48
+ b3BlcnR5S2V5IjoiaW50ZXJQYXJzaW5nIiwicHJvcGVydHlWYWx1ZSI6ImZh
49
+ bHNlIn1dfV0=
50
+ http_version:
51
+ recorded_at: Wed, 29 May 2013 16:11:33 GMT
52
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,44 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://admin:password@localhost:8080/webapi/api/v1/rules
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"domain":"tesla.com","twoWays":false,"enabled":true,"name":"Email
9
+ footer - inside","created":"1370629428226","fromDirection":{"directionType":"domain","domain":"tesla.com","freeValue":"tesla.com"},"toDirection":{"directionType":"domain","domain":"tesla.com","freeValue":"tesla.com"},"properties":[{"propertyKey":"return.message","propertyValue":"A
10
+ test with a <b>Footer</b> in strong"},{"propertyKey":"interParsing","propertyValue":false}],"component":"org.mxhero.feature.disclaimer"}'
11
+ headers:
12
+ Accept:
13
+ - application/json
14
+ Content-Type:
15
+ - application/json
16
+ Authorization:
17
+ - Basic YWRtaW46cGFzc3dvcmQ=
18
+ response:
19
+ status:
20
+ code: 500
21
+ message: !binary |-
22
+ SW50ZXJuYWwgU2VydmVyIEVycm9y
23
+ headers:
24
+ !binary "U2VydmVy":
25
+ - !binary |-
26
+ QXBhY2hlLUNveW90ZS8xLjE=
27
+ !binary "Q29udGVudC1UeXBl":
28
+ - !binary |-
29
+ YXBwbGljYXRpb24vanNvbg==
30
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
31
+ - !binary |-
32
+ Y2h1bmtlZA==
33
+ !binary "RGF0ZQ==":
34
+ - !binary |-
35
+ RnJpLCAwNyBKdW4gMjAxMyAxODoyMzo1MCBHTVQ=
36
+ !binary "Q29ubmVjdGlvbg==":
37
+ - !binary |-
38
+ Y2xvc2U=
39
+ body:
40
+ encoding: US-ASCII
41
+ string: ! '{"status":500,"code":500,"developerMessage":"rule.domain.admin.only","moreInfoUrl":"mailto:support@mxhero.com"}'
42
+ http_version:
43
+ recorded_at: Fri, 07 Jun 2013 18:23:49 GMT
44
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,73 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://admin:password@localhost:8080/webapi/api/v1/domains/tesla.com/rules
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Content-Type:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: !binary |-
18
+ T0s=
19
+ headers:
20
+ !binary "U2VydmVy":
21
+ - !binary |-
22
+ QXBhY2hlLUNveW90ZS8xLjE=
23
+ !binary "Q29udGVudC1UeXBl":
24
+ - !binary |-
25
+ YXBwbGljYXRpb24vanNvbg==
26
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
27
+ - !binary |-
28
+ Y2h1bmtlZA==
29
+ !binary "RGF0ZQ==":
30
+ - !binary |-
31
+ RnJpLCAzMSBNYXkgMjAxMyAwMjowNDo0OCBHTVQ=
32
+ body:
33
+ encoding: ASCII-8BIT
34
+ string: !binary |-
35
+ W3siaWQiOjEwNCwiZG9tYWluIjoidGVzbGEuY29tIiwibmFtZSI6ImFhYWFh
36
+ IiwiY3JlYXRlZCI6MTM2OTk2MTc3NzAwMCwidXBkYXRlZCI6MTM2OTk2MTc3
37
+ NzAwMCwiZW5hYmxlZCI6dHJ1ZSwidHdvV2F5cyI6ZmFsc2UsImFkbWluT3Jk
38
+ ZXIiOm51bGwsImNvbXBvbmVudCI6Im9yZy5teGhlcm8uZmVhdHVyZS5kaXNj
39
+ bGFpbWVyIiwiZnJvbURpcmVjdGlvbiI6eyJpZCI6MTk3LCJkaXJlY3Rpb25U
40
+ eXBlIjoiZG9tYWluIiwiZnJlZVZhbHVlIjoidGVzbGEuY29tIiwiZG9tYWlu
41
+ IjoidGVzbGEuY29tIiwiYWNjb3VudCI6bnVsbCwiZ3JvdXAiOm51bGx9LCJ0
42
+ b0RpcmVjdGlvbiI6eyJpZCI6MTk4LCJkaXJlY3Rpb25UeXBlIjoiZG9tYWlu
43
+ IiwiZnJlZVZhbHVlIjoidGVzbGEuY29tIiwiZG9tYWluIjoidGVzbGEuY29t
44
+ IiwiYWNjb3VudCI6bnVsbCwiZ3JvdXAiOm51bGx9LCJwcm9wZXJ0aWVzIjpb
45
+ eyJwcm9wZXJ0eUtleSI6InJldHVybi5tZXNzYWdlIiwicHJvcGVydHlWYWx1
46
+ ZSI6IjxCT0RZPlxuICA8UCBTVFlMRT1cInRleHQtYWxpZ246bGVmdDtcIj5c
47
+ biAgICA8U1BBTiBTVFlMRT1cImxldHRlci1zcGFjaW5nOjBweDtjb2xvcjoj
48
+ MDAwMDAwO2ZvbnQtc2l6ZToxMnB4O2ZvbnQtZmFtaWx5OidBcmlhbCc7XCI+
49
+ VGhpcyBtZXNzYWdlIGlzIGludGVuZGVkIG9ubHkgZm9yICR7bXhyZWNpcGll
50
+ bnR9LiBJZiB5b3UgYXJlIG5vdCB0aGUgaW50ZW5kZWQgcmVjaXBpZW50IHlv
51
+ dSBhcmUgbm90aWZpZWQgdGhhdCBkaXNjbG9zaW5nLCBjb3B5aW5nLCBkaXN0
52
+ cmlidXRpbmcgb3IgdGFraW5nIGFueSBhY3Rpb24gaW4gcmVsaWFuY2Ugb24g
53
+ dGhlIGNvbnRlbnRzIG9mIHRoaXMgaW5mb3JtYXRpb24gaXMgc3RyaWN0bHkg
54
+ cHJvaGliaXRlZC48L1NQQU4+XG4gIDwvUD5cbjwvQk9EWT4ifSx7InByb3Bl
55
+ cnR5S2V5IjoicmV0dXJuLm1lc3NhZ2UucGxhaW4iLCJwcm9wZXJ0eVZhbHVl
56
+ IjoiVGhpcyBtZXNzYWdlIGlzIGludGVuZGVkIG9ubHkgZm9yICR7bXhyZWNp
57
+ cGllbnR9LiBJZiB5b3UgYXJlIG5vdCB0aGUgaW50ZW5kZWQgcmVjaXBpZW50
58
+ IHlvdSBhcmUgbm90aWZpZWQgdGhhdCBkaXNjbG9zaW5nLCBjb3B5aW5nLCBk
59
+ aXN0cmlidXRpbmcgb3IgdGFraW5nIGFueSBhY3Rpb24gaW4gcmVsaWFuY2Ug
60
+ b24gdGhlIGNvbnRlbnRzIG9mIHRoaXMgaW5mb3JtYXRpb24gaXMgc3RyaWN0
61
+ bHkgcHJvaGliaXRlZC4ifSx7InByb3BlcnR5S2V5IjoicmV0dXJuLm1lc3Nh
62
+ Z2UucnRlIiwicHJvcGVydHlWYWx1ZSI6IjxUZXh0RmxvdyB3aGl0ZVNwYWNl
63
+ Q29sbGFwc2U9XCJwcmVzZXJ2ZVwiIHZlcnNpb249XCIyLjAuMFwiIHhtbG5z
64
+ PVwiaHR0cDovL25zLmFkb2JlLmNvbS90ZXh0TGF5b3V0LzIwMDhcIj48cD48
65
+ c3Bhbj5UaGlzIG1lc3NhZ2UgaXMgaW50ZW5kZWQgb25seSBmb3IgJHtteHJl
66
+ Y2lwaWVudH0uIElmIHlvdSBhcmUgbm90IHRoZSBpbnRlbmRlZCByZWNpcGll
67
+ bnQgeW91IGFyZSBub3RpZmllZCB0aGF0IGRpc2Nsb3NpbmcsIGNvcHlpbmcs
68
+ IGRpc3RyaWJ1dGluZyBvciB0YWtpbmcgYW55IGFjdGlvbiBpbiByZWxpYW5j
69
+ ZSBvbiB0aGUgY29udGVudHMgb2YgdGhpcyBpbmZvcm1hdGlvbiBpcyBzdHJp
70
+ Y3RseSBwcm9oaWJpdGVkLjwvc3Bhbj48L3A+PC9UZXh0Rmxvdz4ifV19XQ==
71
+ http_version:
72
+ recorded_at: Fri, 31 May 2013 18:15:22 GMT
73
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,83 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: http://admin:password@localhost:8080/webapi/api/v1/domains/tesla.com/rules/97
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"twoWays":false,"enabled":true,"name":"Email footer","created":1369682598000,"fromDirection":{"directionType":"domain","domain":"tesla.com","freeValue":"tesla.com"},"toDirection":{"directionType":"domain","domain":"tesla.com","freeValue":"tesla.com"},"properties":[{"propertyKey":"return.message","propertyValue":"another
9
+ content"}],"component":"org.mxhero.feature.disclaimer","domain":"tesla.com","id":97}'
10
+ headers:
11
+ Accept:
12
+ - application/json
13
+ Content-Type:
14
+ - application/json
15
+ !binary "RXhwZWN0":
16
+ - !binary ""
17
+ response:
18
+ status:
19
+ code: 200
20
+ message: !binary |-
21
+ T0s=
22
+ headers:
23
+ !binary "U2VydmVy":
24
+ - !binary |-
25
+ QXBhY2hlLUNveW90ZS8xLjE=
26
+ !binary "Q29udGVudC1MZW5ndGg=":
27
+ - !binary |-
28
+ MA==
29
+ !binary "RGF0ZQ==":
30
+ - !binary |-
31
+ V2VkLCAyOSBNYXkgMjAxMyAyMDoyMDozOCBHTVQ=
32
+ body:
33
+ encoding: ASCII-8BIT
34
+ string: !binary ""
35
+ http_version:
36
+ recorded_at: Wed, 29 May 2013 20:19:56 GMT
37
+ - request:
38
+ method: get
39
+ uri: http://admin:password@localhost:8080/webapi/api/v1/domains/tesla.com/rules/97
40
+ body:
41
+ encoding: US-ASCII
42
+ string: ''
43
+ headers:
44
+ Accept:
45
+ - application/json
46
+ Content-Type:
47
+ - application/json
48
+ response:
49
+ status:
50
+ code: 200
51
+ message: !binary |-
52
+ T0s=
53
+ headers:
54
+ !binary "U2VydmVy":
55
+ - !binary |-
56
+ QXBhY2hlLUNveW90ZS8xLjE=
57
+ !binary "Q29udGVudC1UeXBl":
58
+ - !binary |-
59
+ YXBwbGljYXRpb24vanNvbg==
60
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
61
+ - !binary |-
62
+ Y2h1bmtlZA==
63
+ !binary "RGF0ZQ==":
64
+ - !binary |-
65
+ V2VkLCAyOSBNYXkgMjAxMyAyMDoyMDozOCBHTVQ=
66
+ body:
67
+ encoding: ASCII-8BIT
68
+ string: !binary |-
69
+ eyJpZCI6OTcsImRvbWFpbiI6InRlc2xhLmNvbSIsIm5hbWUiOiJFbWFpbCBm
70
+ b290ZXIiLCJjcmVhdGVkIjoxMzY5ODM4NTY5MDAwLCJ1cGRhdGVkIjoxMzY5
71
+ ODU4ODM4MDAwLCJlbmFibGVkIjp0cnVlLCJ0d29XYXlzIjpmYWxzZSwiYWRt
72
+ aW5PcmRlciI6bnVsbCwiY29tcG9uZW50Ijoib3JnLm14aGVyby5mZWF0dXJl
73
+ LmRpc2NsYWltZXIiLCJmcm9tRGlyZWN0aW9uIjp7ImlkIjoxOTMsImRpcmVj
74
+ dGlvblR5cGUiOiJkb21haW4iLCJmcmVlVmFsdWUiOiJ0ZXNsYS5jb20iLCJk
75
+ b21haW4iOiJ0ZXNsYS5jb20iLCJhY2NvdW50IjpudWxsLCJncm91cCI6bnVs
76
+ bH0sInRvRGlyZWN0aW9uIjp7ImlkIjoxOTQsImRpcmVjdGlvblR5cGUiOiJk
77
+ b21haW4iLCJmcmVlVmFsdWUiOiJ0ZXNsYS5jb20iLCJkb21haW4iOiJ0ZXNs
78
+ YS5jb20iLCJhY2NvdW50IjpudWxsLCJncm91cCI6bnVsbH0sInByb3BlcnRp
79
+ ZXMiOlt7InByb3BlcnR5S2V5IjoicmV0dXJuLm1lc3NhZ2UiLCJwcm9wZXJ0
80
+ eVZhbHVlIjoiYW5vdGhlciBjb250ZW50In1dfQ==
81
+ http_version:
82
+ recorded_at: Wed, 29 May 2013 20:19:56 GMT
83
+ recorded_with: VCR 2.5.0
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+
4
+ Dir['./lib/**/*.rb'].each { |rb| require rb }
5
+
6
+ TEST_API_DOMAIN = 'tesla.com'
7
+ TEST_API_URL = 'http://localhost:8080/webapi/api/v1'
8
+ TEST_API_USER = 'admin'
9
+ TEST_API_PASSWORD = 'password'
10
+
11
+ require 'vcr'
12
+
13
+ VCR.configure do |c|
14
+ c.cassette_library_dir = 'test/fixtures/api'
15
+ c.allow_http_connections_when_no_cassette = true
16
+ c.hook_into :webmock
17
+ end
18
+
@@ -0,0 +1,92 @@
1
+ require_relative 'helper'
2
+
3
+ class MxHeroAPITest < MiniTest::Unit::TestCase
4
+
5
+ def setup
6
+ @api = MxHero::API::Client.new(username: TEST_API_USER, password: TEST_API_PASSWORD, verbose: false, api_url: TEST_API_URL)
7
+ end
8
+
9
+ def test_update_rule
10
+ VCR.use_cassette('update_rule') do
11
+ msg = rule_msg_with_domain('tesla.com')
12
+ msg[:id] = 97
13
+ msg[:properties].first[:propertyValue] = 'another content'
14
+ assert @api.update_rule(msg)
15
+
16
+ rule = @api.domain_rule(msg[:domain], msg[:id])
17
+ assert 97, rule[:id]
18
+ assert 'another content', rule[:properties].first[:propertyValue]
19
+ end
20
+ end
21
+
22
+ def test_domain_rule
23
+ VCR.use_cassette('domain_rule') do
24
+ rule = @api.domain_rule('tesla.com', 97)
25
+ assert 97, rule[:id]
26
+ assert 'tesla.com', rule[:domain]
27
+ end
28
+ end
29
+
30
+ def test_rules_for_domain
31
+ VCR.use_cassette('rules_for_domain') do
32
+ response = @api.rules_for_domain('tesla.com')
33
+ assert response.code == 200
34
+ rules = response.msg
35
+ assert_equal 'tesla.com', rules.first[:domain]
36
+ end
37
+ end
38
+
39
+ def test_domains
40
+ VCR.use_cassette('domains') do
41
+ domains = @api.domains
42
+ assert domains.key?(:elements)
43
+ assert domains.key?(:totalElements)
44
+ assert domains.key?(:totalPages)
45
+ assert domains.key?(:actualPage)
46
+ end
47
+ end
48
+
49
+ def rule_msg_with_domain(domain)
50
+ msg = create_rule_msg
51
+ msg[:domain] = domain
52
+ msg
53
+ end
54
+
55
+ def create_rule_msg
56
+ {
57
+ #"domain" => "tesla.com",
58
+ twoWays: false,
59
+ enabled: true,
60
+ name: "Email footer",
61
+ created: 1369682598000,
62
+ fromDirection: { directionType: "domain", domain: "tesla.com", freeValue: "tesla.com" },
63
+ toDirection: { directionType: "domain", domain: "tesla.com", freeValue: "tesla.com" },
64
+ properties: [{ propertyKey: "return.message", propertyValue: "footer content" }],
65
+ component: "org.mxhero.feature.disclaimer"
66
+ }
67
+ end
68
+
69
+ def test_create_rule
70
+ VCR.use_cassette('create_rule_success') do
71
+ response = @api.create_rule(create_rule_msg)
72
+ assert response.code == 201
73
+ end
74
+ end
75
+
76
+ def test_try_to_create_rule_that_alredy_exist
77
+ VCR.use_cassette('create_rule_alredy_exist') do
78
+ response = @api.create_rule(create_rule_msg)
79
+ assert response.code == 201
80
+ new_response = @api.create_rule(create_rule_msg)
81
+ assert new_response.code == 500
82
+ assert_equal "rules.already.exists.for.component", new_response.msg[:developerMessage]
83
+ end
84
+ end
85
+
86
+ def test_create_rule_for_domain
87
+ VCR.use_cassette('create_rule_for_domain') do
88
+ response = @api.create_rule_for_domain('tesla.com', create_rule_msg.merge({"domain" => "tesla.com"}))
89
+ assert response.code == 201
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,12 @@
1
+ require_relative 'helper'
2
+
3
+ class MxHeroResponseTest < MiniTest::Unit::TestCase
4
+ def test_sucess
5
+ [200, 201, '200', '201'].each do |success_code|
6
+ response = MxHero::API::Response.new(success_code, '')
7
+ assert response.success?
8
+ assert response.msg == ''
9
+ end
10
+ end
11
+ end
12
+
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mxhero-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Maximiliano Dello Russo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: vcr
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.5.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.5.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: webmock
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - '='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.11.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.11.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: httpclient
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: 2.3.3
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.3.3
62
+ description: A gem to provide easy access to the API of MxHero platform (http://www.mxhero.com/)
63
+ email:
64
+ - maxidr@mxhero.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - README.md
72
+ - Rakefile
73
+ - lib/mxhero_api.rb
74
+ - mxhero-api.gemspec
75
+ - test/fixtures/api/create_rule_alredy_exist.yml
76
+ - test/fixtures/api/create_rule_for_domain.yml
77
+ - test/fixtures/api/create_rule_success.yml
78
+ - test/fixtures/api/domain_rule.yml
79
+ - test/fixtures/api/domains.yml
80
+ - test/fixtures/api/rules_for_domain.yml
81
+ - test/fixtures/api/service_create_footer.yml
82
+ - test/fixtures/api/service_footer_for_domain.yml
83
+ - test/fixtures/api/update_rule.yml
84
+ - test/helper.rb
85
+ - test/test_mxhero_api.rb
86
+ - test/test_mxhero_api_response.rb
87
+ homepage: http://github.com/mxhero/mxhero-api
88
+ licenses: []
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.23
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: A MxHero API client for ruby
111
+ test_files: []
112
+ has_rdoc: