caren-api 0.4.3 → 0.4.4

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/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm use 1.8.7@api
1
+ rvm use 1.8.7@caren-api
data/Gemfile CHANGED
@@ -3,13 +3,13 @@ source "http://rubygems.org"
3
3
  gem "i18n", ">= 0"
4
4
  gem "activesupport", ">= 0"
5
5
  gem "builder", ">= 0"
6
- gem "rest-client", ">= 0"
6
+ gem "rest-client", "1.6.7"
7
7
 
8
8
  group :development do
9
9
  gem "bundler"
10
10
  gem "rcov"
11
11
  gem "capybara"
12
12
  gem "rspec"
13
- gem "fakeweb", :git => "git://github.com/nedap/fakeweb.git", :branch => "master"
13
+ gem "fakeweb"
14
14
  gem "jeweler"
15
- end
15
+ end
data/Gemfile.lock CHANGED
@@ -1,14 +1,8 @@
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
1
  GEM
9
2
  remote: http://rubygems.org/
10
3
  specs:
11
- activesupport (3.0.0)
4
+ activesupport (3.1.1)
5
+ multi_json (~> 1.0)
12
6
  builder (3.0.0)
13
7
  capybara (1.1.1)
14
8
  mime-types (>= 1.16)
@@ -20,6 +14,7 @@ GEM
20
14
  childprocess (0.2.2)
21
15
  ffi (~> 1.0.6)
22
16
  diff-lcs (1.1.3)
17
+ fakeweb (1.3.0)
23
18
  ffi (1.0.9)
24
19
  git (1.2.5)
25
20
  i18n (0.6.0)
@@ -28,12 +23,13 @@ GEM
28
23
  git (>= 1.2.5)
29
24
  rake
30
25
  json_pure (1.6.1)
31
- mime-types (1.16)
26
+ mime-types (1.17.1)
27
+ multi_json (1.0.3)
32
28
  nokogiri (1.5.0)
33
29
  rack (1.3.5)
34
30
  rack-test (0.6.1)
35
31
  rack (>= 1.0)
36
- rake (0.8.7)
32
+ rake (0.9.2.2)
37
33
  rcov (0.9.11)
38
34
  rest-client (1.6.7)
39
35
  mime-types (>= 1.16)
@@ -41,14 +37,14 @@ GEM
41
37
  rspec-core (~> 2.7.0)
42
38
  rspec-expectations (~> 2.7.0)
43
39
  rspec-mocks (~> 2.7.0)
44
- rspec-core (2.7.0)
40
+ rspec-core (2.7.1)
45
41
  rspec-expectations (2.7.0)
46
42
  diff-lcs (~> 1.1.2)
47
43
  rspec-mocks (2.7.0)
48
44
  rubyzip (0.9.4)
49
- selenium-webdriver (2.8.0)
45
+ selenium-webdriver (2.9.1)
50
46
  childprocess (>= 0.2.1)
51
- ffi (>= 1.0.7)
47
+ ffi (= 1.0.9)
52
48
  json_pure
53
49
  rubyzip
54
50
  xpath (0.1.4)
@@ -62,9 +58,9 @@ DEPENDENCIES
62
58
  builder
63
59
  bundler
64
60
  capybara
65
- fakeweb!
61
+ fakeweb
66
62
  i18n
67
63
  jeweler
68
64
  rcov
69
- rest-client
65
+ rest-client (= 1.6.7)
70
66
  rspec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.3
1
+ 0.4.4
data/caren-api.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{caren-api}
8
- s.version = "0.4.3"
8
+ s.version = "0.4.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andre Foeken"]
12
- s.date = %q{2011-10-21}
12
+ s.date = %q{2011-10-26}
13
13
  s.description = %q{You can use this gem as inspiration of the base of your connections with Caren.}
14
14
  s.email = %q{andre.foeken@nedap.com}
15
15
  s.extra_rdoc_files = [
@@ -38,6 +38,8 @@ Gem::Specification.new do |s|
38
38
  "lib/caren/external_message.rb",
39
39
  "lib/caren/link.rb",
40
40
  "lib/caren/person.rb",
41
+ "lib/caren/product.rb",
42
+ "lib/caren/product_category.rb",
41
43
  "spec/.DS_Store",
42
44
  "spec/care_provider_spec.rb",
43
45
  "spec/caren_spec.rb",
@@ -47,12 +49,20 @@ Gem::Specification.new do |s|
47
49
  "spec/fixtures/caren_care_provider_validation.xml",
48
50
  "spec/fixtures/caren_care_providers.xml",
49
51
  "spec/fixtures/caren_care_providers_search.xml",
52
+ "spec/fixtures/caren_external_messages.xml",
50
53
  "spec/fixtures/caren_links.xml",
51
54
  "spec/fixtures/caren_links_search.xml",
55
+ "spec/fixtures/caren_product_categories.xml",
56
+ "spec/fixtures/caren_product_categories_search.xml",
57
+ "spec/fixtures/caren_products.xml",
58
+ "spec/fixtures/caren_products_search.xml",
52
59
  "spec/fixtures/caren_unauthorized.xml",
53
60
  "spec/fixtures/incoming.xml",
61
+ "spec/fixtures/incoming_single_object.xml",
54
62
  "spec/link_spec.rb",
55
63
  "spec/person_spec.rb",
64
+ "spec/product_category_spec.rb",
65
+ "spec/product_spec.rb",
56
66
  "spec/spec.opts",
57
67
  "spec/spec_helper.rb"
58
68
  ]
@@ -70,7 +80,7 @@ Gem::Specification.new do |s|
70
80
  s.add_runtime_dependency(%q<i18n>, [">= 0"])
71
81
  s.add_runtime_dependency(%q<activesupport>, [">= 0"])
72
82
  s.add_runtime_dependency(%q<builder>, [">= 0"])
73
- s.add_runtime_dependency(%q<rest-client>, [">= 0"])
83
+ s.add_runtime_dependency(%q<rest-client>, ["= 1.6.7"])
74
84
  s.add_development_dependency(%q<bundler>, [">= 0"])
75
85
  s.add_development_dependency(%q<rcov>, [">= 0"])
76
86
  s.add_development_dependency(%q<capybara>, [">= 0"])
@@ -81,7 +91,7 @@ Gem::Specification.new do |s|
81
91
  s.add_dependency(%q<i18n>, [">= 0"])
82
92
  s.add_dependency(%q<activesupport>, [">= 0"])
83
93
  s.add_dependency(%q<builder>, [">= 0"])
84
- s.add_dependency(%q<rest-client>, [">= 0"])
94
+ s.add_dependency(%q<rest-client>, ["= 1.6.7"])
85
95
  s.add_dependency(%q<bundler>, [">= 0"])
86
96
  s.add_dependency(%q<rcov>, [">= 0"])
87
97
  s.add_dependency(%q<capybara>, [">= 0"])
@@ -93,7 +103,7 @@ Gem::Specification.new do |s|
93
103
  s.add_dependency(%q<i18n>, [">= 0"])
94
104
  s.add_dependency(%q<activesupport>, [">= 0"])
95
105
  s.add_dependency(%q<builder>, [">= 0"])
96
- s.add_dependency(%q<rest-client>, [">= 0"])
106
+ s.add_dependency(%q<rest-client>, ["= 1.6.7"])
97
107
  s.add_dependency(%q<bundler>, [">= 0"])
98
108
  s.add_dependency(%q<rcov>, [">= 0"])
99
109
  s.add_dependency(%q<capybara>, [">= 0"])
data/lib/caren/base.rb CHANGED
@@ -17,7 +17,7 @@ class Caren::Base
17
17
 
18
18
  # List of available attributes for this object
19
19
  def self.keys
20
- []
20
+ [ :updated_at, :created_at, :action ]
21
21
  end
22
22
 
23
23
  # Root name of the XML array of objects
@@ -43,6 +43,7 @@ class Caren::Base
43
43
  # Convert a XML string to a single object or an array of objects
44
44
  def self.from_xml xml
45
45
  hash = xml.is_a?(Hash) ? xml : Hash.from_xml(xml)
46
+ raise Caren::Exceptions::InvalidXmlResponse unless hash
46
47
  if hash.has_key?(self.array_root.to_s)
47
48
  return hash[self.array_root.to_s].map{ |h| self.from_xml(h) }
48
49
  elsif hash.has_key?(self.node_root)
@@ -76,6 +77,13 @@ class Caren::Base
76
77
  self.class.resource_url(id)
77
78
  end
78
79
 
80
+ def self.hash_from_image hash_or_path
81
+ return hash_or_path if hash_or_path.is_a?(Hash)
82
+ { :name => File.basename(hash_or_path),
83
+ :content => Base64.encode64(File.open(hash_or_path).read),
84
+ :content_type => `file -Ib #{hash_or_path}`.gsub(/\n/,"").split(";")[0] }
85
+ end
86
+
79
87
  private
80
88
 
81
89
  # Method missing calls to enable getters/setters
@@ -5,12 +5,13 @@
5
5
  class Caren::CareProvider < Caren::Base
6
6
 
7
7
  def self.keys
8
- [ :id, # String (The id of this CP inside Caren)
8
+ [ :id, # Integer (The id of this CP inside Caren)
9
9
  :name, # String
10
10
  :telephone, # String
11
11
  :website, # String
12
12
  :email, # String
13
13
  :address_line, # String (Kerkstraat 1, 7522AH, Enschede)
14
+ :logo, # String
14
15
  :url_shortcut, # String
15
16
  :time_zone, # String (Amsterdam)
16
17
  :resolution, # String (exact,daypart,range)
@@ -22,7 +23,7 @@ class Caren::CareProvider < Caren::Base
22
23
  :communication, # Boolean
23
24
  :api_push_support, # Boolean
24
25
  :api_url # String (Required url to api resources)
25
- ]
26
+ ] + super
26
27
  end
27
28
 
28
29
  def self.search key, value, session
@@ -62,19 +63,12 @@ class Caren::CareProvider < Caren::Base
62
63
 
63
64
  def to_logo_xml logo_hash_or_path
64
65
  builder = Builder::XmlMarkup.new
65
- logo = self.class.logo_hash(logo_hash_or_path)
66
+ logo = self.class.hash_from_image(logo_hash_or_path)
66
67
  xml = builder.care_provider do |care_provider|
67
68
  care_provider.tag!("logo", logo[:content], "name" => logo[:name], "content-type" => logo[:content_type] ) if logo
68
69
  end
69
70
  end
70
-
71
- def self.logo_hash logo_hash_or_path
72
- return logo_hash_or_path if logo_hash_or_path.is_a?(Hash)
73
- { :name => File.basename(logo_hash_or_path),
74
- :content => Base64.encode64(File.open(logo_hash_or_path).read),
75
- :content_type => `file -Ib #{logo_hash_or_path}`.gsub(/\n/,"").split(";")[0] }
76
- end
77
-
71
+
78
72
  def self.resource_location
79
73
  "/api/pro/care_providers/"
80
74
  end
data/lib/caren/caren.rb CHANGED
@@ -6,6 +6,8 @@ module Caren
6
6
 
7
7
  class SignatureMismatch < Caren::Exceptions::StandardError ; end
8
8
 
9
+ class InvalidXmlResponse < Caren::Exceptions::StandardError ; end
10
+
9
11
  class ServerSideError < Caren::Exceptions::StandardError
10
12
 
11
13
  attr_accessor :errors
@@ -102,20 +104,48 @@ module Caren
102
104
  }
103
105
  end
104
106
 
107
+ # These types of Caren objects are supported by the Caren::Api.incoming method
108
+ def self.supported_incoming_single_objects
109
+ singles = {}
110
+ self.supported_incoming_objects.each do |object,klass|
111
+ singles[ klass.node_root ] = klass
112
+ end
113
+ return singles
114
+ end
115
+
105
116
  # Pass an XML string to be handled. Only a valid caren_objects xml hash will be parsed.
106
- def incoming xml, signature
107
- if self.verify_signature(signature,xml)
108
- objects = []
109
- hash = Hash.from_xml(xml)["caren_objects"]
110
- Caren::Api.supported_incoming_objects.each do |key,klass|
111
- objects << (hash[key]||hash[key.to_s]||[]).map{ |h| klass.new(h) }
112
- end
113
- return objects.flatten
117
+ def incoming xml, signature, timestamp
118
+ if self.verify_signature(signature,timestamp, xml)
119
+ return parse(xml)
114
120
  else
115
121
  raise Caren::Exceptions::SignatureMismatch.new
116
122
  end
117
123
  end
118
124
 
125
+ def parse xml
126
+ objects = []
127
+ hash = Hash.from_xml(xml)
128
+ if hash["caren_objects"]
129
+ hash = hash["caren_objects"]
130
+ end
131
+ Caren::Api.supported_incoming_objects.each do |key,klass|
132
+ objects << (hash[key]||hash[key.to_s]||[]).map{ |h| klass.new(h) }
133
+ end
134
+ return objects.flatten
135
+ end
136
+
137
+ def parse_object xml
138
+ hash = Hash.from_xml(xml)
139
+ #todo: rewrite so we lookup the xml tag in the supported_incoming_single_objects hash, faster :)
140
+ Caren::Api.supported_incoming_single_objects.each do |key, klass|
141
+ object = hash[key] || hash[key.to_s]
142
+ if object
143
+ return klass.new(object)
144
+ end
145
+ end
146
+ end
147
+
148
+
119
149
  # Sign your string and timestamp using private key
120
150
  # Timestamp is UNIX timestamp seconds since 1970
121
151
  def sign timestamp, string=nil, private_key=self.private_key
@@ -132,6 +162,7 @@ module Caren
132
162
 
133
163
  # Verify the signature using the caren public key
134
164
  def verify_signature signature, timestamp, string=nil, public_key=self.caren_public_key
165
+ return false unless public_key
135
166
  signature = Base64.decode64(CGI.unescape(signature.to_s))
