caren-api 0.4.29 → 0.4.30
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 +3 -1
- data/lib/caren-api.rb +13 -22
- data/lib/caren/base.rb +17 -17
- data/lib/caren/event_slot.rb +20 -0
- data/lib/caren/link.rb +11 -11
- data/spec/event_slot_spec.rb +18 -0
- data/spec/event_spec.rb +10 -10
- data/spec/spec_helper.rb +4 -4
- metadata +5 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.30
|
data/caren-api.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "caren-api"
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.30"
|
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"]
|
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
|
|
37
37
|
"lib/caren/client.rb",
|
38
38
|
"lib/caren/error.rb",
|
39
39
|
"lib/caren/event.rb",
|
40
|
+
"lib/caren/event_slot.rb",
|
40
41
|
"lib/caren/external_message.rb",
|
41
42
|
"lib/caren/link.rb",
|
42
43
|
"spec/.DS_Store",
|
@@ -45,6 +46,7 @@ Gem::Specification.new do |s|
|
|
45
46
|
"spec/care_provider_spec.rb",
|
46
47
|
"spec/caren_spec.rb",
|
47
48
|
"spec/client_spec.rb",
|
49
|
+
"spec/event_slot_spec.rb",
|
48
50
|
"spec/event_spec.rb",
|
49
51
|
"spec/external_message_spec.rb",
|
50
52
|
"spec/fixtures/bacon.jpg",
|
data/lib/caren-api.rb
CHANGED
@@ -1,28 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
rescue LoadError
|
4
|
-
end
|
5
|
-
|
6
|
-
require "active_support"
|
7
|
-
require "active_support/core_ext"
|
8
|
-
|
9
|
-
begin
|
10
|
-
require "active_support/secure_random"
|
11
|
-
rescue LoadError
|
12
|
-
end
|
1
|
+
require "active_support/core_ext/hash/conversions"
|
2
|
+
require "active_support/core_ext/array/conversions"
|
13
3
|
|
14
4
|
require "builder"
|
15
5
|
require "rest_client"
|
16
6
|
require "rexml/document"
|
17
7
|
require "base64"
|
18
8
|
|
19
|
-
require "
|
20
|
-
require "
|
21
|
-
require "
|
22
|
-
require "
|
23
|
-
require "
|
24
|
-
require "
|
25
|
-
require "
|
26
|
-
require "
|
27
|
-
require "
|
28
|
-
require "
|
9
|
+
require "caren/caren.rb"
|
10
|
+
require "caren/error.rb"
|
11
|
+
require "caren/base.rb"
|
12
|
+
require "caren/event.rb"
|
13
|
+
require "caren/event_slot.rb"
|
14
|
+
require "caren/client.rb"
|
15
|
+
require "caren/care_provider.rb"
|
16
|
+
require "caren/external_message.rb"
|
17
|
+
require "caren/link.rb"
|
18
|
+
require "caren/billable.rb"
|
19
|
+
require "caren/billable_category.rb"
|
data/lib/caren/base.rb
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
# The class provides basic functionality to convert objects to and from xml based
|
3
3
|
# on the default Caren API format.
|
4
4
|
class Caren::Base
|
5
|
-
|
5
|
+
|
6
6
|
attr_accessor :attributes
|
7
|
-
|
7
|
+
|
8
8
|
# Basic initializer, handles quick setting of passed attributes.
|
9
9
|
def initialize args={}
|
10
10
|
self.attributes = {}
|
@@ -21,32 +21,32 @@ class Caren::Base
|
|
21
21
|
self.instance_eval('undef id') if self.respond_to?(:id)
|
22
22
|
self.instance_eval('undef type') if self.respond_to?(:type)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
# List of available attributes for this object
|
26
26
|
def self.keys
|
27
27
|
[ :updated_at, :created_at, :action ]
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
# Root name of the XML array of objects
|
31
31
|
def self.array_root
|
32
32
|
:objects
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
# Name of each XML if converted to XML
|
36
36
|
def self.node_root
|
37
37
|
:object
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
# The relative location of this resource.
|
41
41
|
def self.resource_location
|
42
42
|
raise "No resource location found"
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
# Convert an array of these objects to XML
|
46
46
|
def self.to_xml array
|
47
47
|
array.to_xml( :root => self.array_root )
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
# Convert a XML string to a single object or an array of objects
|
51
51
|
def self.from_xml xml
|
52
52
|
return nil if xml == ''
|
@@ -60,45 +60,45 @@ class Caren::Base
|
|
60
60
|
return self.new( hash )
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
# Convert this object to XML
|
65
65
|
def to_xml options={}
|
66
66
|
self.as_xml.to_xml(options.merge( :root => self.class.node_root ))
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
# Overridable hash of attributes that is used for converting to XML.
|
70
70
|
def as_xml
|
71
71
|
attributes.reject{ |k,v| k == :action }
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
# The absolute (constructed url) to the resource.
|
75
75
|
def self.resource_url id=nil
|
76
76
|
[self.resource_location,id].compact.join("/")
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
def self.search_url key, value
|
80
80
|
"#{self.resource_url}?key=#{key.to_s.dasherize}&value=#{value}"
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
# The absolute (constructed url) to the resource.
|
84
84
|
def resource_url id=nil
|
85
85
|
self.class.resource_url(id)
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def self.hash_from_image hash_or_path
|
89
89
|
return hash_or_path if hash_or_path.is_a?(Hash)
|
90
90
|
{ :name => File.basename(hash_or_path),
|
91
91
|
:content => Base64.encode64(File.open(hash_or_path).read),
|
92
92
|
:content_type => `file -b --mime-type #{hash_or_path}`.gsub(/\n/,"").split(";")[0] }
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
private
|
96
|
-
|
96
|
+
|
97
97
|
# Method missing calls to enable getters/setters
|
98
98
|
def method_missing args, value=nil
|
99
99
|
return self.attributes[args] if self.class.keys.include?(args)
|
100
100
|
return self.attributes[args.to_s.gsub('=','').to_sym] = value if self.class.keys.include?(args.to_s.gsub('=','').to_sym)
|
101
101
|
super
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# This class is just an intermediate for representing potential event occurences.
|
2
|
+
class Caren::EventSlot < Caren::Base
|
3
|
+
|
4
|
+
def self.keys
|
5
|
+
[ :date, # Date
|
6
|
+
:start, # String
|
7
|
+
:duration, # Integer
|
8
|
+
] + super
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.array_root
|
12
|
+
:event_slots
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.node_root
|
16
|
+
:event_slot
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
data/lib/caren/link.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Caren::Link < Caren::Base
|
2
|
-
|
2
|
+
|
3
3
|
def self.keys
|
4
4
|
[:id, # Integer (Caren id)
|
5
5
|
:person_name, # String (Caren person name)
|
@@ -11,19 +11,19 @@ class Caren::Link < Caren::Base
|
|
11
11
|
:status # String (pending,confirmed,cancelled)
|
12
12
|
] + super
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def self.search key, value, session
|
16
16
|
from_xml session.get( self.search_url(key,value) )
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def self.find id, session
|
20
20
|
from_xml session.get(self.resource_url(id))
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def self.all session
|
24
24
|
from_xml session.get(self.resource_url)
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
# Request to create a new link. Example:
|
28
28
|
# Caren::Link.new( :patient_number => 1234 ).create
|
29
29
|
def create session
|
@@ -31,20 +31,20 @@ class Caren::Link < Caren::Base
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def as_xml
|
34
|
-
{ :patient_number => self.patient_number,
|
34
|
+
{ :patient_number => self.patient_number,
|
35
35
|
:external_id => self.external_id }
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def self.array_root
|
39
39
|
:links
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def self.node_root
|
43
43
|
:link
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def self.resource_location
|
47
47
|
"/api/pro/links"
|
48
48
|
end
|
49
|
-
|
50
|
-
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Event", "converting to xml" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@slot_a = Caren::EventSlot.new( :date => Date.today, :start => "10:00", :duration => 3600)
|
7
|
+
@slot_b = Caren::EventSlot.new( :date => Date.today + 1, :start => "10:00", :duration => 7200)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be able to convert an event to valid xml" do
|
11
|
+
@slot_a.should convert_to_valid_caren_xml
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should be able to convert an array of events to valid xml" do
|
15
|
+
[@slot_a,@slot_b].should convert_to_valid_caren_array_xml
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/spec/event_spec.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Event", "converting to xml" do
|
4
|
-
|
4
|
+
|
5
5
|
before do
|
6
|
-
@event_a = Caren::Event.new( :external_id => 1, :name => "Washing", :comment => "Real good", :start => "12:00",
|
7
|
-
:duration => 30, :valid_from => Date.today, :valid_to => Date.today+1.day,
|
6
|
+
@event_a = Caren::Event.new( :external_id => 1, :name => "Washing", :comment => "Real good", :start => "12:00",
|
7
|
+
:duration => 30, :valid_from => Date.today, :valid_to => Date.today+1.day,
|
8
8
|
:person_first_name => "Andre", :person_last_name => "Foeken", :person_male => true, :external_person_id => 100 )
|
9
|
-
|
10
|
-
@event_b = Caren::Event.new( :external_id => 2, :name => "Clothing", :comment => "Real bad",
|
11
|
-
:start => "13:00", :duration => 30, :valid_from => Date.today, :valid_to => Date.today+1.day,
|
9
|
+
|
10
|
+
@event_b = Caren::Event.new( :external_id => 2, :name => "Clothing", :comment => "Real bad",
|
11
|
+
:start => "13:00", :duration => 30, :valid_from => Date.today, :valid_to => Date.today+1.day,
|
12
12
|
:person_first_name => "Oscar", :person_last_name => "Foeken", :person_male => true, :external_person_id => 101 )
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
it "should be able to convert an event to valid xml" do
|
16
16
|
@event_a.should convert_to_valid_caren_xml
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
it "should be able to convert an array of events to valid xml" do
|
20
20
|
[@event_a,@event_b].should convert_to_valid_caren_array_xml
|
21
21
|
end
|
22
|
-
|
23
|
-
end
|
22
|
+
|
23
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,11 +5,11 @@ require 'fakeweb'
|
|
5
5
|
require 'capybara'
|
6
6
|
|
7
7
|
class Integer
|
8
|
-
|
8
|
+
|
9
9
|
def euros
|
10
10
|
self*100
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
end
|
14
14
|
|
15
15
|
# For the tests we need to know both the public and private key, so we share them here.
|
@@ -39,5 +39,5 @@ RSpec::Matchers.define :convert_to_valid_caren_array_xml do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
RSpec.configure do |config|
|
42
|
-
|
43
|
-
end
|
42
|
+
|
43
|
+
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: 51
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 30
|
10
|
+
version: 0.4.30
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andre Foeken
|
@@ -175,6 +175,7 @@ files:
|
|
175
175
|
- lib/caren/client.rb
|
176
176
|
- lib/caren/error.rb
|
177
177
|
- lib/caren/event.rb
|
178
|
+
- lib/caren/event_slot.rb
|
178
179
|
- lib/caren/external_message.rb
|
179
180
|
- lib/caren/link.rb
|
180
181
|
- spec/.DS_Store
|
@@ -183,6 +184,7 @@ files:
|
|
183
184
|
- spec/care_provider_spec.rb
|
184
185
|
- spec/caren_spec.rb
|
185
186
|
- spec/client_spec.rb
|
187
|
+
- spec/event_slot_spec.rb
|
186
188
|
- spec/event_spec.rb
|
187
189
|
- spec/external_message_spec.rb
|
188
190
|
- spec/fixtures/bacon.jpg
|