mxhero-api 0.1.24 → 0.1.25
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.
- checksums.yaml +8 -8
- data/VERSION +1 -1
- data/lib/groups.rb +0 -28
- data/lib/mxhero-api.rb +27 -51
- data/lib/resource.rb +103 -0
- data/lib/resources/account.rb +18 -0
- data/lib/resources/domain.rb +58 -0
- data/lib/resources/group.rb +15 -0
- data/mxhero-api.gemspec +5 -5
- data/test/fixtures/api/move_to_trial.yml +39 -0
- data/test/fixtures/api/test_domain.yml +5 -5
- data/test/fixtures/domain.rb +29 -0
- data/test/helper.rb +3 -0
- data/test/test_domain.rb +29 -0
- data/test/test_feature.rb +34 -0
- data/test/test_mxhero_api.rb +7 -5
- data/test/test_resource.rb +59 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGQ3ZGYzMWMwZDkwNDVkYTFkNzZmZjVkYmY5MDliYmZjMzA3MmJjZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
N2JkNGE1ODBhOWM5Y2NmZTRhMjE3OGYyNzg3Njk4NDczY2M2NzI0Zg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZWYxYWE4NDIzODY5NTIxMjk5OTQ1YzI5NGJmMjhmZjcxNmUyY2M5ZTQ2MGRl
|
10
|
+
OTI1OTFjOTAwZjdlY2Y1NTY4M2M2MGI5YWJhNDAwN2Y4MGQzYTUwOGM5MTAw
|
11
|
+
Yzc2MjdkNTQ0N2Y5NDUwY2U0ZGY3YjI3NDI2ZDgyY2JjYmE2MTU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWU3Y2EyMzVmMmQ0ODQ5NjIyNWIzMDQyOGY3N2NiZjU2NWIzMzg0MmRiYjY5
|
14
|
+
MjdmYWZlZTI2OWUzZWFkNjQwODY5Y2M0NWQzYzQ2MzUwMjMzZDQ1ZWE1MTgw
|
15
|
+
YjQzYzRiOGUyZGE2MDA5ZDM1ZGQxODJkNzc5MTlkZjQ1ZTdlMmU=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.25
|
data/lib/groups.rb
CHANGED
@@ -6,34 +6,6 @@ require 'delegate'
|
|
6
6
|
|
7
7
|
module MxHero::API
|
8
8
|
|
9
|
-
# A group instance
|
10
|
-
#
|
11
|
-
class Group < Struct.new(:name, :domain, :description)
|
12
|
-
def initialize(elements)
|
13
|
-
elements.each { |prop, value| send("#{prop}=", value) if respond_to?("#{prop}") }
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_json
|
17
|
-
{ name: name, domain: domain, description: description }.to_json
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
class Account < Struct.new(:account, :domain, :created_date, :updated_date, :group)
|
23
|
-
def initialize(elements)
|
24
|
-
elements.each { |prop, value| send("#{prop}=", value) if respond_to?("#{prop}") }
|
25
|
-
end
|
26
|
-
|
27
|
-
def to_json
|
28
|
-
{ account: account, domain: domain, createdDate: created_date, updatedDate: updated_date, group: group }.to_json
|
29
|
-
end
|
30
|
-
|
31
|
-
def to_s
|
32
|
-
"account: #{account}, domain: #{domain}, group: #{group}"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
9
|
class PaginatedElements < SimpleDelegator
|
38
10
|
attr_reader :total_elements, :total_pages, :actual_page
|
39
11
|
def initialize(paginable, total_elements, total_pages, actual_page)
|
data/lib/mxhero-api.rb
CHANGED
@@ -2,11 +2,15 @@
|
|
2
2
|
require 'httpclient'
|
3
3
|
require 'json'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
require 'communication'
|
6
|
+
require 'urls'
|
7
|
+
require 'groups'
|
8
|
+
require 'dto'
|
9
|
+
require 'directories'
|
10
|
+
require 'resource'
|
11
|
+
require 'resources/account'
|
12
|
+
require 'resources/domain'
|
13
|
+
require 'resources/group'
|
10
14
|
|
11
15
|
module MxHero::API
|
12
16
|
# The class that contains the response information
|
@@ -35,41 +39,6 @@ module MxHero::API
|
|
35
39
|
alias_method :content=, :msg=
|
36
40
|
end
|
37
41
|
|
38
|
-
|
39
|
-
#class Account
|
40
|
-
# attr_accessor :account, :domain, :created_date, :updated_date, :group, :properties
|
41
|
-
#
|
42
|
-
# def initialize(props = {})
|
43
|
-
# @account = props[:account]
|
44
|
-
# @domain = props[:domain]
|
45
|
-
# @created_date = props[:created_date] || props[:createdDate]
|
46
|
-
# @updated_date = props[:updated_date] || props[:updatedDate]
|
47
|
-
# @group = props[:group]
|
48
|
-
# @properties = props[:properties] || []
|
49
|
-
# end
|
50
|
-
|
51
|
-
# def to_json
|
52
|
-
# { account: account, domain: domain,
|
53
|
-
# createdDate: created_date,
|
54
|
-
# updatedDate: updated_date,
|
55
|
-
# group: group,
|
56
|
-
# properties: properties }.to_json
|
57
|
-
# end
|
58
|
-
|
59
|
-
# def to_s
|
60
|
-
# """
|
61
|
-
# account: #{account}
|
62
|
-
# domain: #{domain}
|
63
|
-
# updated_date: #{updated_date}
|
64
|
-
# created_date: #{created_date}
|
65
|
-
# group: #{group}
|
66
|
-
# properties: #{properties}
|
67
|
-
# """
|
68
|
-
# end
|
69
|
-
|
70
|
-
#end
|
71
|
-
|
72
|
-
|
73
42
|
# A client to interact with mxhero engine API
|
74
43
|
class Client
|
75
44
|
include Communication
|
@@ -143,27 +112,34 @@ module MxHero::API
|
|
143
112
|
response_as_a_hash
|
144
113
|
end
|
145
114
|
|
115
|
+
|
116
|
+
# Move COS to trial
|
117
|
+
# @return true | false
|
118
|
+
def move_to_trial(domain)
|
119
|
+
url = domain_by_id_url(domain) + '/cos/trial'
|
120
|
+
response = call(:put, url)
|
121
|
+
response.status == 200
|
122
|
+
end
|
123
|
+
|
146
124
|
|
147
125
|
# Retrive the domain information
|
148
126
|
#
|
149
127
|
# @param name The domain name or id. For example: 'mydomain.com'
|
150
|
-
# @return [
|
151
|
-
# * :domain [String]
|
152
|
-
# * :server [String]
|
153
|
-
# * :creationDate [Fixnum]
|
154
|
-
# * :updateDate [Fixnum]
|
155
|
-
# * :aliases [Array<String>]
|
156
|
-
# * :ldap
|
157
|
-
#
|
158
|
-
# Or nil if not found
|
128
|
+
# @return [Domain] or nil if not found
|
159
129
|
#
|
160
130
|
# @raise an exception when the status code is not 200 (ok) or 404 (not found)
|
161
131
|
#
|
162
132
|
def domain(name)
|
163
|
-
fetch domain_by_id_url(name),
|
164
|
-
|
133
|
+
domain_info = fetch domain_by_id_url(name), on_error: "An error ocurred when try to fetch the domain #{name}."
|
134
|
+
return nil unless domain_info
|
135
|
+
Domain.new domain_info
|
165
136
|
end
|
166
137
|
|
138
|
+
#def update_cos(domain, cos)
|
139
|
+
# domain_by_id_url(name) + "cos/#{cos}"
|
140
|
+
# response = call(:post, url, msg.to_json, throw_exception: false)
|
141
|
+
#end
|
142
|
+
|
167
143
|
|
168
144
|
# Fetch the LDAP information of the domain
|
169
145
|
#
|
data/lib/resource.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
module MxHero::API
|
2
|
+
|
3
|
+
# Base resource
|
4
|
+
#
|
5
|
+
# Example of use:
|
6
|
+
#
|
7
|
+
# class User < MxHero::API::Resource
|
8
|
+
# attribute :first_name, map: 'firstName' # Map the resource attribute (hash key) from firstName
|
9
|
+
# attribute :last_name, map: 'lastName'
|
10
|
+
# attribute :updated, date: true
|
11
|
+
# attribute :age
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# The map in attribute indicate that can build an instance with a Hash that contains :firstName to set
|
15
|
+
# first_name instance attribute.
|
16
|
+
#
|
17
|
+
# Or:
|
18
|
+
#
|
19
|
+
# class User < MxHero::API::Resource
|
20
|
+
# attributes :first_name, :last_name, :age
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
class Resource
|
24
|
+
|
25
|
+
# Create an instance attribute and accessors
|
26
|
+
# If indicate map in more parameter (ex.: map: 'firstName') that can
|
27
|
+
# be set in the construction with a Hash that contains :firstName
|
28
|
+
# Can use date: true to manage date fields as Unix epoch integers
|
29
|
+
#
|
30
|
+
# Ex.: attribute :first_name, map: 'firstName'
|
31
|
+
#
|
32
|
+
def self.attribute(name, more = {})
|
33
|
+
instance_variable_set(:"@#{name}", nil)
|
34
|
+
attr_accessor :"#{name}"
|
35
|
+
map(name, more[:map]) if more.has_key?(:map)
|
36
|
+
date_accessor(name) if more.fetch(:date, false)
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# Create a list of attributes
|
41
|
+
#
|
42
|
+
# Ex.: attributes :first_name, :last_name, :age
|
43
|
+
#
|
44
|
+
def self.attributes(*attrs)
|
45
|
+
attrs.each { |attr| attribute(attr) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def initialize(data)
|
49
|
+
return unless data
|
50
|
+
data.each do |variable, value|
|
51
|
+
set = "#{variable}="
|
52
|
+
send(set, value) if respond_to? set
|
53
|
+
end
|
54
|
+
self.class.mappings.each do |attr, map|
|
55
|
+
send("#{attr}=", data[map]) if data.key?(map)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_json
|
60
|
+
hash = Hash.new
|
61
|
+
instance_variables.each do |variable|
|
62
|
+
attr = variable[1..-1].to_sym
|
63
|
+
key = self.class.mappings.fetch(attr, attr)
|
64
|
+
hash[key] = instance_variable_get(variable)
|
65
|
+
if self.class.date_attributes.include?(attr)
|
66
|
+
hash[key] = hash[key].strftime('%Q')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
hash.to_json
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def self.mappings
|
75
|
+
@mappings
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.map(attr, map)
|
79
|
+
@mappings ||= {}
|
80
|
+
@mappings[attr.to_sym] = map.to_sym
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.date_attributes
|
84
|
+
@date_attributes || []
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.date_accessor(attribute)
|
88
|
+
@date_attributes ||= []
|
89
|
+
@date_attributes << attribute
|
90
|
+
|
91
|
+
# Redefine the setter to support Unix Epoch (integer or string) or date
|
92
|
+
define_method("#{attribute}=") do |date|
|
93
|
+
if date.is_a? Integer or date.is_a? String
|
94
|
+
instance_variable_set "@#{attribute}", DateTime.strptime(date.to_s, '%Q')
|
95
|
+
else
|
96
|
+
instance_variable_set "@#{attribute}", date
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
module MxHero::API
|
3
|
+
|
4
|
+
class Account < Struct.new(:account, :domain, :created_date, :updated_date, :group)
|
5
|
+
def initialize(elements)
|
6
|
+
elements.each { |prop, value| send("#{prop}=", value) if respond_to?("#{prop}") }
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_json
|
10
|
+
{ account: account, domain: domain, createdDate: created_date, updatedDate: updated_date, group: group }.to_json
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
"account: #{account}, domain: #{domain}, group: #{group}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module MxHero::API
|
2
|
+
|
3
|
+
class Domain < Resource
|
4
|
+
|
5
|
+
attributes :domain, :server, :creation_date, :update_date,
|
6
|
+
:aliases, :features, :cos, :cos_last_change
|
7
|
+
|
8
|
+
attribute :creation_date, map: 'creationDate', date: true
|
9
|
+
attribute :update_date, map: 'updateDate', date: true
|
10
|
+
attribute :cos_last_change, map: 'cosLastChange', date: true
|
11
|
+
|
12
|
+
def initialize(data = {})
|
13
|
+
super(data)
|
14
|
+
load_features(features)
|
15
|
+
load_cos(cos)
|
16
|
+
end
|
17
|
+
|
18
|
+
def change_to_trial
|
19
|
+
if cos.type == 'free'
|
20
|
+
cos.type = 'trial'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def load_cos(cos)
|
27
|
+
@cos = Cos.new cos
|
28
|
+
end
|
29
|
+
|
30
|
+
def load_features(features)
|
31
|
+
@features = features.map { |feature| Feature.new feature }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
class Feature < Resource
|
37
|
+
attribute :component, map: 'feature'
|
38
|
+
attributes :created, :updated, :metadata
|
39
|
+
attribute :max_rules_amount, map: 'maxRulesAmount'
|
40
|
+
|
41
|
+
def initialize(data = {})
|
42
|
+
super(data)
|
43
|
+
if max_rules_amount == 0 || max_rules_amount.nil?
|
44
|
+
@max_rules_amount = Float::INFINITY
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def unlimited_use?
|
49
|
+
max_rules_amount == Float::INFINITY
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Cos < Resource
|
54
|
+
attribute :type, map: 'cos'
|
55
|
+
attribute :edition
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MxHero::API
|
2
|
+
|
3
|
+
# A group instance
|
4
|
+
#
|
5
|
+
class Group < Struct.new(:name, :domain, :description)
|
6
|
+
def initialize(elements)
|
7
|
+
elements.each { |prop, value| send("#{prop}=", value) if respond_to?("#{prop}") }
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_json
|
11
|
+
{ name: name, domain: domain, description: description }.to_json
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/mxhero-api.gemspec
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: mxhero-api 0.1.
|
2
|
+
# stub: mxhero-api 0.1.25 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "mxhero-api"
|
6
|
-
s.version = "0.1.
|
6
|
+
s.version = "0.1.25"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.authors = ["Maximiliano Dello Russo", "Juan Pablo Royo", "mxHero"]
|
10
|
-
s.date = "2013-12-
|
10
|
+
s.date = "2013-12-27"
|
11
11
|
s.description = "A gem to provide easy access to the API of MxHero platform (http://www.mxhero.com/)"
|
12
12
|
s.email = ["maxidr@mxhero.com", "juanpablo.royo@gmail.com", "mxhero@mxhero.com"]
|
13
|
-
s.files = [".gitignore", ".rvmrc", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "VERSION", "lib/communication.rb", "lib/directories.rb", "lib/dto.rb", "lib/groups.rb", "lib/mxhero-api.rb", "lib/urls.rb", "mxhero-api.gemspec", "test/fixtures/api/account_properties.yml", "test/fixtures/api/account_properties_not_found.yml", "test/fixtures/api/accounts.yml", "test/fixtures/api/accounts_filtered.yml", "test/fixtures/api/accounts_from_domain.yml", "test/fixtures/api/accounts_from_domain_paginated.yml", "test/fixtures/api/accounts_without_group.yml", "test/fixtures/api/add_an_inexistent_account_to_group.yml", "test/fixtures/api/add_and_remove_account.yml", "test/fixtures/api/all_groups.yml", "test/fixtures/api/create_directory.yml", "test/fixtures/api/create_rule_for_domain.yml", "test/fixtures/api/delete_directory.yml", "test/fixtures/api/delete_group.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/fetch_directory.yml", "test/fixtures/api/ldap_info.yml", "test/fixtures/api/refresh_directory.yml", "test/fixtures/api/remove_account_from_group_twice.yml", "test/fixtures/api/remove_inexistente_account_from_group.yml", "test/fixtures/api/rules_for_domain.yml", "test/fixtures/api/rules_for_domain_by_component.yml", "test/fixtures/api/save_group.yml", "test/fixtures/api/test_domain.yml", "test/fixtures/api/update_account_properties.yml", "test/fixtures/api/update_accounts_group_scope.yml", "test/fixtures/api/update_accounts_properties_scope.yml", "test/fixtures/api/update_directory.yml", "test/fixtures/api/update_rule.yml", "test/helper.rb", "test/test_directories.rb", "test/test_dto.rb", "test/test_groups.rb", "test/test_mxhero_api.rb", "test/test_mxhero_api_response.rb"]
|
13
|
+
s.files = [".gitignore", ".rvmrc", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "VERSION", "lib/communication.rb", "lib/directories.rb", "lib/dto.rb", "lib/groups.rb", "lib/mxhero-api.rb", "lib/resource.rb", "lib/resources/account.rb", "lib/resources/domain.rb", "lib/resources/group.rb", "lib/urls.rb", "mxhero-api.gemspec", "test/fixtures/api/account_properties.yml", "test/fixtures/api/account_properties_not_found.yml", "test/fixtures/api/accounts.yml", "test/fixtures/api/accounts_filtered.yml", "test/fixtures/api/accounts_from_domain.yml", "test/fixtures/api/accounts_from_domain_paginated.yml", "test/fixtures/api/accounts_without_group.yml", "test/fixtures/api/add_an_inexistent_account_to_group.yml", "test/fixtures/api/add_and_remove_account.yml", "test/fixtures/api/all_groups.yml", "test/fixtures/api/create_directory.yml", "test/fixtures/api/create_rule_for_domain.yml", "test/fixtures/api/delete_directory.yml", "test/fixtures/api/delete_group.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/fetch_directory.yml", "test/fixtures/api/ldap_info.yml", "test/fixtures/api/move_to_trial.yml", "test/fixtures/api/refresh_directory.yml", "test/fixtures/api/remove_account_from_group_twice.yml", "test/fixtures/api/remove_inexistente_account_from_group.yml", "test/fixtures/api/rules_for_domain.yml", "test/fixtures/api/rules_for_domain_by_component.yml", "test/fixtures/api/save_group.yml", "test/fixtures/api/test_domain.yml", "test/fixtures/api/update_account_properties.yml", "test/fixtures/api/update_accounts_group_scope.yml", "test/fixtures/api/update_accounts_properties_scope.yml", "test/fixtures/api/update_directory.yml", "test/fixtures/api/update_rule.yml", "test/fixtures/domain.rb", "test/helper.rb", "test/test_directories.rb", "test/test_domain.rb", "test/test_dto.rb", "test/test_feature.rb", "test/test_groups.rb", "test/test_mxhero_api.rb", "test/test_mxhero_api_response.rb", "test/test_resource.rb"]
|
14
14
|
s.homepage = "http://github.com/mxhero/mxhero-api"
|
15
15
|
s.licenses = ["GPL-3"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubygems_version = "2.1.9"
|
18
18
|
s.summary = "A MxHero API client for ruby"
|
19
|
-
s.test_files = ["test/fixtures/api/account_properties.yml", "test/fixtures/api/account_properties_not_found.yml", "test/fixtures/api/accounts.yml", "test/fixtures/api/accounts_filtered.yml", "test/fixtures/api/accounts_from_domain.yml", "test/fixtures/api/accounts_from_domain_paginated.yml", "test/fixtures/api/accounts_without_group.yml", "test/fixtures/api/add_an_inexistent_account_to_group.yml", "test/fixtures/api/add_and_remove_account.yml", "test/fixtures/api/all_groups.yml", "test/fixtures/api/create_directory.yml", "test/fixtures/api/create_rule_for_domain.yml", "test/fixtures/api/delete_directory.yml", "test/fixtures/api/delete_group.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/fetch_directory.yml", "test/fixtures/api/ldap_info.yml", "test/fixtures/api/refresh_directory.yml", "test/fixtures/api/remove_account_from_group_twice.yml", "test/fixtures/api/remove_inexistente_account_from_group.yml", "test/fixtures/api/rules_for_domain.yml", "test/fixtures/api/rules_for_domain_by_component.yml", "test/fixtures/api/save_group.yml", "test/fixtures/api/test_domain.yml", "test/fixtures/api/update_account_properties.yml", "test/fixtures/api/update_accounts_group_scope.yml", "test/fixtures/api/update_accounts_properties_scope.yml", "test/fixtures/api/update_directory.yml", "test/fixtures/api/update_rule.yml", "test/helper.rb", "test/test_directories.rb", "test/test_dto.rb", "test/test_groups.rb", "test/test_mxhero_api.rb", "test/test_mxhero_api_response.rb"]
|
19
|
+
s.test_files = ["test/fixtures/api/account_properties.yml", "test/fixtures/api/account_properties_not_found.yml", "test/fixtures/api/accounts.yml", "test/fixtures/api/accounts_filtered.yml", "test/fixtures/api/accounts_from_domain.yml", "test/fixtures/api/accounts_from_domain_paginated.yml", "test/fixtures/api/accounts_without_group.yml", "test/fixtures/api/add_an_inexistent_account_to_group.yml", "test/fixtures/api/add_and_remove_account.yml", "test/fixtures/api/all_groups.yml", "test/fixtures/api/create_directory.yml", "test/fixtures/api/create_rule_for_domain.yml", "test/fixtures/api/delete_directory.yml", "test/fixtures/api/delete_group.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/fetch_directory.yml", "test/fixtures/api/ldap_info.yml", "test/fixtures/api/move_to_trial.yml", "test/fixtures/api/refresh_directory.yml", "test/fixtures/api/remove_account_from_group_twice.yml", "test/fixtures/api/remove_inexistente_account_from_group.yml", "test/fixtures/api/rules_for_domain.yml", "test/fixtures/api/rules_for_domain_by_component.yml", "test/fixtures/api/save_group.yml", "test/fixtures/api/test_domain.yml", "test/fixtures/api/update_account_properties.yml", "test/fixtures/api/update_accounts_group_scope.yml", "test/fixtures/api/update_accounts_properties_scope.yml", "test/fixtures/api/update_directory.yml", "test/fixtures/api/update_rule.yml", "test/fixtures/domain.rb", "test/helper.rb", "test/test_directories.rb", "test/test_domain.rb", "test/test_dto.rb", "test/test_feature.rb", "test/test_groups.rb", "test/test_mxhero_api.rb", "test/test_mxhero_api_response.rb", "test/test_resource.rb"]
|
20
20
|
|
21
21
|
if s.respond_to? :specification_version then
|
22
22
|
s.specification_version = 4
|
@@ -0,0 +1,39 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: put
|
5
|
+
uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/mxhero.com//cos/trial
|
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
|
+
VGh1LCAyNiBEZWMgMjAxMyAxOToxNTo0NCBHTVQ=
|
25
|
+
!binary "U2VydmVy":
|
26
|
+
- !binary |-
|
27
|
+
QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
|
28
|
+
!binary "Q29udGVudC1MZW5ndGg=":
|
29
|
+
- !binary |-
|
30
|
+
MA==
|
31
|
+
!binary "Q29udGVudC1UeXBl":
|
32
|
+
- !binary |-
|
33
|
+
dGV4dC9wbGFpbg==
|
34
|
+
body:
|
35
|
+
encoding: US-ASCII
|
36
|
+
string: ''
|
37
|
+
http_version:
|
38
|
+
recorded_at: Thu, 26 Dec 2013 19:15:44 GMT
|
39
|
+
recorded_with: VCR 2.5.0
|
@@ -21,7 +21,7 @@ http_interactions:
|
|
21
21
|
headers:
|
22
22
|
!binary "RGF0ZQ==":
|
23
23
|
- !binary |-
|
24
|
-
|
24
|
+
VHVlLCAxNyBEZWMgMjAxMyAxOTozMTozMiBHTVQ=
|
25
25
|
!binary "U2VydmVy":
|
26
26
|
- !binary |-
|
27
27
|
QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
|
@@ -33,9 +33,9 @@ http_interactions:
|
|
33
33
|
YXBwbGljYXRpb24vanNvbg==
|
34
34
|
body:
|
35
35
|
encoding: US-ASCII
|
36
|
-
string: ! '{"domain":"mxhero.com","server":"
|
36
|
+
string: ! '{"domain":"mxhero.com","server":"aspmx.l.google.com","relayServer":null,"inbound":true,"outbound":true,"creationDate":1371737853000,"updatedDate":1371741047000,"aliases":["hero.mx","mxhero.com","mxhero.net","mxhero.org"],"ldap":null,"features":[{"feature":"org.mxhero.feature.signature","created":1387296659000,"updated":null,"metadata":null,"maxRulesAmount":0}],"cos":{"cos":"test","edition":null},"cosLastChange":1387303649000}'
|
37
37
|
http_version:
|
38
|
-
recorded_at:
|
38
|
+
recorded_at: Tue, 17 Dec 2013 19:31:32 GMT
|
39
39
|
- request:
|
40
40
|
method: get
|
41
41
|
uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/xxxx.xxx/
|
@@ -57,7 +57,7 @@ http_interactions:
|
|
57
57
|
headers:
|
58
58
|
!binary "RGF0ZQ==":
|
59
59
|
- !binary |-
|
60
|
-
|
60
|
+
VHVlLCAxNyBEZWMgMjAxMyAxOTozMTozMyBHTVQ=
|
61
61
|
!binary "U2VydmVy":
|
62
62
|
- !binary |-
|
63
63
|
QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
|
@@ -71,5 +71,5 @@ http_interactions:
|
|
71
71
|
encoding: US-ASCII
|
72
72
|
string: ! '{"status":404,"code":404,"message":"domain.not.found","developerMessage":"domain.not.found","moreInfoUrl":"mailto:support@mxhero.com"}'
|
73
73
|
http_version:
|
74
|
-
recorded_at:
|
74
|
+
recorded_at: Tue, 17 Dec 2013 19:31:52 GMT
|
75
75
|
recorded_with: VCR 2.5.0
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Fixtures
|
2
|
+
module Domain
|
3
|
+
|
4
|
+
def self.data
|
5
|
+
@data ||= {
|
6
|
+
domain: "mxhero.com",
|
7
|
+
server: "aspmx.l.google.com",
|
8
|
+
relayServer: nil,
|
9
|
+
inbound: true, outbound: true,
|
10
|
+
creationDate: 1371737853000,
|
11
|
+
updatedDate: 1371741047000,
|
12
|
+
aliases: [ "hero.mx", "mxhero.com", "mxhero.net", "mxhero.org" ],
|
13
|
+
ldap: nil,
|
14
|
+
features: [
|
15
|
+
{
|
16
|
+
feature: "org.mxhero.feature.signature",
|
17
|
+
created: 1387296659000,
|
18
|
+
updated: nil,
|
19
|
+
metadata: nil,
|
20
|
+
maxRulesAmount: 2
|
21
|
+
}
|
22
|
+
],
|
23
|
+
cos: { cos: "trial", edition: nil },
|
24
|
+
cosLastChange: 1387303649000
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/test/helper.rb
CHANGED
@@ -9,6 +9,9 @@ require 'minitest/pride'
|
|
9
9
|
|
10
10
|
require_relative '../lib/mxhero-api'
|
11
11
|
|
12
|
+
# Load fixtures
|
13
|
+
Dir["#{File.dirname(__FILE__)}/fixtures/**/*.rb"].each { |rb| require rb }
|
14
|
+
|
12
15
|
TEST_API_DOMAIN = 'tesla.com'
|
13
16
|
TEST_API_URL = ENV['TEST_API_URL'] || 'http://test.mxhero.com/webapi/api/v1'
|
14
17
|
TEST_API_USER = 'admin'
|
data/test/test_domain.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class DomainTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def test_build_domain
|
6
|
+
domain = MxHero::API::Domain.new data
|
7
|
+
assert_equal data[:domain], domain.domain
|
8
|
+
assert_equal data[:features].first[:feature], domain.features.first.component
|
9
|
+
assert_equal DateTime.strptime(data[:cosLastChange].to_s, '%Q'), domain.cos_last_change
|
10
|
+
assert domain.cos.is_a? MxHero::API::Cos
|
11
|
+
assert_equal data[:cos][:cos], domain.cos.type
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_change_domain_to_trial
|
15
|
+
domain = MxHero::API::Domain.new data
|
16
|
+
domain.change_to_trial
|
17
|
+
assert_equal 'trial', domain.cos.type
|
18
|
+
|
19
|
+
domain = MxHero::API::Domain.new data.merge(cos: { cos: "post_trial", edition: nil })
|
20
|
+
domain.change_to_trial
|
21
|
+
assert_equal 'post_trial', domain.cos.type
|
22
|
+
end
|
23
|
+
|
24
|
+
def data
|
25
|
+
Fixtures::Domain.data
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class FeatureTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def test_build_feature_domain
|
6
|
+
feature = MxHero::API::Feature.new data
|
7
|
+
assert_equal data[:feature], feature.component
|
8
|
+
assert_nil feature.updated
|
9
|
+
assert_equal data[:maxRulesAmount], feature.max_rules_amount
|
10
|
+
assert ! feature.unlimited_use?
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_unlimited_use
|
14
|
+
feature = MxHero::API::Feature.new data
|
15
|
+
assert feature.max_rules_amount > 0
|
16
|
+
assert ! feature.unlimited_use?
|
17
|
+
|
18
|
+
unlimited_use = data.dup
|
19
|
+
unlimited_use[:maxRulesAmount] = 0
|
20
|
+
feature = MxHero::API::Feature.new unlimited_use
|
21
|
+
assert_equal Float::INFINITY, feature.max_rules_amount
|
22
|
+
assert feature.unlimited_use?
|
23
|
+
|
24
|
+
unlimited_use[:maxRulesAmount] = nil
|
25
|
+
feature = MxHero::API::Feature.new unlimited_use
|
26
|
+
assert_equal Float::INFINITY, feature.max_rules_amount
|
27
|
+
assert feature.unlimited_use?
|
28
|
+
end
|
29
|
+
|
30
|
+
def data
|
31
|
+
Fixtures::Domain.data[:features].first
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/test/test_mxhero_api.rb
CHANGED
@@ -231,11 +231,6 @@ def test_domain_by_name
|
|
231
231
|
def test_domain
|
232
232
|
VCR.use_cassette('test_domain') do
|
233
233
|
domain = @api.domain('mxhero.com')
|
234
|
-
assert domain.key?(:domain)
|
235
|
-
assert domain.key?(:server)
|
236
|
-
assert domain.key?(:creationDate)
|
237
|
-
assert domain.key?(:aliases)
|
238
|
-
assert domain.key?(:ldap)
|
239
234
|
|
240
235
|
response = @api.domain('xxxx.xxx')
|
241
236
|
assert response.nil?
|
@@ -276,6 +271,13 @@ def test_domain_by_name
|
|
276
271
|
end
|
277
272
|
end
|
278
273
|
|
274
|
+
def test_move_to_trial
|
275
|
+
VCR.use_cassette('move_to_trial') do
|
276
|
+
response = @api.move_to_trial('mxhero.com')
|
277
|
+
assert response
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
279
281
|
private
|
280
282
|
|
281
283
|
def delete_all_rules
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
module Test
|
4
|
+
class User < MxHero::API::Resource
|
5
|
+
|
6
|
+
attribute :name, map: 'firstName'
|
7
|
+
attribute :last_name, map: 'lastName'
|
8
|
+
attribute :age
|
9
|
+
attribute :last_update, map: 'lastUpdate', date: true
|
10
|
+
end
|
11
|
+
|
12
|
+
class Account < MxHero::API::Resource
|
13
|
+
attributes :name, :number, :active
|
14
|
+
|
15
|
+
attribute :name, map: 'accountName'
|
16
|
+
attribute :number, map: 'sn'
|
17
|
+
attribute :updated, date: true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class ResourceTest < MiniTest::Unit::TestCase
|
22
|
+
|
23
|
+
def info
|
24
|
+
@info ||= {
|
25
|
+
age: 23,
|
26
|
+
firstName: 'John',
|
27
|
+
lastName: 'Doe',
|
28
|
+
lastUpdate: "1371741047000"
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_instance
|
33
|
+
user = Test::User.new info
|
34
|
+
|
35
|
+
assert_equal 23, user.age
|
36
|
+
assert_equal 'John', user.name
|
37
|
+
assert_equal 'Doe', user.last_name
|
38
|
+
assert_equal DateTime.strptime(info[:lastUpdate].to_s, '%Q'), user.last_update
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_to_json
|
42
|
+
user = Test::User.new info
|
43
|
+
assert_equal info.to_json, user.to_json
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_attributes_and_map
|
47
|
+
data = {
|
48
|
+
accountName: 'account 12',
|
49
|
+
sn: 1234567890,
|
50
|
+
active: true,
|
51
|
+
updated: 1371741047000
|
52
|
+
}
|
53
|
+
account = Test::Account.new data
|
54
|
+
|
55
|
+
assert_equal data[:accountName], account.name
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
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.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maximiliano Dello Russo
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-12-
|
13
|
+
date: 2013-12-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: vcr
|
@@ -75,6 +75,10 @@ files:
|
|
75
75
|
- lib/dto.rb
|
76
76
|
- lib/groups.rb
|
77
77
|
- lib/mxhero-api.rb
|
78
|
+
- lib/resource.rb
|
79
|
+
- lib/resources/account.rb
|
80
|
+
- lib/resources/domain.rb
|
81
|
+
- lib/resources/group.rb
|
78
82
|
- lib/urls.rb
|
79
83
|
- mxhero-api.gemspec
|
80
84
|
- test/fixtures/api/account_properties.yml
|
@@ -98,6 +102,7 @@ files:
|
|
98
102
|
- test/fixtures/api/domains.yml
|
99
103
|
- test/fixtures/api/fetch_directory.yml
|
100
104
|
- test/fixtures/api/ldap_info.yml
|
105
|
+
- test/fixtures/api/move_to_trial.yml
|
101
106
|
- test/fixtures/api/refresh_directory.yml
|
102
107
|
- test/fixtures/api/remove_account_from_group_twice.yml
|
103
108
|
- test/fixtures/api/remove_inexistente_account_from_group.yml
|
@@ -110,12 +115,16 @@ files:
|
|
110
115
|
- test/fixtures/api/update_accounts_properties_scope.yml
|
111
116
|
- test/fixtures/api/update_directory.yml
|
112
117
|
- test/fixtures/api/update_rule.yml
|
118
|
+
- test/fixtures/domain.rb
|
113
119
|
- test/helper.rb
|
114
120
|
- test/test_directories.rb
|
121
|
+
- test/test_domain.rb
|
115
122
|
- test/test_dto.rb
|
123
|
+
- test/test_feature.rb
|
116
124
|
- test/test_groups.rb
|
117
125
|
- test/test_mxhero_api.rb
|
118
126
|
- test/test_mxhero_api_response.rb
|
127
|
+
- test/test_resource.rb
|
119
128
|
homepage: http://github.com/mxhero/mxhero-api
|
120
129
|
licenses:
|
121
130
|
- GPL-3
|
@@ -162,6 +171,7 @@ test_files:
|
|
162
171
|
- test/fixtures/api/domains.yml
|
163
172
|
- test/fixtures/api/fetch_directory.yml
|
164
173
|
- test/fixtures/api/ldap_info.yml
|
174
|
+
- test/fixtures/api/move_to_trial.yml
|
165
175
|
- test/fixtures/api/refresh_directory.yml
|
166
176
|
- test/fixtures/api/remove_account_from_group_twice.yml
|
167
177
|
- test/fixtures/api/remove_inexistente_account_from_group.yml
|
@@ -174,10 +184,14 @@ test_files:
|
|
174
184
|
- test/fixtures/api/update_accounts_properties_scope.yml
|
175
185
|
- test/fixtures/api/update_directory.yml
|
176
186
|
- test/fixtures/api/update_rule.yml
|
187
|
+
- test/fixtures/domain.rb
|
177
188
|
- test/helper.rb
|
178
189
|
- test/test_directories.rb
|
190
|
+
- test/test_domain.rb
|
179
191
|
- test/test_dto.rb
|
192
|
+
- test/test_feature.rb
|
180
193
|
- test/test_groups.rb
|
181
194
|
- test/test_mxhero_api.rb
|
182
195
|
- test/test_mxhero_api_response.rb
|
196
|
+
- test/test_resource.rb
|
183
197
|
has_rdoc:
|