caren-api 0.5.13 → 0.5.14
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/caren-api.gemspec +2 -2
- data/lib/caren/caren.rb +23 -9
- data/lib/caren/error.rb +16 -1
- data/spec/store/invoice_spec.rb +0 -6
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.14
|
data/caren-api.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "caren-api"
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.14"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andre Foeken"]
|
12
|
-
s.date = "2012-04-
|
12
|
+
s.date = "2012-04-11"
|
13
13
|
s.description = "You can use this gem as inspiration of the base of your connections with Caren."
|
14
14
|
s.email = "andre.foeken@nedap.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/caren/caren.rb
CHANGED
@@ -10,10 +10,11 @@ module Caren
|
|
10
10
|
|
11
11
|
class ServerSideError < Caren::Exceptions::StandardError
|
12
12
|
|
13
|
-
attr_accessor :errors
|
13
|
+
attr_accessor :errors, :http_code
|
14
14
|
|
15
|
-
def initialize errors=[]
|
15
|
+
def initialize errors=[], http_code=nil
|
16
16
|
self.errors = errors
|
17
|
+
self.http_code = http_code
|
17
18
|
end
|
18
19
|
|
19
20
|
end
|
@@ -67,7 +68,7 @@ module Caren
|
|
67
68
|
:user_agent => user_agent
|
68
69
|
return check_signature(response)
|
69
70
|
rescue RestClient::Exception => e
|
70
|
-
handle_error(e.response)
|
71
|
+
handle_error(e.response,e.http_code)
|
71
72
|
end
|
72
73
|
end
|
73
74
|
|
@@ -81,7 +82,7 @@ module Caren
|
|
81
82
|
:user_agent => user_agent
|
82
83
|
return check_signature(response)
|
83
84
|
rescue RestClient::Exception => e
|
84
|
-
handle_error(e.response)
|
85
|
+
handle_error(e.response,e.http_code)
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
@@ -95,7 +96,7 @@ module Caren
|
|
95
96
|
:user_agent => user_agent
|
96
97
|
return check_signature(response)
|
97
98
|
rescue RestClient::Exception => e
|
98
|
-
handle_error(e.response)
|
99
|
+
handle_error(e.response,e.http_code)
|
99
100
|
end
|
100
101
|
end
|
101
102
|
|
@@ -109,7 +110,7 @@ module Caren
|
|
109
110
|
:user_agent => user_agent
|
110
111
|
return check_signature(response)
|
111
112
|
rescue RestClient::Exception => e
|
112
|
-
handle_error(e.response)
|
113
|
+
handle_error(e.response,e.http_code)
|
113
114
|
end
|
114
115
|
end
|
115
116
|
|
@@ -204,7 +205,7 @@ module Caren
|
|
204
205
|
private
|
205
206
|
|
206
207
|
# Raise a Caren exception on errors
|
207
|
-
def handle_error response
|
208
|
+
def handle_error response, http_code
|
208
209
|
errors = []
|
209
210
|
doc = REXML::Document.new(response)
|
210
211
|
doc.elements.each('errors/error') do |error|
|
@@ -212,10 +213,23 @@ module Caren
|
|
212
213
|
attrs = { :on => error.attributes["on"].to_s.underscore.to_sym }
|
213
214
|
errors << Caren::ValidationError.new( error.attributes["category"], error.text.strip, attrs )
|
214
215
|
else
|
215
|
-
|
216
|
+
case http_code
|
217
|
+
when 400
|
218
|
+
errors << Caren::BadRequestError.new( error.attributes["category"], error.text.strip )
|
219
|
+
when 401
|
220
|
+
errors << Caren::UnauthorizedError.new( error.attributes["category"], error.text.strip )
|
221
|
+
when 404
|
222
|
+
errors << Caren::NotFoundError.new( error.attributes["category"], error.text.strip )
|
223
|
+
when 405
|
224
|
+
errors << Caren::MethodNotAllowedError.new( error.attributes["category"], error.text.strip )
|
225
|
+
when 406
|
226
|
+
errors << Caren::NotAcceptableError.new( error.attributes["category"], error.text.strip )
|
227
|
+
else
|
228
|
+
errors << Caren::Error.new( error.attributes["category"], error.text.strip )
|
229
|
+
end
|
216
230
|
end
|
217
231
|
end
|
218
|
-
raise Caren::Exceptions::ServerSideError.new(errors)
|
232
|
+
raise Caren::Exceptions::ServerSideError.new(errors,http_code)
|
219
233
|
end
|
220
234
|
|
221
235
|
end
|
data/lib/caren/error.rb
CHANGED
@@ -11,7 +11,22 @@ class Caren::Error
|
|
11
11
|
|
12
12
|
end
|
13
13
|
|
14
|
-
class Caren::
|
14
|
+
class Caren::UnauthorizedError < Caren::Error
|
15
|
+
end
|
16
|
+
|
17
|
+
class Caren::NotFoundError < Caren::Error
|
18
|
+
end
|
19
|
+
|
20
|
+
class Caren::BadRequestError < Caren::Error
|
21
|
+
end
|
22
|
+
|
23
|
+
class Caren::NotAcceptableError < Caren::Error
|
24
|
+
end
|
25
|
+
|
26
|
+
class Caren::MethodNotAllowedError < Caren::Error
|
27
|
+
end
|
28
|
+
|
29
|
+
class Caren::ValidationError < Caren::NotAcceptableError
|
15
30
|
|
16
31
|
def field
|
17
32
|
attributes[:on]
|
data/spec/store/invoice_spec.rb
CHANGED
@@ -46,7 +46,6 @@ describe "Store::Invoice", "REST methods" do
|
|
46
46
|
invoices_search = File.read("spec/fixtures/caren_invoices_search.xml")
|
47
47
|
|
48
48
|
invoice_url = Caren::Api.session.url_for( Caren::Store::Invoice.resource_url(17) )
|
49
|
-
invoice_email_url = Caren::Api.session.url_for( "#{Caren::Store::Invoice.resource_url(17)}/email" )
|
50
49
|
invoices_url = Caren::Api.session.url_for( Caren::Store::Invoice.resource_url )
|
51
50
|
invoices_search_url = Caren::Api.session.url_for( "#{Caren::Store::Invoice.resource_url}?key=reference&value=NW-05463-12-0" )
|
52
51
|
timestamp = DateTime.now.to_i
|
@@ -55,7 +54,6 @@ describe "Store::Invoice", "REST methods" do
|
|
55
54
|
FakeWeb.register_uri(:get, invoices_search_url, :body => invoices_search, :signature => Caren::Api.session.sign(timestamp,nil,invoices_search), :timestamp => timestamp )
|
56
55
|
FakeWeb.register_uri(:get, invoice_url, :body => invoice, :signature => Caren::Api.session.sign(timestamp,nil,invoice), :timestamp => timestamp )
|
57
56
|
|
58
|
-
FakeWeb.register_uri(:post, invoice_email_url, :status => 201, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
|
59
57
|
FakeWeb.register_uri(:post, invoices_url, :status => 201, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
|
60
58
|
FakeWeb.register_uri(:put, invoice_url, :body => invoice, :signature => Caren::Api.session.sign(timestamp,nil,invoice), :timestamp => timestamp )
|
61
59
|
FakeWeb.register_uri(:delete, invoice_url, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
|
@@ -85,10 +83,6 @@ describe "Store::Invoice", "REST methods" do
|
|
85
83
|
it "should be able to update an invoice" do
|
86
84
|
lambda{ Caren::Store::Invoice.new( :id => 17, :reference => "JL-1" ).update(Caren::Api.session) }.should_not raise_error
|
87
85
|
end
|
88
|
-
|
89
|
-
it "should be able to email an invoice" do
|
90
|
-
lambda{ Caren::Store::Invoice.new( :id => 17 ).email(Caren::Api.session) }.should_not raise_error
|
91
|
-
end
|
92
86
|
|
93
87
|
it "should be able to delete an external invoice" do
|
94
88
|
lambda{ Caren::Store::Invoice.new( :id => 17 ).delete(Caren::Api.session) }.should_not raise_error
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caren-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 14
|
10
|
+
version: 0.5.14
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andre Foeken
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-04-
|
18
|
+
date: 2012-04-11 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
requirement: &id001 !ruby/object:Gem::Requirement
|