caren-api 0.4.4 → 0.4.5
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 +6 -1
- data/lib/caren/base.rb +1 -1
- data/lib/caren/care_provider.rb +4 -0
- data/lib/caren/external_message.rb +4 -0
- data/lib/caren/link.rb +4 -0
- data/lib/caren/product.rb +4 -0
- data/lib/caren/product_category.rb +4 -0
- data/spec/care_provider_spec.rb +8 -1
- data/spec/external_message_spec.rb +9 -2
- data/spec/fixtures/caren_care_provider.xml +17 -0
- data/spec/fixtures/caren_external_message.xml +13 -0
- data/spec/fixtures/caren_link.xml +12 -0
- data/spec/fixtures/caren_product.xml +17 -0
- data/spec/fixtures/caren_product_category.xml +10 -0
- data/spec/link_spec.rb +8 -0
- data/spec/product_category_spec.rb +9 -1
- data/spec/product_spec.rb +8 -1
- metadata +7 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.5
|
data/caren-api.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{caren-api}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.5"
|
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"]
|
@@ -46,14 +46,19 @@ Gem::Specification.new do |s|
|
|
46
46
|
"spec/event_spec.rb",
|
47
47
|
"spec/external_message_spec.rb",
|
48
48
|
"spec/fixtures/bacon.jpg",
|
49
|
+
"spec/fixtures/caren_care_provider.xml",
|
49
50
|
"spec/fixtures/caren_care_provider_validation.xml",
|
50
51
|
"spec/fixtures/caren_care_providers.xml",
|
51
52
|
"spec/fixtures/caren_care_providers_search.xml",
|
53
|
+
"spec/fixtures/caren_external_message.xml",
|
52
54
|
"spec/fixtures/caren_external_messages.xml",
|
55
|
+
"spec/fixtures/caren_link.xml",
|
53
56
|
"spec/fixtures/caren_links.xml",
|
54
57
|
"spec/fixtures/caren_links_search.xml",
|
58
|
+
"spec/fixtures/caren_product.xml",
|
55
59
|
"spec/fixtures/caren_product_categories.xml",
|
56
60
|
"spec/fixtures/caren_product_categories_search.xml",
|
61
|
+
"spec/fixtures/caren_product_category.xml",
|
57
62
|
"spec/fixtures/caren_products.xml",
|
58
63
|
"spec/fixtures/caren_products_search.xml",
|
59
64
|
"spec/fixtures/caren_unauthorized.xml",
|
data/lib/caren/base.rb
CHANGED
@@ -46,7 +46,7 @@ class Caren::Base
|
|
46
46
|
raise Caren::Exceptions::InvalidXmlResponse unless hash
|
47
47
|
if hash.has_key?(self.array_root.to_s)
|
48
48
|
return hash[self.array_root.to_s].map{ |h| self.from_xml(h) }
|
49
|
-
elsif hash.has_key?(self.node_root)
|
49
|
+
elsif hash.has_key?(self.node_root.to_s)
|
50
50
|
return self.new( hash[self.node_root.to_s] )
|
51
51
|
else
|
52
52
|
return self.new( hash )
|
data/lib/caren/care_provider.rb
CHANGED
@@ -30,6 +30,10 @@ class Caren::CareProvider < Caren::Base
|
|
30
30
|
from_xml session.get( self.search_url(key,value) )
|
31
31
|
end
|
32
32
|
|
33
|
+
def self.find id, session
|
34
|
+
from_xml session.get(self.resource_url(id))
|
35
|
+
end
|
36
|
+
|
33
37
|
def self.all session
|
34
38
|
from_xml session.get(self.resource_url)
|
35
39
|
end
|
@@ -18,6 +18,10 @@ class Caren::ExternalMessage < Caren::Base
|
|
18
18
|
from_xml session.get(self.resource_url(subject_id))
|
19
19
|
end
|
20
20
|
|
21
|
+
def self.find subject_id, id, session
|
22
|
+
from_xml session.get(self.resource_url(subject_id,id))
|
23
|
+
end
|
24
|
+
|
21
25
|
def create session
|
22
26
|
session.post self.class.resource_url(self.subject_id), self.to_xml
|
23
27
|
end
|
data/lib/caren/link.rb
CHANGED
@@ -16,6 +16,10 @@ class Caren::Link < Caren::Base
|
|
16
16
|
from_xml session.get( self.search_url(key,value) )
|
17
17
|
end
|
18
18
|
|
19
|
+
def self.find id, session
|
20
|
+
from_xml session.get(self.resource_url(id))
|
21
|
+
end
|
22
|
+
|
19
23
|
def self.all session
|
20
24
|
from_xml session.get(self.resource_url)
|
21
25
|
end
|
data/lib/caren/product.rb
CHANGED
@@ -22,6 +22,10 @@ class Caren::Product < Caren::Base
|
|
22
22
|
from_xml session.get( self.search_url(key,value) )
|
23
23
|
end
|
24
24
|
|
25
|
+
def self.find id, session
|
26
|
+
from_xml session.get(self.resource_url(id))
|
27
|
+
end
|
28
|
+
|
25
29
|
def self.all session
|
26
30
|
from_xml session.get(self.resource_url)
|
27
31
|
end
|
@@ -13,6 +13,10 @@ class Caren::ProductCategory < Caren::Base
|
|
13
13
|
from_xml session.get( self.search_url(key,value) )
|
14
14
|
end
|
15
15
|
|
16
|
+
def self.find id, session
|
17
|
+
from_xml session.get(self.resource_url(id))
|
18
|
+
end
|
19
|
+
|
16
20
|
def self.all session
|
17
21
|
from_xml session.get(self.resource_url)
|
18
22
|
end
|
data/spec/care_provider_spec.rb
CHANGED
@@ -70,6 +70,7 @@ end
|
|
70
70
|
describe "CareProvider", "REST methods" do
|
71
71
|
|
72
72
|
before do
|
73
|
+
care_provider = File.read("spec/fixtures/caren_care_provider.xml")
|
73
74
|
care_providers = File.read("spec/fixtures/caren_care_providers.xml")
|
74
75
|
care_providers_search = File.read("spec/fixtures/caren_care_providers_search.xml")
|
75
76
|
|
@@ -80,7 +81,8 @@ describe "CareProvider", "REST methods" do
|
|
80
81
|
timestamp = DateTime.now.to_i
|
81
82
|
|
82
83
|
FakeWeb.register_uri(:put, care_provider_url, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp) )
|
83
|
-
FakeWeb.register_uri(:get,
|
84
|
+
FakeWeb.register_uri(:get, care_provider_url, :body => care_provider, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,care_provider) )
|
85
|
+
FakeWeb.register_uri(:get, care_providers_url, :body => care_providers, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,care_providers) )
|
84
86
|
FakeWeb.register_uri(:get, search_url, :body => care_providers_search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,care_providers_search) )
|
85
87
|
end
|
86
88
|
|
@@ -105,5 +107,10 @@ describe "CareProvider", "REST methods" do
|
|
105
107
|
care_providers.first.name.should == "Demo"
|
106
108
|
care_providers.first.url_shortcut.should == "demo"
|
107
109
|
end
|
110
|
+
|
111
|
+
it "should be able to find one care providers" do
|
112
|
+
care_provider = Caren::CareProvider.find 1, Caren::Api.session
|
113
|
+
care_provider.name.should == "Demo"
|
114
|
+
end
|
108
115
|
|
109
116
|
end
|
@@ -29,15 +29,17 @@ end
|
|
29
29
|
describe "ExternalMessage", "REST methods" do
|
30
30
|
|
31
31
|
before do
|
32
|
+
message = File.read("spec/fixtures/caren_external_message.xml")
|
32
33
|
messages = File.read("spec/fixtures/caren_external_messages.xml")
|
33
34
|
|
34
35
|
messages_url = Caren::Api.session.url_for( Caren::ExternalMessage.resource_url(1) )
|
35
|
-
|
36
|
+
message_url = Caren::Api.session.url_for( Caren::ExternalMessage.resource_url(1,1) )
|
36
37
|
timestamp = DateTime.now.to_i
|
37
38
|
|
38
39
|
FakeWeb.register_uri(:get, messages_url, :body => messages, :signature => Caren::Api.session.sign(timestamp,messages), :timestamp => timestamp )
|
40
|
+
FakeWeb.register_uri(:get, message_url, :body => message, :signature => Caren::Api.session.sign(timestamp,message), :timestamp => timestamp )
|
39
41
|
FakeWeb.register_uri(:post, messages_url, :status => 201, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
|
40
|
-
FakeWeb.register_uri(:delete,
|
42
|
+
FakeWeb.register_uri(:delete, message_url, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
|
41
43
|
end
|
42
44
|
|
43
45
|
it "should be able to find all external messages" do
|
@@ -46,6 +48,11 @@ describe "ExternalMessage", "REST methods" do
|
|
46
48
|
messages.first.body.should == "Test"
|
47
49
|
end
|
48
50
|
|
51
|
+
it "should be able to find one external messages" do
|
52
|
+
message = Caren::ExternalMessage.find 1, 1, Caren::Api.session
|
53
|
+
message.body.should == "Test"
|
54
|
+
end
|
55
|
+
|
49
56
|
it "should be able to create an external message" do
|
50
57
|
lambda{ Caren::ExternalMessage.new( :person_name => "Andre Foeken",
|
51
58
|
:external_person_id => 1,
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<care-provider>
|
3
|
+
<url-shortcut>demo</url-shortcut>
|
4
|
+
<name>Demo</name>
|
5
|
+
<created-at type="datetime">2011-10-10T10:38:13+02:00</created-at>
|
6
|
+
<address-line></address-line>
|
7
|
+
<updated-at type="datetime">2011-10-10T10:38:13+02:00</updated-at>
|
8
|
+
<lng type="float">5.29127</lng>
|
9
|
+
<id type="integer">1</id>
|
10
|
+
<website></website>
|
11
|
+
<telephone></telephone>
|
12
|
+
<time-zone>Europe/Amsterdam</time-zone>
|
13
|
+
<lat type="float">52.1326</lat>
|
14
|
+
<email></email>
|
15
|
+
<logo></logo>
|
16
|
+
<linkable>true</linkable>
|
17
|
+
</care-provider>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<external-message>
|
3
|
+
<created-at type="datetime">2011-09-09T15:14:13+02:00</created-at>
|
4
|
+
<body>Test</body>
|
5
|
+
<updated-at type="datetime">2011-09-09T15:14:13+02:00</updated-at>
|
6
|
+
<in-reply-to-id type="integer" nil="true"></in-reply-to-id>
|
7
|
+
<subject-id type="integer">5</subject-id>
|
8
|
+
<id type="integer">1</id>
|
9
|
+
<in-reply-to-type nil="true"></in-reply-to-type>
|
10
|
+
<care-provider-id type="integer">1</care-provider-id>
|
11
|
+
<person-id type="integer">1</person-id>
|
12
|
+
<external-person-id nil="true"></external-person-id>
|
13
|
+
</external-message>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<link>
|
3
|
+
<created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
|
4
|
+
<updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
|
5
|
+
<id type="integer">1</id>
|
6
|
+
<care-provider-id type="integer">1</care-provider-id>
|
7
|
+
<person-id type="integer">3</person-id>
|
8
|
+
<person-name>Andre Foeken</person-name>
|
9
|
+
<person-photo>http://example.com/1.png</person-photo>
|
10
|
+
<external-id>1</external-id>
|
11
|
+
<status>confirmed</status>
|
12
|
+
</link>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<product>
|
3
|
+
<price type="integer">10000</price>
|
4
|
+
<in-store type="boolean">true</in-store>
|
5
|
+
<name>Dishwashing</name>
|
6
|
+
<created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
|
7
|
+
<updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
|
8
|
+
<valid-to type="date">9999-01-01</valid-to>
|
9
|
+
<product-category-id type="integer">1</product-category-id>
|
10
|
+
<id type="integer">1</id>
|
11
|
+
<valid-from type="date">2011-01-01</valid-from>
|
12
|
+
<unit>piece</unit>
|
13
|
+
<description>Nice Dishwashing</description>
|
14
|
+
<status>pending</status>
|
15
|
+
<rounding type="integer">0</rounding>
|
16
|
+
<photo>http://example.com/1.png</photo>
|
17
|
+
</product>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<product-category>
|
3
|
+
<name>Products</name>
|
4
|
+
<created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
|
5
|
+
<updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
|
6
|
+
<product-category-id type="integer"></product-category-id>
|
7
|
+
<id type="integer">1</id>
|
8
|
+
<description>Generic products</description>
|
9
|
+
<icon>http://example.com/1.png</icon>
|
10
|
+
</product-category>
|
data/spec/link_spec.rb
CHANGED
@@ -20,14 +20,17 @@ end
|
|
20
20
|
describe "Link", "REST methods" do
|
21
21
|
|
22
22
|
before do
|
23
|
+
link = File.read("spec/fixtures/caren_link.xml")
|
23
24
|
links = File.read("spec/fixtures/caren_links.xml")
|
24
25
|
search = File.read("spec/fixtures/caren_links_search.xml")
|
25
26
|
|
27
|
+
link_url = Caren::Api.session.url_for(Caren::Link.resource_url(1))
|
26
28
|
links_url = Caren::Api.session.url_for(Caren::Link.resource_url)
|
27
29
|
search_url = Caren::Api.session.url_for("#{Caren::Link.resource_url}?key=external-id&value=1")
|
28
30
|
|
29
31
|
timestamp = DateTime.now.to_i
|
30
32
|
|
33
|
+
FakeWeb.register_uri(:get, link_url, :body => link, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,link) )
|
31
34
|
FakeWeb.register_uri(:get, links_url, :body => links, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,links) )
|
32
35
|
FakeWeb.register_uri(:get, search_url, :body => search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,search) )
|
33
36
|
FakeWeb.register_uri(:post, links_url, :status => 201, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp) )
|
@@ -47,6 +50,11 @@ describe "Link", "REST methods" do
|
|
47
50
|
links.first.person_id.should == 3
|
48
51
|
end
|
49
52
|
|
53
|
+
it "should be find all links using the API" do
|
54
|
+
link = Caren::Link.find(1,Caren::Api.session)
|
55
|
+
link.id.should == 1
|
56
|
+
end
|
57
|
+
|
50
58
|
it "should be find a specific link using the API" do
|
51
59
|
links = Caren::Link.search(:external_id, 1, Caren::Api.session)
|
52
60
|
links.should have(1).thing
|
@@ -20,15 +20,18 @@ end
|
|
20
20
|
describe "ProductCategory", "REST methods" do
|
21
21
|
|
22
22
|
before do
|
23
|
+
product_category = File.read("spec/fixtures/caren_product_category.xml")
|
23
24
|
product_categories = File.read("spec/fixtures/caren_product_categories.xml")
|
24
25
|
product_categories_search = File.read("spec/fixtures/caren_product_categories_search.xml")
|
25
26
|
|
27
|
+
product_category_url = Caren::Api.session.url_for( Caren::ProductCategory.resource_url(1) )
|
26
28
|
product_categories_url = Caren::Api.session.url_for( Caren::ProductCategory.resource_url )
|
27
29
|
search_url = Caren::Api.session.url_for( "#{Caren::ProductCategory.resource_url}?key=name&value=products" )
|
28
30
|
|
29
31
|
timestamp = DateTime.now.to_i
|
30
32
|
|
31
|
-
FakeWeb.register_uri(:get, product_categories_url, :body => product_categories, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,product_categories) )
|
33
|
+
FakeWeb.register_uri(:get, product_categories_url, :body => product_categories, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,product_categories) )
|
34
|
+
FakeWeb.register_uri(:get, product_category_url, :body => product_category, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,product_category) )
|
32
35
|
FakeWeb.register_uri(:get, search_url, :body => product_categories_search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,product_categories_search) )
|
33
36
|
end
|
34
37
|
|
@@ -37,6 +40,11 @@ describe "ProductCategory", "REST methods" do
|
|
37
40
|
product_categories.should have(1).things
|
38
41
|
product_categories.first.name.should == "products"
|
39
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
|
40
48
|
|
41
49
|
it "should be able to find all product category" do
|
42
50
|
product_categories = Caren::ProductCategory.all Caren::Api.session
|
data/spec/product_spec.rb
CHANGED
@@ -20,6 +20,7 @@ end
|
|
20
20
|
describe "Product", "REST methods" do
|
21
21
|
|
22
22
|
before do
|
23
|
+
product = File.read("spec/fixtures/caren_product.xml")
|
23
24
|
products = File.read("spec/fixtures/caren_products.xml")
|
24
25
|
product_search = File.read("spec/fixtures/caren_products_search.xml")
|
25
26
|
|
@@ -31,7 +32,8 @@ describe "Product", "REST methods" do
|
|
31
32
|
|
32
33
|
FakeWeb.register_uri(:post, products_url, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp) )
|
33
34
|
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, products_url, :body => products, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,products) )
|
36
|
+
FakeWeb.register_uri(:get, product_url, :body => product, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,product) )
|
35
37
|
FakeWeb.register_uri(:get, search_url, :body => product_search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,product_search) )
|
36
38
|
end
|
37
39
|
|
@@ -42,6 +44,11 @@ describe "Product", "REST methods" do
|
|
42
44
|
it "should be able to update the photo for a product" do
|
43
45
|
lambda{ Caren::Product.new( :id => 1 ).update_photo( "spec/fixtures/bacon.jpg", Caren::Api.session ) }.should_not raise_error
|
44
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
|
45
52
|
|
46
53
|
it "should be able to search for a specific product" do
|
47
54
|
products = Caren::Product.search :name, "bedpan", Caren::Api.session
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
segments_generated: true
|
10
|
-
version: 0.4.
|
10
|
+
version: 0.4.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andre Foeken
|
@@ -189,14 +189,19 @@ files:
|
|
189
189
|
- spec/event_spec.rb
|
190
190
|
- spec/external_message_spec.rb
|
191
191
|
- spec/fixtures/bacon.jpg
|
192
|
+
- spec/fixtures/caren_care_provider.xml
|
192
193
|
- spec/fixtures/caren_care_provider_validation.xml
|
193
194
|
- spec/fixtures/caren_care_providers.xml
|
194
195
|
- spec/fixtures/caren_care_providers_search.xml
|
196
|
+
- spec/fixtures/caren_external_message.xml
|
195
197
|
- spec/fixtures/caren_external_messages.xml
|
198
|
+
- spec/fixtures/caren_link.xml
|
196
199
|
- spec/fixtures/caren_links.xml
|
197
200
|
- spec/fixtures/caren_links_search.xml
|
201
|
+
- spec/fixtures/caren_product.xml
|
198
202
|
- spec/fixtures/caren_product_categories.xml
|
199
203
|
- spec/fixtures/caren_product_categories_search.xml
|
204
|
+
- spec/fixtures/caren_product_category.xml
|
200
205
|
- spec/fixtures/caren_products.xml
|
201
206
|
- spec/fixtures/caren_products_search.xml
|
202
207
|
- spec/fixtures/caren_unauthorized.xml
|