gerry 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gerry/client/accounts.rb +12 -3
- data/lib/gerry/client/changes.rb +23 -5
- data/lib/gerry/client/request.rb +12 -30
- data/lib/gerry/version.rb +1 -1
- data/spec/changes_spec.rb +6 -0
- data/spec/fixtures/changes_batch_1.json +2 -1
- data/spec/fixtures/changes_batch_2.json +17 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50cbfe20d0fa8c4f9a179cb5e74fc4ed0bdf346c
|
4
|
+
data.tar.gz: e865e925bda4a23be8df637f48278174fd3ae048
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0f656b7564de7d4f0a68bbd3a90323f3392e1fca2724d22ba7847a3063f81337531194eb5129b269f47a126efbef728673d1a25dc77cff79923b5ffcceb5760
|
7
|
+
data.tar.gz: 9cd7d00b43322b5dbc68fe116d80e16a5d26d594be79778b4cebee17bb813e7dacd40dcdb1bcdbe484a73d1b92e0f0d9bfcd8d2710e684cebb1315f8fd86548e
|
@@ -1,17 +1,26 @@
|
|
1
1
|
module Gerry
|
2
2
|
class Client
|
3
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
|
+
|
4
13
|
# Get the global capabilities that are enabled for the calling user.
|
5
14
|
#
|
6
15
|
# @param [Array] options the query parameters.
|
7
16
|
# @return [Hash] the account capabilities.
|
8
17
|
def account_capabilities(options = [])
|
9
18
|
url = '/accounts/self/capabilities'
|
10
|
-
|
19
|
+
|
11
20
|
if options.empty?
|
12
21
|
return get(url)
|
13
22
|
end
|
14
|
-
|
23
|
+
|
15
24
|
options = map_options(options)
|
16
25
|
get("#{url}?#{options}")
|
17
26
|
end
|
@@ -26,4 +35,4 @@ module Gerry
|
|
26
35
|
end
|
27
36
|
end
|
28
37
|
end
|
29
|
-
end
|
38
|
+
end
|
data/lib/gerry/client/changes.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
1
3
|
module Gerry
|
2
4
|
class Client
|
3
5
|
module Changes
|
@@ -6,14 +8,30 @@ module Gerry
|
|
6
8
|
# @param [Array] options the query parameters.
|
7
9
|
# @return [Hash] the changes.
|
8
10
|
def changes(options = [])
|
9
|
-
|
11
|
+
endpoint = '/changes/'
|
12
|
+
url = endpoint
|
10
13
|
|
11
|
-
if options.empty?
|
12
|
-
|
14
|
+
if !options.empty?
|
15
|
+
url += '?' + map_options(options)
|
13
16
|
end
|
14
17
|
|
15
|
-
|
16
|
-
|
18
|
+
response = get(url)
|
19
|
+
return response unless 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 unless response.last.delete('_more_changes')
|
34
|
+
end
|
17
35
|
end
|
18
36
|
end
|
19
37
|
end
|
data/lib/gerry/client/request.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
require 'cgi'
|
2
|
-
|
3
1
|
module Gerry
|
4
2
|
class Client
|
5
3
|
module Request
|
6
4
|
# Get the mapped options.
|
7
5
|
#
|
8
|
-
# @param [Array] options the query parameters.
|
6
|
+
# @param [Array] or [Hash] options the query parameters.
|
9
7
|
# @return [String] the mapped options.
|
10
8
|
def map_options(options)
|
11
|
-
options.
|
9
|
+
if options.is_a?(Array)
|
10
|
+
options.map { |v| "#{v}" }.join('&')
|
11
|
+
elsif options.is_a?(Hash)
|
12
|
+
options.map { |k,v| "#{k}=#{v.join(',')}" }.join('&')
|
13
|
+
end
|
12
14
|
end
|
13
15
|
|
14
16
|
private
|
@@ -16,33 +18,13 @@ module Gerry
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def get(url)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
# Keep requesting data until there are no more changes.
|
26
|
-
all_results = []
|
27
|
-
loop do
|
28
|
-
response = if @username && @password
|
29
|
-
auth = { username: @username, password: @password }
|
30
|
-
self.class.get("/a#{url}", digest_auth: auth)
|
31
|
-
else
|
32
|
-
self.class.get(url)
|
33
|
-
end
|
34
|
-
|
35
|
-
result = parse(response)
|
36
|
-
return result unless result.is_a?(Array) && result.last.is_a?(Hash)
|
37
|
-
|
38
|
-
all_results.concat(result)
|
39
|
-
return all_results unless result.last.delete('_more_changes')
|
40
|
-
|
41
|
-
# Append the start parameter to the URL, overriding any previous start parameter.
|
42
|
-
url = orig_url + "#{query ? '&' : '?'}S=#{start + all_results.size}"
|
21
|
+
response = if @username && @password
|
22
|
+
auth = { username: @username, password: @password }
|
23
|
+
self.class.get("/a#{url}", digest_auth: auth)
|
24
|
+
else
|
25
|
+
self.class.get(url)
|
43
26
|
end
|
44
|
-
|
45
|
-
all_results
|
27
|
+
parse(response)
|
46
28
|
end
|
47
29
|
|
48
30
|
def put(url, body)
|
data/lib/gerry/version.rb
CHANGED
data/spec/changes_spec.rb
CHANGED
@@ -20,6 +20,7 @@ describe '.changes' do
|
|
20
20
|
it 'should fetch all changes in batches' do
|
21
21
|
stub_batch_0 = stub_get('/changes/', 'changes_batch_0.json')
|
22
22
|
stub_batch_1 = stub_get('/changes/?S=1', 'changes_batch_1.json')
|
23
|
+
stub_batch_2 = stub_get('/changes/?S=2', 'changes_batch_2.json')
|
23
24
|
|
24
25
|
client = MockGerry.new
|
25
26
|
changes = client.changes
|
@@ -29,10 +30,15 @@ describe '.changes' do
|
|
29
30
|
|
30
31
|
expect(changes[0]['project']).to eq('awesome')
|
31
32
|
expect(changes[0]['branch']).to eq('master')
|
33
|
+
expect(changes[0]['owner']['name']).to eq('The Duke')
|
32
34
|
|
33
35
|
expect(changes[1]['project']).to eq('clean')
|
34
36
|
expect(changes[1]['subject']).to eq('Refactor code')
|
35
37
|
expect(changes[1]['owner']['name']).to eq('Batman')
|
38
|
+
|
39
|
+
expect(changes[2]['project']).to eq('X')
|
40
|
+
expect(changes[2]['subject']).to eq('Remove unused imports')
|
41
|
+
expect(changes[2]['owner']['name']).to eq('Bill')
|
36
42
|
end
|
37
43
|
|
38
44
|
it 'should fetch all open changes' do
|
@@ -0,0 +1,17 @@
|
|
1
|
+
)]}'
|
2
|
+
[
|
3
|
+
{
|
4
|
+
"project": "X",
|
5
|
+
"branch": "default",
|
6
|
+
"id": "Ieb185f4da8725ae35e9f940e614c6eaa7b88eff5",
|
7
|
+
"subject": "Remove unused imports",
|
8
|
+
"status": "NEW",
|
9
|
+
"created": "2016-01-11 15:51:30.605000000",
|
10
|
+
"updated": "2016-02-12 00:45:26.431000000",
|
11
|
+
"_sortkey": "002e4203000187d5",
|
12
|
+
"_number": 4711,
|
13
|
+
"owner": {
|
14
|
+
"name": "Bill"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gerry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabian Mettler
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-01-
|
14
|
+
date: 2016-01-13 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: httparty
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- spec/fixtures/changes.json
|
153
153
|
- spec/fixtures/changes_batch_0.json
|
154
154
|
- spec/fixtures/changes_batch_1.json
|
155
|
+
- spec/fixtures/changes_batch_2.json
|
155
156
|
- spec/fixtures/group_members.json
|
156
157
|
- spec/fixtures/groups.json
|
157
158
|
- spec/fixtures/open_changes.json
|
@@ -195,6 +196,7 @@ test_files:
|
|
195
196
|
- spec/fixtures/changes.json
|
196
197
|
- spec/fixtures/changes_batch_0.json
|
197
198
|
- spec/fixtures/changes_batch_1.json
|
199
|
+
- spec/fixtures/changes_batch_2.json
|
198
200
|
- spec/fixtures/group_members.json
|
199
201
|
- spec/fixtures/groups.json
|
200
202
|
- spec/fixtures/open_changes.json
|