mxhero-api 0.1.18 → 0.1.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTZkZmZhYWI5ODJmMGQyNzIwMjE1YmJiNmU3YWNmZDNjYmMwM2QzZg==
4
+ OGRmM2JmNjliZTQyOWQ1ZTE5OTU4ZWQzOTEzNTY4ZDc5Yzg0ODJlZQ==
5
5
  data.tar.gz: !binary |-
6
- MjJmYWYxZDg4NWQyMjlhNWM5ZGU3YjE1ODBhMmIxZGRmNjAwZWMxZQ==
6
+ ZGQ0YzY5YzZjNDUxZGYxYWQwMGZiYmM4OTZkOTU5Y2QyMTE5NWJmMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDhkZmI3MjRiN2U4MjMyMzZhZWNmOTY0ZjA4MzExYmQ2ODJjYzlmM2U3Njdh
10
- OTk1MzY2ZGQwNDU3N2NlMGFiMTIwM2M5Y2FlZjA1MjU1M2QyOGMwMmUyMWVi
11
- NTg0NjI1NTZkYWViNGEyMDgxZGJmMTMzM2ZkYWNjMGExNTNmMGQ=
9
+ Y2ZhYWM4ZTExNDlkMmUyMzJlZjMxMmJmNzk1MjRjOGVkYzNkYmJiODMzNjVk
10
+ ODY1YWY3YmZlODI0MWI0Mzg0Y2ZiYmIyNjZmZWY1YmU3ZDdmMjc5YWQ4ZTZl
11
+ OTAyOTIzMTA4MzJkMGUyMWNjZWZjZjYzM2NjZWZhZDdiOTBmZTE=
12
12
  data.tar.gz: !binary |-
13
- ZTRkN2JhZmEyYjAxZjFmNTdiZDNhNWM1NWViMmIwYjE5NWYwMjlhM2JiOGIy
14
- MzI2ZGZkOWYwMzk1ZDM2MmY1ZDk4OTc4MzBhZmM5MWIzN2IwYjBmMmJjZjQ0
15
- MTgwYThkMWM0ZDBiOTM4MDExM2IzNjdiN2IzODA2MzBmM2I5Y2E=
13
+ NTc4YmIwOWIwYmU1ZDRjYmU5ODNkMTFhMmYwY2Q3ODIzMGI3ZDUxN2U1ZGQ1
14
+ OGE4YzBlZTUyMjVlMjc4MzRkNDRjYWZjMWYxYzE3MzE5NjEwYWIyMzVhMTI2
15
+ NGE4Y2RjNWQ5MGRjMDU0ODRlMTkwZTQ5MTA5YTY1YTU4YWU4NmM=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.18
1
+ 0.1.19
@@ -60,10 +60,13 @@ module MxHero::API
60
60
 
61
61
  # Retrieve all the groups
62
62
  #
63
+ # @params pagination info. Ex.: page: 2, per_page: 10 or simple page: 2
64
+ #
63
65
  # @return [PaginatedElement] that contains an array of Group elements
64
66
  # Basically its an Array with instances of [MxHero::API::Group] with the methods total_elements, total_pages and actual_page
65
- def all(limit = nil, offset = nil)
66
- response = call(:get, groups_url)
67
+ #
68
+ def all(pagination = { page: nil, per_page: nil })
69
+ response = call(:get, groups_url(pagination))
67
70
  paginate_wrap(response) do |hash|
68
71
  hash[:elements].map { |e| Group.new(e) }
69
72
  end
@@ -94,10 +97,12 @@ module MxHero::API
94
97
  # Retrieve all the accounts for one group
95
98
  #
96
99
  # @param group_name [String]
100
+ # @param options [Hash] pagination options (page and/or per_page)
97
101
  #
98
102
  # @return [MxHero::API::PaginatedElements] the list of accounts [MxHero::API::Account]
99
- def accounts(group_name)
100
- response = call(:get, group_accounts_url(group_name))
103
+ #
104
+ def accounts(group_name, options = { per_page: nil, page: nil })
105
+ response = call(:get, group_accounts_url(group_name, options))
101
106
  paginate_wrap response do |hash|
102
107
  hash[:elements].map { |e| Account.new(e) }
103
108
  end
@@ -153,16 +158,24 @@ module MxHero::API
153
158
  hash[:elements].map { |e| Group.new(e) }
154
159
  end
155
160
 
156
- def groups_url
157
- domain_by_id_url(domain) + 'groups'
161
+ def groups_url(pagination = {})
162
+ domain_by_id_url(domain) + 'groups' + pagination_query(pagination)
163
+ end
164
+
165
+ def pagination_query(params = { page: nil, per_page: nil })
166
+ return '' unless params[:page] || params[:per_page]
167
+ '?' + [].tap do |section|
168
+ section << "limit=#{params[:per_page]}" if params[:per_page]
169
+ section << "offset=#{params[:page]}" if params[:page]
170
+ end.join('&')
158
171
  end
159
172
 
160
173
  def group_url(group_name)
161
174
  groups_url + "/#{group_name}"
162
175
  end
163
176
 
164
- def group_accounts_url(group_name)
165
- group_url(group_name) + "/accounts"
177
+ def group_accounts_url(group_name, pagination = {})
178
+ group_url(group_name) + "/accounts" + pagination_query(pagination)
166
179
  end
167
180
 
168
181
  def group_add_accounts_url(group_name, account_name)
@@ -1,13 +1,13 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: mxhero-api 0.1.18 ruby lib
2
+ # stub: mxhero-api 0.1.19 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "mxhero-api"
6
- s.version = "0.1.18"
6
+ s.version = "0.1.19"
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-11-20"
10
+ s.date = "2013-11-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
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/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"]
@@ -99,6 +99,14 @@ class GroupsTest < MiniTest::Unit::TestCase
99
99
  assert_equal 'domain.account.not.found', response.content[:developerMessage]
100
100
  end
101
101
  end
102
+
103
+
104
+ def test_pagination
105
+ assert @groups.send(:pagination_query).empty?
106
+ assert_equal '?offset=10', @groups.send(:pagination_query, page: 10)
107
+ assert_equal '?limit=10', @groups.send(:pagination_query, per_page: 10)
108
+ assert_equal '?limit=10&offset=2', @groups.send(:pagination_query, per_page: 10, page: 2)
109
+ end
102
110
 
103
111
  end
104
112
 
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.18
4
+ version: 0.1.19
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-11-20 00:00:00.000000000 Z
13
+ date: 2013-11-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: vcr