136
167
  public_key.verify( "sha1", signature, string.to_s + timestamp.to_s )
137
168
  end
@@ -149,8 +180,7 @@ module Caren
149
180
  else
150
181
  errors << Caren::Error.new( error.attributes["category"], error.text.strip )
151
182
  end
152
- end
153
- y errors
183
+ end
154
184
  raise Caren::Exceptions::ServerSideError.new(errors)
155
185
  end
156
186
 
data/lib/caren/event.rb CHANGED
@@ -14,7 +14,7 @@ class Caren::Event < Caren::Base
14
14
  :person_last_name, # String
15
15
  :person_male, # Boolean
16
16
  :external_person_id # String (Your person id)
17
- ]
17
+ ] + super
18
18
  end
19
19
 
20
20
  def self.array_root
@@ -1,17 +1,23 @@
1
1
  class Caren::ExternalMessage < Caren::Base
2
2
 
3
3
  def self.keys
4
- [ :id, # String (Caren message id)
4
+ [ :id, # Integer (Caren message id)
5
5
  :person_name, # String (Andre Foeken)
6
+ :person_id, # Integer (Caren person id)
6
7
  :external_person_id, # String (Your person id)
8
+ :care_provider_id, # Integer (Caren CP id)
7
9
  :body, # Text
8
10
  :external_id, # String (Your message id)
9
11
  :in_reply_to_id, # Integer (Caren message id)
10
12
  :in_reply_to_type, # The type of message this is a reply to. (Always ExternalMessage if reply is set)
11
13
  :subject_id # Integer (Caren person id)
12
- ]
14
+ ] + super
13
15
  end
14
-
16
+
17
+ def self.all subject_id, session
18
+ from_xml session.get(self.resource_url(subject_id))
19
+ end
20
+
15
21
  def create session
16
22
  session.post self.class.resource_url(self.subject_id), self.to_xml
17
23
  end
data/lib/caren/link.rb CHANGED
@@ -1,14 +1,15 @@
1
1
  class Caren::Link < Caren::Base
2
2
 
3
3
  def self.keys
4
- [:id, # String (Caren id)
5
- :person_name, # String (Caren person name)
6
- :person_id, # String (Caren person id)
7
- :person_photo, # String (url of photo)
8
- :patient_number, # String (12345)
9
- :external_id, # String (Your person id)
10
- :status # String (pending,confirmed,cancelled)
11
- ]
4
+ [:id, # Integer (Caren id)
5
+ :person_name, # String (Caren person name)
6
+ :care_provider_id, # Integer
7
+ :person_id, # String (Caren person id)
8
+ :person_photo, # String (url of photo)
9
+ :patient_number, # String (12345)
10
+ :external_id, # String (Your person id)
11
+ :status # String (pending,confirmed,cancelled)
12
+ ] + super
12
13
  end
13
14
 
14
15
  def self.search key, value, session
data/lib/caren/person.rb CHANGED
@@ -11,7 +11,7 @@ class Caren::Person < Caren::Base
11
11
  :address_zipcode, # String
12
12
  :address_city, # String
13
13
  :address_country # String
14
- ]
14
+ ] + super
15
15
  end
16
16
 
17
17
  def self.array_root
