redminerb 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fab0c9d47ded9d94c9f5493d83e86303c47eaac
4
- data.tar.gz: 23719db05f4831efc40eb52cbf896ec0191f5c65
3
+ metadata.gz: d73c75d31889c043847cbfa88509d83971a19dd3
4
+ data.tar.gz: 757a41cad5019c335107d80a83058db166bd973c
5
5
  SHA512:
6
- metadata.gz: 4e79942f238f54007293d5a9be204a69c894c9abc14df14ca486e7813af15dd479f0b6d1914820878a56dda54458604179ed14a4657ce88c311c3dd9561f4ed0
7
- data.tar.gz: 954359ec39e9d9a983a765f962c30b7b305d8322748c0a086b0d5577ab60894a2fa0a72c19eaf83348b6fe7b5aa82c420d56decae5aa93ee1c734b036d673566
6
+ metadata.gz: 0546f70d8f26ec3ba49c0c12199b938808ba37349b39c1a0f921b8308a7c2446f3427e0828298a3fa8350f872121e71eaac90cc20c598419509d4ea55d9fd23d
7
+ data.tar.gz: 60eed842cc876d662fb9b4ee73c88ea91b2d0602e3cae0acf44da678cc733c11e89781712ebbf79d2f9e9df490b7d43140f88cec23ae94e28467a39b2c65296d
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
@@ -1,6 +1,8 @@
1
1
  # Personal preferences
2
+ Metrics/MethodLength:
3
+ Max: 12
2
4
  Metrics/LineLength:
3
- Max: 99
5
+ Max: 92
4
6
  Style/SpaceInsideBlockBraces:
5
7
  Enabled: false
6
8
  Style/TrailingWhitespace:
data/README.md CHANGED
@@ -145,6 +145,8 @@ Will return only the ID following by the user's email.
145
145
 
146
146
  You can see **all the fields available** with `redminerb user me`.
147
147
 
148
+ **To list all the users at the database** you can use the `--all` option. Internally it will make as many HTTP requests to the REST API as needed. Here the `--limit` option let's manage the maximum number of users it will get with each request (to search, if possible, consider using the `--query` option instead).
149
+
148
150
  #### Show our info in the Redmine server
149
151
 
150
152
  $ redminerb user me
@@ -26,7 +26,9 @@ module Redminerb
26
26
  option :template, aliases: :t
27
27
  def show(project_id)
28
28
  Redminerb.init!
29
- puts Redminerb::Template.render(:project, Redminerb::Projects.read(project_id), options)
29
+ puts Redminerb::Template.render(:project,
30
+ Redminerb::Projects.read(project_id),
31
+ options)
30
32
  end
31
33
  end
32
34
  end
@@ -12,6 +12,14 @@ module Redminerb
12
12
  option :name, aliases: [:q, '--query'], banner: '<FILTER>'
13
13
  option :offset, aliases: :o
14
14
  option :limit, aliases: :l
15
+ option :all, type: :boolean,
16
+ desc: "List all the users at the database. Internally it makes\n" + <<-DESC
17
+ # as many HTTP requests to the REST API as needed (the
18
+ # --limit option us manage that number setting the maximum
19
+ # number of users it will get each time). To search consider
20
+ # using the --query option instead (if possible).
21
+ DESC
22
+
15
23
  def list(user_id = nil)
16
24
  if user_id
17
25
  show user_id
@@ -42,7 +50,8 @@ module Redminerb
42
50
  end
43
51
  initializer_data[:current_command].options.keys.each do |option|
44
52
  next if option == :ask
45
- value = ask("#{option.capitalize} [#{options[option]}]:", Thor::Shell::Color::GREEN)
53
+ value = ask("#{option.capitalize} [#{options[option]}]:",
54
+ Thor::Shell::Color::GREEN)
46
55
  options[option] = value unless value.empty?
47
56
  end
48
57
  break if yes?('Is everything OK? (NO/yes)')
@@ -14,6 +14,23 @@ module Redminerb
14
14
  @connection.basic_auth(cfg.api_key, cfg.api_key)
15
15
  end
16
16
 
17
+ # Uses pagination (limit&offset) params to retreive all the resources of
18
+ # the collection "name" using "params" in each request. Returns an array
19
+ # with all the resources.
20
+ def get_collection(name, params = { 'limit': 100 })
21
+ offset = 0
22
+ limit = params['limit'].to_i
23
+ [].tap do |resources|
24
+ loop do
25
+ params['offset'] = offset
26
+ response = get_json("/#{name}.json", params)
27
+ resources << response[name.to_s]
28
+ offset += limit
29
+ break unless offset < response['total_count']
30
+ end
31
+ end.flatten
32
+ end
33
+
17
34
  # Makes a GET request of the given 'path' param and returns the body of the
18
35
  # response parsed as JSON.
19
36
  def get_json(path, params = {})
@@ -14,13 +14,16 @@ module Redminerb
14
14
  # end
15
15
  #
16
16
  # See lib/reminerb/cli/user.rb code to see other example/s.
17
-
18
17
  def list(params)
19
- Redminerb.client.get_json('/users.json', params)['users'].map do |user|
18
+ if params.delete('all')
19
+ Redminerb.client.get_collection(:users, params)
20
+ else
21
+ Redminerb.client.get_json('/users.json', params)['users']
22
+ end.map do |user|
20
23
  OpenStruct.new user
21
24
  end
22
25
  end
23
-
26
+
24
27
  # Creates a brand new user with the given params. In lib/reminerb/cli/user.rb
25
28
  # you can see which ones are required (or running 'redminerb users create'
26
29
  # from the command line).
@@ -1,4 +1,4 @@
1
1
  # Copyright (c) The Cocktail Experience S.L. (2015)
2
2
  module Redminerb
3
- VERSION = '0.8.0'
3
+ VERSION = '0.8.1'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redminerb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Garcia Samblas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-09 00:00:00.000000000 Z
11
+ date: 2015-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor