caren-api 0.4.30 → 0.4.31
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 +1 -1
- data/lib/caren/billable_category.rb +9 -9
- data/lib/caren/care_provider.rb +14 -14
- data/lib/caren/caren.rb +48 -48
- data/lib/caren/client.rb +5 -5
- data/lib/caren/error.rb +8 -8
- data/lib/caren/event.rb +6 -6
- data/lib/caren/event_slot.rb +1 -1
- data/lib/caren/external_message.rb +16 -16
- data/lib/caren-api.rb +11 -11
- data/spec/billable_category_spec.rb +14 -14
- data/spec/billable_spec.rb +16 -16
- data/spec/care_provider_spec.rb +21 -21
- data/spec/caren_spec.rb +22 -22
- data/spec/client_spec.rb +22 -22
- data/spec/external_message_spec.rb +19 -19
- data/spec/link_spec.rb +14 -14
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.31
|
data/caren-api.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Caren::BillableCategory < Caren::Base
|
2
|
-
|
2
|
+
|
3
3
|
def self.keys
|
4
4
|
[ :id, # Integer (Id of this category in Caren)
|
5
5
|
:name, # String
|
@@ -8,29 +8,29 @@ class Caren::BillableCategory < Caren::Base
|
|
8
8
|
:billable_category_id # Integer (Parent category; Caren id; Nil for root node)
|
9
9
|
] + super
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def self.search key, value, session
|
13
13
|
from_xml session.get( self.search_url(key,value) )
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def self.find id, session
|
17
17
|
from_xml session.get(self.resource_url(id))
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def self.all session
|
21
21
|
from_xml session.get(self.resource_url)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def self.array_root
|
25
25
|
:billable_categories
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def self.node_root
|
29
29
|
:billable_category
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def self.resource_location
|
33
33
|
"/api/pro/store/billable_categories"
|
34
34
|
end
|
35
|
-
|
36
|
-
end
|
35
|
+
|
36
|
+
end
|
data/lib/caren/care_provider.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# * Get a list of care providers
|
4
4
|
# * Search for a specific care provider based on key/value
|
5
5
|
class Caren::CareProvider < Caren::Base
|
6
|
-
|
6
|
+
|
7
7
|
def self.keys
|
8
8
|
[ :id, # Integer (The id of this CP inside Caren)
|
9
9
|
:name, # String
|
@@ -28,30 +28,30 @@ class Caren::CareProvider < Caren::Base
|
|
28
28
|
:closed_beta, # Boolean
|
29
29
|
:locale, # String
|
30
30
|
:lat,
|
31
|
-
:lng
|
31
|
+
:lng
|
32
32
|
] + super
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def self.search key, value, session
|
36
36
|
from_xml session.get( self.search_url(key,value) )
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def self.find id, session
|
40
40
|
from_xml session.get(self.resource_url(id))
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def self.all session
|
44
44
|
from_xml session.get(self.resource_url)
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def update session
|
48
48
|
self.class.from_xml session.put(self.resource_url(self.id), self.to_xml)
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
def update_logo logo_hash_or_path, session
|
52
52
|
self.class.from_xml session.put(self.resource_url(self.id), self.to_logo_xml(logo_hash_or_path))
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def as_xml
|
56
56
|
{ :name => self.name,
|
57
57
|
:telephone => self.telephone,
|
@@ -76,7 +76,7 @@ class Caren::CareProvider < Caren::Base
|
|
76
76
|
:lng => self.lng
|
77
77
|
}
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
def to_logo_xml logo_hash_or_path
|
81
81
|
builder = Builder::XmlMarkup.new
|
82
82
|
logo = self.class.hash_from_image(logo_hash_or_path)
|
@@ -84,17 +84,17 @@ class Caren::CareProvider < Caren::Base
|
|
84
84
|
care_provider.tag!("logo", logo[:content], "name" => logo[:name], "content-type" => logo[:content_type] ) if logo
|
85
85
|
end
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def self.resource_location
|
89
89
|
"/api/pro/care_providers"
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
def self.array_root
|
93
93
|
:care_providers
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
def self.node_root
|
97
97
|
:care_provider
|
98
98
|
end
|
99
|
-
|
100
|
-
end
|
99
|
+
|
100
|
+
end
|
data/lib/caren/caren.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
module Caren
|
2
|
-
|
2
|
+
|
3
3
|
module Exceptions
|
4
|
-
|
4
|
+
|
5
5
|
class StandardError < ::StandardError ; end
|
6
|
-
|
6
|
+
|
7
7
|
class SignatureMismatch < Caren::Exceptions::StandardError ; end
|
8
|
-
|
8
|
+
|
9
9
|
class InvalidXmlResponse < Caren::Exceptions::StandardError ; end
|
10
|
-
|
10
|
+
|
11
11
|
class ServerSideError < Caren::Exceptions::StandardError
|
12
|
-
|
12
|
+
|
13
13
|
attr_accessor :errors
|
14
|
-
|
14
|
+
|
15
15
|
def initialize errors=[]
|
16
16
|
self.errors = errors
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
end
|
22
22
|
|
23
23
|
class Api
|
24
|
-
|
24
|
+
|
25
25
|
class << self
|
26
26
|
attr_accessor :session
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
# The user_agent is an optional identifier
|
30
30
|
attr_accessor :url, :caren_public_key, :private_key, :user_agent
|
31
|
-
|
31
|
+
|
32
32
|
# Initialize new API session. Specify your private key to sign outgoing messages and your care provider url.
|
33
33
|
# Optionally you can pass the caren public key used to verify incoming requests.
|
34
34
|
def initialize private_key, url, caren_public_key=nil
|
@@ -36,33 +36,33 @@ module Caren
|
|
36
36
|
self.private_key = private_key.is_a?(String) ? Caren::Api.key_from_string(private_key) : private_key
|
37
37
|
self.caren_public_key = caren_public_key || Caren::Api.key_from_path("#{File.dirname(__FILE__)}/../../certs/caren-api.pub")
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
# Create key from string
|
41
41
|
def self.key_from_string string
|
42
42
|
OpenSSL::PKey::RSA.new(string)
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
# Read a file and create key from string
|
46
46
|
def self.key_from_path path
|
47
47
|
self.key_from_string( File.read(path) )
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
# Generate a new private key
|
51
51
|
def self.generate_private_key size=2048
|
52
52
|
OpenSSL::PKey::RSA.generate( size )
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
# URL from path using session base url
|
56
56
|
def url_for path
|
57
57
|
"#{self.url}#{path}"
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def put path, xml
|
61
61
|
begin
|
62
62
|
timestamp = DateTime.now.to_i
|
63
|
-
response = RestClient.put url_for(path), xml, :content_type => :xml,
|
64
|
-
:accept => :xml,
|
65
|
-
:timestamp => timestamp,
|
63
|
+
response = RestClient.put url_for(path), xml, :content_type => :xml,
|
64
|
+
:accept => :xml,
|
65
|
+
:timestamp => timestamp,
|
66
66
|
:signature => sign(timestamp,path,xml),
|
67
67
|
:user_agent => user_agent
|
68
68
|
return check_signature(response)
|
@@ -70,13 +70,13 @@ module Caren
|
|
70
70
|
handle_error(e.response)
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
def post path, xml
|
75
75
|
begin
|
76
76
|
timestamp = DateTime.now.to_i
|
77
|
-
response = RestClient.post url_for(path), xml, :content_type => :xml,
|
78
|
-
:accept => :xml,
|
79
|
-
:timestamp => timestamp,
|
77
|
+
response = RestClient.post url_for(path), xml, :content_type => :xml,
|
78
|
+
:accept => :xml,
|
79
|
+
:timestamp => timestamp,
|
80
80
|
:signature => sign(timestamp,path,xml),
|
81
81
|
:user_agent => user_agent
|
82
82
|
return check_signature(response)
|
@@ -84,13 +84,13 @@ module Caren
|
|
84
84
|
handle_error(e.response)
|
85
85
|
end
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def delete path
|
89
89
|
begin
|
90
90
|
timestamp = DateTime.now.to_i
|
91
|
-
response = RestClient.delete url_for(path), :content_type => :xml,
|
92
|
-
:accept => :xml,
|
93
|
-
:timestamp => timestamp,
|
91
|
+
response = RestClient.delete url_for(path), :content_type => :xml,
|
92
|
+
:accept => :xml,
|
93
|
+
:timestamp => timestamp,
|
94
94
|
:signature => sign(timestamp,path),
|
95
95
|
:user_agent => user_agent
|
96
96
|
return check_signature(response)
|
@@ -98,13 +98,13 @@ module Caren
|
|
98
98
|
handle_error(e.response)
|
99
99
|
end
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
def get path
|
103
103
|
begin
|
104
104
|
timestamp = DateTime.now.to_i
|
105
|
-
response = RestClient.get url_for(path), :content_type => :xml,
|
106
|
-
:accept => :xml,
|
107
|
-
:timestamp => timestamp,
|
105
|
+
response = RestClient.get url_for(path), :content_type => :xml,
|
106
|
+
:accept => :xml,
|
107
|
+
:timestamp => timestamp,
|
108
108
|
:signature => sign(timestamp,path),
|
109
109
|
:user_agent => user_agent
|
110
110
|
return check_signature(response)
|
@@ -112,17 +112,17 @@ module Caren
|
|
112
112
|
handle_error(e.response)
|
113
113
|
end
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
# These types of Caren objects are supported by the Caren::Api.incoming method
|
117
117
|
def self.supported_incoming_objects
|
118
|
-
{ :links => Caren::Link,
|
119
|
-
:external_messages => Caren::ExternalMessage,
|
118
|
+
{ :links => Caren::Link,
|
119
|
+
:external_messages => Caren::ExternalMessage,
|
120
120
|
:care_providers => Caren::CareProvider,
|
121
121
|
:billable_categories => Caren::BillableCategory,
|
122
122
|
:billables => Caren::Billable
|
123
123
|
}
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
# These types of Caren objects are supported by the Caren::Api.incoming method
|
127
127
|
def self.supported_incoming_single_objects
|
128
128
|
singles = {}
|
@@ -131,7 +131,7 @@ module Caren
|
|
131
131
|
end
|
132
132
|
return singles
|
133
133
|
end
|
134
|
-
|
134
|
+
|
135
135
|
# Pass an XML string to be handled. Only a valid caren_objects xml hash will be parsed.
|
136
136
|
def incoming xml, signature, timestamp
|
137
137
|
if self.verify_signature(signature,timestamp, xml)
|
@@ -140,22 +140,22 @@ module Caren
|
|
140
140
|
raise Caren::Exceptions::SignatureMismatch.new
|
141
141
|
end
|
142
142
|
end
|
143
|
-
|
143
|
+
|
144
144
|
def parse xml
|
145
145
|
objects = []
|
146
146
|
hash = Hash.from_xml(xml)
|
147
147
|
if hash["caren_objects"]
|
148
148
|
hash = hash["caren_objects"]
|
149
|
-
end
|
149
|
+
end
|
150
150
|
Caren::Api.supported_incoming_objects.each do |key,klass|
|
151
151
|
objects << (hash[key]||hash[key.to_s]||[]).map{ |h| klass.new(h) }
|
152
152
|
end
|
153
153
|
return objects.flatten
|
154
154
|
end
|
155
|
-
|
155
|
+
|
156
156
|
def parse_object xml
|
157
157
|
hash = Hash.from_xml(xml)
|
158
|
-
#todo: rewrite so we lookup the xml tag in the supported_incoming_single_objects hash, faster :)
|
158
|
+
#todo: rewrite so we lookup the xml tag in the supported_incoming_single_objects hash, faster :)
|
159
159
|
Caren::Api.supported_incoming_single_objects.each do |key, klass|
|
160
160
|
object = hash[key] || hash[key.to_s]
|
161
161
|
if object
|
@@ -172,34 +172,34 @@ module Caren
|
|
172
172
|
signature = CGI.escape(Base64.encode64(encrypted_digest))
|
173
173
|
return signature
|
174
174
|
end
|
175
|
-
|
175
|
+
|
176
176
|
# Check the signature of the response from rest-client
|
177
177
|
def check_signature response
|
178
178
|
return response if self.verify_signature( response.headers[:signature], response.headers[:timestamp], nil, response )
|
179
179
|
raise Caren::Exceptions::SignatureMismatch.new
|
180
180
|
end
|
181
|
-
|
181
|
+
|
182
182
|
# Verify the signature using the caren public key
|
183
183
|
def verify_signature signature, timestamp, path, string=nil, public_key=self.caren_public_key
|
184
184
|
return false unless public_key
|
185
185
|
signature = Base64.decode64(CGI.unescape(signature.to_s))
|
186
186
|
public_key.verify( OpenSSL::Digest::SHA1.new, signature, path.to_s + string.to_s + timestamp.to_s )
|
187
187
|
end
|
188
|
-
|
188
|
+
|
189
189
|
def create_photo_signature url_shortcut, external_or_caren_id, private_key=self.private_key
|
190
190
|
digest = OpenSSL::PKey::RSA.new(private_key).sign( OpenSSL::Digest::SHA1.new, url_shortcut.to_s + external_or_caren_id.to_s )
|
191
191
|
return CGI.escape(Base64.encode64(digest))
|
192
192
|
end
|
193
|
-
|
193
|
+
|
194
194
|
# Verify photo url signature using the caren public key
|
195
195
|
def verify_photo_signature signature, url_shortcut, external_id, public_key=self.caren_public_key
|
196
196
|
return false unless public_key
|
197
197
|
signature = Base64.decode64(CGI.unescape(signature.to_s))
|
198
198
|
public_key.verify( OpenSSL::Digest::SHA1.new, signature, url_shortcut.to_s + external_id.to_s )
|
199
199
|
end
|
200
|
-
|
200
|
+
|
201
201
|
private
|
202
|
-
|
202
|
+
|
203
203
|
# Raise a Caren exception on errors
|
204
204
|
def handle_error response
|
205
205
|
errors = []
|
@@ -214,7 +214,7 @@ module Caren
|
|
214
214
|
end
|
215
215
|
raise Caren::Exceptions::ServerSideError.new(errors)
|
216
216
|
end
|
217
|
-
|
217
|
+
|
218
218
|
end
|
219
219
|
|
220
220
|
end
|
data/lib/caren/client.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Caren::Client < Caren::Base
|
2
|
-
|
2
|
+
|
3
3
|
def self.keys
|
4
4
|
[ :external_id, # String (Your client id)
|
5
5
|
:uid, # String (Customer unique code)
|
@@ -13,13 +13,13 @@ class Caren::Client < Caren::Base
|
|
13
13
|
:address_country # String
|
14
14
|
] + super
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def self.array_root
|
18
18
|
:clients
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def self.node_root
|
22
22
|
:client
|
23
23
|
end
|
24
|
-
|
25
|
-
end
|
24
|
+
|
25
|
+
end
|
data/lib/caren/error.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# This class provides a wrapper for caren's server side errors.
|
2
|
-
class Caren::Error
|
3
|
-
|
2
|
+
class Caren::Error
|
3
|
+
|
4
4
|
attr_accessor :category, :message, :attributes
|
5
|
-
|
5
|
+
|
6
6
|
def initialize category, message="", attributes={}
|
7
7
|
self.category = category
|
8
8
|
self.message = message
|
9
9
|
self.attributes = attributes
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
end
|
13
13
|
|
14
14
|
class Caren::ValidationError < Caren::Error
|
15
|
-
|
15
|
+
|
16
16
|
def field
|
17
17
|
attributes[:on]
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def to_s
|
21
21
|
"`#{field}` #{message}"
|
22
22
|
end
|
23
|
-
|
24
|
-
end
|
23
|
+
|
24
|
+
end
|
data/lib/caren/event.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# This class is just an intermediate for exporting events to Caren.
|
2
|
-
# It has the correct format for exports.
|
1
|
+
# This class is just an intermediate for exporting events to Caren.
|
2
|
+
# It has the correct format for exports.
|
3
3
|
class Caren::Event < Caren::Base
|
4
|
-
|
4
|
+
|
5
5
|
def self.keys
|
6
6
|
[ :external_id, # String Unique identifying string (Your event id)
|
7
7
|
:name, # String
|
@@ -17,7 +17,7 @@ class Caren::Event < Caren::Base
|
|
17
17
|
:source # String (remote_schedule,remote_realisation)
|
18
18
|
] + super
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def self.array_root
|
22
22
|
:events
|
23
23
|
end
|
@@ -25,5 +25,5 @@ class Caren::Event < Caren::Base
|
|
25
25
|
def self.node_root
|
26
26
|
:event
|
27
27
|
end
|
28
|
-
|
29
|
-
end
|
28
|
+
|
29
|
+
end
|
data/lib/caren/event_slot.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
class Caren::ExternalMessage < Caren::Base
|
2
|
-
|
2
|
+
|
3
3
|
def self.keys
|
4
|
-
[ :id, # Integer (Caren message id)
|
4
|
+
[ :id, # Integer (Caren message id)
|
5
5
|
:person_name, # String (Andre Foeken)
|
6
|
-
:person_id, # Integer (Caren person id)
|
7
|
-
:external_person_id, # String (Your person id)
|
6
|
+
:person_id, # Integer (Caren person id)
|
7
|
+
:external_person_id, # String (Your person id)
|
8
8
|
:care_provider_id, # Integer (Caren CP id)
|
9
9
|
:body, # Text
|
10
10
|
:external_id, # String (Your message id)
|
@@ -13,31 +13,31 @@ class Caren::ExternalMessage < Caren::Base
|
|
13
13
|
:subject_id # Integer (Caren person id)
|
14
14
|
] + super
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def self.all subject_id, session
|
18
18
|
from_xml session.get(self.resource_url(subject_id))
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def self.find subject_id, id, session
|
22
22
|
from_xml session.get(self.resource_url(subject_id,id))
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def create session
|
26
26
|
self.class.from_xml session.post self.class.resource_url(self.subject_id), self.to_xml
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def delete session
|
30
30
|
session.delete self.class.resource_url(self.subject_id,self.id)
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def self.array_root
|
34
34
|
:external_messages
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def self.node_root
|
38
38
|
:external_message
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def as_xml
|
42
42
|
{ :person_name => self.person_name,
|
43
43
|
:external_person_id => self.external_person_id,
|
@@ -45,19 +45,19 @@ class Caren::ExternalMessage < Caren::Base
|
|
45
45
|
:external_id => self.external_id,
|
46
46
|
:in_reply_to_id => self.in_reply_to_id }
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def self.resource_location
|
50
50
|
"/api/pro/people/%i/external_messages"
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
private
|
54
54
|
|
55
55
|
def resource_url subject_id, id=nil
|
56
56
|
self.class.resource_url(subject_id,id)
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def self.resource_url subject_id, id=nil
|
60
60
|
"#{self.resource_location % subject_id}#{id}"
|
61
61
|
end
|
62
|
-
|
63
|
-
end
|
62
|
+
|
63
|
+
end
|
data/lib/caren-api.rb
CHANGED
@@ -6,14 +6,14 @@ require "rest_client"
|
|
6
6
|
require "rexml/document"
|
7
7
|
require "base64"
|
8
8
|
|
9
|
-
require "caren/caren
|
10
|
-
require "caren/error
|
11
|
-
require "caren/base
|
12
|
-
require "caren/event
|
13
|
-
require "caren/event_slot
|
14
|
-
require "caren/client
|
15
|
-
require "caren/care_provider
|
16
|
-
require "caren/external_message
|
17
|
-
require "caren/link
|
18
|
-
require "caren/billable
|
19
|
-
require "caren/billable_category
|
9
|
+
require "caren/caren"
|
10
|
+
require "caren/error"
|
11
|
+
require "caren/base"
|
12
|
+
require "caren/event"
|
13
|
+
require "caren/event_slot"
|
14
|
+
require "caren/client"
|
15
|
+
require "caren/care_provider"
|
16
|
+
require "caren/external_message"
|
17
|
+
require "caren/link"
|
18
|
+
require "caren/billable"
|
19
|
+
require "caren/billable_category"
|
@@ -1,40 +1,40 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "BillableCategory", "converting to xml" do
|
4
|
-
|
4
|
+
|
5
5
|
before do
|
6
6
|
@billable_category_a = Caren::BillableCategory.new( :name => "Services" )
|
7
7
|
@billable_category_b = Caren::BillableCategory.new( :name => "Products" )
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "should be able to convert a product to valid xml" do
|
11
11
|
@billable_category_a.should convert_to_valid_caren_xml
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it "should be able to convert an array of products to valid xml" do
|
15
15
|
[@billable_category_a,@billable_category_b].should convert_to_valid_caren_array_xml
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "BillableCategory", "REST methods" do
|
21
|
-
|
21
|
+
|
22
22
|
before do
|
23
23
|
billable_category = File.read("spec/fixtures/caren_billable_category.xml")
|
24
24
|
billable_categories = File.read("spec/fixtures/caren_billable_categories.xml")
|
25
25
|
billable_categories_search = File.read("spec/fixtures/caren_billable_categories_search.xml")
|
26
|
-
|
26
|
+
|
27
27
|
billable_category_url = Caren::Api.session.url_for( Caren::BillableCategory.resource_url(1) )
|
28
28
|
billable_categories_url = Caren::Api.session.url_for( Caren::BillableCategory.resource_url )
|
29
29
|
search_url = Caren::Api.session.url_for( "#{Caren::BillableCategory.resource_url}?key=name&value=billables" )
|
30
|
-
|
30
|
+
|
31
31
|
timestamp = DateTime.now.to_i
|
32
|
-
|
33
|
-
FakeWeb.register_uri(:get, billable_categories_url, :body => billable_categories, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billable_categories) )
|
34
|
-
FakeWeb.register_uri(:get, billable_category_url, :body => billable_category, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billable_category) )
|
32
|
+
|
33
|
+
FakeWeb.register_uri(:get, billable_categories_url, :body => billable_categories, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billable_categories) )
|
34
|
+
FakeWeb.register_uri(:get, billable_category_url, :body => billable_category, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billable_category) )
|
35
35
|
FakeWeb.register_uri(:get, search_url, :body => billable_categories_search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billable_categories_search) )
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
it "should be able to search for a specific billable category" do
|
39
39
|
billable_categories = Caren::BillableCategory.search :name, "billables", Caren::Api.session
|
40
40
|
billable_categories.should have(1).things
|
@@ -45,11 +45,11 @@ describe "BillableCategory", "REST methods" do
|
|
45
45
|
billable_category = Caren::BillableCategory.find 1, Caren::Api.session
|
46
46
|
billable_category.name.should == "Billables"
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
it "should be able to find all billable category" do
|
50
50
|
billable_categories = Caren::BillableCategory.all Caren::Api.session
|
51
51
|
billable_categories.should have(2).things
|
52
52
|
billable_categories.first.name.should == "Products"
|
53
53
|
end
|
54
|
-
|
55
|
-
end
|
54
|
+
|
55
|
+
end
|
data/spec/billable_spec.rb
CHANGED
@@ -1,46 +1,46 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Billable", "converting to xml" do
|
4
|
-
|
4
|
+
|
5
5
|
before do
|
6
6
|
@billable_a = Caren::Billable.new( :name => "Washing", :price => 100.euros, :in_store => true, :type => "Product" )
|
7
7
|
@billable_b = Caren::Billable.new( :name => "Bedpan", :price => 100.euros, :in_store => false, :type => "Product" )
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "should be able to convert a billable to valid xml" do
|
11
11
|
@billable_a.should convert_to_valid_caren_xml
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it "should be able to convert an array of billables to valid xml" do
|
15
15
|
[@billable_a,@billable_b].should convert_to_valid_caren_array_xml
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "Billable", "REST methods" do
|
21
|
-
|
21
|
+
|
22
22
|
before do
|
23
23
|
billable = File.read("spec/fixtures/caren_billable.xml")
|
24
24
|
billables = File.read("spec/fixtures/caren_billables.xml")
|
25
25
|
billable_search = File.read("spec/fixtures/caren_billables_search.xml")
|
26
|
-
|
27
|
-
billable_url = Caren::Api.session.url_for( Caren::Billable.resource_url(1) )
|
26
|
+
|
27
|
+
billable_url = Caren::Api.session.url_for( Caren::Billable.resource_url(1) )
|
28
28
|
billables_url = Caren::Api.session.url_for( Caren::Billable.resource_url )
|
29
29
|
search_url = Caren::Api.session.url_for( "#{Caren::Billable.resource_url}?key=name&value=bedpan" )
|
30
|
-
|
30
|
+
|
31
31
|
timestamp = DateTime.now.to_i
|
32
32
|
|
33
33
|
FakeWeb.register_uri(:post, billables_url, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp) )
|
34
34
|
FakeWeb.register_uri(:put, billable_url, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp) )
|
35
|
-
FakeWeb.register_uri(:get, billables_url, :body => billables, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billables) )
|
36
|
-
FakeWeb.register_uri(:get, billable_url, :body => billable, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billable) )
|
35
|
+
FakeWeb.register_uri(:get, billables_url, :body => billables, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billables) )
|
36
|
+
FakeWeb.register_uri(:get, billable_url, :body => billable, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billable) )
|
37
37
|
FakeWeb.register_uri(:get, search_url, :body => billable_search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billable_search) )
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
it "should be able to update a billable" do
|
41
41
|
lambda{ Caren::Billable.new( :id => 1, :name => "Bedpan" ).update( Caren::Api.session ) }.should_not raise_error
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
it "should be able to update the photo for a product" do
|
45
45
|
lambda{ Caren::Billable.new( :id => 1 ).update_photo( "spec/fixtures/bacon.jpg", Caren::Api.session ) }.should_not raise_error
|
46
46
|
end
|
@@ -49,17 +49,17 @@ describe "Billable", "REST methods" do
|
|
49
49
|
billable = Caren::Billable.find 1, Caren::Api.session
|
50
50
|
billable.name.should == "Dishwashing"
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
it "should be able to search for a specific product" do
|
54
54
|
billables = Caren::Billable.search :name, "bedpan", Caren::Api.session
|
55
55
|
billables.should have(1).things
|
56
56
|
billables.first.name.should == "bedpan"
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
it "should be able to find all billables" do
|
60
60
|
billables = Caren::Billable.all Caren::Api.session
|
61
61
|
billables.should have(2).things
|
62
62
|
billables.first.name.should == "Dishwashing"
|
63
63
|
end
|
64
|
-
|
65
|
-
end
|
64
|
+
|
65
|
+
end
|
data/spec/care_provider_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "CareProvider", "converting to xml" do
|
4
|
-
|
4
|
+
|
5
5
|
before do
|
6
6
|
@care_provider_a = Caren::CareProvider.new( :name => "Zuwe",
|
7
7
|
:telephone => "112",
|
@@ -17,7 +17,7 @@ describe "CareProvider", "converting to xml" do
|
|
17
17
|
:show_employee_name_as_title => true,
|
18
18
|
:show_employee_names => true,
|
19
19
|
:communication => true )
|
20
|
-
|
20
|
+
|
21
21
|
@care_provider_b = Caren::CareProvider.new( :name => "Aveant",
|
22
22
|
:telephone => "112",
|
23
23
|
:website => "http://www.aveant.nl",
|
@@ -31,17 +31,17 @@ describe "CareProvider", "converting to xml" do
|
|
31
31
|
:max_start => "00:00",
|
32
32
|
:show_employee_name_as_title => true,
|
33
33
|
:show_employee_names => true,
|
34
|
-
:communication => true )
|
34
|
+
:communication => true )
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
it "should be able to convert a person to valid xml" do
|
38
38
|
@care_provider_a.should convert_to_valid_caren_xml
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it "should be able to convert an array of people to valid xml" do
|
42
42
|
[@care_provider_a,@care_provider_b].should convert_to_valid_caren_array_xml
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
it "should be able to generate a proper xml file to update the logo" do
|
46
46
|
filename = "spec/fixtures/bacon.jpg"
|
47
47
|
xml = @care_provider_a.to_logo_xml filename
|
@@ -52,11 +52,11 @@ describe "CareProvider", "converting to xml" do
|
|
52
52
|
cp.text.should == Base64.encode64(File.open(filename).read)
|
53
53
|
end
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
end
|
57
57
|
|
58
58
|
describe "CareProvider" do
|
59
|
-
|
59
|
+
|
60
60
|
it "should be able to convert a image file path to a hash suited for xml conversion" do
|
61
61
|
filename = "spec/fixtures/bacon.jpg"
|
62
62
|
logo = Caren::CareProvider.hash_from_image( filename )
|
@@ -64,53 +64,53 @@ describe "CareProvider" do
|
|
64
64
|
logo[:name].should == "bacon.jpg"
|
65
65
|
logo[:content].should == Base64.encode64(File.open(filename).read)
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
end
|
69
69
|
|
70
70
|
describe "CareProvider", "REST methods" do
|
71
|
-
|
71
|
+
|
72
72
|
before do
|
73
73
|
care_provider = File.read("spec/fixtures/caren_care_provider.xml")
|
74
74
|
care_providers = File.read("spec/fixtures/caren_care_providers.xml")
|
75
75
|
care_providers_search = File.read("spec/fixtures/caren_care_providers_search.xml")
|
76
76
|
|
77
|
-
care_provider_url = Caren::Api.session.url_for( Caren::CareProvider.resource_url(1) )
|
77
|
+
care_provider_url = Caren::Api.session.url_for( Caren::CareProvider.resource_url(1) )
|
78
78
|
care_providers_url = Caren::Api.session.url_for( Caren::CareProvider.resource_url )
|
79
79
|
search_url = Caren::Api.session.url_for( "#{Caren::CareProvider.resource_url}?key=url-shortcut&value=pantein" )
|
80
|
-
|
80
|
+
|
81
81
|
timestamp = DateTime.now.to_i
|
82
|
-
|
83
|
-
FakeWeb.register_uri(:put, care_provider_url, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp) )
|
82
|
+
|
83
|
+
FakeWeb.register_uri(:put, care_provider_url, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp) )
|
84
84
|
FakeWeb.register_uri(:get, care_provider_url, :body => care_provider, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,care_provider) )
|
85
85
|
FakeWeb.register_uri(:get, care_providers_url, :body => care_providers, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,care_providers) )
|
86
86
|
FakeWeb.register_uri(:get, search_url, :body => care_providers_search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,care_providers_search) )
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
it "should be able to update a care provider" do
|
90
90
|
lambda{ Caren::CareProvider.new( :id => 1, :name => "Test" ).update( Caren::Api.session ) }.should_not raise_error
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
it "should be able to update the logo for a care provider" do
|
94
94
|
lambda{ Caren::CareProvider.new( :id => 1 ).update_logo( "spec/fixtures/bacon.jpg", Caren::Api.session ) }.should_not raise_error
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
it "should be able to search for a specific care provider" do
|
98
98
|
care_providers = Caren::CareProvider.search :url_shortcut, "pantein", Caren::Api.session
|
99
99
|
care_providers.should have(1).things
|
100
100
|
care_providers.first.name.should == "Pantein"
|
101
101
|
care_providers.first.url_shortcut.should == "pantein"
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
it "should be able to find all care providers" do
|
105
105
|
care_providers = Caren::CareProvider.all Caren::Api.session
|
106
106
|
care_providers.should have(2).things
|
107
107
|
care_providers.first.name.should == "Demo"
|
108
108
|
care_providers.first.url_shortcut.should == "demo"
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
it "should be able to find one care providers" do
|
112
112
|
care_provider = Caren::CareProvider.find 1, Caren::Api.session
|
113
113
|
care_provider.name.should == "Demo"
|
114
114
|
end
|
115
|
-
|
116
|
-
end
|
115
|
+
|
116
|
+
end
|
data/spec/caren_spec.rb
CHANGED
@@ -1,53 +1,53 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Caren", "signature checks" do
|
4
|
-
|
4
|
+
|
5
5
|
before do
|
6
6
|
@incorrect_url = "/test_with_incorrect_signature"
|
7
7
|
@correct_url = "/test_with_correct_signature"
|
8
8
|
@error_url = "/test_with_errors"
|
9
|
-
|
9
|
+
|
10
10
|
FakeWeb.register_uri(:get, Caren::Api.session.url_for(@incorrect_url), :body => "TEST", :signature => "[INCORRECT]" )
|
11
11
|
FakeWeb.register_uri(:post, Caren::Api.session.url_for(@incorrect_url), :body => "TEST", :signature => "[INCORRECT]" )
|
12
12
|
FakeWeb.register_uri(:put, Caren::Api.session.url_for(@incorrect_url), :body => "TEST", :signature => "[INCORRECT]" )
|
13
13
|
FakeWeb.register_uri(:delete, Caren::Api.session.url_for(@incorrect_url), :body => "TEST", :signature => "[INCORRECT]" )
|
14
|
-
|
14
|
+
|
15
15
|
FakeWeb.register_uri(:get, Caren::Api.session.url_for(@correct_url), :body => "TEST", :signature => Caren::Api.session.sign("TEST") )
|
16
16
|
FakeWeb.register_uri(:post, Caren::Api.session.url_for(@correct_url), :body => "TEST", :signature => Caren::Api.session.sign("TEST") )
|
17
17
|
FakeWeb.register_uri(:put, Caren::Api.session.url_for(@correct_url), :body => "TEST", :signature => Caren::Api.session.sign("TEST") )
|
18
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
|
-
unauth = File.read "spec/fixtures/caren_unauthorized.xml"
|
21
|
+
unauth = File.read "spec/fixtures/caren_unauthorized.xml"
|
22
22
|
FakeWeb.register_uri(:get, Caren::Api.session.url_for(@error_url), :status => 406, :body => errors, :signature => Caren::Api.session.sign(errors) )
|
23
23
|
FakeWeb.register_uri(:post, Caren::Api.session.url_for(@error_url), :status => 406, :body => errors, :signature => Caren::Api.session.sign(errors) )
|
24
24
|
FakeWeb.register_uri(:put, Caren::Api.session.url_for(@error_url), :status => 406, :body => errors, :signature => Caren::Api.session.sign(errors) )
|
25
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
29
|
lambda{ Caren::Api.session.get @incorrect_url }.should raise_error
|
30
30
|
lambda{ Caren::Api.session.post @incorrect_url, "" }.should raise_error
|
31
31
|
lambda{ Caren::Api.session.put @incorrect_url, "" }.should raise_error
|
32
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
36
|
lambda{ Caren::Api.session.get @correct_url }.should_not raise_error
|
37
37
|
lambda{ Caren::Api.session.post @correct_url, "" }.should_not raise_error
|
38
38
|
lambda{ Caren::Api.session.put @correct_url, "" }.should_not raise_error
|
39
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
44
|
lambda{ Caren::Api.session.get @error_url }.should raise_error(Caren::Exceptions::ServerSideError)
|
45
45
|
lambda{ Caren::Api.session.put @error_url, "" }.should raise_error(Caren::Exceptions::ServerSideError)
|
46
46
|
lambda{ Caren::Api.session.post @error_url, "" }.should raise_error(Caren::Exceptions::ServerSideError)
|
47
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
53
|
Caren::Api.session.delete @error_url
|
@@ -56,9 +56,9 @@ describe "Caren", "signature checks" do
|
|
56
56
|
e.errors.first.class.should == Caren::Error
|
57
57
|
e.errors.first.category.should == "unauthorized"
|
58
58
|
e.errors.first.message.should == "You are not allowed to perform this action."
|
59
|
-
end
|
59
|
+
end
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
it "should be able to handle validation errors" do
|
63
63
|
begin
|
64
64
|
Caren::Api.session.get @error_url
|
@@ -68,25 +68,25 @@ describe "Caren", "signature checks" do
|
|
68
68
|
e.errors.first.message.should == "has already been taken"
|
69
69
|
e.errors.first.field.should == :url_shortcut
|
70
70
|
e.errors.first.to_s.should == "`url_shortcut` has already been taken"
|
71
|
-
end
|
71
|
+
end
|
72
72
|
end
|
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
76
|
timestamp = DateTime.now.to_i
|
77
77
|
results = Caren::Api.session.incoming(incoming, Caren::Api.session.sign(timestamp, nil, incoming), timestamp )
|
78
|
-
results.should have(4).things
|
78
|
+
results.should have(4).things
|
79
79
|
external_messages = results.select{ |x| x.is_a?(Caren::ExternalMessage) }
|
80
|
-
external_messages.first.id.should == 1
|
80
|
+
external_messages.first.id.should == 1
|
81
81
|
links = results.select{ |x| x.is_a?(Caren::Link) }
|
82
82
|
links.last.id.should == 3
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
it "should be able to parse just one incoming object from xml from caren" do
|
86
86
|
incoming = File.read "spec/fixtures/incoming_single_object.xml"
|
87
|
-
object = Caren::Api.session.parse_object(incoming)
|
88
|
-
object.body.should == 'Expecting this to work somehow ...'
|
87
|
+
object = Caren::Api.session.parse_object(incoming)
|
88
|
+
object.body.should == 'Expecting this to work somehow ...'
|
89
89
|
object.id.should == 1
|
90
90
|
end
|
91
|
-
|
92
|
-
end
|
91
|
+
|
92
|
+
end
|
data/spec/client_spec.rb
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Client", "converting to xml" do
|
4
|
-
|
4
|
+
|
5
5
|
before do
|
6
|
-
@client_a = Caren::Client.new( :external_id => 1,
|
7
|
-
:uid => "ABC123",
|
8
|
-
:first_name => "Andre",
|
9
|
-
:last_name => "Foeken",
|
10
|
-
:male => true,
|
6
|
+
@client_a = Caren::Client.new( :external_id => 1,
|
7
|
+
:uid => "ABC123",
|
8
|
+
:first_name => "Andre",
|
9
|
+
:last_name => "Foeken",
|
10
|
+
:male => true,
|
11
11
|
:date_of_birth => 80.years.ago.to_date,
|
12
|
-
:address_street => "Sesamestreet 1",
|
13
|
-
:address_zipcode => "7500AA",
|
14
|
-
:address_city => "Groenlo",
|
12
|
+
:address_street => "Sesamestreet 1",
|
13
|
+
:address_zipcode => "7500AA",
|
14
|
+
:address_city => "Groenlo",
|
15
15
|
:address_country => "The Netherlands" )
|
16
|
-
|
17
|
-
@client_b = Caren::Client.new( :external_id => 2,
|
18
|
-
:uid => "ABC456",
|
19
|
-
:first_name => "Oscar",
|
20
|
-
:last_name => "Foeken",
|
21
|
-
:male => true,
|
16
|
+
|
17
|
+
@client_b = Caren::Client.new( :external_id => 2,
|
18
|
+
:uid => "ABC456",
|
19
|
+
:first_name => "Oscar",
|
20
|
+
:last_name => "Foeken",
|
21
|
+
:male => true,
|
22
22
|
:date_of_birth => 80.years.ago.to_date,
|
23
|
-
:address_street => "Sesamestreet 1",
|
24
|
-
:address_zipcode => "7500AA",
|
25
|
-
:address_city => "Groenlo",
|
23
|
+
:address_street => "Sesamestreet 1",
|
24
|
+
:address_zipcode => "7500AA",
|
25
|
+
:address_city => "Groenlo",
|
26
26
|
:address_country => "The Netherlands" )
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it "should be able to convert a client to valid xml" do
|
30
30
|
@client_a.should convert_to_valid_caren_xml
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
it "should be able to convert an array of people to valid xml" do
|
34
34
|
[@client_a,@client_b].should convert_to_valid_caren_array_xml
|
35
35
|
end
|
36
|
-
|
37
|
-
end
|
36
|
+
|
37
|
+
end
|
@@ -1,68 +1,68 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "ExternalMessage", "converting to xml" do
|
4
|
-
|
4
|
+
|
5
5
|
before do
|
6
6
|
@external_message_a = Caren::ExternalMessage.new( :person_name => "Andre Foeken",
|
7
7
|
:external_person_id => 1,
|
8
8
|
:body => "Test message",
|
9
9
|
:external_id => 1,
|
10
10
|
:in_reply_to_id => nil )
|
11
|
-
|
11
|
+
|
12
12
|
@external_message_b = Caren::ExternalMessage.new( :person_name => "Ria Foeken",
|
13
13
|
:external_person_id => 2,
|
14
14
|
:body => "Test message reply",
|
15
15
|
:external_id => 2,
|
16
16
|
:in_reply_to_id => 99 )
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
it "should be able to convert a link to valid xml" do
|
20
20
|
@external_message_a.should convert_to_valid_caren_xml
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
it "should be able to convert an array of links to valid xml" do
|
24
24
|
[@external_message_a,@external_message_b].should convert_to_valid_caren_array_xml
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "ExternalMessage", "REST methods" do
|
30
|
-
|
30
|
+
|
31
31
|
before do
|
32
32
|
message = File.read("spec/fixtures/caren_external_message.xml")
|
33
33
|
messages = File.read("spec/fixtures/caren_external_messages.xml")
|
34
|
-
|
34
|
+
|
35
35
|
messages_url = Caren::Api.session.url_for( Caren::ExternalMessage.resource_url(1) )
|
36
|
-
message_url = Caren::Api.session.url_for( Caren::ExternalMessage.resource_url(1,1) )
|
36
|
+
message_url = Caren::Api.session.url_for( Caren::ExternalMessage.resource_url(1,1) )
|
37
37
|
timestamp = DateTime.now.to_i
|
38
|
-
|
38
|
+
|
39
39
|
FakeWeb.register_uri(:get, messages_url, :body => messages, :signature => Caren::Api.session.sign(timestamp,nil,messages), :timestamp => timestamp )
|
40
40
|
FakeWeb.register_uri(:get, message_url, :body => message, :signature => Caren::Api.session.sign(timestamp,nil,message), :timestamp => timestamp )
|
41
41
|
FakeWeb.register_uri(:post, messages_url, :status => 201, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
|
42
42
|
FakeWeb.register_uri(:delete, message_url, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
it "should be able to find all external messages" do
|
46
46
|
messages = Caren::ExternalMessage.all 1, Caren::Api.session
|
47
47
|
messages.should have(2).things
|
48
48
|
messages.first.body.should == "Test"
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
it "should be able to find one external messages" do
|
52
52
|
message = Caren::ExternalMessage.find 1, 1, Caren::Api.session
|
53
53
|
message.body.should == "Test"
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
it "should be able to create an external message" do
|
57
|
-
lambda{ Caren::ExternalMessage.new( :person_name => "Andre Foeken",
|
58
|
-
:external_person_id => 1,
|
59
|
-
:body => "Test message",
|
60
|
-
:external_id => 1,
|
57
|
+
lambda{ Caren::ExternalMessage.new( :person_name => "Andre Foeken",
|
58
|
+
:external_person_id => 1,
|
59
|
+
:body => "Test message",
|
60
|
+
:external_id => 1,
|
61
61
|
:subject_id => 1 ).create(Caren::Api.session) }.should_not raise_error
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
it "should be able to delete an external message" do
|
65
65
|
lambda{ Caren::ExternalMessage.new( :subject_id => 1, :id => 1 ).delete(Caren::Api.session) }.should_not raise_error
|
66
66
|
end
|
67
|
-
|
68
|
-
end
|
67
|
+
|
68
|
+
end
|
data/spec/link_spec.rb
CHANGED
@@ -1,45 +1,45 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Link", "converting to xml" do
|
4
|
-
|
4
|
+
|
5
5
|
before do
|
6
6
|
@link_a = Caren::Link.new( :patient_number => "12345" )
|
7
7
|
@link_b = Caren::Link.new( :patient_number => "67890" )
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "should be able to convert a link to valid xml" do
|
11
11
|
@link_a.should convert_to_valid_caren_xml
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it "should be able to convert an array of links to valid xml" do
|
15
15
|
[@link_a,@link_b].should convert_to_valid_caren_array_xml
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "Link", "REST methods" do
|
21
|
-
|
21
|
+
|
22
22
|
before do
|
23
23
|
link = File.read("spec/fixtures/caren_link.xml")
|
24
24
|
links = File.read("spec/fixtures/caren_links.xml")
|
25
25
|
search = File.read("spec/fixtures/caren_links_search.xml")
|
26
|
-
|
26
|
+
|
27
27
|
link_url = Caren::Api.session.url_for(Caren::Link.resource_url(1))
|
28
28
|
links_url = Caren::Api.session.url_for(Caren::Link.resource_url)
|
29
29
|
search_url = Caren::Api.session.url_for("#{Caren::Link.resource_url}?key=external-id&value=1")
|
30
|
-
|
30
|
+
|
31
31
|
timestamp = DateTime.now.to_i
|
32
|
-
|
32
|
+
|
33
33
|
FakeWeb.register_uri(:get, link_url, :body => link, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,link) )
|
34
34
|
FakeWeb.register_uri(:get, links_url, :body => links, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,links) )
|
35
35
|
FakeWeb.register_uri(:get, search_url, :body => search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,search) )
|
36
36
|
FakeWeb.register_uri(:post, links_url, :status => 201, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp) )
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it "should be able to create a new link using the API" do
|
40
40
|
lambda{ Caren::Link.new( :patient_number => "12345" ).create(Caren::Api.session) }.should_not raise_error
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
it "should be find all links using the API" do
|
44
44
|
links = Caren::Link.all(Caren::Api.session)
|
45
45
|
links.should have(3).things
|
@@ -49,15 +49,15 @@ describe "Link", "REST methods" do
|
|
49
49
|
links.first.person_name.should == "Andre Foeken"
|
50
50
|
links.first.person_id.should == 3
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
it "should be find all links using the API" do
|
54
54
|
link = Caren::Link.find(1,Caren::Api.session)
|
55
55
|
link.id.should == 1
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
it "should be find a specific link using the API" do
|
59
59
|
links = Caren::Link.search(:external_id, 1, Caren::Api.session)
|
60
60
|
links.should have(1).thing
|
61
61
|
end
|
62
|
-
|
63
|
-
end
|
62
|
+
|
63
|
+
end
|
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: 49
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 31
|
10
|
+
version: 0.4.31
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andre Foeken
|