@@ -0,0 +1,75 @@
1
+ class Caren::Product < Caren::Base
2
+
3
+ def self.keys
4
+ [ :id, # Integer (Id of this product in Caren)
5
+ :name, # String
6
+ :description, # Text
7
+ :care_provider_id, # Integer (Care provider id)
8
+ :product_category_id, # Integer (Reference to product category; Caren id)
9
+ :photo, # String
10
+ :in_store, # Boolean (Use in store)
11
+ :unit, # String (piece, minute, hour)
12
+ :price, # Integer (in eurocents)
13
+ :rounding, # Integer (in minutes)
14
+ :min_amount, # Integer (in minutes)
15
+ :status, # String (pending, active)
16
+ :valid_from, # Date
17
+ :valid_to # Date
18
+ ] + super
19
+ end
20
+
21
+ def self.search key, value, session
22
+ from_xml session.get( self.search_url(key,value) )
23
+ end
24
+
25
+ def self.all session
26
+ from_xml session.get(self.resource_url)
27
+ end
28
+
29
+ def create session
30
+ session.post(self.resource_url, self.to_xml)
31
+ end
32
+
33
+ def update session
34
+ session.put(self.resource_url(self.id), self.to_xml)
35
+ end
36
+
37
+ def update_photo photo_hash_or_path, session
38
+ session.put(self.resource_url(self.id), self.to_photo_xml(photo_hash_or_path))
39
+ end
40
+
41
+ def as_xml
42
+ { :name => self.name,
43
+ :description => self.description,
44
+ :product_category_id => self.product_category_id,
45
+ :in_store => self.in_store,
46
+ :unit => self.unit,
47
+ :price => self.price,
48
+ :rounding => self.rounding,
49
+ :min_amount => self.min_amount,
50
+ :valid_from => self.valid_from,
51
+ :valid_to => self.valid_to
52
+ }
53
+ end
54
+
55
+ def to_photo_xml photo_hash_or_path
56
+ builder = Builder::XmlMarkup.new
57
+ photo = self.class.hash_from_image(photo_hash_or_path)
58
+ xml = builder.product do |product|
59
+ product.tag!("photo", photo[:content], "name" => photo[:name], "content-type" => photo[:content_type] ) if photo
60
+ end
61
+ end
62
+
63
+ def self.array_root
64
+ :products
65
+ end
66
+
67
+ def self.node_root
68
+ :product
69
+ end
70
+
71
+ def self.resource_location
72
+ "/api/pro/products/"
73
+ end
74
+
75
+ end
@@ -0,0 +1,32 @@
1
+ class Caren::ProductCategory < Caren::Base
2
+
3
+ def self.keys
4
+ [ :id, # Integer (Id of this category in Caren)
5
+ :name, # String
6
+ :description, # Text
7
+ :icon, # String
8
+ :product_category_id # Integer (Parent category; Caren id; Nil for root node)
9
+ ] + super
10
+ end
11
+
12
+ def self.search key, value, session
13
+ from_xml session.get( self.search_url(key,value) )
14
+ end
15
+
16
+ def self.all session
17
+ from_xml session.get(self.resource_url)
18
+ end
19
+
20
+ def self.array_root
21
+ :product_categories
22
+ end
23
+
24
+ def self.node_root
25
+ :product_category
26
+ end
27
+
28
+ def self.resource_location
29
+ "/api/pro/product_categories/"
30
+ end
31
+
32
+ end
data/lib/caren-api.rb CHANGED
@@ -18,4 +18,6 @@ require "#{File.dirname(__FILE__)}/caren/event.rb"
18
18
  require "#{File.dirname(__FILE__)}/caren/person.rb"
19
19
  require "#{File.dirname(__FILE__)}/caren/care_provider.rb"
20
20
  require "#{File.dirname(__FILE__)}/caren/external_message.rb"
21
- require "#{File.dirname(__FILE__)}/caren/link.rb"
21
+ require "#{File.dirname(__FILE__)}/caren/link.rb"
22
+ require "#{File.dirname(__FILE__)}/caren/product.rb"
23
+ require "#{File.dirname(__FILE__)}/caren/product_category.rb"
@@ -59,7 +59,7 @@ 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
- logo = Caren::CareProvider.logo_hash( filename )
62
+ logo = Caren::CareProvider.hash_from_image( filename )
63
63
  logo[:content_type].should == "image/jpeg"
64
64
  logo[:name].should == "bacon.jpg"
65
65
  logo[:content].should == Base64.encode64(File.open(filename).read)
@@ -72,7 +72,7 @@ describe "CareProvider", "REST methods" do
72
72
  before do
73
73
  care_providers = File.read("spec/fixtures/caren_care_providers.xml")
74
74
  care_providers_search = File.read("spec/fixtures/caren_care_providers_search.xml")
75
-
75
+
76
76
  care_provider_url = Caren::Api.session.url_for( Caren::CareProvider.resource_url(1) )
77
77
  care_providers_url = Caren::Api.session.url_for( Caren::CareProvider.resource_url )
78
78
  search_url = Caren::Api.session.url_for( "#{Caren::CareProvider.resource_url}?key=url-shortcut&value=pantein" )
data/spec/caren_spec.rb CHANGED
@@ -73,7 +73,8 @@ describe "Caren", "signature checks" do
73
73
 
74
74
  it "should be able to handle incoming xml from caren" do
75
75
  incoming = File.read "spec/fixtures/incoming.xml"
76
- results = Caren::Api.session.incoming(incoming, Caren::Api.session.sign(incoming))
76
+ timestamp = DateTime.now.to_i
77
+ results = Caren::Api.session.incoming(incoming, Caren::Api.session.sign(timestamp, incoming), timestamp )
77
78
  results.should have(4).things
78
79
  external_messages = results.select{ |x| x.is_a?(Caren::ExternalMessage) }
79
80
  external_messages.first.id.should == 1
@@ -81,4 +82,11 @@ describe "Caren", "signature checks" do
81
82
  links.last.id.should == 3
82
83
  end
83
84
 
85
+ it "should be able to parse just one incoming object from xml from caren" do
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 ...'
89
+ object.id.should == 1
90
+ end
91
+
84
92
  end
