redmine-client 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/redmine/client.rb +35 -1
- data/lib/redmine/client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1b6d8d4f3db8f3bc1d826eef346559d1110aa53
|
4
|
+
data.tar.gz: 70118cc8188b44bb98c2e9b5aa3273e5fdf81397
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 245f4112778b0c9afa3694cd8bd9d97563b10b64070cb40ba155befb7095dab84719aca44b062d891aaeef1b97209c8bab7ea1220851cd0db0c6cd4998ff3dd7
|
7
|
+
data.tar.gz: e646218f3364b589a5d4fc2b97488951960de2800bfee1728a51143cdd26bac70ea42c85546f11cb7f6c9da3b1e9c5d271ce04ad166ffaa8e28bcf306d439229
|
data/lib/redmine/client.rb
CHANGED
@@ -5,8 +5,29 @@ require 'redmine/client/authorization_token'
|
|
5
5
|
|
6
6
|
module Redmine
|
7
7
|
class Client
|
8
|
+
class ResponseError < StandardError
|
9
|
+
attr_reader :response
|
10
|
+
def initialize(response)
|
11
|
+
@response = response
|
12
|
+
end
|
13
|
+
|
14
|
+
def body
|
15
|
+
response.body
|
16
|
+
end
|
17
|
+
|
18
|
+
def message
|
19
|
+
"Error #{response.status}: #{response.body}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
8
23
|
class << self
|
9
24
|
attr_accessor :base_url
|
25
|
+
attr_writer :raise_on_error
|
26
|
+
def raise_on_error?
|
27
|
+
return @raise_on_error if defined?(@raise_on_error)
|
28
|
+
|
29
|
+
@raise_on_error = true
|
30
|
+
end
|
10
31
|
end
|
11
32
|
|
12
33
|
attr_reader :base_url, :access_key
|
@@ -33,21 +54,25 @@ module Redmine
|
|
33
54
|
class_eval <<-EOF
|
34
55
|
def create_#{singular}(params, full_response=false)
|
35
56
|
resp = faraday.post("/#{plural}.json", {"#{singular}" => params})
|
57
|
+
check_errors(resp)
|
36
58
|
full_response ? resp : resp.body
|
37
59
|
end
|
38
60
|
|
39
61
|
def find_#{singular}(id, full_response=false)
|
40
62
|
resp = faraday.get("/#{plural}/\#{id}.json")
|
63
|
+
check_errors(resp)
|
41
64
|
full_response ? resp : resp.body
|
42
65
|
end
|
43
66
|
|
44
67
|
def update_#{singular}(id, params, full_response=false)
|
45
68
|
resp = faraday.put("/#{plural}/\#{id}.json", {"#{singular}" => params})
|
69
|
+
check_errors(resp)
|
46
70
|
full_response ? resp : resp.body
|
47
71
|
end
|
48
72
|
|
49
|
-
def delete_#{singular}(id, full_response=false)
|
73
|
+
def delete_#{singular}(id, full_response=false, raise_on_error=true)
|
50
74
|
resp = faraday.delete("/#{plural}/\#{id}.json")
|
75
|
+
check_errors(resp)
|
51
76
|
full_response ? resp : resp.body
|
52
77
|
end
|
53
78
|
EOF
|
@@ -65,5 +90,14 @@ module Redmine
|
|
65
90
|
"role_ids" => Array(role_ids),
|
66
91
|
}})
|
67
92
|
end
|
93
|
+
|
94
|
+
def check_errors(response)
|
95
|
+
return if response.success?
|
96
|
+
$stderr.puts "REDMINE ERROR (#{response.status}): #{response.body}"
|
97
|
+
|
98
|
+
if self.class.raise_on_error?
|
99
|
+
raise ResponseError.new(response)
|
100
|
+
end
|
101
|
+
end
|
68
102
|
end
|
69
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redmine-client
|
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
|
- Andy Delcambre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|