caren-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.8.7@api
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "i18n"
4
+ gem "active_support"
5
+ gem "builder"
6
+ gem "rest-client"
7
+
8
+ group :development do
9
+ gem "bundler"
10
+ gem "rcov"
11
+ gem "capybara"
12
+ gem "rspec"
13
+ gem "fakeweb", :git => "git://github.com/nedap/fakeweb.git", :branch => "master"
14
+ gem "jeweler"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,72 @@
1
+ GIT
2
+ remote: git://github.com/nedap/fakeweb.git
3
+ revision: c91964160483fa2aeed89945461b50d75b9016b5
4
+ branch: master
5
+ specs:
6
+ fakeweb (1.2.2.1)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ active_support (3.0.0)
12
+ activesupport (= 3.0.0)
13
+ activesupport (3.0.0)
14
+ builder (3.0.0)
15
+ capybara (1.1.1)
16
+ mime-types (>= 1.16)
17
+ nokogiri (>= 1.3.3)
18
+ rack (>= 1.0.0)
19
+ rack-test (>= 0.5.4)
20
+ selenium-webdriver (~> 2.0)
21
+ xpath (~> 0.1.4)
22
+ childprocess (0.2.2)
23
+ ffi (~> 1.0.6)
24
+ diff-lcs (1.1.3)
25
+ ffi (1.0.9)
26
+ git (1.2.5)
27
+ i18n (0.6.0)
28
+ jeweler (1.6.4)
29
+ bundler (~> 1.0)
30
+ git (>= 1.2.5)
31
+ rake
32
+ json_pure (1.6.1)
33
+ mime-types (1.16)
34
+ nokogiri (1.5.0)
35
+ rack (1.3.5)
36
+ rack-test (0.6.1)
37
+ rack (>= 1.0)
38
+ rake (0.8.7)
39
+ rcov (0.9.11)
40
+ rest-client (1.6.7)
41
+ mime-types (>= 1.16)
42
+ rspec (2.7.0)
43
+ rspec-core (~> 2.7.0)
44
+ rspec-expectations (~> 2.7.0)
45
+ rspec-mocks (~> 2.7.0)
46
+ rspec-core (2.7.0)
47
+ rspec-expectations (2.7.0)
48
+ diff-lcs (~> 1.1.2)
49
+ rspec-mocks (2.7.0)
50
+ rubyzip (0.9.4)
51
+ selenium-webdriver (2.8.0)
52
+ childprocess (>= 0.2.1)
53
+ ffi (>= 1.0.7)
54
+ json_pure
55
+ rubyzip
56
+ xpath (0.1.4)
57
+ nokogiri (~> 1.3)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ active_support
64
+ builder
65
+ bundler
66
+ capybara
67
+ fakeweb!
68
+ i18n
69
+ jeweler
70
+ rcov
71
+ rest-client
72
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Andre Foeken
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,21 @@
1
+ = Caren API reference implementation
2
+
3
+ This is the reference implementation for the Caren CareProvider API (http://caren-cares.com).
4
+ To get started you will need a care provider API shared key. Set `Caren::Api.shared_key` to that key.
5
+ Next you will need to set your care provider url `Caren::Api.url` to your specific URL like https://example.caren-cares.com
6
+
7
+ == Contributing to caren-api
8
+
9
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
10
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
11
+ * Fork the project
12
+ * Start a feature/bugfix branch
13
+ * Commit and push until you are happy with your contribution
14
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
15
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
16
+
17
+ == Copyright
18
+
19
+ Copyright (c) 2011 Andre Foeken. See LICENSE.txt for
20
+ further details.
21
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "caren-api"
18
+ gem.homepage = "http://github.com/foeken/caren-api"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Reference implementation of Caren CareProvider API}
21
+ gem.description = %Q{You can use this gem as inspiration of the base of your connections with Caren.}
22
+ gem.email = "andre.foeken@nedap.com"
23
+ gem.authors = ["Andre Foeken"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "caren-api #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/caren-api.gemspec ADDED
@@ -0,0 +1,101 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{caren-api}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andre Foeken"]
12
+ s.date = %q{2011-10-20}
13
+ s.description = %q{You can use this gem as inspiration of the base of your connections with Caren.}
14
+ s.email = %q{andre.foeken@nedap.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".rvmrc",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "caren-api.gemspec",
28
+ "init.rb",
29
+ "lib/caren-api.rb",
30
+ "lib/caren/base.rb",
31
+ "lib/caren/care_provider.rb",
32
+ "lib/caren/caren.rb",
33
+ "lib/caren/error.rb",
34
+ "lib/caren/event.rb",
35
+ "lib/caren/external_message.rb",
36
+ "lib/caren/link.rb",
37
+ "lib/caren/person.rb",
38
+ "spec/.DS_Store",
39
+ "spec/care_provider_spec.rb",
40
+ "spec/caren_spec.rb",
41
+ "spec/event_spec.rb",
42
+ "spec/external_message_spec.rb",
43
+ "spec/fixtures/bacon.jpg",
44
+ "spec/fixtures/caren_care_provider_validation.xml",
45
+ "spec/fixtures/caren_care_providers.xml",
46
+ "spec/fixtures/caren_care_providers_search.xml",
47
+ "spec/fixtures/caren_links.xml",
48
+ "spec/fixtures/caren_links_search.xml",
49
+ "spec/fixtures/caren_unauthorized.xml",
50
+ "spec/link_spec.rb",
51
+ "spec/person_spec.rb",
52
+ "spec/spec.opts",
53
+ "spec/spec_helper.rb"
54
+ ]
55
+ s.homepage = %q{http://github.com/foeken/caren-api}
56
+ s.licenses = ["MIT"]
57
+ s.require_paths = ["lib"]
58
+ s.rubygems_version = %q{1.3.6}
59
+ s.summary = %q{Reference implementation of Caren CareProvider API}
60
+
61
+ if s.respond_to? :specification_version then
62
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
63
+ s.specification_version = 3
64
+
65
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
66
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
67
+ s.add_runtime_dependency(%q<active_support>, [">= 0"])
68
+ s.add_runtime_dependency(%q<builder>, [">= 0"])
69
+ s.add_runtime_dependency(%q<rest-client>, [">= 0"])
70
+ s.add_development_dependency(%q<bundler>, [">= 0"])
71
+ s.add_development_dependency(%q<rcov>, [">= 0"])
72
+ s.add_development_dependency(%q<capybara>, [">= 0"])
73
+ s.add_development_dependency(%q<rspec>, [">= 0"])
74
+ s.add_development_dependency(%q<fakeweb>, [">= 0"])
75
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
76
+ else
77
+ s.add_dependency(%q<i18n>, [">= 0"])
78
+ s.add_dependency(%q<active_support>, [">= 0"])
79
+ s.add_dependency(%q<builder>, [">= 0"])
80
+ s.add_dependency(%q<rest-client>, [">= 0"])
81
+ s.add_dependency(%q<bundler>, [">= 0"])
82
+ s.add_dependency(%q<rcov>, [">= 0"])
83
+ s.add_dependency(%q<capybara>, [">= 0"])
84
+ s.add_dependency(%q<rspec>, [">= 0"])
85
+ s.add_dependency(%q<fakeweb>, [">= 0"])
86
+ s.add_dependency(%q<jeweler>, [">= 0"])
87
+ end
88
+ else
89
+ s.add_dependency(%q<i18n>, [">= 0"])
90
+ s.add_dependency(%q<active_support>, [">= 0"])
91
+ s.add_dependency(%q<builder>, [">= 0"])
92
+ s.add_dependency(%q<rest-client>, [">= 0"])
93
+ s.add_dependency(%q<bundler>, [">= 0"])
94
+ s.add_dependency(%q<rcov>, [">= 0"])
95
+ s.add_dependency(%q<capybara>, [">= 0"])
96
+ s.add_dependency(%q<rspec>, [">= 0"])
97
+ s.add_dependency(%q<fakeweb>, [">= 0"])
98
+ s.add_dependency(%q<jeweler>, [">= 0"])
99
+ end
100
+ end
101
+
data/init.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "lib/caren.rb"
2
+
3
+ Caren::Api.url = "https://www.carenzorgt.nl"
4
+ Caren::Api.shared_key = ""
data/lib/caren/base.rb ADDED
@@ -0,0 +1,86 @@
1
+ # The base class for all API objects that can be converted to XML.
2
+ # The class provides basic functionality to convert objects to and from xml based
3
+ # on the default Caren API format.
4
+ class Caren::Base
5
+
6
+ attr_accessor :attributes
7
+
8
+ # Basic initializer, handles quick setting of passed attributes.
9
+ def initialize args={}
10
+ self.attributes = {}
11
+ self.class.keys.each do |key|
12
+ self.attributes[key] = args[key] || args[key.to_s] || nil
13
+ end
14
+ end
15
+
16
+ # List of available attributes for this object
17
+ def self.keys
18
+ []
19
+ end
20
+
21
+ # Root name of the XML array of objects
22
+ def self.array_root
23
+ :objects
24
+ end
25
+
26
+ # Name of each XML if converted to XML
27
+ def self.node_root
28
+ :object
29
+ end
30
+
31
+ # The relative location of this resource.
32
+ def self.resource_location
33
+ raise "No resource location found"
34
+ end
35
+
36
+ # Convert an array of these objects to XML
37
+ def self.to_xml array
38
+ array.to_xml( :root => self.array_root )
39
+ end
40
+
41
+ # Convert a XML string to a single object or an array of objects
42
+ def self.from_xml xml
43
+ hash = xml.is_a?(Hash) ? xml : Hash.from_xml(xml)
44
+ if hash.has_key?(self.array_root.to_s)
45
+ return hash[self.array_root.to_s].map{ |h| self.from_xml(h) }
46
+ elsif hash.has_key?(self.node_root)
47
+ return self.new( hash[self.node_root.to_s] )
48
+ else
49
+ return self.new( hash )
50
+ end
51
+ end
52
+
53
+ # Convert this object to XML
54
+ def to_xml options={}
55
+ self.as_xml.to_xml(options.merge( :root => self.class.node_root ))
56
+ end
57
+
58
+ # Overridable hash of attributes that is used for converting to XML.
59
+ def as_xml
60
+ attributes
61
+ end
62
+
63
+ # The absolute (constructed url) to the resource.
64
+ def self.resource_url id=nil
65
+ "#{Caren::Api.url}#{self.resource_location}#{id}"
66
+ end
67
+
68
+ def self.search_url key, value
69
+ "#{self.resource_url}?key=#{key.to_s.dasherize}&value=#{value}"
70
+ end
71
+
72
+ # The absolute (constructed url) to the resource.
73
+ def resource_url id=nil
74
+ self.class.resource_url(id)
75
+ end
76
+
77
+ private
78
+
79
+ # Method missing calls to enable getters/setters
80
+ def method_missing args, value=nil
81
+ return self.attributes[args] if self.class.keys.include?(args)
82
+ return self.attributes[args] = value if self.class.keys.include?(args.to_s.gsub('=','').to_sym)
83
+ super
84
+ end
85
+
86
+ end
@@ -0,0 +1,86 @@
1
+ # The CareProvider class enables the following features:
2
+ # * Update care provider settings
3
+ # * Get a list of care providers
4
+ # * Search for a specific care provider based on key/value
5
+ class Caren::CareProvider < Caren::Base
6
+
7
+ def self.keys
8
+ [ :caren_id, # String (The id of this CP inside Caren)
9
+ :name, # String
10
+ :telephone, # String
11
+ :website, # String
12
+ :email, # String
13
+ :address_line, # String (Kerkstraat 1, 7522AH, Enschede)
14
+ :url_shortcut, # String
15
+ :time_zone, # String (Amsterdam)
16
+ :resolution, # String (exact,daypart,range)
17
+ :bandwidth, # Integer (60 -> 60 minutes)
18
+ :show_employee_names, # Boolean
19
+ :max_start, # String (23:00)
20
+ :min_start, # String (07:00)
21
+ :show_employee_name_as_title, # Boolean
22
+ :communication # Boolean
23
+ ]
24
+ end
25
+
26
+ def self.search key, value
27
+ from_xml Caren::Api.get( self.search_url(key,value) )
28
+ end
29
+
30
+ def self.all
31
+ from_xml Caren::Api.get(self.resource_url)
32
+ end
33
+
34
+ def update
35
+ Caren::Api.put(self.resource_url(self.caren_id), self.to_xml)
36
+ end
37
+
38
+ def update_logo logo_hash_or_path
39
+ Caren::Api.put(self.resource_url(self.caren_id), self.to_logo_xml(logo_hash_or_path))
40
+ end
41
+
42
+ def as_xml
43
+ { :name => self.name,
44
+ :telephone => self.telephone,
45
+ :website => self.website,
46
+ :email => self.email,
47
+ :address_line => self.address_line,
48
+ :url_shortcut => self.url_shortcut,
49
+ :time_zone => self.time_zone,
50
+ :resolution => self.resolution,
51
+ :bandwidth => self.bandwidth,
52
+ :min_start => self.min_start,
53
+ :max_start => self.max_start,
54
+ :show_employee_name_as_title => self.show_employee_name_as_title,
55
+ :show_employee_names => self.show_employee_names,
56
+ :communication => self.communication }
57
+ end
58
+
59
+ def to_logo_xml logo_hash_or_path
60
+ builder = Builder::XmlMarkup.new
61
+ logo = self.class.logo_hash(logo_hash_or_path)
62
+ xml = builder.care_provider do |care_provider|
63
+ care_provider.tag!("logo", logo[:content], "name" => logo[:name], "content-type" => logo[:content_type] ) if logo
64
+ end
65
+ end
66
+
67
+ def self.logo_hash logo_hash_or_path
68
+ return logo_hash_or_path if logo_hash_or_path.is_a?(Hash)
69
+ { :name => File.basename(logo_hash_or_path),
70
+ :content => Base64.encode64(File.open(logo_hash_or_path).read),
71
+ :content_type => `file -Ib #{logo_hash_or_path}`.gsub(/\n/,"").split(";")[0] }
72
+ end
73
+
74
+ def self.resource_location
75
+ "/api/care_providers/"
76
+ end
77
+
78
+ def self.array_root
79
+ :care_providers
80
+ end
81
+
82
+ def self.node_root
83
+ :care_provider
84
+ end
85
+
86
+ end
@@ -0,0 +1,91 @@
1
+ module Caren
2
+
3
+ module Exceptions
4
+
5
+ class StandardError < ::StandardError ; end
6
+
7
+ class SignatureMismatch < Caren::Exceptions::StandardError ; end
8
+
9
+ class ServerSideError < Caren::Exceptions::StandardError
10
+
11
+ attr_accessor :errors
12
+
13
+ def initialize errors=[]
14
+ self.errors = errors
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+
21
+ class Api
22
+ class << self
23
+ attr_accessor :shared_key
24
+ attr_accessor :url
25
+ end
26
+
27
+ def self.put url, xml
28
+ begin
29
+ response = RestClient.put url, xml, :content_type => :xml, :accept => :xml, :signature => Caren::Api.sign(xml)
30
+ return check_signature(response)
31
+ rescue RestClient::Exception => e
32
+ handle_error(e.response)
33
+ end
34
+ end
35
+
36
+ def self.post url, xml
37
+ begin
38
+ response = RestClient.post url, xml, :content_type => :xml, :accept => :xml, :signature => Caren::Api.sign(xml)
39
+ return check_signature(response)
40
+ rescue RestClient::Exception => e
41
+ handle_error(e.response)
42
+ end
43
+ end
44
+
45
+ def self.delete url
46
+ begin
47
+ response = RestClient.delete url, :content_type => :xml, :accept => :xml, :signature => Caren::Api.sign
48
+ return check_signature(response)
49
+ rescue RestClient::Exception => e
50
+ handle_error(e.response)
51
+ end
52
+ end
53
+
54
+ def self.get url
55
+ begin
56
+ response = RestClient.get url, :content_type => :xml, :accept => :xml, :signature => Caren::Api.sign
57
+ return check_signature(response)
58
+ rescue RestClient::Exception => e
59
+ handle_error(e.response)
60
+ end
61
+ end
62
+
63
+ def self.sign string=""
64
+ raise "No API key given: Caren::Api.shared_key" unless Caren::Api.shared_key
65
+ Digest::SHA256.hexdigest(string+Caren::Api.shared_key)
66
+ end
67
+
68
+ private
69
+
70
+ def self.check_signature response
71
+ return response if response.headers[:signature] == Caren::Api.sign(response.to_str)
72
+ raise Caren::Exceptions::SignatureMismatch.new
73
+ end
74
+
75
+ def self.handle_error response
76
+ errors = []
77
+ doc = REXML::Document.new(response)
78
+ doc.elements.each('errors/error') do |error|
79
+ if error.attributes["category"] == "validation"
80
+ attrs = { :on => error.attributes["on"].to_s.underscore.to_sym }
81
+ errors << Caren::ValidationError.new( error.attributes["category"], error.text.strip, attrs )
82
+ else
83
+ errors << Caren::Error.new( error.attributes["category"], error.text.strip )
84
+ end
85
+ end
86
+ raise Caren::Exceptions::ServerSideError.new(errors)
87
+ end
88
+
89
+ end
90
+
91
+ end
@@ -0,0 +1,24 @@
1
+ # This class provides a wrapper for caren's server side errors.
2
+ class Caren::Error
3
+
4
+ attr_accessor :category, :message, :attributes
5
+
6
+ def initialize category, message="", attributes={}
7
+ self.category = category
8
+ self.message = message
9
+ self.attributes = attributes
10
+ end
11
+
12
+ end
13
+
14
+ class Caren::ValidationError < Caren::Error
15
+
16
+ def field
17
+ attributes[:on]
18
+ end
19
+
20
+ def to_s
21
+ "`#{field}` #{message}"
22
+ end
23
+
24
+ end
@@ -0,0 +1,28 @@
1
+ # This class is just an intermediate for exporting events to Caren.
2
+ # It has the correct format for exports.
3
+ class Caren::Event < Caren::Base
4
+
5
+ def self.keys
6
+ [ :external_id, # String Unique identifying string (Your event id)
7
+ :name, # String
8
+ :comment, # String
9
+ :start, # String (14:00)
10
+ :duration, # Integer
11
+ :valid_from, # Date
12
+ :valid_to, # Date
13
+ :person_first_name, # String
14
+ :person_last_name, # String
15
+ :person_male, # Boolean
16
+ :external_person_id # String (Your person id)
17
+ ]
18
+ end
19
+
20
+ def self.array_root
21
+ :events
22
+ end
23
+
24
+ def self.node_root
25
+ :event
26
+ end
27
+
28
+ end
@@ -0,0 +1,52 @@
1
+ class Caren::ExternalMessage < Caren::Base
2
+
3
+ def self.keys
4
+ [ :caren_id, # String (Caren message id)
5
+ :person_name, # String (Andre Foeken)
6
+ :external_person_id, # String (Your person id)
7
+ :body, # Text
8
+ :external_id, # String (Your message id)
9
+ :in_reply_to_id, # Integer (Caren message id)
10
+ :subject_id # Integer (Caren person id)
11
+ ]
12
+ end
13
+
14
+ def create
15
+ Caren::Api.post self.class.resource_url(self.subject_id), self.to_xml
16
+ end
17
+
18
+ def delete
19
+ Caren::Api.delete self.class.resource_url(self.subject_id,self.caren_id)
20
+ end
21
+
22
+ def self.array_root
23
+ :external_messages
24
+ end
25
+
26
+ def self.node_root
27
+ :external_message
28
+ end
29
+
30
+ def as_xml
31
+ { :person_name => self.person_name,
32
+ :external_person_id => self.external_person_id,
33
+ :body => self.body,
34
+ :external_id => self.external_id,
35
+ :in_reply_to_id => self.in_reply_to_id }
36
+ end
37
+
38
+ def self.resource_location
39
+ "/api/people/%i/external_messages/"
40
+ end
41
+
42
+ private
43
+
44
+ def resource_url subject_id, id=nil
45
+ self.class.resource_url(subject_id,id)
46
+ end
47
+
48
+ def self.resource_url subject_id, id=nil
49
+ "#{Caren::Api.url}#{self.resource_location % subject_id}#{id}"
50
+ end
51
+
52
+ end