@@ -29,14 +29,23 @@ end
29
29
  describe "ExternalMessage", "REST methods" do
30
30
 
31
31
  before do
32
- post_url = Caren::Api.session.url_for( Caren::ExternalMessage.resource_url(1) )
32
+ messages = File.read("spec/fixtures/caren_external_messages.xml")
33
+
34
+ messages_url = Caren::Api.session.url_for( Caren::ExternalMessage.resource_url(1) )
33
35
  delete_url = Caren::Api.session.url_for( Caren::ExternalMessage.resource_url(1,1) )
34
36
  timestamp = DateTime.now.to_i
35
37
 
36
- FakeWeb.register_uri(:post, post_url, :status => 201, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
38
+ FakeWeb.register_uri(:get, messages_url, :body => messages, :signature => Caren::Api.session.sign(timestamp,messages), :timestamp => timestamp )
39
+ FakeWeb.register_uri(:post, messages_url, :status => 201, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
37
40
  FakeWeb.register_uri(:delete, delete_url, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
38
41
  end
39
42
 
43
+ it "should be able to find all external messages" do
44
+ messages = Caren::ExternalMessage.all 1, Caren::Api.session
45
+ messages.should have(2).things
46
+ messages.first.body.should == "Test"
47
+ end
48
+
40
49
  it "should be able to create an external message" do
41
50
  lambda{ Caren::ExternalMessage.new( :person_name => "Andre Foeken",
42
51
  :external_person_id => 1,
@@ -0,0 +1,27 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <external-messages type="array">
3
+ <external-message>
4
+ <created-at type="datetime">2011-09-09T15:14:13+02:00</created-at>
5
+ <body>Test</body>
6
+ <updated-at type="datetime">2011-09-09T15:14:13+02:00</updated-at>
7
+ <in-reply-to-id type="integer" nil="true"></in-reply-to-id>
8
+ <subject-id type="integer">5</subject-id>
9
+ <id type="integer">1</id>
10
+ <in-reply-to-type nil="true"></in-reply-to-type>
11
+ <care-provider-id type="integer">1</care-provider-id>
12
+ <person-id type="integer">1</person-id>
13
+ <external-person-id nil="true"></external-person-id>
14
+ </external-message>
15
+ <external-message>
16
+ <created-at type="datetime">2011-09-09T15:14:13+02:00</created-at>
17
+ <body>Does it work ...</body>
18
+ <updated-at type="datetime">2011-09-09T15:14:13+02:00</updated-at>
19
+ <in-reply-to-id type="integer" nil="true"></in-reply-to-id>
20
+ <subject-id type="integer">5</subject-id>
21
+ <id type="integer">2</id>
22
+ <in-reply-to-type nil="true"></in-reply-to-type>
23
+ <care-provider-id type="integer">1</care-provider-id>
24
+ <person-id type="integer">1</person-id>
25
+ <external-person-id nil="true"></external-person-id>
26
+ </external-message>
27
+ </external-messages>
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <product-categories type="array">
3
+ <product-category>
4
+ <name>Products</name>
5
+ <created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
6
+ <updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
7
+ <product-category-id type="integer"></product-category-id>
8
+ <id type="integer">1</id>
9
+ <description>Generic products</description>
10
+ <icon>http://example.com/1.png</icon>
11
+ </product-category>
12
+ <product-category>
13
+ <name>Services</name>
14
+ <created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
15
+ <updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
16
+ <product-category-id type="integer"></product-category-id>
17
+ <id type="integer">2</id>
18
+ <description>Generic services</description>
19
+ <icon>http://example.com/2.png</icon>
20
+ </product-category>
21
+ </product-categories>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <product-categories type="array">
3
+ <product-category>
4
+ <name>products</name>
5
+ <created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
6
+ <updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
7
+ <product-category-id type="integer"></product-category-id>
8
+ <id type="integer">1</id>
9
+ <description>Generic products</description>
10
+ <icon>http://example.com/1.png</icon>
11
+ </product-category>
12
+ </product-categories>
@@ -0,0 +1,35 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <products type="array">
3
+ <product>
4
+ <price type="integer">10000</price>
5
+ <in-store type="boolean">true</in-store>
6
+ <name>Dishwashing</name>
7
+ <created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
8
+ <updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
9
+ <valid-to type="date">9999-01-01</valid-to>
10
+ <product-category-id type="integer">1</product-category-id>
11
+ <id type="integer">1</id>
12
+ <valid-from type="date">2011-01-01</valid-from>
13
+ <unit>piece</unit>
14
+ <description>Nice Dishwashing</description>
15
+ <status>pending</status>
16
+ <rounding type="integer">0</rounding>
17
+ <photo>http://example.com/1.png</photo>
18
+ </product>
19
+ <product>
20
+ <price type="integer">12000</price>
21
+ <in-store type="boolean">true</in-store>
22
+ <name>Krukken</name>
23
+ <created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
24
+ <updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
25
+ <valid-to type="date">9999-01-01</valid-to>
26
+ <product-category-id type="integer">1</product-category-id>
27
+ <id type="integer">2</id>
28
+ <valid-from type="date">2011-01-01</valid-from>
29
+ <unit>piece</unit>
30
+ <description>Nice krukken</description>
31
+ <status>pending</status>
32
+ <rounding type="integer">0</rounding>
33
+ <photo>http://example.com/2.png</photo>
34
+ </product>
35
+ </products>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <products type="array">
3
+ <product>
4
+ <price type="integer">10000</price>
5
+ <in-store type="boolean">true</in-store>
6
+ <name>bedpan</name>
7
+ <created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
8
+ <updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
9
+ <valid-to type="date">9999-01-01</valid-to>
10
+ <product-category-id type="integer">1</product-category-id>
11
+ <id type="integer">1</id>
12
+ <valid-from type="date">2011-01-01</valid-from>
13
+ <unit>piece</unit>
14
+ <description>Nice bedpan</description>
15
+ <status>pending</status>
16
+ <rounding type="integer">0</rounding>
17
+ <photo>http://example.com/1.png</photo>
18
+ </product>
19
+ </products>
@@ -0,0 +1,14 @@
1
+ <external-message>
2
+ <created-at type="datetime">2011-09-09T15:14:13+02:00</created-at>
3
+ <body>Expecting this to work somehow ...</body>
4
+ <updated-at type="datetime">2011-09-09T15:14:13+02:00</updated-at>
5
+ <in-reply-to-id type="integer" nil="true"></in-reply-to-id>
6
+ <subject-id type="integer">5</subject-id>
7
+ <id type="integer">1</id>
8
+ <in-reply-to-type nil="true"></in-reply-to-type>
9
+ <care-provider-id type="integer">1</care-provider-id>
10
+ <person-id type="integer">2</person-id>
11
+ <person-first-name>Matthijs Langenberg</person-first-name>
12
+ <person-last-name></person-last-name>
13
+ <person-photo>http://example.com/1.png</person-photo>
14
+ </external-message>
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ProductCategory", "converting to xml" do
4
+
5
+ before do
6
+ @product_category_a = Caren::ProductCategory.new( :name => "Services" )
7
+ @product_category_b = Caren::ProductCategory.new( :name => "Products" )
8
+ end
9
+
10
+ it "should be able to convert a product to valid xml" do
11
+ @product_category_a.should convert_to_valid_caren_xml
12
+ end
13
+
14
+ it "should be able to convert an array of products to valid xml" do
15
+ [@product_category_a,@product_category_b].should convert_to_valid_caren_array_xml
16
+ end
17
+
18
+ end
19
+
20
+ describe "ProductCategory", "REST methods" do
21
+
22
+ before do
23
+ product_categories = File.read("spec/fixtures/caren_product_categories.xml")
24
+ product_categories_search = File.read("spec/fixtures/caren_product_categories_search.xml")
25
+
26
+ product_categories_url = Caren::Api.session.url_for( Caren::ProductCategory.resource_url )
27
+ search_url = Caren::Api.session.url_for( "#{Caren::ProductCategory.resource_url}?key=name&value=products" )
28
+
29
+ timestamp = DateTime.now.to_i
30
+
31
+ FakeWeb.register_uri(:get, product_categories_url, :body => product_categories, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,product_categories) )
32
+ FakeWeb.register_uri(:get, search_url, :body => product_categories_search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,product_categories_search) )
33
+ end
34
+
35
+ it "should be able to search for a specific product category" do
36
+ product_categories = Caren::ProductCategory.search :name, "products", Caren::Api.session
37
+ product_categories.should have(1).things
38
+ product_categories.first.name.should == "products"
39
+ end
40
+
41
+ it "should be able to find all product category" do
42
+ product_categories = Caren::ProductCategory.all Caren::Api.session
43
+ product_categories.should have(2).things
44
+ product_categories.first.name.should == "Products"
45
+ end
46
+
47
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Product", "converting to xml" do
4
+
5
+ before do
6
+ @product_a = Caren::Product.new( :name => "Washing", :price => 100.euros, :in_store => true )
7
+ @product_b = Caren::Product.new( :name => "Bedpan", :price => 100.euros, :in_store => false )
8
+ end
9
+
10
+ it "should be able to convert a product to valid xml" do
11
+ @product_a.should convert_to_valid_caren_xml
12
+ end
13
+
14
+ it "should be able to convert an array of products to valid xml" do
15
+ [@product_a,@product_b].should convert_to_valid_caren_array_xml
16
+ end
17
+
18
+ end
19
+
20
+ describe "Product", "REST methods" do
21
+
22
+ before do
23
+ products = File.read("spec/fixtures/caren_products.xml")
24
+ product_search = File.read("spec/fixtures/caren_products_search.xml")
25
+
26
+ product_url = Caren::Api.session.url_for( Caren::Product.resource_url(1) )
27
+ products_url = Caren::Api.session.url_for( Caren::Product.resource_url )
28
+ search_url = Caren::Api.session.url_for( "#{Caren::Product.resource_url}?key=name&value=bedpan" )
29
+
30
+ timestamp = DateTime.now.to_i
31
+
32
+ FakeWeb.register_uri(:post, products_url, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp) )
33
+ FakeWeb.register_uri(:put, product_url, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp) )
34
+ FakeWeb.register_uri(:get, products_url, :body => products, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,products) )
35
+ FakeWeb.register_uri(:get, search_url, :body => product_search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,product_search) )
36
+ end
37
+
38
+ it "should be able to update a product" do
39
+ lambda{ Caren::Product.new( :id => 1, :name => "Bedpan" ).update( Caren::Api.session ) }.should_not raise_error
40
+ end
41
+
42
+ it "should be able to update the photo for a product" do
43
+ lambda{ Caren::Product.new( :id => 1 ).update_photo( "spec/fixtures/bacon.jpg", Caren::Api.session ) }.should_not raise_error
44
+ end
45
+
46
+ it "should be able to search for a specific product" do
47
+ products = Caren::Product.search :name, "bedpan", Caren::Api.session
48
+ products.should have(1).things
49
+ products.first.name.should == "bedpan"
50
+ end
51
+
52
+ it "should be able to find all products" do
53
+ products = Caren::Product.all Caren::Api.session
54
+ products.should have(2).things
55
+ products.first.name.should == "Dishwashing"
56
+ end
57
+
58
+ end
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,14 @@ require 'rspec'
4
4
  require 'fakeweb'
