redminerb 0.1.0 → 0.2.0

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: 09692d9434819135c770d6163223cb5e2cf92126
4
- data.tar.gz: 0ec505a1977c800b76f21062722480d305335760
3
+ metadata.gz: 06151d01eec527cbe1bd4ffaae591261853927c5
4
+ data.tar.gz: aba32467e103b17ee396e9971ad962ee509420ce
5
5
  SHA512:
6
- metadata.gz: d78eae292b557efd6293da0656d6151b19285a6bf8b824850c75c5e46cf6e96008fac23378ae5c008a02b6947b3533c76b39b7e8989e0d55ced27c423045d9f9
7
- data.tar.gz: d09e236d5d596aca2ddb445f42e86c2013b59f45d011b86c3b6d547b116a3a70033377f3d28cd8d28e6045331dfaef7e141c37f933d516fedfeeae94a2cbf7eb
6
+ metadata.gz: aefb44e25b2fcd44cf66bb8bd369fb0e096b1a788b6379916fbbc6d0d6031a8f0177e0337796e1463277eea016057f1fc79b097999f7ad0e5817b1da0a9103fb
7
+ data.tar.gz: 6e1b9acab0953a026a0f88614b016c4fe69239845a6d449ee05f1485025af4254c57ca1850723318d49f6b6e1cddb04a26f0502e7a8d8d58c0b71275397f791a
@@ -1,4 +1,11 @@
1
+ == 0.2, released 2015-09-17
2
+
3
+ * 'redminerb users create' to create a brand new user!
4
+
1
5
  == 0.1, released 2015-09-16
2
6
 
3
7
  * 'redminerb config' to get current config
4
8
  * 'redminerb users [list]' to see current users
9
+
10
+ * 'redminerb config' to get current config
11
+ * 'redminerb users [list]' to see current users
data/README.md CHANGED
@@ -34,6 +34,12 @@ Or install it yourself as:
34
34
 
35
35
  ## Usage
36
36
 
37
+ The URL of your Redmine server and your API key needs to be in your
38
+ `~/.redminerb.yml` in order to connect to its REST API. For example:
39
+
40
+ url: http://localhost:3000/
41
+ api_key: 69b47d74e36a6757bac5d45f8398dd23bfa8f52c
42
+
37
43
  ### Configuration (config)
38
44
 
39
45
  To see the current configuration used by Redminerb we have the `config` command:
@@ -42,15 +48,25 @@ To see the current configuration used by Redminerb we have the `config` command:
42
48
  URL: http://localhost:3000/
43
49
  API-KEY: 69b47d74e36a6757bac5d45f8398dd23bfa8f52c
44
50
 
45
- Currently the config is read only from the **~/.redminerb.yml** file.
46
-
51
+ *NOTICE: soon will be possible to specify this values using env. vars and this
52
+ command will have more sense.*
47
53
 
48
54
  ### Users
49
55
 
56
+ **IMPORTANT: Be sure that you API key have the right permissions in the server.**
57
+
58
+ #### List current users
59
+
50
60
  $ redminerb users # a.k.a. redminerb users list
51
61
 
52
62
  That should give you the current users on your Redmine server, one per line.
53
63
 
64
+ #### Create new user
65
+
66
+ $ redminerb users create --login "wadus" --password "ultrasecret" \
67
+ --firstname="Wadux" --lastname="Wallace" \
68
+ --mail "wadus@waduxwallace.out"
69
+
54
70
  ## Development
55
71
 
56
72
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -11,5 +11,16 @@ module Redminerb
11
11
  puts [user.id, user.login, user.mail].join("\t").green
12
12
  end
13
13
  end
14
+
15
+ desc 'create', 'Creates a user.'
16
+ option :login, required: true
17
+ option :password, required: true
18
+ option :firstname, required: true
19
+ option :lastname, required: true
20
+ option :mail, required: true
21
+ def create
22
+ Redminerb.init!
23
+ puts Redminerb.client.create_user(options).green
24
+ end
14
25
  end
15
26
  end
@@ -6,6 +6,8 @@ require 'ostruct'
6
6
  module Redminerb
7
7
  # HTTP client to communicate w/ the Redmine server.
8
8
  class Client
9
+ class UnprocessableEntity < StandardError; end
10
+
9
11
  attr_reader :connection
10
12
 
11
13
  def initialize(cfg)
@@ -31,14 +33,57 @@ module Redminerb
31
33
  end
32
34
  end
33
35
 
36
+ # Creates a brand new user with the given params. In lib/reminerb/cli/user.rb
37
+ # you can see which ones are required (or running 'redminerb users create'
38
+ # from the command line).
39
+ #
40
+ # Example (missing required params):
41
+ # Redminerb.init!
42
+ # Redminerb.client.create_user login: 'wadus'
43
+
44
+ def create_user(params)
45
+ response = post_json('/users.json', user: params)
46
+
47
+ if response.success?
48
+ 'Created'
49
+ else
50
+ raise_error! response
51
+ end
52
+ end
53
+
34
54
  private
35
55
 
36
- # Requests the path that receives as param and parses the body of the
37
- # response received as JSON.
56
+ # Makes a GET request of the given 'path' param and returns the body of the
57
+ # response parsed as JSON.
38
58
  def get_json(path)
39
59
  Redminerb.init_required!
40
- JSON.parse(@connection.get(path).body)
60
+ res = @connection.get(path)
61
+ JSON.parse(res.body)
62
+ rescue JSON::ParserError => e
63
+ raise e, "HTTP status code #{res.status}"
64
+ end
65
+
66
+ # Makes a POST request to 'path' with 'params' in JSON format.
67
+ def post_json(path, params)
68
+ @connection.post do |req|
69
+ req.url path
70
+ req.headers['Content-Type'] = 'application/json'
71
+ req.body = params.to_json
72
+ end
41
73
  end
42
74
 
75
+ # It raises an exception giving the validation messages for 422 responses
76
+ def raise_error!(res)
77
+ if res.status == 422
78
+ begin
79
+ errors = JSON.parse(res.body)['errors']
80
+ rescue JSON::ParserError
81
+ errors = [res.body]
82
+ end
83
+ fail UnprocessableEntity, errors.join("\n")
84
+ else
85
+ fail StandardError, "ERROR (status code #{res.status})"
86
+ end
87
+ end
43
88
  end
44
89
  end
@@ -1,4 +1,4 @@
1
1
  # Copyright (c) The Cocktail Experience S.L. (2015)
2
2
  module Redminerb
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
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.1.0
4
+ version: 0.2.0
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-09-16 00:00:00.000000000 Z
11
+ date: 2015-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor