caren-api 0.6.18 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/caren-api.gemspec +11 -3
- data/lib/caren/caren.rb +6 -4
- data/lib/caren/event.rb +37 -2
- data/lib/caren/store/account.rb +3 -27
- data/lib/caren/store/account_entry.rb +5 -5
- data/spec/.DS_Store +0 -0
- data/spec/event_spec.rb +50 -0
- data/spec/fixtures/caren_account.xml +9 -0
- data/spec/fixtures/caren_account_entries.xml +47 -0
- data/spec/fixtures/caren_account_entry.xml +12 -0
- data/spec/fixtures/caren_accounts.xml +19 -0
- data/spec/fixtures/caren_event.xml +18 -0
- data/spec/fixtures/caren_events.xml +37 -0
- data/spec/store/account_entry_spec.rb +57 -0
- data/spec/store/account_spec.rb +79 -0
- metadata +151 -140
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
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.
|
8
|
+
s.version = "0.7.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 = "2012-
|
12
|
+
s.date = "2012-09-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 = [
|
@@ -59,6 +59,10 @@ Gem::Specification.new do |s|
|
|
59
59
|
"spec/event_spec.rb",
|
60
60
|
"spec/external_message_spec.rb",
|
61
61
|
"spec/fixtures/bacon.jpg",
|
62
|
+
"spec/fixtures/caren_account.xml",
|
63
|
+
"spec/fixtures/caren_account_entries.xml",
|
64
|
+
"spec/fixtures/caren_account_entry.xml",
|
65
|
+
"spec/fixtures/caren_accounts.xml",
|
62
66
|
"spec/fixtures/caren_billable.xml",
|
63
67
|
"spec/fixtures/caren_billable_categories.xml",
|
64
68
|
"spec/fixtures/caren_billable_categories_search.xml",
|
@@ -69,6 +73,8 @@ Gem::Specification.new do |s|
|
|
69
73
|
"spec/fixtures/caren_care_provider_validation.xml",
|
70
74
|
"spec/fixtures/caren_care_providers.xml",
|
71
75
|
"spec/fixtures/caren_care_providers_search.xml",
|
76
|
+
"spec/fixtures/caren_event.xml",
|
77
|
+
"spec/fixtures/caren_events.xml",
|
72
78
|
"spec/fixtures/caren_external_message.xml",
|
73
79
|
"spec/fixtures/caren_external_messages.xml",
|
74
80
|
"spec/fixtures/caren_invoice.xml",
|
@@ -85,6 +91,8 @@ Gem::Specification.new do |s|
|
|
85
91
|
"spec/link_spec.rb",
|
86
92
|
"spec/spec.opts",
|
87
93
|
"spec/spec_helper.rb",
|
94
|
+
"spec/store/account_entry_spec.rb",
|
95
|
+
"spec/store/account_spec.rb",
|
88
96
|
"spec/store/address_spec.rb",
|
89
97
|
"spec/store/billable_category_spec.rb",
|
90
98
|
"spec/store/billable_spec.rb",
|
@@ -95,7 +103,7 @@ Gem::Specification.new do |s|
|
|
95
103
|
s.homepage = "http://github.com/foeken/caren-api"
|
96
104
|
s.licenses = ["MIT"]
|
97
105
|
s.require_paths = ["lib"]
|
98
|
-
s.rubygems_version = "1.8.
|
106
|
+
s.rubygems_version = "1.8.24"
|
99
107
|
s.summary = "Reference implementation of Caren CareProvider API"
|
100
108
|
|
101
109
|
if s.respond_to? :specification_version then
|
data/lib/caren/caren.rb
CHANGED
@@ -23,6 +23,8 @@ module Caren
|
|
23
23
|
|
24
24
|
class Api
|
25
25
|
|
26
|
+
DIGEST_ALGORITHMS = [OpenSSL::Digest::SHA256.new, OpenSSL::Digest::SHA1.new]
|
27
|
+
|
26
28
|
class << self
|
27
29
|
attr_accessor :session
|
28
30
|
end
|
@@ -174,7 +176,7 @@ module Caren
|
|
174
176
|
# Timestamp is UNIX timestamp seconds since 1970
|
175
177
|
def sign timestamp, path=nil, string=nil, private_key=self.private_key
|
176
178
|
path = URI.parse(path).path if path
|
177
|
-
encrypted_digest = private_key.sign(
|
179
|
+
encrypted_digest = private_key.sign( DIGEST_ALGORITHMS.first, "#{path}#{string}#{timestamp}".strip )
|
178
180
|
signature = CGI.escape(Base64.encode64(encrypted_digest))
|
179
181
|
return signature
|
180
182
|
end
|
@@ -189,11 +191,11 @@ module Caren
|
|
189
191
|
def verify_signature signature, timestamp, path, string=nil, public_key=self.caren_public_key
|
190
192
|
return false unless public_key
|
191
193
|
signature = Base64.decode64(CGI.unescape(signature.to_s))
|
192
|
-
public_key.verify(
|
194
|
+
DIGEST_ALGORITHMS.map{ |algorithm| public_key.verify( algorithm, signature, "#{path}#{string}#{timestamp}".strip ) }.any?
|
193
195
|
end
|
194
196
|
|
195
197
|
def create_photo_signature url_shortcut, external_or_caren_id, private_key=self.private_key
|
196
|
-
digest = OpenSSL::PKey::RSA.new(private_key).sign(
|
198
|
+
digest = OpenSSL::PKey::RSA.new(private_key).sign( DIGEST_ALGORITHMS.first, url_shortcut.to_s + external_or_caren_id.to_s )
|
197
199
|
return CGI.escape(Base64.encode64(digest))
|
198
200
|
end
|
199
201
|
|
@@ -201,7 +203,7 @@ module Caren
|
|
201
203
|
def verify_photo_signature signature, url_shortcut, external_id, public_key=self.caren_public_key
|
202
204
|
return false unless public_key
|
203
205
|
signature = Base64.decode64(CGI.unescape(signature.to_s))
|
204
|
-
public_key.verify(
|
206
|
+
DIGEST_ALGORITHMS.map{ |algorithm| public_key.verify( algorithm, signature, url_shortcut.to_s + external_id.to_s ) }.any?
|
205
207
|
end
|
206
208
|
|
207
209
|
private
|
data/lib/caren/event.rb
CHANGED
@@ -3,7 +3,8 @@
|
|
3
3
|
class Caren::Event < Caren::Base
|
4
4
|
|
5
5
|
def self.keys
|
6
|
-
[ :
|
6
|
+
[ :id, # Integer (Caren id, optional)
|
7
|
+
:external_id, # String Unique identifying string (Your event id)
|
7
8
|
:name, # String
|
8
9
|
:comment, # String
|
9
10
|
:start, # String (14:00)
|
@@ -22,7 +23,31 @@ class Caren::Event < Caren::Base
|
|
22
23
|
:source # String (remote_schedule,remote_realisation)
|
23
24
|
] + super
|
24
25
|
end
|
25
|
-
|
26
|
+
|
27
|
+
def self.all session
|
28
|
+
from_xml session.get(self.resource_url)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.find id, session
|
32
|
+
from_xml session.get(self.resource_url(id))
|
33
|
+
end
|
34
|
+
|
35
|
+
def create session
|
36
|
+
self.class.from_xml session.post self.class.resource_url, self.to_xml
|
37
|
+
end
|
38
|
+
|
39
|
+
def charge session
|
40
|
+
self.class.from_xml session.post self.class.charge_url(self.id), self.to_xml
|
41
|
+
end
|
42
|
+
|
43
|
+
def update session
|
44
|
+
self.class.from_xml session.put self.class.resource_url(self.id), self.to_xml
|
45
|
+
end
|
46
|
+
|
47
|
+
def delete session
|
48
|
+
session.delete self.class.resource_url(self.id)
|
49
|
+
end
|
50
|
+
|
26
51
|
def self.array_root
|
27
52
|
:events
|
28
53
|
end
|
@@ -31,4 +56,14 @@ class Caren::Event < Caren::Base
|
|
31
56
|
:event
|
32
57
|
end
|
33
58
|
|
59
|
+
def self.charge_url id=nil
|
60
|
+
"#{resource_location}/#{id}/charge"
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def self.resource_location
|
66
|
+
"/api/pro/events"
|
67
|
+
end
|
68
|
+
|
34
69
|
end
|
data/lib/caren/store/account.rb
CHANGED
@@ -15,26 +15,14 @@ class Caren::Store::Account < Caren::Base
|
|
15
15
|
def self.all session
|
16
16
|
from_xml session.get(self.resource_url)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def deposit_credits amount, session
|
20
20
|
self.class.from_xml session.post self.deposit_credits_url, amount_xml(amount)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def withdraw_credits amount, session
|
24
24
|
self.class.from_xml session.post self.withdraw_credits_url, amount_xml(amount)
|
25
25
|
end
|
26
|
-
|
27
|
-
def self.confirm_credits caren_event, session
|
28
|
-
from_xml session.post confirm_credits_url, caren_event.to_xml
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.reserve_credits caren_event, session
|
32
|
-
from_xml session.post reserve_credits_url, caren_event.to_xml
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.release_credits caren_event, session
|
36
|
-
from_xml session.post release_credits_url, caren_event.to_xml
|
37
|
-
end
|
38
26
|
|
39
27
|
def self.array_root
|
40
28
|
:accounts
|
@@ -56,7 +44,7 @@ class Caren::Store::Account < Caren::Base
|
|
56
44
|
"/api/pro/people/#{person_id}/accounts/deposit_credits/#{billable_timeline_id}"
|
57
45
|
end
|
58
46
|
end
|
59
|
-
|
47
|
+
|
60
48
|
def withdraw_credits_url
|
61
49
|
if id
|
62
50
|
"/api/pro/store/accounts/#{id}/withdraw_credits"
|
@@ -65,18 +53,6 @@ class Caren::Store::Account < Caren::Base
|
|
65
53
|
end
|
66
54
|
end
|
67
55
|
|
68
|
-
def self.confirm_credits_url
|
69
|
-
"/api/pro/store/accounts/confirm_credits"
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.reserve_credits_url
|
73
|
-
"/api/pro/store/accounts/reserve_credits"
|
74
|
-
end
|
75
|
-
|
76
|
-
def self.release_credits_url
|
77
|
-
"/api/pro/store/accounts/release_credits"
|
78
|
-
end
|
79
|
-
|
80
56
|
def self.resource_location
|
81
57
|
"/api/pro/store/accounts"
|
82
58
|
end
|
@@ -4,7 +4,7 @@ class Caren::Store::AccountEntry < Caren::Base
|
|
4
4
|
[:id, # Integer (Caren id)
|
5
5
|
:account_id, # Integer (Caren account id)
|
6
6
|
:amount, # Integer (Delta amount in credits, unit depends on account billable)
|
7
|
-
:reserved, # Boolean (Is this a reservation)
|
7
|
+
:reserved, # Boolean (Is this a reservation?)
|
8
8
|
:source_id, # Integer (Source of the account entry, Caren object id)
|
9
9
|
:source_type, # String (Source of the account entry, Caren object class string)
|
10
10
|
:external_source_id # Integer (Source of the account entry, Your object id, if known)
|
@@ -18,7 +18,7 @@ class Caren::Store::AccountEntry < Caren::Base
|
|
18
18
|
def self.all account_id, session
|
19
19
|
from_xml session.get(self.resource_url(account_id))
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def self.array_root
|
23
23
|
:account_entries
|
24
24
|
end
|
@@ -26,13 +26,13 @@ class Caren::Store::AccountEntry < Caren::Base
|
|
26
26
|
def self.node_root
|
27
27
|
:account_entry
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def self.resource_location
|
31
31
|
"/api/pro/store/account/%i/account_entries"
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
private
|
35
|
-
|
35
|
+
|
36
36
|
def resource_url account_id, id=nil
|
37
37
|
self.class.resource_url(account_id,id)
|
38
38
|
end
|
data/spec/.DS_Store
CHANGED
Binary file
|
data/spec/event_spec.rb
CHANGED
@@ -21,3 +21,53 @@ describe "Event", "converting to xml" do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
24
|
+
|
25
|
+
describe "Event", "REST methods" do
|
26
|
+
|
27
|
+
before do
|
28
|
+
event = File.read("spec/fixtures/caren_event.xml")
|
29
|
+
events = File.read("spec/fixtures/caren_events.xml")
|
30
|
+
|
31
|
+
event_url = Caren::Api.session.url_for( Caren::Event.resource_url(17) )
|
32
|
+
events_url = Caren::Api.session.url_for( Caren::Event.resource_url )
|
33
|
+
charge_event_url = Caren::Api.session.url_for( Caren::Event.charge_url(17) )
|
34
|
+
|
35
|
+
timestamp = DateTime.now.to_i
|
36
|
+
|
37
|
+
FakeWeb.register_uri(:get, events_url, :body => events, :signature => Caren::Api.session.sign(timestamp,nil,events), :timestamp => timestamp )
|
38
|
+
FakeWeb.register_uri(:get, event_url, :body => event, :signature => Caren::Api.session.sign(timestamp,nil,event), :timestamp => timestamp )
|
39
|
+
|
40
|
+
FakeWeb.register_uri(:post, charge_event_url, :status => 201, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
|
41
|
+
FakeWeb.register_uri(:post, events_url, :status => 201, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
|
42
|
+
FakeWeb.register_uri(:put, event_url, :body => event, :signature => Caren::Api.session.sign(timestamp,nil,event), :timestamp => timestamp )
|
43
|
+
FakeWeb.register_uri(:delete, event_url, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should be able to find all events" do
|
47
|
+
events = Caren::Event.all Caren::Api.session
|
48
|
+
events.should have(2).things
|
49
|
+
events.first.name.should == "E-consult"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should be able to find one event" do
|
53
|
+
event = Caren::Event.find 17, Caren::Api.session
|
54
|
+
event.name.should == "E-consult"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should be able to charge an event" do
|
58
|
+
lambda{ Caren::Event.new( :id => 17 ).charge(Caren::Api.session) }.should_not raise_error
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should be able to create an event" do
|
62
|
+
lambda{ Caren::Event.new( :name => "TEST" ).create(Caren::Api.session) }.should_not raise_error
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should be able to update an event" do
|
66
|
+
lambda{ Caren::Event.new( :id => 17, :name => "TEST" ).update(Caren::Api.session) }.should_not raise_error
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should be able to delete an event" do
|
70
|
+
lambda{ Caren::Event.new( :id => 17 ).delete(Caren::Api.session) }.should_not raise_error
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<account>
|
3
|
+
<balance type="integer">900</balance>
|
4
|
+
<billable-timeline-id type="integer">2</billable-timeline-id>
|
5
|
+
<created-at type="datetime">2012-08-22T11:07:11+02:00</created-at>
|
6
|
+
<id type="integer">2</id>
|
7
|
+
<person-id type="integer">2</person-id>
|
8
|
+
<updated-at type="datetime">2012-08-23T12:30:31+02:00</updated-at>
|
9
|
+
</account>
|
@@ -0,0 +1,47 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<account-entries type="array">
|
3
|
+
<account-entry>
|
4
|
+
<account-id type="integer">2</account-id>
|
5
|
+
<amount type="integer">1800</amount>
|
6
|
+
<created-at type="datetime">2012-08-22T11:07:11+02:00</created-at>
|
7
|
+
<id type="integer">6</id>
|
8
|
+
<reserved type="boolean" nil="true"></reserved>
|
9
|
+
<source-id type="integer">2</source-id>
|
10
|
+
<source-type>CareProvider</source-type>
|
11
|
+
<updated-at type="datetime">2012-08-22T11:07:11+02:00</updated-at>
|
12
|
+
<external-source-id></external-source-id>
|
13
|
+
</account-entry>
|
14
|
+
<account-entry>
|
15
|
+
<account-id type="integer">3</account-id>
|
16
|
+
<amount type="integer">5</amount>
|
17
|
+
<created-at type="datetime">2012-08-22T11:48:31+02:00</created-at>
|
18
|
+
<id type="integer">7</id>
|
19
|
+
<reserved type="boolean" nil="true"></reserved>
|
20
|
+
<source-id type="integer">2</source-id>
|
21
|
+
<source-type>CareProvider</source-type>
|
22
|
+
<updated-at type="datetime">2012-08-22T11:48:31+02:00</updated-at>
|
23
|
+
<external-source-id></external-source-id>
|
24
|
+
</account-entry>
|
25
|
+
<account-entry>
|
26
|
+
<account-id type="integer">2</account-id>
|
27
|
+
<amount type="integer">900</amount>
|
28
|
+
<created-at type="datetime">2012-08-22T11:52:57+02:00</created-at>
|
29
|
+
<id type="integer">8</id>
|
30
|
+
<reserved type="boolean" nil="true"></reserved>
|
31
|
+
<source-id type="integer">2</source-id>
|
32
|
+
<source-type>CareProvider</source-type>
|
33
|
+
<updated-at type="datetime">2012-08-22T11:52:57+02:00</updated-at>
|
34
|
+
<external-source-id></external-source-id>
|
35
|
+
</account-entry>
|
36
|
+
<account-entry>
|
37
|
+
<account-id type="integer">2</account-id>
|
38
|
+
<amount type="integer">-1800</amount>
|
39
|
+
<created-at type="datetime">2012-08-23T12:30:31+02:00</created-at>
|
40
|
+
<id type="integer">9</id>
|
41
|
+
<reserved type="boolean">true</reserved>
|
42
|
+
<source-id type="integer">1</source-id>
|
43
|
+
<source-type>Connections::ExternalEvent</source-type>
|
44
|
+
<updated-at type="datetime">2012-08-23T12:30:31+02:00</updated-at>
|
45
|
+
<external-source-id>2</external-source-id>
|
46
|
+
</account-entry>
|
47
|
+
</account-entries>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<account-entry>
|
3
|
+
<account-id type="integer">2</account-id>
|
4
|
+
<amount type="integer">1800</amount>
|
5
|
+
<created-at type="datetime">2012-08-22T11:07:11+02:00</created-at>
|
6
|
+
<id type="integer">6</id>
|
7
|
+
<reserved type="boolean" nil="true"></reserved>
|
8
|
+
<source-id type="integer">2</source-id>
|
9
|
+
<source-type>CareProvider</source-type>
|
10
|
+
<updated-at type="datetime">2012-08-22T11:07:11+02:00</updated-at>
|
11
|
+
<external-source-id></external-source-id>
|
12
|
+
</account-entry>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<accounts type="array">
|
3
|
+
<account>
|
4
|
+
<balance type="integer">900</balance>
|
5
|
+
<billable-timeline-id type="integer">2</billable-timeline-id>
|
6
|
+
<created-at type="datetime">2012-08-22T11:07:11+02:00</created-at>
|
7
|
+
<id type="integer">2</id>
|
8
|
+
<person-id type="integer">2</person-id>
|
9
|
+
<updated-at type="datetime">2012-08-23T12:30:31+02:00</updated-at>
|
10
|
+
</account>
|
11
|
+
<account>
|
12
|
+
<balance type="integer">5</balance>
|
13
|
+
<billable-timeline-id type="integer">3</billable-timeline-id>
|
14
|
+
<created-at type="datetime">2012-08-22T11:48:31+02:00</created-at>
|
15
|
+
<id type="integer">3</id>
|
16
|
+
<person-id type="integer">2</person-id>
|
17
|
+
<updated-at type="datetime">2012-08-22T11:48:31+02:00</updated-at>
|
18
|
+
</account>
|
19
|
+
</accounts>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<event>
|
3
|
+
<billable-amount type="integer">1800</billable-amount>
|
4
|
+
<billable-id type="integer">2</billable-id>
|
5
|
+
<cancel-before type="datetime">2012-08-24T10:15:00+02:00</cancel-before>
|
6
|
+
<care-provider-id type="integer">2</care-provider-id>
|
7
|
+
<comment nil="true"></comment>
|
8
|
+
<created-at type="datetime">2012-08-23T12:30:31+02:00</created-at>
|
9
|
+
<duration type="integer">1800</duration>
|
10
|
+
<external-id type="integer">2</external-id>
|
11
|
+
<id type="integer">1</id>
|
12
|
+
<name>E-consult</name>
|
13
|
+
<reservation type="boolean">true</reservation>
|
14
|
+
<subject-id type="integer">2</subject-id>
|
15
|
+
<updated-at type="datetime">2012-08-23T12:31:38+02:00</updated-at>
|
16
|
+
<valid-from type="date">2012-08-25</valid-from>
|
17
|
+
<valid-to type="date">2012-08-26</valid-to>
|
18
|
+
</event>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<events type="array">
|
3
|
+
<event>
|
4
|
+
<billable-amount type="integer">1800</billable-amount>
|
5
|
+
<billable-id type="integer">2</billable-id>
|
6
|
+
<cancel-before type="datetime">2012-08-24T10:15:00+02:00</cancel-before>
|
7
|
+
<care-provider-id type="integer">2</care-provider-id>
|
8
|
+
<comment nil="true"></comment>
|
9
|
+
<created-at type="datetime">2012-08-23T12:30:31+02:00</created-at>
|
10
|
+
<duration type="integer">1800</duration>
|
11
|
+
<external-id type="integer">2</external-id>
|
12
|
+
<id type="integer">1</id>
|
13
|
+
<name>E-consult</name>
|
14
|
+
<reservation type="boolean">true</reservation>
|
15
|
+
<subject-id type="integer">2</subject-id>
|
16
|
+
<updated-at type="datetime">2012-08-23T12:31:38+02:00</updated-at>
|
17
|
+
<valid-from type="date">2012-08-25</valid-from>
|
18
|
+
<valid-to type="date">2012-08-26</valid-to>
|
19
|
+
</event>
|
20
|
+
<event>
|
21
|
+
<billable-amount type="integer">1800</billable-amount>
|
22
|
+
<billable-id type="integer">2</billable-id>
|
23
|
+
<cancel-before type="datetime">2012-08-24T10:15:00+02:00</cancel-before>
|
24
|
+
<care-provider-id type="integer">2</care-provider-id>
|
25
|
+
<comment nil="true"></comment>
|
26
|
+
<created-at type="datetime">2012-08-23T12:30:31+02:00</created-at>
|
27
|
+
<duration type="integer">1800</duration>
|
28
|
+
<external-id type="integer">2</external-id>
|
29
|
+
<id type="integer">2</id>
|
30
|
+
<name>E-consult</name>
|
31
|
+
<reservation type="boolean">true</reservation>
|
32
|
+
<subject-id type="integer">2</subject-id>
|
33
|
+
<updated-at type="datetime">2012-08-23T12:31:38+02:00</updated-at>
|
34
|
+
<valid-from type="date">2012-08-25</valid-from>
|
35
|
+
<valid-to type="date">2012-08-26</valid-to>
|
36
|
+
</event>
|
37
|
+
</events>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "AccountEntry", "converting to xml" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@account_entry_a = Caren::Store::AccountEntry.new( :account_id => 1,
|
7
|
+
:amount => 3600,
|
8
|
+
:reserved => true,
|
9
|
+
:source_id => 1,
|
10
|
+
:source_type => "CareProvider",
|
11
|
+
:external_source_id => 1 )
|
12
|
+
|
13
|
+
@account_entry_b = Caren::Store::AccountEntry.new( :account_id => 2,
|
14
|
+
:amount => 3600,
|
15
|
+
:reserved => true,
|
16
|
+
:source_id => 1,
|
17
|
+
:source_type => "CareProvider",
|
18
|
+
:external_source_id => 1 )
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be able to convert an account entry to valid xml" do
|
22
|
+
@account_entry_a.should convert_to_valid_caren_xml
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be able to convert an array of account entries to valid xml" do
|
26
|
+
[@account_entry_a,@account_entry_b].should convert_to_valid_caren_array_xml
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "AccountEntry", "REST methods" do
|
32
|
+
|
33
|
+
before do
|
34
|
+
account_entry = File.read("spec/fixtures/caren_account_entry.xml")
|
35
|
+
account_entries = File.read("spec/fixtures/caren_account_entries.xml")
|
36
|
+
|
37
|
+
account_entry_url = Caren::Api.session.url_for( Caren::Store::AccountEntry.resource_url(1,1) )
|
38
|
+
account_entries_url = Caren::Api.session.url_for( Caren::Store::AccountEntry.resource_url(1) )
|
39
|
+
|
40
|
+
timestamp = DateTime.now.to_i
|
41
|
+
|
42
|
+
FakeWeb.register_uri(:get, account_entries_url, :body => account_entries, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,account_entries) )
|
43
|
+
FakeWeb.register_uri(:get, account_entry_url, :body => account_entry, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,account_entry) )
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should be able to find a specific account entry" do
|
47
|
+
account_entry = Caren::Store::AccountEntry.find 1, 1, Caren::Api.session
|
48
|
+
account_entry.amount.should == 1800
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should be able to find all account entries" do
|
52
|
+
account_entries = Caren::Store::AccountEntry.all 1, Caren::Api.session
|
53
|
+
account_entries.should have(4).things
|
54
|
+
account_entries.first.amount.should == 1800
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Account", "converting to xml" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@account_a = Caren::Store::Account.new( :balance => 3600, :person_id => 1, :billable_timeline_id => 1 )
|
7
|
+
@account_b = Caren::Store::Account.new( :balance => 3600, :person_id => 1, :billable_timeline_id => 2 )
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be able to convert an account to valid xml" do
|
11
|
+
@account_a.should convert_to_valid_caren_xml
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should be able to convert an array of accounts to valid xml" do
|
15
|
+
[@account_a,@account_b].should convert_to_valid_caren_array_xml
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "Account", "REST methods" do
|
21
|
+
|
22
|
+
before do
|
23
|
+
account = File.read("spec/fixtures/caren_account.xml")
|
24
|
+
accounts = File.read("spec/fixtures/caren_accounts.xml")
|
25
|
+
amount_xml = "<amount>900</amount>"
|
26
|
+
|
27
|
+
account_url = Caren::Api.session.url_for( Caren::Store::Account.resource_url(1) )
|
28
|
+
accounts_url = Caren::Api.session.url_for( Caren::Store::Account.resource_url )
|
29
|
+
|
30
|
+
deposit_url = Caren::Api.session.url_for( Caren::Store::Account.new(:id=>1).deposit_credits_url )
|
31
|
+
withdraw_url = Caren::Api.session.url_for( Caren::Store::Account.new(:id=>1).withdraw_credits_url )
|
32
|
+
|
33
|
+
alt_deposit_url = Caren::Api.session.url_for( Caren::Store::Account.new(:person_id => 1, :billable_timeline_id => 1).deposit_credits_url )
|
34
|
+
alt_withdraw_url = Caren::Api.session.url_for( Caren::Store::Account.new(:person_id => 1, :billable_timeline_id => 1).withdraw_credits_url )
|
35
|
+
|
36
|
+
timestamp = DateTime.now.to_i
|
37
|
+
|
38
|
+
FakeWeb.register_uri(:get, accounts_url, :body => accounts, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,accounts) )
|
39
|
+
FakeWeb.register_uri(:get, account_url, :body => account, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,account) )
|
40
|
+
|
41
|
+
FakeWeb.register_uri(:post, deposit_url, :body => account, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,account) )
|
42
|
+
FakeWeb.register_uri(:post, withdraw_url, :body => account, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,account) )
|
43
|
+
|
44
|
+
FakeWeb.register_uri(:post, alt_deposit_url, :body => account, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,account) )
|
45
|
+
FakeWeb.register_uri(:post, alt_withdraw_url, :body => account, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,account) )
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should be able to deposit credits to a specific account" do
|
49
|
+
account = Caren::Store::Account.new(:id=>1).deposit_credits(900,Caren::Api.session)
|
50
|
+
account.balance.should == 900
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should be able to withdraw credits to a specific account" do
|
54
|
+
account = Caren::Store::Account.new(:id=>1).withdraw_credits(900,Caren::Api.session)
|
55
|
+
account.balance.should == 900
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should be able to deposit credits to a specific account (ALT)" do
|
59
|
+
account = Caren::Store::Account.new(:person_id => 1, :billable_timeline_id => 1).deposit_credits(900,Caren::Api.session)
|
60
|
+
account.balance.should == 900
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should be able to withdraw credits to a specific account (ALT)" do
|
64
|
+
account = Caren::Store::Account.new(:person_id => 1, :billable_timeline_id => 1).withdraw_credits(900,Caren::Api.session)
|
65
|
+
account.balance.should == 900
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should be able to find a specific account" do
|
69
|
+
account = Caren::Store::Account.find 1, Caren::Api.session
|
70
|
+
account.balance.should == 900
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should be able to find all accounts" do
|
74
|
+
accounts = Caren::Store::Account.all Caren::Api.session
|
75
|
+
accounts.should have(2).things
|
76
|
+
accounts.first.balance.should == 900
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
metadata
CHANGED
@@ -1,160 +1,169 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: caren-api
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 6
|
9
|
-
- 18
|
10
|
-
version: 0.6.18
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Andre Foeken
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
-
none: false
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
hash: 3
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
version: "0"
|
30
|
-
version_requirements: *id001
|
12
|
+
date: 2012-09-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
31
15
|
name: i18n
|
32
|
-
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :runtime
|
34
|
-
|
35
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
25
|
none: false
|
37
|
-
requirements:
|
38
|
-
- -
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
|
41
|
-
|
42
|
-
- 0
|
43
|
-
version: "0"
|
44
|
-
version_requirements: *id002
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
45
31
|
name: activesupport
|
46
|
-
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
47
38
|
type: :runtime
|
48
|
-
|
49
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
41
|
none: false
|
51
|
-
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
|
55
|
-
|
56
|
-
- 0
|
57
|
-
version: "0"
|
58
|
-
version_requirements: *id003
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
59
47
|
name: builder
|
60
|
-
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
61
54
|
type: :runtime
|
62
|
-
|
63
|
-
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
57
|
none: false
|
65
|
-
requirements:
|
66
|
-
- -
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
|
69
|
-
|
70
|
-
- 1
|
71
|
-
- 6
|
72
|
-
- 7
|
73
|
-
version: 1.6.7
|
74
|
-
version_requirements: *id004
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
75
63
|
name: rest-client
|
76
|
-
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - '='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.6.7
|
77
70
|
type: :runtime
|
78
|
-
|
79
|
-
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
73
|
none: false
|
81
|
-
requirements:
|
82
|
-
- -
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
|
85
|
-
|
86
|
-
- 0
|
87
|
-
version: "0"
|
88
|
-
version_requirements: *id005
|
74
|
+
requirements:
|
75
|
+
- - '='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.6.7
|
78
|
+
- !ruby/object:Gem::Dependency
|
89
79
|
name: bundler
|
90
|
-
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
91
86
|
type: :development
|
92
|
-
|
93
|
-
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
89
|
none: false
|
95
|
-
requirements:
|
96
|
-
- -
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
|
99
|
-
|
100
|
-
- 0
|
101
|
-
version: "0"
|
102
|
-
version_requirements: *id006
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
103
95
|
name: capybara
|
104
|
-
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
105
102
|
type: :development
|
106
|
-
|
107
|
-
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
105
|
none: false
|
109
|
-
requirements:
|
110
|
-
- -
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
|
113
|
-
|
114
|
-
- 0
|
115
|
-
version: "0"
|
116
|
-
version_requirements: *id007
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
117
111
|
name: rspec
|
118
|
-
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
119
118
|
type: :development
|
120
|
-
|
121
|
-
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
121
|
none: false
|
123
|
-
requirements:
|
124
|
-
- -
|
125
|
-
- !ruby/object:Gem::Version
|
126
|
-
|
127
|
-
|
128
|
-
- 0
|
129
|
-
version: "0"
|
130
|
-
version_requirements: *id008
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
131
127
|
name: fakeweb
|
132
|
-
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
133
134
|
type: :development
|
134
|
-
|
135
|
-
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
137
|
none: false
|
137
|
-
requirements:
|
138
|
-
- -
|
139
|
-
- !ruby/object:Gem::Version
|
140
|
-
|
141
|
-
|
142
|
-
- 0
|
143
|
-
version: "0"
|
144
|
-
version_requirements: *id009
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
145
143
|
name: jeweler
|
146
|
-
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
147
150
|
type: :development
|
148
|
-
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
description: You can use this gem as inspiration of the base of your connections with
|
159
|
+
Caren.
|
149
160
|
email: andre.foeken@nedap.com
|
150
161
|
executables: []
|
151
|
-
|
152
162
|
extensions: []
|
153
|
-
|
154
|
-
extra_rdoc_files:
|
163
|
+
extra_rdoc_files:
|
155
164
|
- LICENSE.txt
|
156
165
|
- README.rdoc
|
157
|
-
files:
|
166
|
+
files:
|
158
167
|
- .travis.yml
|
159
168
|
- Gemfile
|
160
169
|
- LICENSE.txt
|
@@ -197,6 +206,10 @@ files:
|
|
197
206
|
- spec/event_spec.rb
|
198
207
|
- spec/external_message_spec.rb
|
199
208
|
- spec/fixtures/bacon.jpg
|
209
|
+
- spec/fixtures/caren_account.xml
|
210
|
+
- spec/fixtures/caren_account_entries.xml
|
211
|
+
- spec/fixtures/caren_account_entry.xml
|
212
|
+
- spec/fixtures/caren_accounts.xml
|
200
213
|
- spec/fixtures/caren_billable.xml
|
201
214
|
- spec/fixtures/caren_billable_categories.xml
|
202
215
|
- spec/fixtures/caren_billable_categories_search.xml
|
@@ -207,6 +220,8 @@ files:
|
|
207
220
|
- spec/fixtures/caren_care_provider_validation.xml
|
208
221
|
- spec/fixtures/caren_care_providers.xml
|
209
222
|
- spec/fixtures/caren_care_providers_search.xml
|
223
|
+
- spec/fixtures/caren_event.xml
|
224
|
+
- spec/fixtures/caren_events.xml
|
210
225
|
- spec/fixtures/caren_external_message.xml
|
211
226
|
- spec/fixtures/caren_external_messages.xml
|
212
227
|
- spec/fixtures/caren_invoice.xml
|
@@ -223,6 +238,8 @@ files:
|
|
223
238
|
- spec/link_spec.rb
|
224
239
|
- spec/spec.opts
|
225
240
|
- spec/spec_helper.rb
|
241
|
+
- spec/store/account_entry_spec.rb
|
242
|
+
- spec/store/account_spec.rb
|
226
243
|
- spec/store/address_spec.rb
|
227
244
|
- spec/store/billable_category_spec.rb
|
228
245
|
- spec/store/billable_spec.rb
|
@@ -230,37 +247,31 @@ files:
|
|
230
247
|
- spec/store/line_items_spec.rb
|
231
248
|
- spec/store/payment_spec.rb
|
232
249
|
homepage: http://github.com/foeken/caren-api
|
233
|
-
licenses:
|
250
|
+
licenses:
|
234
251
|
- MIT
|
235
252
|
post_install_message:
|
236
253
|
rdoc_options: []
|
237
|
-
|
238
|
-
require_paths:
|
254
|
+
require_paths:
|
239
255
|
- lib
|
240
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
256
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
241
257
|
none: false
|
242
|
-
requirements:
|
243
|
-
- -
|
244
|
-
- !ruby/object:Gem::Version
|
245
|
-
|
246
|
-
segments:
|
258
|
+
requirements:
|
259
|
+
- - ! '>='
|
260
|
+
- !ruby/object:Gem::Version
|
261
|
+
version: '0'
|
262
|
+
segments:
|
247
263
|
- 0
|
248
|
-
|
249
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
264
|
+
hash: -2135287108305207608
|
265
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
250
266
|
none: false
|
251
|
-
requirements:
|
252
|
-
- -
|
253
|
-
- !ruby/object:Gem::Version
|
254
|
-
|
255
|
-
segments:
|
256
|
-
- 0
|
257
|
-
version: "0"
|
267
|
+
requirements:
|
268
|
+
- - ! '>='
|
269
|
+
- !ruby/object:Gem::Version
|
270
|
+
version: '0'
|
258
271
|
requirements: []
|
259
|
-
|
260
272
|
rubyforge_project:
|
261
|
-
rubygems_version: 1.8.
|
273
|
+
rubygems_version: 1.8.24
|
262
274
|
signing_key:
|
263
275
|
specification_version: 3
|
264
276
|
summary: Reference implementation of Caren CareProvider API
|
265
277
|
test_files: []
|
266
|
-
|