5
5
  require 'capybara'
6
6
 
7
+ class Integer
8
+
9
+ def euros
10
+ self*100
11
+ end
12
+
13
+ end
14
+
7
15
  # For the tests we need to know both the public and private key, so we share them here.
8
16
  # We also use a smaller key here, to make the tests faster.
9
17
  new_private_key = Caren::Api.generate_private_key( 512 )
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 3
8
+ - 4
9
9
  segments_generated: true
10
- version: 0.4.3
10
+ version: 0.4.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andre Foeken
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-21 00:00:00 +02:00
18
+ date: 2011-10-26 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -62,12 +62,14 @@ dependencies:
62
62
  name: rest-client
63
63
  version_requirements: &id004 !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ">="
65
+ - - "="
66
66
  - !ruby/object:Gem::Version
67
67
  segments:
68
- - 0
68
+ - 1
69
+ - 6
70
+ - 7
69
71
  segments_generated: true
70
- version: "0"
72
+ version: 1.6.7
71
73
  requirement: *id004
72
74
  prerelease: false
73
75
  - !ruby/object:Gem::Dependency
@@ -179,6 +181,8 @@ files:
179
181
  - lib/caren/external_message.rb
180
182
  - lib/caren/link.rb
181
183
  - lib/caren/person.rb
184
+ - lib/caren/product.rb
185
+ - lib/caren/product_category.rb
182
186
  - spec/.DS_Store
183
187
  - spec/care_provider_spec.rb
184
188
  - spec/caren_spec.rb
@@ -188,12 +192,20 @@ files:
188
192
  - spec/fixtures/caren_care_provider_validation.xml
189
193
  - spec/fixtures/caren_care_providers.xml
190
194
  - spec/fixtures/caren_care_providers_search.xml
195
+ - spec/fixtures/caren_external_messages.xml
191
196
  - spec/fixtures/caren_links.xml
192
197
  - spec/fixtures/caren_links_search.xml
198
+ - spec/fixtures/caren_product_categories.xml
199
+ - spec/fixtures/caren_product_categories_search.xml
200
+ - spec/fixtures/caren_products.xml
201
+ - spec/fixtures/caren_products_search.xml
193
202
  - spec/fixtures/caren_unauthorized.xml
194
203
  - spec/fixtures/incoming.xml
204
+ - spec/fixtures/incoming_single_object.xml
195
205
  - spec/link_spec.rb
196
206
  - spec/person_spec.rb
207
+ - spec/product_category_spec.rb
208
+ - spec/product_spec.rb
197
209
  - spec/spec.opts
198
210
  - spec/spec_helper.rb
199
211
  has_rdoc: true