audc-gerry 0.1.6 → 0.1.7
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 +4 -4
- data/README.md +62 -62
- data/Rakefile +7 -7
- data/lib/gerry/api/access.rb +17 -17
- data/lib/gerry/api/accounts.rb +38 -38
- data/lib/gerry/api/branches.rb +45 -45
- data/lib/gerry/api/changes.rb +38 -38
- data/lib/gerry/api/groups.rb +72 -72
- data/lib/gerry/api/projects.rb +73 -73
- data/lib/gerry/api/request.rb +86 -86
- data/lib/gerry/client.rb +58 -58
- data/lib/gerry/version.rb +5 -5
- data/lib/gerry.rb +11 -11
- data/spec/access_spec.rb +15 -15
- data/spec/accounts_spec.rb +35 -35
- data/spec/branches_spec.rb +36 -36
- data/spec/changes_spec.rb +55 -55
- data/spec/fixtures/README.md.json +2 -2
- data/spec/fixtures/access_rights.json +250 -250
- data/spec/fixtures/account_groups.json +32 -32
- data/spec/fixtures/branch_access.json +50 -50
- data/spec/fixtures/capabilities.json +7 -7
- data/spec/fixtures/changes.json +30 -30
- data/spec/fixtures/changes_batch_0.json +18 -18
- data/spec/fixtures/changes_batch_1.json +18 -18
- data/spec/fixtures/changes_batch_2.json +17 -17
- data/spec/fixtures/group_members.json +14 -14
- data/spec/fixtures/groups.json +68 -68
- data/spec/fixtures/open_changes.json +16 -16
- data/spec/fixtures/project_branch.json +6 -6
- data/spec/fixtures/project_branches.json +21 -21
- data/spec/fixtures/project_head.json +2 -2
- data/spec/fixtures/projects.json +9 -9
- data/spec/fixtures/query_capabilities.json +4 -4
- data/spec/groups_spec.rb +92 -92
- data/spec/projects_spec.rb +90 -90
- data/spec/request_spec.rb +46 -46
- data/spec/spec_helper.rb +49 -49
- metadata +52 -54
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b12a1fa0d20e356d302e7f0f8c3808df6c7a30b0e1dd1a1b07c1267549ed0a8e
|
|
4
|
+
data.tar.gz: 242457c10be36038c1882737381248ebb2bbe75dfa05242e086d4cc2c5824b8a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4834e5ce469bffad2bc29919d840c847d3af193a3e0f19141b25fff000363d7e2dd47e9d8fa07e0bc739816e92c1fafb17762a69e77ecf993da2c3388c9f6185
|
|
7
|
+
data.tar.gz: 8783ee2ca1775dd505750bc45eedb49c75982b7c881283d1ad71b1ef1765e8127ae7f73089efe3ed443ea4f689622fba33f2190e482bbcc085a3a0c4cb36097b
|
data/README.md
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
# gerry[][travis]
|
|
2
|
-
|
|
3
|
-
Base Gerrit Version V2.14.6
|
|
4
|
-
|
|
5
|
-
Simple Ruby wrapper for the Gerrit Code Review REST-API.
|
|
6
|
-
|
|
7
|
-

