caren-api 0.4.22 → 0.4.23
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 +12 -12
- data/lib/caren-api.rb +2 -2
- data/lib/caren/base.rb +2 -1
- data/lib/caren/billable.rb +102 -0
- data/lib/caren/{product_category.rb → billable_category.rb} +5 -5
- data/lib/caren/caren.rb +2 -2
- data/spec/billable_category_spec.rb +55 -0
- data/spec/billable_spec.rb +65 -0
- data/spec/fixtures/{caren_product.xml → caren_billable.xml} +4 -3
- data/spec/fixtures/{caren_product_categories.xml → caren_billable_categories.xml} +9 -9
- data/spec/fixtures/{caren_product_categories_search.xml → caren_billable_categories_search.xml} +7 -7
- data/spec/fixtures/{caren_product_category.xml → caren_billable_category.xml} +5 -5
- data/spec/fixtures/{caren_products.xml → caren_billables.xml} +10 -8
- data/spec/fixtures/{caren_products_search.xml → caren_billables_search.xml} +6 -5
- metadata +14 -14
- data/lib/caren/product.rb +0 -83
- data/spec/product_category_spec.rb +0 -55
- data/spec/product_spec.rb +0 -65
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.23
|
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.4.
|
8
|
+
s.version = "0.4.23"
|
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-02-
|
12
|
+
s.date = "2012-02-08"
|
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 = [
|
@@ -31,6 +31,8 @@ Gem::Specification.new do |s|
|
|
31
31
|
"init.rb",
|
32
32
|
"lib/caren-api.rb",
|
33
33
|
"lib/caren/base.rb",
|
34
|
+
"lib/caren/billable.rb",
|
35
|
+
"lib/caren/billable_category.rb",
|
34
36
|
"lib/caren/care_provider.rb",
|
35
37
|
"lib/caren/caren.rb",
|
36
38
|
"lib/caren/client.rb",
|
@@ -38,15 +40,21 @@ Gem::Specification.new do |s|
|
|
38
40
|
"lib/caren/event.rb",
|
39
41
|
"lib/caren/external_message.rb",
|
40
42
|
"lib/caren/link.rb",
|
41
|
-
"lib/caren/product.rb",
|
42
|
-
"lib/caren/product_category.rb",
|
43
43
|
"spec/.DS_Store",
|
44
|
+
"spec/billable_category_spec.rb",
|
45
|
+
"spec/billable_spec.rb",
|
44
46
|
"spec/care_provider_spec.rb",
|
45
47
|
"spec/caren_spec.rb",
|
46
48
|
"spec/client_spec.rb",
|
47
49
|
"spec/event_spec.rb",
|
48
50
|
"spec/external_message_spec.rb",
|
49
51
|
"spec/fixtures/bacon.jpg",
|
52
|
+
"spec/fixtures/caren_billable.xml",
|
53
|
+
"spec/fixtures/caren_billable_categories.xml",
|
54
|
+
"spec/fixtures/caren_billable_categories_search.xml",
|
55
|
+
"spec/fixtures/caren_billable_category.xml",
|
56
|
+
"spec/fixtures/caren_billables.xml",
|
57
|
+
"spec/fixtures/caren_billables_search.xml",
|
50
58
|
"spec/fixtures/caren_care_provider.xml",
|
51
59
|
"spec/fixtures/caren_care_provider_validation.xml",
|
52
60
|
"spec/fixtures/caren_care_providers.xml",
|
@@ -56,18 +64,10 @@ Gem::Specification.new do |s|
|
|
56
64
|
"spec/fixtures/caren_link.xml",
|
57
65
|
"spec/fixtures/caren_links.xml",
|
58
66
|
"spec/fixtures/caren_links_search.xml",
|
59
|
-
"spec/fixtures/caren_product.xml",
|
60
|
-
"spec/fixtures/caren_product_categories.xml",
|
61
|
-
"spec/fixtures/caren_product_categories_search.xml",
|
62
|
-
"spec/fixtures/caren_product_category.xml",
|
63
|
-
"spec/fixtures/caren_products.xml",
|
64
|
-
"spec/fixtures/caren_products_search.xml",
|
65
67
|
"spec/fixtures/caren_unauthorized.xml",
|
66
68
|
"spec/fixtures/incoming.xml",
|
67
69
|
"spec/fixtures/incoming_single_object.xml",
|
68
70
|
"spec/link_spec.rb",
|
69
|
-
"spec/product_category_spec.rb",
|
70
|
-
"spec/product_spec.rb",
|
71
71
|
"spec/spec.opts",
|
72
72
|
"spec/spec_helper.rb"
|
73
73
|
]
|
data/lib/caren-api.rb
CHANGED
@@ -24,5 +24,5 @@ require "#{File.dirname(__FILE__)}/caren/client.rb"
|
|
24
24
|
require "#{File.dirname(__FILE__)}/caren/care_provider.rb"
|
25
25
|
require "#{File.dirname(__FILE__)}/caren/external_message.rb"
|
26
26
|
require "#{File.dirname(__FILE__)}/caren/link.rb"
|
27
|
-
require "#{File.dirname(__FILE__)}/caren/
|
28
|
-
require "#{File.dirname(__FILE__)}/caren/
|
27
|
+
require "#{File.dirname(__FILE__)}/caren/billable.rb"
|
28
|
+
require "#{File.dirname(__FILE__)}/caren/billable_category.rb"
|
data/lib/caren/base.rb
CHANGED
@@ -11,8 +11,9 @@ class Caren::Base
|
|
11
11
|
self.class.keys.each do |key|
|
12
12
|
self.attributes[key] = args[key] || args[key.to_s] || nil
|
13
13
|
end
|
14
|
-
# We want to use #id (in Ruby 1.8.x we need to undef it)
|
14
|
+
# We want to use #id and #type (in Ruby 1.8.x we need to undef it)
|
15
15
|
self.instance_eval('undef id') if self.respond_to?(:id)
|
16
|
+
self.instance_eval('undef type') if self.respond_to?(:type)
|
16
17
|
end
|
17
18
|
|
18
19
|
# List of available attributes for this object
|
@@ -0,0 +1,102 @@
|
|
1
|
+
class Caren::Billable < Caren::Base
|
2
|
+
|
3
|
+
def self.keys
|
4
|
+
[ :id, # Integer (Id of this product in Caren)
|
5
|
+
:external_id, # Integer (Your id)
|
6
|
+
:name, # String
|
7
|
+
:description, # Text
|
8
|
+
:care_provider_id, # Integer (Care provider id)
|
9
|
+
:billable_category_id, # Integer (Reference to product category; Caren id)
|
10
|
+
:photo, # String
|
11
|
+
:in_store, # Boolean (Use in store)
|
12
|
+
:unit, # String (piece, minute, hour)
|
13
|
+
:price_with_vat_in_cents, # Integer
|
14
|
+
:currency, # String (EUR,USD)
|
15
|
+
:rounding, # Integer (in minutes)
|
16
|
+
:min_amount, # Integer (in minutes)
|
17
|
+
:default_amount, # Integer (in minutes)
|
18
|
+
:vat_promillage, # Integer
|
19
|
+
:type, # String (Product,Service,ChatSession)
|
20
|
+
:status, # String (pending, active)
|
21
|
+
:send_reminder_subject, # Boolean
|
22
|
+
:send_reminder_person, # Boolean
|
23
|
+
:send_reminder_in_advance,# Integer (in minutes)
|
24
|
+
:plannable_by_subject, # Boolean
|
25
|
+
:plannable_margin_before, # Integer (in minutes)
|
26
|
+
:plannable_margin_after, # Integer (in minutes)
|
27
|
+
:valid_from, # Date
|
28
|
+
:valid_to # Date
|
29
|
+
] + super
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.search key, value, session
|
33
|
+
from_xml session.get( self.search_url(key,value) )
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.find id, session
|
37
|
+
from_xml session.get(self.resource_url(id))
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.all session
|
41
|
+
from_xml session.get(self.resource_url)
|
42
|
+
end
|
43
|
+
|
44
|
+
def create session
|
45
|
+
self.class.from_xml session.post(self.resource_url, self.to_xml)
|
46
|
+
end
|
47
|
+
|
48
|
+
def update session
|
49
|
+
self.class.from_xml session.put(self.resource_url(self.id), self.to_xml)
|
50
|
+
end
|
51
|
+
|
52
|
+
def update_photo photo_hash_or_path, session
|
53
|
+
self.class.from_xml session.put(self.resource_url(self.id), self.to_photo_xml(photo_hash_or_path))
|
54
|
+
end
|
55
|
+
|
56
|
+
def as_xml
|
57
|
+
{ :name => self.name,
|
58
|
+
:description => self.description,
|
59
|
+
:billable_category_id => self.billable_category_id,
|
60
|
+
:in_store => self.in_store,
|
61
|
+
:unit => self.unit,
|
62
|
+
:photo => self.photo,
|
63
|
+
:price_with_vat_in_cents => self.price_with_vat_in_cents,
|
64
|
+
:currency => self.currency,
|
65
|
+
:type => self.type,
|
66
|
+
:rounding => self.rounding,
|
67
|
+
:vat_promillage => self.vat_promillage,
|
68
|
+
:external_id => self.external_id,
|
69
|
+
:min_amount => self.min_amount,
|
70
|
+
:default_amount => self.default_amount,
|
71
|
+
:send_reminder_subject => self.send_reminder_subject,
|
72
|
+
:send_reminder_person => self.send_reminder_person,
|
73
|
+
:send_reminder_in_advance => self.send_reminder_in_advance,
|
74
|
+
:plannable_by_subject => self.plannable_by_subject,
|
75
|
+
:plannable_margin_before => self.plannable_margin_before,
|
76
|
+
:plannable_margin_after => self.plannable_margin_after,
|
77
|
+
:valid_from => self.valid_from,
|
78
|
+
:valid_to => self.valid_to
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
def to_photo_xml photo_hash_or_path
|
83
|
+
builder = Builder::XmlMarkup.new
|
84
|
+
photo = self.class.hash_from_image(photo_hash_or_path)
|
85
|
+
xml = builder.billable do |billable|
|
86
|
+
billable.tag!("photo", photo[:content], "name" => photo[:name], "content-type" => photo[:content_type] ) if photo
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.array_root
|
91
|
+
:billables
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.node_root
|
95
|
+
:billable
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.resource_location
|
99
|
+
"/api/pro/store/billables"
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class Caren::
|
1
|
+
class Caren::BillableCategory < Caren::Base
|
2
2
|
|
3
3
|
def self.keys
|
4
4
|
[ :id, # Integer (Id of this category in Caren)
|
5
5
|
:name, # String
|
6
6
|
:description, # Text
|
7
7
|
:icon, # String
|
8
|
-
:
|
8
|
+
:billable_category_id # Integer (Parent category; Caren id; Nil for root node)
|
9
9
|
] + super
|
10
10
|
end
|
11
11
|
|
@@ -22,15 +22,15 @@ class Caren::ProductCategory < Caren::Base
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.array_root
|
25
|
-
:
|
25
|
+
:billable_categories
|
26
26
|
end
|
27
27
|
|
28
28
|
def self.node_root
|
29
|
-
:
|
29
|
+
:billable_category
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.resource_location
|
33
|
-
"/api/pro/store/
|
33
|
+
"/api/pro/store/billable_categories"
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
data/lib/caren/caren.rb
CHANGED
@@ -118,8 +118,8 @@ module Caren
|
|
118
118
|
{ :links => Caren::Link,
|
119
119
|
:external_messages => Caren::ExternalMessage,
|
120
120
|
:care_providers => Caren::CareProvider,
|
121
|
-
:
|
122
|
-
:
|
121
|
+
:billable_categories => Caren::BillableCategory,
|
122
|
+
:billables => Caren::Billable
|
123
123
|
}
|
124
124
|
end
|
125
125
|
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "BillableCategory", "converting to xml" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@billable_category_a = Caren::BillableCategory.new( :name => "Services" )
|
7
|
+
@billable_category_b = Caren::BillableCategory.new( :name => "Products" )
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be able to convert a product to valid xml" do
|
11
|
+
@billable_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
|
+
[@billable_category_a,@billable_category_b].should convert_to_valid_caren_array_xml
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "BillableCategory", "REST methods" do
|
21
|
+
|
22
|
+
before do
|
23
|
+
billable_category = File.read("spec/fixtures/caren_billable_category.xml")
|
24
|
+
billable_categories = File.read("spec/fixtures/caren_billable_categories.xml")
|
25
|
+
billable_categories_search = File.read("spec/fixtures/caren_billable_categories_search.xml")
|
26
|
+
|
27
|
+
billable_category_url = Caren::Api.session.url_for( Caren::BillableCategory.resource_url(1) )
|
28
|
+
billable_categories_url = Caren::Api.session.url_for( Caren::BillableCategory.resource_url )
|
29
|
+
search_url = Caren::Api.session.url_for( "#{Caren::BillableCategory.resource_url}?key=name&value=billables" )
|
30
|
+
|
31
|
+
timestamp = DateTime.now.to_i
|
32
|
+
|
33
|
+
FakeWeb.register_uri(:get, billable_categories_url, :body => billable_categories, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billable_categories) )
|
34
|
+
FakeWeb.register_uri(:get, billable_category_url, :body => billable_category, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billable_category) )
|
35
|
+
FakeWeb.register_uri(:get, search_url, :body => billable_categories_search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billable_categories_search) )
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be able to search for a specific billable category" do
|
39
|
+
billable_categories = Caren::BillableCategory.search :name, "billables", Caren::Api.session
|
40
|
+
billable_categories.should have(1).things
|
41
|
+
billable_categories.first.name.should == "Billables"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be able to find a billable category" do
|
45
|
+
billable_category = Caren::BillableCategory.find 1, Caren::Api.session
|
46
|
+
billable_category.name.should == "Billables"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should be able to find all billable category" do
|
50
|
+
billable_categories = Caren::BillableCategory.all Caren::Api.session
|
51
|
+
billable_categories.should have(2).things
|
52
|
+
billable_categories.first.name.should == "Products"
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Billable", "converting to xml" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@billable_a = Caren::Billable.new( :name => "Washing", :price => 100.euros, :in_store => true, :type => "Product" )
|
7
|
+
@billable_b = Caren::Billable.new( :name => "Bedpan", :price => 100.euros, :in_store => false, :type => "Product" )
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be able to convert a billable to valid xml" do
|
11
|
+
@billable_a.should convert_to_valid_caren_xml
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should be able to convert an array of billables to valid xml" do
|
15
|
+
[@billable_a,@billable_b].should convert_to_valid_caren_array_xml
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "Billable", "REST methods" do
|
21
|
+
|
22
|
+
before do
|
23
|
+
billable = File.read("spec/fixtures/caren_billable.xml")
|
24
|
+
billables = File.read("spec/fixtures/caren_billables.xml")
|
25
|
+
billable_search = File.read("spec/fixtures/caren_billables_search.xml")
|
26
|
+
|
27
|
+
billable_url = Caren::Api.session.url_for( Caren::Billable.resource_url(1) )
|
28
|
+
billables_url = Caren::Api.session.url_for( Caren::Billable.resource_url )
|
29
|
+
search_url = Caren::Api.session.url_for( "#{Caren::Billable.resource_url}?key=name&value=bedpan" )
|
30
|
+
|
31
|
+
timestamp = DateTime.now.to_i
|
32
|
+
|
33
|
+
FakeWeb.register_uri(:post, billables_url, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp) )
|
34
|
+
FakeWeb.register_uri(:put, billable_url, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp) )
|
35
|
+
FakeWeb.register_uri(:get, billables_url, :body => billables, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billables) )
|
36
|
+
FakeWeb.register_uri(:get, billable_url, :body => billable, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billable) )
|
37
|
+
FakeWeb.register_uri(:get, search_url, :body => billable_search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billable_search) )
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be able to update a billable" do
|
41
|
+
lambda{ Caren::Billable.new( :id => 1, :name => "Bedpan" ).update( Caren::Api.session ) }.should_not raise_error
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be able to update the photo for a product" do
|
45
|
+
lambda{ Caren::Billable.new( :id => 1 ).update_photo( "spec/fixtures/bacon.jpg", Caren::Api.session ) }.should_not raise_error
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should be able to find a specific billable" do
|
49
|
+
billable = Caren::Billable.find 1, Caren::Api.session
|
50
|
+
billable.name.should == "Dishwashing"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should be able to search for a specific product" do
|
54
|
+
billables = Caren::Billable.search :name, "bedpan", Caren::Api.session
|
55
|
+
billables.should have(1).things
|
56
|
+
billables.first.name.should == "bedpan"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should be able to find all billables" do
|
60
|
+
billables = Caren::Billable.all Caren::Api.session
|
61
|
+
billables.should have(2).things
|
62
|
+
billables.first.name.should == "Dishwashing"
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<
|
2
|
+
<billable>
|
3
3
|
<price type="integer">10000</price>
|
4
4
|
<in-store type="boolean">true</in-store>
|
5
5
|
<name>Dishwashing</name>
|
6
6
|
<created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
|
7
7
|
<updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
|
8
8
|
<valid-to type="date">9999-01-01</valid-to>
|
9
|
-
<
|
9
|
+
<billable-category-id type="integer">1</billable-category-id>
|
10
10
|
<id type="integer">1</id>
|
11
11
|
<valid-from type="date">2011-01-01</valid-from>
|
12
12
|
<unit>piece</unit>
|
@@ -14,4 +14,5 @@
|
|
14
14
|
<status>pending</status>
|
15
15
|
<rounding type="integer">0</rounding>
|
16
16
|
<photo>http://example.com/1.png</photo>
|
17
|
-
</
|
17
|
+
<type>Product</type>
|
18
|
+
</billable>
|
@@ -1,21 +1,21 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<
|
3
|
-
<
|
2
|
+
<billable-categories type="array">
|
3
|
+
<billable-category>
|
4
4
|
<name>Products</name>
|
5
5
|
<created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
|
6
6
|
<updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
|
7
|
-
<
|
7
|
+
<billable-category-id type="integer"></billable-category-id>
|
8
8
|
<id type="integer">1</id>
|
9
|
-
<description>Generic
|
9
|
+
<description>Generic billables</description>
|
10
10
|
<icon>http://example.com/1.png</icon>
|
11
|
-
</
|
12
|
-
<
|
11
|
+
</billable-category>
|
12
|
+
<billable-category>
|
13
13
|
<name>Services</name>
|
14
14
|
<created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
|
15
15
|
<updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
|
16
|
-
<
|
16
|
+
<billable-category-id type="integer"></billable-category-id>
|
17
17
|
<id type="integer">2</id>
|
18
18
|
<description>Generic services</description>
|
19
19
|
<icon>http://example.com/2.png</icon>
|
20
|
-
</
|
21
|
-
</
|
20
|
+
</billable-category>
|
21
|
+
</billable-categories>
|
data/spec/fixtures/{caren_product_categories_search.xml → caren_billable_categories_search.xml}
RENAMED
@@ -1,12 +1,12 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<
|
3
|
-
<
|
4
|
-
<name>
|
2
|
+
<billable-categories type="array">
|
3
|
+
<billable-category>
|
4
|
+
<name>Billables</name>
|
5
5
|
<created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
|
6
6
|
<updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
|
7
|
-
<
|
7
|
+
<billable-category-id type="integer"></billable-category-id>
|
8
8
|
<id type="integer">1</id>
|
9
|
-
<description>Generic
|
9
|
+
<description>Generic billables</description>
|
10
10
|
<icon>http://example.com/1.png</icon>
|
11
|
-
</
|
12
|
-
</
|
11
|
+
</billable-category>
|
12
|
+
</billable-categories>
|
@@ -1,10 +1,10 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<
|
3
|
-
<name>
|
2
|
+
<billable-category>
|
3
|
+
<name>Billables</name>
|
4
4
|
<created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
|
5
5
|
<updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
|
6
|
-
<
|
6
|
+
<billable-category-id type="integer"></billable-category-id>
|
7
7
|
<id type="integer">1</id>
|
8
|
-
<description>Generic
|
8
|
+
<description>Generic billables</description>
|
9
9
|
<icon>http://example.com/1.png</icon>
|
10
|
-
</
|
10
|
+
</billable-category>
|
@@ -1,35 +1,37 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<
|
3
|
-
<
|
2
|
+
<billables type="array">
|
3
|
+
<billable>
|
4
4
|
<price type="integer">10000</price>
|
5
5
|
<in-store type="boolean">true</in-store>
|
6
6
|
<name>Dishwashing</name>
|
7
7
|
<created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
|
8
8
|
<updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
|
9
9
|
<valid-to type="date">9999-01-01</valid-to>
|
10
|
-
<
|
10
|
+
<billable-category-id type="integer">1</billable-category-id>
|
11
11
|
<id type="integer">1</id>
|
12
12
|
<valid-from type="date">2011-01-01</valid-from>
|
13
13
|
<unit>piece</unit>
|
14
14
|
<description>Nice Dishwashing</description>
|
15
15
|
<status>pending</status>
|
16
16
|
<rounding type="integer">0</rounding>
|
17
|
+
<type>Product</type>
|
17
18
|
<photo>http://example.com/1.png</photo>
|
18
|
-
</
|
19
|
-
<
|
19
|
+
</billable>
|
20
|
+
<billable>
|
20
21
|
<price type="integer">12000</price>
|
21
22
|
<in-store type="boolean">true</in-store>
|
22
23
|
<name>Krukken</name>
|
23
24
|
<created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
|
24
25
|
<updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
|
25
26
|
<valid-to type="date">9999-01-01</valid-to>
|
26
|
-
<
|
27
|
+
<billable-category-id type="integer">1</billable-category-id>
|
27
28
|
<id type="integer">2</id>
|
28
29
|
<valid-from type="date">2011-01-01</valid-from>
|
29
30
|
<unit>piece</unit>
|
30
31
|
<description>Nice krukken</description>
|
31
32
|
<status>pending</status>
|
32
33
|
<rounding type="integer">0</rounding>
|
34
|
+
<type>Product</type>
|
33
35
|
<photo>http://example.com/2.png</photo>
|
34
|
-
</
|
35
|
-
</
|
36
|
+
</billable>
|
37
|
+
</billables>
|
@@ -1,19 +1,20 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<
|
3
|
-
<
|
2
|
+
<billables type="array">
|
3
|
+
<billable>
|
4
4
|
<price type="integer">10000</price>
|
5
5
|
<in-store type="boolean">true</in-store>
|
6
6
|
<name>bedpan</name>
|
7
7
|
<created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
|
8
8
|
<updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
|
9
9
|
<valid-to type="date">9999-01-01</valid-to>
|
10
|
-
<
|
10
|
+
<billable-category-id type="integer">1</billable-category-id>
|
11
11
|
<id type="integer">1</id>
|
12
12
|
<valid-from type="date">2011-01-01</valid-from>
|
13
13
|
<unit>piece</unit>
|
14
14
|
<description>Nice bedpan</description>
|
15
15
|
<status>pending</status>
|
16
16
|
<rounding type="integer">0</rounding>
|
17
|
+
<type>Product</type>
|
17
18
|
<photo>http://example.com/1.png</photo>
|
18
|
-
</
|
19
|
-
</
|
19
|
+
</billable>
|
20
|
+
</billables>
|
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: 33
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 23
|
10
|
+
version: 0.4.23
|
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: 2012-02-
|
18
|
+
date: 2012-02-08 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
requirement: &id001 !ruby/object:Gem::Requirement
|
@@ -183,6 +183,8 @@ files:
|
|
183
183
|
- init.rb
|
184
184
|
- lib/caren-api.rb
|
185
185
|
- lib/caren/base.rb
|
186
|
+
- lib/caren/billable.rb
|
187
|
+
- lib/caren/billable_category.rb
|
186
188
|
- lib/caren/care_provider.rb
|
187
189
|
- lib/caren/caren.rb
|
188
190
|
- lib/caren/client.rb
|
@@ -190,15 +192,21 @@ files:
|
|
190
192
|
- lib/caren/event.rb
|
191
193
|
- lib/caren/external_message.rb
|
192
194
|
- lib/caren/link.rb
|
193
|
-
- lib/caren/product.rb
|
194
|
-
- lib/caren/product_category.rb
|
195
195
|
- spec/.DS_Store
|
196
|
+
- spec/billable_category_spec.rb
|
197
|
+
- spec/billable_spec.rb
|
196
198
|
- spec/care_provider_spec.rb
|
197
199
|
- spec/caren_spec.rb
|
198
200
|
- spec/client_spec.rb
|
199
201
|
- spec/event_spec.rb
|
200
202
|
- spec/external_message_spec.rb
|
201
203
|
- spec/fixtures/bacon.jpg
|
204
|
+
- spec/fixtures/caren_billable.xml
|
205
|
+
- spec/fixtures/caren_billable_categories.xml
|
206
|
+
- spec/fixtures/caren_billable_categories_search.xml
|
207
|
+
- spec/fixtures/caren_billable_category.xml
|
208
|
+
- spec/fixtures/caren_billables.xml
|
209
|
+
- spec/fixtures/caren_billables_search.xml
|
202
210
|
- spec/fixtures/caren_care_provider.xml
|
203
211
|
- spec/fixtures/caren_care_provider_validation.xml
|
204
212
|
- spec/fixtures/caren_care_providers.xml
|
@@ -208,18 +216,10 @@ files:
|
|
208
216
|
- spec/fixtures/caren_link.xml
|
209
217
|
- spec/fixtures/caren_links.xml
|
210
218
|
- spec/fixtures/caren_links_search.xml
|
211
|
-
- spec/fixtures/caren_product.xml
|
212
|
-
- spec/fixtures/caren_product_categories.xml
|
213
|
-
- spec/fixtures/caren_product_categories_search.xml
|
214
|
-
- spec/fixtures/caren_product_category.xml
|
215
|
-
- spec/fixtures/caren_products.xml
|
216
|
-
- spec/fixtures/caren_products_search.xml
|
217
219
|
- spec/fixtures/caren_unauthorized.xml
|
218
220
|
- spec/fixtures/incoming.xml
|
219
221
|
- spec/fixtures/incoming_single_object.xml
|
220
222
|
- spec/link_spec.rb
|
221
|
-
- spec/product_category_spec.rb
|
222
|
-
- spec/product_spec.rb
|
223
223
|
- spec/spec.opts
|
224
224
|
- spec/spec_helper.rb
|
225
225
|
homepage: http://github.com/foeken/caren-api
|
data/lib/caren/product.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
class Caren::Product < Caren::Base
|
2
|
-
|
3
|
-
def self.keys
|
4
|
-
[ :id, # Integer (Id of this product in Caren)
|
5
|
-
:external_id, # Integer (Your id)
|
6
|
-
:name, # String
|
7
|
-
:description, # Text
|
8
|
-
:care_provider_id, # Integer (Care provider id)
|
9
|
-
:product_category_id, # Integer (Reference to product category; Caren id)
|
10
|
-
:photo, # String
|
11
|
-
:in_store, # Boolean (Use in store)
|
12
|
-
:unit, # String (piece, minute, hour)
|
13
|
-
:price, # Integer (in eurocents)
|
14
|
-
:rounding, # Integer (in minutes)
|
15
|
-
:min_amount, # Integer (in minutes)
|
16
|
-
:vat_promille, # Integer
|
17
|
-
:status, # String (pending, active)
|
18
|
-
:valid_from, # Date
|
19
|
-
:valid_to # Date
|
20
|
-
] + super
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.search key, value, session
|
24
|
-
from_xml session.get( self.search_url(key,value) )
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.find id, session
|
28
|
-
from_xml session.get(self.resource_url(id))
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.all session
|
32
|
-
from_xml session.get(self.resource_url)
|
33
|
-
end
|
34
|
-
|
35
|
-
def create session
|
36
|
-
self.class.from_xml session.post(self.resource_url, self.to_xml)
|
37
|
-
end
|
38
|
-
|
39
|
-
def update session
|
40
|
-
self.class.from_xml session.put(self.resource_url(self.id), self.to_xml)
|
41
|
-
end
|
42
|
-
|
43
|
-
def update_photo photo_hash_or_path, session
|
44
|
-
self.class.from_xml session.put(self.resource_url(self.id), self.to_photo_xml(photo_hash_or_path))
|
45
|
-
end
|
46
|
-
|
47
|
-
def as_xml
|
48
|
-
{ :name => self.name,
|
49
|
-
:description => self.description,
|
50
|
-
:product_category_id => self.product_category_id,
|
51
|
-
:in_store => self.in_store,
|
52
|
-
:unit => self.unit,
|
53
|
-
:price => self.price,
|
54
|
-
:rounding => self.rounding,
|
55
|
-
:vat_promille => self.vat_promille,
|
56
|
-
:external_id => self.external_id,
|
57
|
-
:min_amount => self.min_amount,
|
58
|
-
:valid_from => self.valid_from,
|
59
|
-
:valid_to => self.valid_to
|
60
|
-
}
|
61
|
-
end
|
62
|
-
|
63
|
-
def to_photo_xml photo_hash_or_path
|
64
|
-
builder = Builder::XmlMarkup.new
|
65
|
-
photo = self.class.hash_from_image(photo_hash_or_path)
|
66
|
-
xml = builder.product do |product|
|
67
|
-
product.tag!("photo", photo[:content], "name" => photo[:name], "content-type" => photo[:content_type] ) if photo
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.array_root
|
72
|
-
:products
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.node_root
|
76
|
-
:product
|
77
|
-
end
|
78
|
-
|
79
|
-
def self.resource_location
|
80
|
-
"/api/pro/store/products"
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
@@ -1,55 +0,0 @@
|
|
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_category = File.read("spec/fixtures/caren_product_category.xml")
|
24
|
-
product_categories = File.read("spec/fixtures/caren_product_categories.xml")
|
25
|
-
product_categories_search = File.read("spec/fixtures/caren_product_categories_search.xml")
|
26
|
-
|
27
|
-
product_category_url = Caren::Api.session.url_for( Caren::ProductCategory.resource_url(1) )
|
28
|
-
product_categories_url = Caren::Api.session.url_for( Caren::ProductCategory.resource_url )
|
29
|
-
search_url = Caren::Api.session.url_for( "#{Caren::ProductCategory.resource_url}?key=name&value=products" )
|
30
|
-
|
31
|
-
timestamp = DateTime.now.to_i
|
32
|
-
|
33
|
-
FakeWeb.register_uri(:get, product_categories_url, :body => product_categories, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,product_categories) )
|
34
|
-
FakeWeb.register_uri(:get, product_category_url, :body => product_category, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,product_category) )
|
35
|
-
FakeWeb.register_uri(:get, search_url, :body => product_categories_search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,product_categories_search) )
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should be able to search for a specific product category" do
|
39
|
-
product_categories = Caren::ProductCategory.search :name, "products", Caren::Api.session
|
40
|
-
product_categories.should have(1).things
|
41
|
-
product_categories.first.name.should == "products"
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should be able to find a product category" do
|
45
|
-
product_category = Caren::ProductCategory.find 1, Caren::Api.session
|
46
|
-
product_category.name.should == "Products"
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should be able to find all product category" do
|
50
|
-
product_categories = Caren::ProductCategory.all Caren::Api.session
|
51
|
-
product_categories.should have(2).things
|
52
|
-
product_categories.first.name.should == "Products"
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
data/spec/product_spec.rb
DELETED
@@ -1,65 +0,0 @@
|
|
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
|
-
product = File.read("spec/fixtures/caren_product.xml")
|
24
|
-
products = File.read("spec/fixtures/caren_products.xml")
|
25
|
-
product_search = File.read("spec/fixtures/caren_products_search.xml")
|
26
|
-
|
27
|
-
product_url = Caren::Api.session.url_for( Caren::Product.resource_url(1) )
|
28
|
-
products_url = Caren::Api.session.url_for( Caren::Product.resource_url )
|
29
|
-
search_url = Caren::Api.session.url_for( "#{Caren::Product.resource_url}?key=name&value=bedpan" )
|
30
|
-
|
31
|
-
timestamp = DateTime.now.to_i
|
32
|
-
|
33
|
-
FakeWeb.register_uri(:post, products_url, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp) )
|
34
|
-
FakeWeb.register_uri(:put, product_url, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp) )
|
35
|
-
FakeWeb.register_uri(:get, products_url, :body => products, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,products) )
|
36
|
-
FakeWeb.register_uri(:get, product_url, :body => product, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,product) )
|
37
|
-
FakeWeb.register_uri(:get, search_url, :body => product_search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,product_search) )
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should be able to update a product" do
|
41
|
-
lambda{ Caren::Product.new( :id => 1, :name => "Bedpan" ).update( Caren::Api.session ) }.should_not raise_error
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should be able to update the photo for a product" do
|
45
|
-
lambda{ Caren::Product.new( :id => 1 ).update_photo( "spec/fixtures/bacon.jpg", Caren::Api.session ) }.should_not raise_error
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should be able to find a specific product" do
|
49
|
-
product = Caren::Product.find 1, Caren::Api.session
|
50
|
-
product.name.should == "Dishwashing"
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should be able to search for a specific product" do
|
54
|
-
products = Caren::Product.search :name, "bedpan", Caren::Api.session
|
55
|
-
products.should have(1).things
|
56
|
-
products.first.name.should == "bedpan"
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should be able to find all products" do
|
60
|
-
products = Caren::Product.all Caren::Api.session
|
61
|
-
products.should have(2).things
|
62
|
-
products.first.name.should == "Dishwashing"
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|