caren-api 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -3
- data/VERSION +1 -1
- data/caren-api.gemspec +2 -2
- data/certs/caren-api.pub +8 -6
- data/init.rb +1 -4
- data/lib/caren/base.rb +1 -1
- data/lib/caren/care_provider.rb +8 -8
- data/lib/caren/caren.rb +46 -45
- data/lib/caren/external_message.rb +6 -6
- data/lib/caren/link.rb +6 -6
- data/spec/care_provider_spec.rb +13 -11
- data/spec/caren_spec.rb +30 -30
- data/spec/external_message_spec.rb +8 -4
- data/spec/link_spec.rb +12 -6
- data/spec/spec_helper.rb +3 -5
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -6,10 +6,10 @@ This is the reference implementation for the Caren CareProvider API (http://care
|
|
6
6
|
|
7
7
|
To get started you will need a care provider API private/public keypair.
|
8
8
|
|
9
|
-
* Generate a private key using:
|
10
|
-
* Extract the public key from it:
|
9
|
+
* Generate a private key using: pk = Caren::Api.generate_private_key
|
10
|
+
* Extract the public key from it: pk.public_key
|
11
11
|
* Send the public key to info@caren-cares.com with an access request.
|
12
|
-
*
|
12
|
+
* Create an Api session and fill your private key and your care provider url (like https://example.caren-cares.com)
|
13
13
|
|
14
14
|
== Getting information from Caren
|
15
15
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/caren-api.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{caren-api}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
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 = %q{2011-10-
|
12
|
+
s.date = %q{2011-10-21}
|
13
13
|
s.description = %q{You can use this gem as inspiration of the base of your connections with Caren.}
|
14
14
|
s.email = %q{andre.foeken@nedap.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/certs/caren-api.pub
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
-----BEGIN PUBLIC KEY-----
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
-----BEGIN RSA PUBLIC KEY-----
|
2
|
+
MIIBCgKCAQEA3sPP1w5IMHMFD2swbNl6LBWBek8QckE9z0MRmIIe4hVTcQcoXRcZ
|
3
|
+
bhK3r3l8yFbYjWjxEuWgk1JTdLx5Y+LjP0tbF4C+yTRZr8FmbEBVJ6Gan0AV0rmP
|
4
|
+
AGyDY8YrrO3FI9A3L0TP1ZYpIY6Lt33zKXMECgHWpXmiQcvRPR2rXRrVZzC5m1zk
|
5
|
+
/fZR+XGQyJ+vcO8MaTRUKs4l28Ih/hGXXGUgT4IYMdF+CIaoympBs8iMcchY4Idn
|
6
|
+
DFdtNgG328QZUouHAa/kp46SC1Xo2DtwNNrJxsbQQyeABNCopGmsBJMmwQPfsV4I
|
7
|
+
CH1U0hkEzBF2LsWJKRk1scTtVYiB8Kcu4QIDAQAB
|
8
|
+
-----END RSA PUBLIC KEY-----
|
data/init.rb
CHANGED
data/lib/caren/base.rb
CHANGED
data/lib/caren/care_provider.rb
CHANGED
@@ -25,20 +25,20 @@ class Caren::CareProvider < Caren::Base
|
|
25
25
|
]
|
26
26
|
end
|
27
27
|
|
28
|
-
def self.search key, value
|
29
|
-
from_xml
|
28
|
+
def self.search key, value, session
|
29
|
+
from_xml session.get( self.search_url(key,value) )
|
30
30
|
end
|
31
31
|
|
32
|
-
def self.all
|
33
|
-
from_xml
|
32
|
+
def self.all session
|
33
|
+
from_xml session.get(self.resource_url)
|
34
34
|
end
|
35
35
|
|
36
|
-
def update
|
37
|
-
|
36
|
+
def update session
|
37
|
+
session.put(self.resource_url(self.id), self.to_xml)
|
38
38
|
end
|
39
39
|
|
40
|
-
def update_logo logo_hash_or_path
|
41
|
-
|
40
|
+
def update_logo logo_hash_or_path, session
|
41
|
+
session.put(self.resource_url(self.id), self.to_logo_xml(logo_hash_or_path))
|
42
42
|
end
|
43
43
|
|
44
44
|
def as_xml
|
data/lib/caren/caren.rb
CHANGED
@@ -20,74 +20,74 @@ module Caren
|
|
20
20
|
|
21
21
|
class Api
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.url
|
28
|
-
Thread.current[:url]
|
23
|
+
class << self
|
24
|
+
attr_accessor :session
|
29
25
|
end
|
30
26
|
|
31
|
-
|
32
|
-
Thread.current[:caren_public_key] = key
|
33
|
-
end
|
34
|
-
|
35
|
-
# The public key file used to verify request coming from Caren
|
36
|
-
def self.caren_public_key
|
37
|
-
Thread.current[:caren_public_key]
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.private_key= key
|
41
|
-
Thread.current[:private_key] = key
|
42
|
-
end
|
27
|
+
attr_accessor :url, :caren_public_key, :private_key
|
43
28
|
|
44
|
-
#
|
45
|
-
|
46
|
-
|
29
|
+
# Initialize new API session. Specify your private key to sign outgoing messages and your care provider url.
|
30
|
+
# Optionally you can pass the caren public key used to verify incoming requests.
|
31
|
+
def initialize private_key, url, caren_public_key=nil
|
32
|
+
self.url = url
|
33
|
+
self.private_key = private_key
|
34
|
+
self.caren_public_key = caren_public_key || Caren::Api.key_from_path("certs/caren-api.pub")
|
47
35
|
end
|
48
36
|
|
37
|
+
# Create key from string
|
49
38
|
def self.key_from_string string
|
50
39
|
OpenSSL::PKey::RSA.new(string)
|
51
40
|
end
|
52
41
|
|
42
|
+
# Read a file and create key from string
|
53
43
|
def self.key_from_path path
|
54
44
|
self.key_from_string( File.read(path) )
|
55
45
|
end
|
56
46
|
|
57
|
-
|
58
|
-
|
47
|
+
# Generate a new private key
|
48
|
+
def self.generate_private_key size=2048
|
49
|
+
OpenSSL::PKey::RSA.generate( size )
|
59
50
|
end
|
60
51
|
|
61
|
-
|
52
|
+
# URL from path using session base url
|
53
|
+
def url_for path
|
54
|
+
"#{self.url}#{path}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def put path, xml
|
62
58
|
begin
|
63
|
-
|
59
|
+
timestamp = DateTime.now.to_i
|
60
|
+
response = RestClient.put url_for(path), xml, :content_type => :xml, :accept => :xml, :timestamp => timestamp, :signature => sign(timestamp,xml)
|
64
61
|
return check_signature(response)
|
65
62
|
rescue RestClient::Exception => e
|
66
63
|
handle_error(e.response)
|
67
64
|
end
|
68
65
|
end
|
69
66
|
|
70
|
-
def
|
67
|
+
def post path, xml
|
71
68
|
begin
|
72
|
-
|
69
|
+
timestamp = DateTime.now.to_i
|
70
|
+
response = RestClient.post url_for(path), xml, :content_type => :xml, :accept => :xml, :timestamp => timestamp, :signature => sign(timestamp,xml)
|
73
71
|
return check_signature(response)
|
74
72
|
rescue RestClient::Exception => e
|
75
73
|
handle_error(e.response)
|
76
74
|
end
|
77
75
|
end
|
78
76
|
|
79
|
-
def
|
77
|
+
def delete path
|
80
78
|
begin
|
81
|
-
|
79
|
+
timestamp = DateTime.now.to_i
|
80
|
+
response = RestClient.delete url_for(path), :content_type => :xml, :accept => :xml, :timestamp => timestamp, :signature => sign(timestamp)
|
82
81
|
return check_signature(response)
|
83
82
|
rescue RestClient::Exception => e
|
84
83
|
handle_error(e.response)
|
85
84
|
end
|
86
85
|
end
|
87
86
|
|
88
|
-
def
|
87
|
+
def get path
|
89
88
|
begin
|
90
|
-
|
89
|
+
timestamp = DateTime.now.to_i
|
90
|
+
response = RestClient.get url_for(path), :content_type => :xml, :accept => :xml, :timestamp => timestamp, :signature => sign(timestamp)
|
91
91
|
return check_signature(response)
|
92
92
|
rescue RestClient::Exception => e
|
93
93
|
handle_error(e.response)
|
@@ -103,11 +103,11 @@ module Caren
|
|
103
103
|
end
|
104
104
|
|
105
105
|
# Pass an XML string to be handled. Only a valid caren_objects xml hash will be parsed.
|
106
|
-
def
|
106
|
+
def incoming xml, signature
|
107
107
|
if self.verify_signature(signature,xml)
|
108
108
|
objects = []
|
109
109
|
hash = Hash.from_xml(xml)["caren_objects"]
|
110
|
-
|
110
|
+
Caren::Api.supported_incoming_objects.each do |key,klass|
|
111
111
|
objects << (hash[key]||hash[key.to_s]||[]).map{ |h| klass.new(h) }
|
112
112
|
end
|
113
113
|
return objects.flatten
|
@@ -116,29 +116,30 @@ module Caren
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
-
# Sign your string using
|
120
|
-
|
121
|
-
|
119
|
+
# Sign your string and timestamp using private key
|
120
|
+
# Timestamp is UNIX timestamp seconds since 1970
|
121
|
+
def sign timestamp, string=nil
|
122
|
+
encrypted_digest = self.private_key.sign( "sha1", string.to_s + timestamp.to_s )
|
122
123
|
signature = CGI.escape(Base64.encode64(encrypted_digest))
|
123
124
|
return signature
|
124
125
|
end
|
125
126
|
|
126
|
-
private
|
127
|
-
|
128
127
|
# Check the signature of the response from rest-client
|
129
|
-
def
|
130
|
-
return response if self.verify_signature( response.headers[:signature], response )
|
128
|
+
def check_signature response
|
129
|
+
return response if self.verify_signature( response.headers[:signature], response.headers[:timestamp], response )
|
131
130
|
raise Caren::Exceptions::SignatureMismatch.new
|
132
131
|
end
|
133
132
|
|
134
|
-
# Verify the signature using the caren public key
|
135
|
-
def
|
133
|
+
# Verify the signature using the caren public key
|
134
|
+
def verify_signature signature, timestamp, string=nil
|
136
135
|
signature = Base64.decode64(CGI.unescape(signature))
|
137
|
-
|
136
|
+
self.caren_public_key.verify( "sha1", signature, string.to_s + timestamp.to_s )
|
138
137
|
end
|
139
|
-
|
138
|
+
|
139
|
+
private
|
140
|
+
|
140
141
|
# Raise a Caren exception on errors
|
141
|
-
def
|
142
|
+
def handle_error response
|
142
143
|
errors = []
|
143
144
|
doc = REXML::Document.new(response)
|
144
145
|
doc.elements.each('errors/error') do |error|
|
@@ -11,13 +11,13 @@ class Caren::ExternalMessage < Caren::Base
|
|
11
11
|
:subject_id # Integer (Caren person id)
|
12
12
|
]
|
13
13
|
end
|
14
|
-
|
15
|
-
def create
|
16
|
-
|
14
|
+
|
15
|
+
def create session
|
16
|
+
session.post self.class.resource_url(self.subject_id), self.to_xml
|
17
17
|
end
|
18
18
|
|
19
|
-
def delete
|
20
|
-
|
19
|
+
def delete session
|
20
|
+
session.delete self.class.resource_url(self.subject_id,self.id)
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.array_root
|
@@ -47,7 +47,7 @@ class Caren::ExternalMessage < Caren::Base
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def self.resource_url subject_id, id=nil
|
50
|
-
"#{
|
50
|
+
"#{self.resource_location % subject_id}#{id}"
|
51
51
|
end
|
52
52
|
|
53
53
|
end
|
data/lib/caren/link.rb
CHANGED
@@ -11,18 +11,18 @@ class Caren::Link < Caren::Base
|
|
11
11
|
]
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.search key, value
|
15
|
-
from_xml
|
14
|
+
def self.search key, value, session
|
15
|
+
from_xml session.get( self.search_url(key,value) )
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.all
|
19
|
-
from_xml
|
18
|
+
def self.all session
|
19
|
+
from_xml session.get(self.resource_url)
|
20
20
|
end
|
21
21
|
|
22
22
|
# Request to create a new link. Example:
|
23
23
|
# Caren::Link.new( :patient_number => 1234 ).create
|
24
|
-
def create
|
25
|
-
|
24
|
+
def create session
|
25
|
+
session.post(self.resource_url, self.to_xml)
|
26
26
|
end
|
27
27
|
|
28
28
|
def as_xml
|
data/spec/care_provider_spec.rb
CHANGED
@@ -72,33 +72,35 @@ describe "CareProvider", "REST methods" do
|
|
72
72
|
before do
|
73
73
|
care_providers = File.read("spec/fixtures/caren_care_providers.xml")
|
74
74
|
care_providers_search = File.read("spec/fixtures/caren_care_providers_search.xml")
|
75
|
-
FakeWeb.register_uri(:put, Caren::CareProvider.resource_url(1), :signature => Caren::Api.sign )
|
76
75
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
76
|
+
care_provider_url = Caren::Api.session.url_for( Caren::CareProvider.resource_url(1) )
|
77
|
+
care_providers_url = Caren::Api.session.url_for( Caren::CareProvider.resource_url )
|
78
|
+
search_url = Caren::Api.session.url_for( "#{Caren::CareProvider.resource_url}?key=url-shortcut&value=pantein" )
|
79
|
+
|
80
|
+
timestamp = DateTime.now.to_i
|
81
|
+
|
82
|
+
FakeWeb.register_uri(:put, care_provider_url, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp) )
|
83
|
+
FakeWeb.register_uri(:get, care_providers_url, :body => care_providers, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,care_providers) )
|
84
|
+
FakeWeb.register_uri(:get, search_url, :body => care_providers_search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,care_providers_search) )
|
83
85
|
end
|
84
86
|
|
85
87
|
it "should be able to update a care provider" do
|
86
|
-
lambda{ Caren::CareProvider.new( :id => 1, :name => "Test" ).update }.should_not raise_error
|
88
|
+
lambda{ Caren::CareProvider.new( :id => 1, :name => "Test" ).update( Caren::Api.session ) }.should_not raise_error
|
87
89
|
end
|
88
90
|
|
89
91
|
it "should be able to update the logo for a care provider" do
|
90
|
-
lambda{ Caren::CareProvider.new( :id => 1 ).update_logo( "spec/fixtures/bacon.jpg" ) }.should_not raise_error
|
92
|
+
lambda{ Caren::CareProvider.new( :id => 1 ).update_logo( "spec/fixtures/bacon.jpg", Caren::Api.session ) }.should_not raise_error
|
91
93
|
end
|
92
94
|
|
93
95
|
it "should be able to search for a specific care provider" do
|
94
|
-
care_providers = Caren::CareProvider.search :url_shortcut, "pantein"
|
96
|
+
care_providers = Caren::CareProvider.search :url_shortcut, "pantein", Caren::Api.session
|
95
97
|
care_providers.should have(1).things
|
96
98
|
care_providers.first.name.should == "Pantein"
|
97
99
|
care_providers.first.url_shortcut.should == "pantein"
|
98
100
|
end
|
99
101
|
|
100
102
|
it "should be able to find all care providers" do
|
101
|
-
care_providers = Caren::CareProvider.all
|
103
|
+
care_providers = Caren::CareProvider.all Caren::Api.session
|
102
104
|
care_providers.should have(2).things
|
103
105
|
care_providers.first.name.should == "Demo"
|
104
106
|
care_providers.first.url_shortcut.should == "demo"
|
data/spec/caren_spec.rb
CHANGED
@@ -3,54 +3,54 @@ require 'spec_helper'
|
|
3
3
|
describe "Caren", "signature checks" do
|
4
4
|
|
5
5
|
before do
|
6
|
-
@incorrect_url = "
|
7
|
-
@correct_url = "
|
8
|
-
@error_url = "
|
6
|
+
@incorrect_url = "/test_with_incorrect_signature"
|
7
|
+
@correct_url = "/test_with_correct_signature"
|
8
|
+
@error_url = "/test_with_errors"
|
9
9
|
|
10
|
-
FakeWeb.register_uri(:get, @incorrect_url, :body => "TEST", :signature => "[INCORRECT]" )
|
11
|
-
FakeWeb.register_uri(:post, @incorrect_url, :body => "TEST", :signature => "[INCORRECT]" )
|
12
|
-
FakeWeb.register_uri(:put, @incorrect_url, :body => "TEST", :signature => "[INCORRECT]" )
|
13
|
-
FakeWeb.register_uri(:delete, @incorrect_url, :body => "TEST", :signature => "[INCORRECT]" )
|
10
|
+
FakeWeb.register_uri(:get, Caren::Api.session.url_for(@incorrect_url), :body => "TEST", :signature => "[INCORRECT]" )
|
11
|
+
FakeWeb.register_uri(:post, Caren::Api.session.url_for(@incorrect_url), :body => "TEST", :signature => "[INCORRECT]" )
|
12
|
+
FakeWeb.register_uri(:put, Caren::Api.session.url_for(@incorrect_url), :body => "TEST", :signature => "[INCORRECT]" )
|
13
|
+
FakeWeb.register_uri(:delete, Caren::Api.session.url_for(@incorrect_url), :body => "TEST", :signature => "[INCORRECT]" )
|
14
14
|
|
15
|
-
FakeWeb.register_uri(:get, @correct_url, :body => "TEST", :signature => Caren::Api.sign("TEST") )
|
16
|
-
FakeWeb.register_uri(:post, @correct_url, :body => "TEST", :signature => Caren::Api.sign("TEST") )
|
17
|
-
FakeWeb.register_uri(:put, @correct_url, :body => "TEST", :signature => Caren::Api.sign("TEST") )
|
18
|
-
FakeWeb.register_uri(:delete, @correct_url, :body => "TEST", :signature => Caren::Api.sign("TEST") )
|
15
|
+
FakeWeb.register_uri(:get, Caren::Api.session.url_for(@correct_url), :body => "TEST", :signature => Caren::Api.session.sign("TEST") )
|
16
|
+
FakeWeb.register_uri(:post, Caren::Api.session.url_for(@correct_url), :body => "TEST", :signature => Caren::Api.session.sign("TEST") )
|
17
|
+
FakeWeb.register_uri(:put, Caren::Api.session.url_for(@correct_url), :body => "TEST", :signature => Caren::Api.session.sign("TEST") )
|
18
|
+
FakeWeb.register_uri(:delete, Caren::Api.session.url_for(@correct_url), :body => "TEST", :signature => Caren::Api.session.sign("TEST") )
|
19
19
|
|
20
20
|
errors = File.read "spec/fixtures/caren_care_provider_validation.xml"
|
21
21
|
unauth = File.read "spec/fixtures/caren_unauthorized.xml"
|
22
|
-
FakeWeb.register_uri(:get, @error_url, :status => 406, :body => errors, :signature => Caren::Api.sign(errors) )
|
23
|
-
FakeWeb.register_uri(:post, @error_url, :status => 406, :body => errors, :signature => Caren::Api.sign(errors) )
|
24
|
-
FakeWeb.register_uri(:put, @error_url, :status => 406, :body => errors, :signature => Caren::Api.sign(errors) )
|
25
|
-
FakeWeb.register_uri(:delete, @error_url, :status => 403, :body => unauth, :signature => Caren::Api.sign(unauth) )
|
22
|
+
FakeWeb.register_uri(:get, Caren::Api.session.url_for(@error_url), :status => 406, :body => errors, :signature => Caren::Api.session.sign(errors) )
|
23
|
+
FakeWeb.register_uri(:post, Caren::Api.session.url_for(@error_url), :status => 406, :body => errors, :signature => Caren::Api.session.sign(errors) )
|
24
|
+
FakeWeb.register_uri(:put, Caren::Api.session.url_for(@error_url), :status => 406, :body => errors, :signature => Caren::Api.session.sign(errors) )
|
25
|
+
FakeWeb.register_uri(:delete, Caren::Api.session.url_for(@error_url), :status => 403, :body => unauth, :signature => Caren::Api.session.sign(unauth) )
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should not accept result swith an incorrect signature" do
|
29
|
-
lambda{ Caren::Api.get @incorrect_url }.should raise_error
|
30
|
-
lambda{ Caren::Api.post @incorrect_url, "" }.should raise_error
|
31
|
-
lambda{ Caren::Api.put @incorrect_url, "" }.should raise_error
|
32
|
-
lambda{ Caren::Api.delete @incorrect_url }.should raise_error
|
29
|
+
lambda{ Caren::Api.session.get @incorrect_url }.should raise_error
|
30
|
+
lambda{ Caren::Api.session.post @incorrect_url, "" }.should raise_error
|
31
|
+
lambda{ Caren::Api.session.put @incorrect_url, "" }.should raise_error
|
32
|
+
lambda{ Caren::Api.session.delete @incorrect_url }.should raise_error
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should accept results with a correct signature" do
|
36
|
-
lambda{ Caren::Api.get @correct_url }.should_not raise_error
|
37
|
-
lambda{ Caren::Api.post @correct_url, "" }.should_not raise_error
|
38
|
-
lambda{ Caren::Api.put @correct_url, "" }.should_not raise_error
|
39
|
-
lambda{ Caren::Api.delete @correct_url }.should_not raise_error
|
36
|
+
lambda{ Caren::Api.session.get @correct_url }.should_not raise_error
|
37
|
+
lambda{ Caren::Api.session.post @correct_url, "" }.should_not raise_error
|
38
|
+
lambda{ Caren::Api.session.put @correct_url, "" }.should_not raise_error
|
39
|
+
lambda{ Caren::Api.session.delete @correct_url }.should_not raise_error
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should be able to handle server side errors" do
|
43
43
|
|
44
|
-
lambda{ Caren::Api.get @error_url }.should raise_error(Caren::Exceptions::ServerSideError)
|
45
|
-
lambda{ Caren::Api.put @error_url, "" }.should raise_error(Caren::Exceptions::ServerSideError)
|
46
|
-
lambda{ Caren::Api.post @error_url, "" }.should raise_error(Caren::Exceptions::ServerSideError)
|
47
|
-
lambda{ Caren::Api.delete @error_url }.should raise_error(Caren::Exceptions::ServerSideError)
|
44
|
+
lambda{ Caren::Api.session.get @error_url }.should raise_error(Caren::Exceptions::ServerSideError)
|
45
|
+
lambda{ Caren::Api.session.put @error_url, "" }.should raise_error(Caren::Exceptions::ServerSideError)
|
46
|
+
lambda{ Caren::Api.session.post @error_url, "" }.should raise_error(Caren::Exceptions::ServerSideError)
|
47
|
+
lambda{ Caren::Api.session.delete @error_url }.should raise_error(Caren::Exceptions::ServerSideError)
|
48
48
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should be able to handle authorization errors" do
|
52
52
|
begin
|
53
|
-
Caren::Api.delete @error_url
|
53
|
+
Caren::Api.session.delete @error_url
|
54
54
|
rescue Caren::Exceptions::ServerSideError => e
|
55
55
|
e.errors.should have(1).things
|
56
56
|
e.errors.first.class.should == Caren::Error
|
@@ -61,7 +61,7 @@ describe "Caren", "signature checks" do
|
|
61
61
|
|
62
62
|
it "should be able to handle validation errors" do
|
63
63
|
begin
|
64
|
-
Caren::Api.get @error_url
|
64
|
+
Caren::Api.session.get @error_url
|
65
65
|
rescue Caren::Exceptions::ServerSideError => e
|
66
66
|
e.errors.should have(1).things
|
67
67
|
e.errors.first.class.should == Caren::ValidationError
|
@@ -73,7 +73,7 @@ describe "Caren", "signature checks" do
|
|
73
73
|
|
74
74
|
it "should be able to handle incoming xml from caren" do
|
75
75
|
incoming = File.read "spec/fixtures/incoming.xml"
|
76
|
-
results = Caren::Api.incoming(incoming, Caren::Api.sign(incoming))
|
76
|
+
results = Caren::Api.session.incoming(incoming, Caren::Api.session.sign(incoming))
|
77
77
|
results.should have(4).things
|
78
78
|
external_messages = results.select{ |x| x.is_a?(Caren::ExternalMessage) }
|
79
79
|
external_messages.first.id.should == 1
|
@@ -29,8 +29,12 @@ end
|
|
29
29
|
describe "ExternalMessage", "REST methods" do
|
30
30
|
|
31
31
|
before do
|
32
|
-
|
33
|
-
|
32
|
+
post_url = Caren::Api.session.url_for( Caren::ExternalMessage.resource_url(1) )
|
33
|
+
delete_url = Caren::Api.session.url_for( Caren::ExternalMessage.resource_url(1,1) )
|
34
|
+
timestamp = DateTime.now.to_i
|
35
|
+
|
36
|
+
FakeWeb.register_uri(:post, post_url, :status => 201, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
|
37
|
+
FakeWeb.register_uri(:delete, delete_url, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
|
34
38
|
end
|
35
39
|
|
36
40
|
it "should be able to create an external message" do
|
@@ -38,11 +42,11 @@ describe "ExternalMessage", "REST methods" do
|
|
38
42
|
:external_person_id => 1,
|
39
43
|
:body => "Test message",
|
40
44
|
:external_id => 1,
|
41
|
-
:subject_id => 1 ).create }.should_not raise_error
|
45
|
+
:subject_id => 1 ).create(Caren::Api.session) }.should_not raise_error
|
42
46
|
end
|
43
47
|
|
44
48
|
it "should be able to delete an external message" do
|
45
|
-
lambda{ Caren::ExternalMessage.new( :subject_id => 1, :id => 1 ).delete }.should_not raise_error
|
49
|
+
lambda{ Caren::ExternalMessage.new( :subject_id => 1, :id => 1 ).delete(Caren::Api.session) }.should_not raise_error
|
46
50
|
end
|
47
51
|
|
48
52
|
end
|
data/spec/link_spec.rb
CHANGED
@@ -22,17 +22,23 @@ describe "Link", "REST methods" do
|
|
22
22
|
before do
|
23
23
|
links = File.read("spec/fixtures/caren_links.xml")
|
24
24
|
search = File.read("spec/fixtures/caren_links_search.xml")
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
|
26
|
+
links_url = Caren::Api.session.url_for(Caren::Link.resource_url)
|
27
|
+
search_url = Caren::Api.session.url_for("#{Caren::Link.resource_url}?key=external-id&value=1")
|
28
|
+
|
29
|
+
timestamp = DateTime.now.to_i
|
30
|
+
|
31
|
+
FakeWeb.register_uri(:get, links_url, :body => links, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,links) )
|
32
|
+
FakeWeb.register_uri(:get, search_url, :body => search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,search) )
|
33
|
+
FakeWeb.register_uri(:post, links_url, :status => 201, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp) )
|
28
34
|
end
|
29
35
|
|
30
36
|
it "should be able to create a new link using the API" do
|
31
|
-
lambda{ Caren::Link.new( :patient_number => "12345" ).create }.should_not raise_error
|
37
|
+
lambda{ Caren::Link.new( :patient_number => "12345" ).create(Caren::Api.session) }.should_not raise_error
|
32
38
|
end
|
33
39
|
|
34
40
|
it "should be find all links using the API" do
|
35
|
-
links = Caren::Link.all
|
41
|
+
links = Caren::Link.all(Caren::Api.session)
|
36
42
|
links.should have(3).things
|
37
43
|
links.first.id.should == 1
|
38
44
|
links.first.status.should == "confirmed"
|
@@ -42,7 +48,7 @@ describe "Link", "REST methods" do
|
|
42
48
|
end
|
43
49
|
|
44
50
|
it "should be find a specific link using the API" do
|
45
|
-
links = Caren::Link.search(:external_id, 1)
|
51
|
+
links = Caren::Link.search(:external_id, 1, Caren::Api.session)
|
46
52
|
links.should have(1).thing
|
47
53
|
end
|
48
54
|
|
data/spec/spec_helper.rb
CHANGED
@@ -5,11 +5,9 @@ require 'fakeweb'
|
|
5
5
|
require 'capybara'
|
6
6
|
|
7
7
|
# For the tests we need to know both the public and private key, so we share them here.
|
8
|
-
|
9
|
-
|
10
|
-
Caren::Api.
|
11
|
-
Caren::Api.private_key = new_private_key
|
12
|
-
Caren::Api.url = "http://example.com"
|
8
|
+
# We also use a smaller key here, to make the tests faster.
|
9
|
+
new_private_key = Caren::Api.generate_private_key( 512 )
|
10
|
+
Caren::Api.session = Caren::Api.new( new_private_key, "http://example.com", new_private_key.public_key )
|
13
11
|
|
14
12
|
FakeWeb.allow_net_connect = false
|
15
13
|
|
metadata
CHANGED
@@ -4,10 +4,10 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
7
|
+
- 4
|
8
|
+
- 0
|
9
9
|
segments_generated: true
|
10
|
-
version: 0.
|
10
|
+
version: 0.4.0
|
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: 2011-10-
|
18
|
+
date: 2011-10-21 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|