|
|
8
|
-
|
|
9
|
-
[travis]: https://travis-ci.org/trumant/gerry
|
|
10
|
-
|
|
11
|
-
## Documentation
|
|
12
|
-
[http://rdoc.info/github/trumant/gerry][documentation]
|
|
13
|
-
|
|
14
|
-
[documentation]: http://rdoc.info/github/trumant/gerry
|
|
15
|
-
|
|
16
|
-
## Install
|
|
17
|
-
```
|
|
18
|
-
bundle
|
|
19
|
-
bundle exec rake install
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Examples
|
|
23
|
-
### Get the global capabilities
|
|
24
|
-
```ruby
|
|
25
|
-
client = Gerry.new('https://review')
|
|
26
|
-
client.account_capabilities
|
|
27
|
-
=> {"queryLimit"=>{"min"=>0, "max"=>250}}
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### List projects
|
|
31
|
-
```ruby
|
|
32
|
-
client = Gerry.new('https://review')
|
|
33
|
-
client.projects
|
|
34
|
-
=> { "awesome"=>{ "description"=>"Awesome project"}}
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### List open changes
|
|
38
|
-
```ruby
|
|
39
|
-
client = Gerry.new('https://review')
|
|
40
|
-
client.changes(['q=is:open'])
|
|
41
|
-
=> [{"project"=>"awesome", "branch"=>"master", "id"=>"Ibfedd978...."}]
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### Authentication type
|
|
45
|
-
Since 2.14, Gerrit no longer supports digest authentication.
|
|
46
|
-
Gerry uses basic authentication against gerrit.
|
|
47
|
-
|
|
48
|
-
## Licence
|
|
49
|
-
The MIT Licence
|
|
50
|
-
|
|
51
|
-
Copyright (c) Fabian Mettler, Andrew Erickson, Travis Truman, Sebastian Schuberth, Orgad Shaneh
|
|
52
|
-
|
|
53
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
54
|
-
|
|
55
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
56
|
-
|
|
57
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
58
|
-
|
|
59
|
-
## References
|
|
60
|
-
https://www.gerritcodereview.com/
|
|
61
|
-
|
|
62
|
-
https://gerrit-review.googlesource.com/Documentation/rest-api.html
|
|
1
|
+
# gerry[][travis]
|
|
2
|
+
|
|
3
|
+
Base Gerrit Version V2.14.6
|
|
4
|
+
|
|
5
|
+
Simple Ruby wrapper for the Gerrit Code Review REST-API.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
[travis]: https://travis-ci.org/trumant/gerry
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
[http://rdoc.info/github/trumant/gerry][documentation]
|
|
13
|
+
|
|
14
|
+
[documentation]: http://rdoc.info/github/trumant/gerry
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
```
|
|
18
|
+
bundle
|
|
19
|
+
bundle exec rake install
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Examples
|
|
23
|
+
### Get the global capabilities
|
|
24
|
+
```ruby
|
|
25
|
+
client = Gerry.new('https://review')
|
|
26
|
+
client.account_capabilities
|
|
27
|
+
=> {"queryLimit"=>{"min"=>0, "max"=>250}}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### List projects
|
|
31
|
+
```ruby
|
|
32
|
+
client = Gerry.new('https://review')
|
|
33
|
+
client.projects
|
|
34
|
+
=> { "awesome"=>{ "description"=>"Awesome project"}}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### List open changes
|
|
38
|
+
```ruby
|
|
39
|
+
client = Gerry.new('https://review')
|
|
40
|
+
client.changes(['q=is:open'])
|
|
41
|
+
=> [{"project"=>"awesome", "branch"=>"master", "id"=>"Ibfedd978...."}]
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Authentication type
|
|
45
|
+
Since 2.14, Gerrit no longer supports digest authentication.
|
|
46
|
+
Gerry uses basic authentication against gerrit.
|
|
47
|
+
|
|
48
|
+
## Licence
|
|
49
|
+
The MIT Licence
|
|
50
|
+
|
|
51
|
+
Copyright (c) Fabian Mettler, Andrew Erickson, Travis Truman, Sebastian Schuberth, Orgad Shaneh
|
|
52
|
+
|
|
53
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
54
|
+
|
|
55
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
56
|
+
|
|
57
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
58
|
+
|
|
59
|
+
## References
|
|
60
|
+
https://www.gerritcodereview.com/
|
|
61
|
+
|
|
62
|
+
https://gerrit-review.googlesource.com/Documentation/rest-api.html
|
data/Rakefile
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
require 'rspec/core/rake_task'
|
|
2
|
-
require 'bundler/gem_tasks'
|
|
3
|
-
|
|
4
|
-
RSpec::Core::RakeTask.new(:spec)
|
|
5
|
-
|
|
6
|
-
task :default => :spec
|
|
7
|
-
|
|
1
|
+
require 'rspec/core/rake_task'
|
|
2
|
+
require 'bundler/gem_tasks'
|
|
3
|
+
|
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
5
|
+
|
|
6
|
+
task :default => :spec
|
|
7
|
+
|
data/lib/gerry/api/access.rb
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
require 'erb'
|
|
2
|
-
|
|
3
|
-
module Gerry
|
|
4
|
-
module Api
|
|
5
|
-
module Access
|
|
6
|
-
# Get access rights for the specified project
|
|
7
|
-
#
|
|
8
|
-
# @param [VarArgs] projects the project names
|
|
9
|
-
# @return [Hash] the list of access rights
|
|
10
|
-
def access(*projects)
|
|
11
|
-
projects = projects.flatten.map { |name| ERB::Util.url_encode(name) }
|
|
12
|
-
url = "/access/?project=#{projects.join('&project=')}"
|
|
13
|
-
get(url)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
1
|
+
require 'erb'
|
|
2
|
+
|
|
3
|
+
module Gerry
|
|
4
|
+
module Api
|
|
5
|
+
module Access
|
|
6
|
+
# Get access rights for the specified project
|
|
7
|
+
#
|
|
8
|
+
# @param [VarArgs] projects the project names
|
|
9
|
+
# @return [Hash] the list of access rights
|
|
10
|
+
def access(*projects)
|
|
11
|
+
projects = projects.flatten.map { |name| ERB::Util.url_encode(name) }
|
|
12
|
+
url = "/access/?project=#{projects.join('&project=')}"
|
|
13
|
+
get(url)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/gerry/api/accounts.rb
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
module Gerry
|
|
2
|
-
module Api
|
|
3
|
-
module Accounts
|
|
4
|
-
# Get the account info for the specified account ID.
|
|
5
|
-
#
|
|
6
|
-
# @param [String] account_id the account.
|
|
7
|
-
# @return [Hash] the account info.
|
|
8
|
-
def account_info(account_id)
|
|
9
|
-
url = "/accounts/#{account_id}"
|
|
10
|
-
get(url)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
# Get the global capabilities that are enabled for the calling user.
|
|
14
|
-
#
|
|
15
|
-
# @param [Array] options the query parameters.
|
|
16
|
-
# @return [Hash] the account capabilities.
|
|
17
|
-
def account_capabilities(options = [])
|
|
18
|
-
url = '/accounts/self/capabilities'
|
|
19
|
-
|
|
20
|
-
if options.empty?
|
|
21
|
-
return get(url)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
options = map_options(options)
|
|
25
|
-
get("#{url}?#{options}")
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Get all groups that contain the specified account as a member
|
|
29
|
-
#
|
|
30
|
-
# @param [String] account_id the account
|
|
31
|
-
# @return [Enumberable] the groups
|
|
32
|
-
def groups_for_account(account_id)
|
|
33
|
-
url = "/accounts/#{account_id}/groups/"
|
|
34
|
-
get(url)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
1
|
+
module Gerry
|
|
2
|
+
module Api
|
|
3
|
+
module Accounts
|
|
4
|
+
# Get the account info for the specified account ID.
|
|
5
|
+
#
|
|
6
|
+
# @param [String] account_id the account.
|
|
7
|
+
# @return [Hash] the account info.
|
|
8
|
+
def account_info(account_id)
|
|
9
|
+
url = "/accounts/#{account_id}"
|
|
10
|
+
get(url)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Get the global capabilities that are enabled for the calling user.
|
|
14
|
+
#
|
|
15
|
+
# @param [Array] options the query parameters.
|
|
16
|
+
# @return [Hash] the account capabilities.
|
|
17
|
+
def account_capabilities(options = [])
|
|
18
|
+
url = '/accounts/self/capabilities'
|
|
19
|
+
|
|
20
|
+
if options.empty?
|
|
21
|
+
return get(url)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
options = map_options(options)
|
|
25
|
+
get("#{url}?#{options}")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Get all groups that contain the specified account as a member
|
|
29
|
+
#
|
|
30
|
+
# @param [String] account_id the account
|
|
31
|
+
# @return [Enumberable] the groups
|
|
32
|
+
def groups_for_account(account_id)
|
|
33
|
+
url = "/accounts/#{account_id}/groups/"
|
|
34
|
+
get(url)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
data/lib/gerry/api/branches.rb
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Gerry
|
|
4
|
-
module Api
|
|
5
|
-
module Branches
|
|
6
|
-
##
|
|
7
|
-
# Get the branches of project
|
|
8
|
-
#
|
|
9
|
-
def branches(project_name)
|
|
10
|
-
get("/projects/#{project_name}/branches")
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
# Get the projects that start with the specified prefix
|
|
14
|
-
# and accessible by the caller.
|
|
15
|
-
#
|
|
16
|
-
# @param [String] name the project name.
|
|
17
|
-
# @return [Hash] the projects.
|
|
18
|
-
def branch(project_name, branch_name)
|
|
19
|
-
get("/projects/#{project_name}/branches/#{branch_name}")
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
##
|
|
23
|
-
# create branch that derived from branch name or revision
|
|
24
|
-
#
|
|
25
|
-
# example: create_branch('foo', 'master', 'stable')
|
|
26
|
-
# create_branch('foo', 'revision', 'stable')
|
|
27
|
-
#
|
|
28
|
-
def create_branch(project_name, source, branch)
|
|
29
|
-
# try source as ref
|
|
30
|
-
body = { ref: source }
|
|
31
|
-
put("/projects/#{project_name}/branches/#{branch}", body)
|
|
32
|
-
rescue Gerry::Api::Request::RequestError
|
|
33
|
-
# try source as revision
|
|
34
|
-
body = { revision: source }
|
|
35
|
-
put("/projects/#{project_name}/branches/#{branch}", body)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
##
|
|
39
|
-
# Gets the reflog of a certain branch.
|
|
40
|
-
def branch_reflog(project_name, branch, number)
|
|
41
|
-
get("/projects/#{project_name}/branches/#{branch}/reflog?n=#{number}")
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Gerry
|
|
4
|
+
module Api
|
|
5
|
+
module Branches
|
|
6
|
+
##
|
|
7
|
+
# Get the branches of project
|
|
8
|
+
#
|
|
9
|
+
def branches(project_name)
|
|
10
|
+
get("/projects/#{project_name}/branches")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Get the projects that start with the specified prefix
|
|
14
|
+
# and accessible by the caller.
|
|
15
|
+
#
|
|
16
|
+
# @param [String] name the project name.
|
|
17
|
+
# @return [Hash] the projects.
|
|
18
|
+
def branch(project_name, branch_name)
|
|
19
|
+
get("/projects/#{project_name}/branches/#{branch_name}")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
##
|
|
23
|
+
# create branch that derived from branch name or revision
|
|
24
|
+
#
|
|
25
|
+
# example: create_branch('foo', 'master', 'stable')
|
|
26
|
+
# create_branch('foo', 'revision', 'stable')
|
|
27
|
+
#
|
|
28
|
+
def create_branch(project_name, source, branch)
|
|
29
|
+
# try source as ref
|
|
30
|
+
body = { ref: source }
|
|
31
|
+
put("/projects/#{project_name}/branches/#{branch}", body)
|
|
32
|
+
rescue Gerry::Api::Request::RequestError
|
|
33
|
+
# try source as revision
|
|
34
|
+
body = { revision: source }
|
|
35
|
+
put("/projects/#{project_name}/branches/#{branch}", body)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
##
|
|
39
|
+
# Gets the reflog of a certain branch.
|
|
40
|
+
def branch_reflog(project_name, branch, number)
|
|
41
|
+
get("/projects/#{project_name}/branches/#{branch}/reflog?n=#{number}")
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/gerry/api/changes.rb
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
require 'cgi'
|
|
2
|
-
|
|
3
|
-
module Gerry
|
|
4
|
-
module Api
|
|
5
|
-
module Changes
|
|
6
|
-
# Get changes visible to the caller.
|
|
7
|
-
#
|
|
8
|
-
# @param [Array] options the query parameters.
|
|
9
|
-
# @return [Hash] the changes.
|
|
10
|
-
def changes(options = [])
|
|
11
|
-
endpoint = '/changes/'
|
|
12
|
-
url = endpoint
|
|
13
|
-
|
|
14
|
-
if !options.empty?
|
|
15
|
-
url += '?' + map_options(options)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
response = get(url)
|
|
19
|
-
return response if response.empty? || !response.last.delete('_more_changes')
|
|
20
|
-
|
|
21
|
-
# Get the original start parameter, if any, else start from 0.
|
|
22
|
-
query = URI.parse(url).query
|
|
23
|
-
query = query ? CGI.parse(query) : { 'S' => ['0'] }
|
|
24
|
-
start = query['S'].join.to_i
|
|
25
|
-
|
|
26
|
-
# Keep getting data until there are no more changes.
|
|
27
|
-
loop do
|
|
28
|
-
# Replace the start parameter, using the original start as an offset.
|
|
29
|
-
query['S'] = ["#{start + response.size}"]
|
|
30
|
-
url = endpoint + '?' + map_options(query)
|
|
31
|
-
|
|
32
|
-
response.concat(get(url))
|
|
33
|
-
return response if response.empty? || !response.last.delete('_more_changes')
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
1
|
+
require 'cgi'
|
|
2
|
+
|
|
3
|
+
module Gerry
|
|
4
|
+
module Api
|
|
5
|
+
module Changes
|
|
6
|
+
# Get changes visible to the caller.
|
|
7
|
+
#
|
|
8
|
+
# @param [Array] options the query parameters.
|
|
9
|
+
# @return [Hash] the changes.
|
|
10
|
+
def changes(options = [])
|
|
11
|
+
endpoint = '/changes/'
|
|
12
|
+
url = endpoint
|
|
13
|
+
|
|
14
|
+
if !options.empty?
|
|
15
|
+
url += '?' + map_options(options)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
response = get(url)
|
|
19
|
+
return response if response.empty? || !response.last.delete('_more_changes')
|
|
20
|
+
|
|
21
|
+
# Get the original start parameter, if any, else start from 0.
|
|
22
|
+
query = URI.parse(url).query
|
|
23
|
+
query = query ? CGI.parse(query) : { 'S' => ['0'] }
|
|
24
|
+
start = query['S'].join.to_i
|
|
25
|
+
|
|
26
|
+
# Keep getting data until there are no more changes.
|
|
27
|
+
loop do
|
|
28
|
+
# Replace the start parameter, using the original start as an offset.
|
|
29
|
+
query['S'] = ["#{start + response.size}"]
|
|
30
|
+
url = endpoint + '?' + map_options(query)
|
|
31
|
+
|
|
32
|
+
response.concat(get(url))
|
|
33
|
+
return response if response.empty? || !response.last.delete('_more_changes')
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
data/lib/gerry/api/groups.rb
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
require 'json'
|
|
2
|
-
|
|
3
|
-
module Gerry
|
|
4
|
-
module Api
|
|
5
|
-
module Groups
|
|
6
|
-
# Get all groups
|
|
7
|
-
#
|
|
8
|
-
# @return [Hash] the groups
|
|
9
|
-
def groups
|
|
10
|
-
url = '/groups/'
|
|
11
|
-
get(url)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# Get all members for a group
|
|
15
|
-
#
|
|
16
|
-
# @param [Array] options the query parameters
|
|
17
|
-
# @return [Array] the members
|
|
18
|
-
def group_members(group_id, options = [])
|
|
19
|
-
url = "/groups/#{group_id}/members/"
|
|
20
|
-
|
|
21
|
-
if options.empty?
|
|
22
|
-
return get(url)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
options = map_options(options)
|
|
26
|
-
get("#{url}?#{options}")
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# Get the directly included groups of a group
|
|
30
|
-
#
|
|
31
|
-
# @return [Array] the included groups
|
|
32
|
-
def included_groups(group_id)
|
|
33
|
-
url = "/groups/#{group_id}/groups/"
|
|
34
|
-
get(url)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# Create a new group
|
|
38
|
-
#
|
|
39
|
-
# @return [Hash] the group details
|
|
40
|
-
def create_group(name, description, visible, owner_id=nil)
|
|
41
|
-
url = "/groups/#{name}"
|
|
42
|
-
body = {
|
|
43
|
-
description: description,
|
|
44
|
-
visible_to_all: visible,
|
|
45
|
-
}
|
|
46
|
-
body[:owner_id] = owner_id unless owner_id.nil? || owner_id.empty?
|
|
47
|
-
put(url, body)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
# Adds one or more users to a group
|
|
51
|
-
#
|
|
52
|
-
# @param [String] group_id the group id
|
|
53
|
-
# @param [Enumberable] users the list of users identified by email address
|
|
54
|
-
# @return [Hash] the account info details for each user added
|
|
55
|
-
def add_to_group(group_id, users)
|
|
56
|
-
url = "/groups/#{group_id}/members"
|
|
57
|
-
body = {
|
|
58
|
-
members: users
|
|
59
|
-
}
|
|
60
|
-
post(url, body)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def remove_from_group(group_id, users)
|
|
64
|
-
url = "/groups/#{group_id}/members.delete"
|
|
65
|
-
body = {
|
|
66
|
-
members: users
|
|
67
|
-
}
|
|
68
|
-
post(url, body)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
module Gerry
|
|
4
|
+
module Api
|
|
5
|
+
module Groups
|
|
6
|
+
# Get all groups
|
|
7
|
+
#
|
|
8
|
+
# @return [Hash] the groups
|
|
9
|
+
def groups
|
|
10
|
+
url = '/groups/'
|
|
11
|
+
get(url)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Get all members for a group
|
|
15
|
+
#
|
|
16
|
+
# @param [Array] options the query parameters
|
|
17
|
+
# @return [Array] the members
|
|
18
|
+
def group_members(group_id, options = [])
|
|
19
|
+
url = "/groups/#{group_id}/members/"
|
|
20
|
+
|
|
21
|
+
if options.empty?
|
|
22
|
+
return get(url)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
options = map_options(options)
|
|
26
|
+
get("#{url}?#{options}")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Get the directly included groups of a group
|
|
30
|
+
#
|
|
31
|
+
# @return [Array] the included groups
|
|
32
|
+
def included_groups(group_id)
|
|
33
|
+
url = "/groups/#{group_id}/groups/"
|
|
34
|
+
get(url)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Create a new group
|
|
38
|
+
#
|
|
39
|
+
# @return [Hash] the group details
|
|
40
|
+
def create_group(name, description, visible, owner_id=nil)
|
|
41
|
+
url = "/groups/#{name}"
|
|
42
|
+
body = {
|
|
43
|
+
description: description,
|
|
44
|
+
visible_to_all: visible,
|
|
45
|
+
}
|
|
46
|
+
body[:owner_id] = owner_id unless owner_id.nil? || owner_id.empty?
|
|
47
|
+
put(url, body)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Adds one or more users to a group
|
|
51
|
+
#
|
|
52
|
+
# @param [String] group_id the group id
|
|
53
|
+
# @param [Enumberable] users the list of users identified by email address
|
|
54
|
+
# @return [Hash] the account info details for each user added
|
|
55
|
+
def add_to_group(group_id, users)
|
|
56
|
+
url = "/groups/#{group_id}/members"
|
|
57
|
+
body = {
|
|
58
|
+
members: users
|
|
59
|
+
}
|
|
60
|
+
post(url, body)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def remove_from_group(group_id, users)
|
|
64
|
+
url = "/groups/#{group_id}/members.delete"
|
|
65
|
+
body = {
|
|
66
|
+
members: users
|
|
67
|
+
}
|
|
68
|
+
post(url, body)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|