almodovar 1.5.3 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +14 -1
- data/lib/almodovar/errors.rb +43 -0
- data/lib/almodovar/http_accessor.rb +4 -1
- data/lib/almodovar/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85aa0a429ca1941cb1cdfb137f9f8955c69b8c9c
|
4
|
+
data.tar.gz: ea1145d5b1682a40c5a6371e275386bc3bb3a534
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef21d0d38978ea475a591ea75ece12e6144c3fafe1ae2c200c56c34cd5ec0fa00c7dbf7c10797ca624c691eee486752e412dd9fc1cf7fc2a147d2e9d70428e1f
|
7
|
+
data.tar.gz: 65d3a7c15e6bb59b33ce3d1d6381d32af237898a6fcfa800fa02442dfb2ce9fb95c19cde5d114c942d8f38724778d7385d1c4a8403cd44e383212ae62e706ab3
|
data/README.rdoc
CHANGED
@@ -109,10 +109,23 @@ And exactly the same with the _delete_ method:
|
|
109
109
|
=> <job> ... </job>
|
110
110
|
>> job.delete
|
111
111
|
|
112
|
+
== Detailed error messages
|
113
|
+
|
114
|
+
In case an incorrect _PUT/POST_ request fails with 422 response status, you can access list of errors using _error_messages_ method of Almodovar::UnprocessableEntityError:
|
115
|
+
|
116
|
+
>> collection_entry = Almodovar::Resource("http://sequence.example.com/api/collection_entries/12345", auth)
|
117
|
+
=> <collection-entry> ... </collection-entry>
|
118
|
+
>> begin
|
119
|
+
collection_entry.update(:collection_entry => {:position => 3.2})
|
120
|
+
rescue Almodovar::UnprocessableEntityError => e
|
121
|
+
e.error_messages
|
122
|
+
end
|
123
|
+
=> ["Position must be an integer"]
|
124
|
+
|
112
125
|
==To-do
|
113
126
|
|
114
127
|
* Better error management
|
115
128
|
* Write the conventions Almodovar expects in an API
|
116
129
|
* Other authentication methods than digest
|
117
130
|
|
118
|
-
Copyright (c) 2010 BeBanjo S.L., released under the MIT license
|
131
|
+
Copyright (c) 2010 BeBanjo S.L., released under the MIT license
|
data/lib/almodovar/errors.rb
CHANGED
@@ -2,6 +2,7 @@ module Almodovar
|
|
2
2
|
class HttpError < StandardError
|
3
3
|
attr_reader :response_status, :response_body
|
4
4
|
|
5
|
+
# Children of this class must not override the initialize method
|
5
6
|
def initialize(response, url)
|
6
7
|
@response_status = response.status
|
7
8
|
@response_body = response.body
|
@@ -20,4 +21,46 @@ module Almodovar
|
|
20
21
|
|
21
22
|
class ConnectTimeoutError < TimeoutError
|
22
23
|
end
|
24
|
+
|
25
|
+
class UnprocessableEntityError < HttpError
|
26
|
+
def errors?
|
27
|
+
error_messages.any?
|
28
|
+
end
|
29
|
+
|
30
|
+
# There are some different kind of errors in Almodovar servers
|
31
|
+
# "errors" => [{"error" => "wadus"}]
|
32
|
+
# "errors" => {"error" => ["wadus", "foo"]
|
33
|
+
# "error" => {"message" => "chaflan"}
|
34
|
+
#
|
35
|
+
# In case we cannot parse the response an empty array is returned
|
36
|
+
def error_messages
|
37
|
+
@error_messages ||= begin
|
38
|
+
if hash.key?('errors')
|
39
|
+
Array.wrap(hash['errors']).flat_map do |error|
|
40
|
+
error.is_a?(Hash) && error.key?('error') ? error['error'] : error.to_s
|
41
|
+
end
|
42
|
+
elsif hash.key?('error')
|
43
|
+
Array.wrap(hash['error'] && hash['error']['message'])
|
44
|
+
else
|
45
|
+
[]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def hash
|
53
|
+
@hash ||= begin
|
54
|
+
Hash.from_xml(@response_body) || {}
|
55
|
+
rescue StandardError
|
56
|
+
# The expected errors depends on the ActiveSupport::XmlMini_parser used that it's REXML by default but there
|
57
|
+
# are other, so just rescue a generic error
|
58
|
+
{}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
HTTP_ERRORS = {
|
64
|
+
422 => UnprocessableEntityError
|
65
|
+
}
|
23
66
|
end
|
@@ -31,7 +31,10 @@ module Almodovar
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def check_errors(response, url)
|
34
|
-
|
34
|
+
if response.status >= 400
|
35
|
+
http_error_klass = Almodovar::HTTP_ERRORS[response.status] || Almodovar::HttpError
|
36
|
+
raise http_error_klass.new(response, url)
|
37
|
+
end
|
35
38
|
end
|
36
39
|
end
|
37
40
|
end
|
data/lib/almodovar/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: almodovar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BeBanjo S.L.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: builder
|
@@ -134,8 +134,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
version: '0'
|
135
135
|
requirements: []
|
136
136
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.
|
137
|
+
rubygems_version: 2.5.1
|
138
138
|
signing_key:
|
139
139
|
specification_version: 4
|
140
140
|
summary: BeBanjo API client
|
141
141
|
test_files: []
|
142
|
+
has_rdoc:
|