caren-api 0.4.34 → 0.5.0

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 CHANGED
@@ -1 +1 @@
1
- 0.4.34
1
+ 0.5.0
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.34"
8
+ s.version = "0.5.0"
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-10"
12
+ s.date = "2012-04-03"
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 = [
@@ -30,8 +30,6 @@ Gem::Specification.new do |s|
30
30
  "init.rb",
31
31
  "lib/caren-api.rb",
32
32
  "lib/caren/base.rb",
33
- "lib/caren/billable.rb",
34
- "lib/caren/billable_category.rb",
35
33
  "lib/caren/care_provider.rb",
36
34
  "lib/caren/caren.rb",
37
35
  "lib/caren/client.rb",
@@ -42,9 +40,14 @@ Gem::Specification.new do |s|
42
40
  "lib/caren/event_slot_container.rb",
43
41
  "lib/caren/external_message.rb",
44
42
  "lib/caren/link.rb",
43
+ "lib/caren/store/address.rb",
44
+ "lib/caren/store/billable.rb",
45
+ "lib/caren/store/billable_category.rb",
46
+ "lib/caren/store/invoice.rb",
47
+ "lib/caren/store/line_item.rb",
48
+ "lib/caren/store/payment.rb",
49
+ "lib/caren/store/store.rb",
45
50
  "spec/.DS_Store",
46
- "spec/billable_category_spec.rb",
47
- "spec/billable_spec.rb",
48
51
  "spec/care_provider_spec.rb",
49
52
  "spec/caren_spec.rb",
50
53
  "spec/client_spec.rb",
@@ -66,15 +69,26 @@ Gem::Specification.new do |s|
66
69
  "spec/fixtures/caren_care_providers_search.xml",
67
70
  "spec/fixtures/caren_external_message.xml",
68
71
  "spec/fixtures/caren_external_messages.xml",
72
+ "spec/fixtures/caren_invoice.xml",
73
+ "spec/fixtures/caren_invoices.xml",
74
+ "spec/fixtures/caren_invoices_search.xml",
69
75
  "spec/fixtures/caren_link.xml",
70
76
  "spec/fixtures/caren_links.xml",
71
77
  "spec/fixtures/caren_links_search.xml",
78
+ "spec/fixtures/caren_payments.xml",
79
+ "spec/fixtures/caren_payments_search.xml",
72
80
  "spec/fixtures/caren_unauthorized.xml",
73
81
  "spec/fixtures/incoming.xml",
74
82
  "spec/fixtures/incoming_single_object.xml",
75
83
  "spec/link_spec.rb",
76
84
  "spec/spec.opts",
77
- "spec/spec_helper.rb"
85
+ "spec/spec_helper.rb",
86
+ "spec/store/address_spec.rb",
87
+ "spec/store/billable_category_spec.rb",
88
+ "spec/store/billable_spec.rb",
89
+ "spec/store/invoice_spec.rb",
90
+ "spec/store/line_items_spec.rb",
91
+ "spec/store/payment_spec.rb"
78
92
  ]
79
93
  s.homepage = "http://github.com/foeken/caren-api"
80
94
  s.licenses = ["MIT"]
data/lib/caren/base.rb CHANGED
@@ -36,6 +36,11 @@ class Caren::Base
36
36
  def self.node_root
37
37
  :object
38
38
  end
39
+
40
+ # Override this for instance specific node roots
41
+ def node_root
42
+ nil
43
+ end
39
44
 
40
45
  # The relative location of this resource.
41
46
  def self.resource_location
@@ -47,23 +52,28 @@ class Caren::Base
47
52
  array.to_xml( :root => self.array_root )
48
53
  end
49
54
 
55
+ # this method is called for each parsed object. So subclasses can add extra parsing later on.
56
+ def self.init_dependent_objects object
57
+ object
58
+ end
59
+
50
60
  # Convert a XML string to a single object or an array of objects
51
61
  def self.from_xml xml
52
62
  return nil if xml == ''
53
63
  hash = xml.is_a?(Hash) ? xml : Hash.from_xml(xml)
54
64
  raise Caren::Exceptions::InvalidXmlResponse unless hash
55
65
  if hash.has_key?(self.array_root.to_s)
56
- return hash[self.array_root.to_s].map{ |h| self.from_xml(h) }
66
+ return hash[self.array_root.to_s].map{ |h| init_dependent_objects(self.from_xml(h)) }
57
67
  elsif hash.has_key?(self.node_root.to_s)
58
- return self.new( hash[self.node_root.to_s] )
68
+ return init_dependent_objects(self.new( hash[self.node_root.to_s] ))
59
69
  else
60
- return self.new( hash )
70
+ return init_dependent_objects(self.new( hash ))
61
71
  end
62
72
  end
63
73
 
64
74
  # Convert this object to XML
65
75
  def to_xml options={}
66
- self.as_xml.to_xml(options.merge( :root => self.class.node_root ))
76
+ self.as_xml.to_xml(options.merge( :root => (self.node_root || self.class.node_root) ))
67
77
  end
68
78
 
69
79
  # Overridable hash of attributes that is used for converting to XML.
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
- :billable_categories => Caren::BillableCategory,
122
- :billables => Caren::Billable
121
+ :billable_categories => Caren::Store::BillableCategory,
122
+ :billables => Caren::Store::Billable
123
123
  }
124
124
  end
125
125
 
@@ -0,0 +1,47 @@
1
+ # This class is just an intermediate for representing potential event occurences.
2
+ class Caren::Store::Address < Caren::Base
3
+
4
+ def self.keys
5
+ [ :full_name, # String
6
+ :address_line_1, # String
7
+ :address_line_2, # String
8
+ :city, # String
9
+ :state_province_or_region, # String
10
+ :zip, # String
11
+ :country, # String
12
+ :purpose, # String (shipping or billing)
13
+ ]
14
+ end
15
+
16
+ def self.array_root
17
+ :addresses
18
+ end
19
+
20
+ def as_xml
21
+ {
22
+ :full_name => self.full_name,
23
+ :address_line_1 => self.address_line_1,
24
+ :address_line_2 => self.address_line_2,
25
+ :city => self.city,
26
+ :state_province_or_region => self.state_province_or_region,
27
+ :zip => self.zip,
28
+ :country => self.country
29
+ }
30
+ end
31
+
32
+ def node_root
33
+ case self.purpose
34
+ when "shipping"
35
+ :shipping_address
36
+ when "billing"
37
+ :billing_address
38
+ else
39
+ self.class.node_root
40
+ end
41
+ end
42
+
43
+ def self.node_root
44
+ :address
45
+ end
46
+
47
+ end
@@ -1,4 +1,4 @@
1
- class Caren::Billable < Caren::Base
1
+ class Caren::Store::Billable < Caren::Base
2
2
 
3
3
  def self.keys
4
4
  [ :id, # Integer (Id of this product in Caren)
@@ -10,13 +10,13 @@ class Caren::Billable < Caren::Base
10
10
  :photo, # String
11
11
  :in_store, # Boolean (Use in store)
12
12
  :unit, # String (piece, minute, hour)
13
- :price_with_vat_in_cents, # Integer
13
+ :price_with_sales_tax_in_cents, # Integer
14
14
  :currency, # String (EUR,USD)
15
15
  :rounding, # Integer (in seconds)
16
16
  :min_amount, # Integer (in seconds)
17
17
  :default_amount, # Integer (in seconds)
18
18
  :piece_duration, # Integer (in seconds)
19
- :vat_promillage, # Integer
19
+ :sales_tax_in_promillage, # Integer
20
20
  :type, # String (Store::Product,Store::Service,Store::ChatSession)
21
21
  :status, # String (pending, active)
22
22
  :send_reminder_in_advance, # Integer (in seconds)
@@ -53,6 +53,10 @@ class Caren::Billable < Caren::Base
53
53
  def update_photo photo_hash_or_path, session
54
54
  self.class.from_xml session.put(self.resource_url(self.id), self.to_photo_xml(photo_hash_or_path))
55
55
  end
56
+
57
+ def delete session
58
+ session.delete self.class.resource_url(self.id)
59
+ end
56
60
 
57
61
  def as_xml
58
62
  { :name => self.name,
@@ -61,11 +65,11 @@ class Caren::Billable < Caren::Base
61
65
  :in_store => self.in_store,
62
66
  :unit => self.unit,
63
67
  :photo => self.photo,
64
- :price_with_vat_in_cents => self.price_with_vat_in_cents,
68
+ :price_with_sales_tax_in_cents => self.price_with_sales_tax_in_cents,
65
69
  :currency => self.currency,
66
70
  :type => self.type,
67
71
  :rounding => self.rounding,
68
- :vat_promillage => self.vat_promillage,
72
+ :sales_tax_in_promillage => self.sales_tax_in_promillage,
69
73
  :external_id => self.external_id,
70
74
  :piece_duration => self.piece_duration,
71
75
  :min_amount => self.min_amount,
@@ -1,4 +1,4 @@
1
- class Caren::BillableCategory < Caren::Base
1
+ class Caren::Store::BillableCategory < Caren::Base
2
2
 
3
3
  def self.keys
4
4
  [ :id, # Integer (Id of this category in Caren)
@@ -0,0 +1,108 @@
1
+ class Caren::Store::Invoice < Caren::Base
2
+
3
+ def self.keys
4
+ [:id, # Integer (Caren id)
5
+ :reference, # String
6
+ :requires_account, # Boolean
7
+ :requires_payment, # Boolean
8
+ :access_token, # String
9
+ :invoice_url, # String
10
+ :payment_url, # String
11
+ :customer_email, # String
12
+ :email_status, # String (unsent,sent,reminder_sent)
13
+ :paid, # Boolean
14
+ :payment_method, # String
15
+ :payment_method_description, # String
16
+ :billing_address, # Store::Address(:purpose => 'billing')
17
+ :shipping_address, # Store::Address(:purpose => 'shipping')
18
+ :line_items, # Array of Store::LineItem
19
+ :invoiced_at, # Datetime
20
+ :paid_at, # Datetime
21
+ ] + super
22
+ end
23
+
24
+ def self.search key, value, session
25
+ from_xml session.get( self.search_url(key,value) )
26
+ end
27
+
28
+ def self.find id, session
29
+ from_xml session.get(self.resource_url(id))
30
+ end
31
+
32
+ def self.all session
33
+ from_xml session.get(self.resource_url)
34
+ end
35
+
36
+ def create session
37
+ self.class.from_xml session.post(self.resource_url, self.to_xml)
38
+ end
39
+
40
+ def update session
41
+ self.class.from_xml session.put(self.resource_url(self.id), self.to_xml)
42
+ end
43
+
44
+ def delete session
45
+ session.delete self.class.resource_url(self.id)
46
+ end
47
+
48
+ def email session
49
+ self.class.from_xml session.post(self.class.email_url(self.id), self.to_xml)
50
+ end
51
+
52
+ def as_xml
53
+ # make sure we have the correct address nodes here
54
+ billing_address.purpose = 'billing' if billing_address
55
+ shipping_address.purpose = 'shipping' if shipping_address
56
+
57
+ {
58
+ :reference => self.reference,
59
+ :requires_account => self.requires_account,
60
+ :requires_payment => self.requires_payment,
61
+ :customer_email => self.customer_email,
62
+ :paid => self.paid,
63
+ :payment_method => self.payment_method,
64
+ :payment_method_description => self.payment_method_description,
65
+ :billing_address => self.billing_address,
66
+ :shipping_address => self.shipping_address,
67
+ :line_items => self.line_items,
68
+ :invoiced_at => self.invoiced_at,
69
+ :paid_at => self.paid_at
70
+ }
71
+ end
72
+
73
+ def self.init_dependent_objects invoice
74
+
75
+ if invoice.shipping_address.is_a?(Hash)
76
+ invoice.shipping_address = Caren::Store::Address.new( invoice.shipping_address.merge(:purpose => 'shipping') )
77
+ end
78
+
79
+ if invoice.billing_address.is_a?(Hash)
80
+ invoice.billing_address = Caren::Store::Address.new( invoice.billing_address.merge(:purpose => 'billing') )
81
+ end
82
+
83
+ if invoice.line_items.is_a?(Array)
84
+ invoice.line_items = invoice.line_items.map do |li|
85
+ Caren::Store::LineItem.new(li) if li.is_a?(Hash)
86
+ end
87
+ end
88
+
89
+ return invoice
90
+ end
91
+
92
+ def self.array_root
93
+ :invoices
94
+ end
95
+
96
+ def self.node_root
97
+ :invoice
98
+ end
99
+
100
+ def self.email_url id
101
+ "#{self.resource_url(id)}/email"
102
+ end
103
+
104
+ def self.resource_location
105
+ "/api/pro/store/invoices"
106
+ end
107
+
108
+ end
@@ -0,0 +1,48 @@
1
+ class Caren::Store::LineItem < Caren::Base
2
+
3
+ def self.keys
4
+ [:id, # Integer (Caren id)
5
+ :sku, # String
6
+ :invoice_id, # Integer (caren invoice id)
7
+ :currency, # String (EUR)
8
+ :description, # String
9
+ :discount_in_cents, # Integer
10
+ :discount_in_promillage, # Integer (190 = 19%)
11
+ :price_in_cents, # Integer
12
+ :quantity, # Integer
13
+ :sales_tax_in_cents, # Integer
14
+ :sales_tax_in_promillage, # Integer
15
+ ] + super
16
+ end
17
+
18
+ def delete session
19
+ session.delete self.class.resource_url(self.id)
20
+ end
21
+
22
+ def as_xml
23
+ {
24
+ :sku => self.sku,
25
+ :currency => self.currency,
26
+ :description => self.description,
27
+ :discount_in_cents => self.discount_in_cents,
28
+ :discount_in_promillage => self.discount_in_promillage,
29
+ :price_in_cents => self.price_in_cents,
30
+ :quantity => self.quantity,
31
+ :sales_tax_in_cents => self.sales_tax_in_cents,
32
+ :sales_tax_in_promillage => self.sales_tax_in_promillage
33
+ }
34
+ end
35
+
36
+ def self.array_root
37
+ :line_items
38
+ end
39
+
40
+ def self.node_root
41
+ :line_item
42
+ end
43
+
44
+ def self.resource_location
45
+ "/api/pro/store/line_items"
46
+ end
47
+
48
+ end
@@ -0,0 +1,42 @@
1
+ class Caren::Store::Payment < Caren::Base
2
+
3
+ def self.keys
4
+ [:id, # Integer (Caren id)
5
+ :invoice_id, # Integer (Caren invoice id)
6
+ :person_id, # Integer (Caren person id)
7
+ :auth_code, # String
8
+ :psp_reference, # String
9
+ :refusal_reason, # String
10
+ :result_code, # String
11
+ :status, # String (new, pending,paid,failed)
12
+ :currency, # String (EUR)
13
+ :amount_in_cents, # Integer
14
+ :gateway, # String (ideal)
15
+ ] + super
16
+ end
17
+
18
+ def self.search key, value, session
19
+ from_xml session.get( self.search_url(key,value) )
20
+ end
21
+
22
+ def self.find id, session
23
+ from_xml session.get(self.resource_url(id))
24
+ end
25
+
26
+ def self.all session
27
+ from_xml session.get(self.resource_url)
28
+ end
29
+
30
+ def self.array_root
31
+ :payments
32
+ end
33
+
34
+ def self.node_root
35
+ :payment
36
+ end
37
+
38
+ def self.resource_location
39
+ "/api/pro/store/payments"
40
+ end
41
+
42
+ end
@@ -0,0 +1,2 @@
1
+ module Caren::Store
2
+ end
data/lib/caren-api.rb CHANGED
@@ -17,5 +17,10 @@ require "caren/employee"
17
17
  require "caren/care_provider"
18
18
  require "caren/external_message"
19
19
  require "caren/link"
20
- require "caren/billable"
21
- require "caren/billable_category"
20
+ require "caren/store/store"
21
+ require "caren/store/billable"
22
+ require "caren/store/billable_category"
23
+ require "caren/store/payment"
24
+ require "caren/store/address"
25
+ require "caren/store/line_item"
26
+ require "caren/store/invoice"
@@ -0,0 +1,60 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <invoice>
3
+ <access-token>06590eb9de2f2baf</access-token>
4
+ <created-at type="datetime">2012-04-03T13:41:15+02:00</created-at>
5
+ <customer-email>jenny@example.com</customer-email>
6
+ <email-status>sent</email-status>
7
+ <id type="integer">17</id>
8
+ <invoiced-at type="datetime">2012-04-03T13:41:15+02:00</invoiced-at>
9
+ <paid type="boolean">true</paid>
10
+ <paid-at type="datetime">2012-04-03T13:45:48+02:00</paid-at>
11
+ <payment-method nil="true"></payment-method>
12
+ <payment-method-description nil="true"></payment-method-description>
13
+ <reference>NW-05463-12-0</reference>
14
+ <requires-account type="boolean">true</requires-account>
15
+ <requires-payment type="boolean">true</requires-payment>
16
+ <updated-at type="datetime">2012-04-03T13:45:48+02:00</updated-at>
17
+ <line-items type="array">
18
+ <line-item type="Invoice::LineItem">
19
+ <created-at type="datetime">2012-04-03T13:41:15+02:00</created-at>
20
+ <currency>EUR</currency>
21
+ <description>Wheel</description>
22
+ <discount-in-cents type="integer" nil="true"></discount-in-cents>
23
+ <discount-in-promillage type="integer" nil="true"></discount-in-promillage>
24
+ <id type="integer">28</id>
25
+ <invoice-id type="integer">17</invoice-id>
26
+ <price-in-cents type="integer">1199</price-in-cents>
27
+ <quantity type="integer">4</quantity>
28
+ <sales-tax-in-cents type="integer" nil="true"></sales-tax-in-cents>
29
+ <sales-tax-in-promillage type="integer">60</sales-tax-in-promillage>
30
+ <sku>wheels-12-nut-56</sku>
31
+ <updated-at type="datetime">2012-04-03T13:41:15+02:00</updated-at>
32
+ </line-item>
33
+ <line-item type="Invoice::LineItem">
34
+ <created-at type="datetime">2012-04-03T13:41:15+02:00</created-at>
35
+ <currency>EUR</currency>
36
+ <description>Nut</description>
37
+ <discount-in-cents type="integer" nil="true"></discount-in-cents>
38
+ <discount-in-promillage type="integer" nil="true"></discount-in-promillage>
39
+ <id type="integer">29</id>
40
+ <invoice-id type="integer">17</invoice-id>
41
+ <price-in-cents type="integer">699</price-in-cents>
42
+ <quantity type="integer">8</quantity>
43
+ <sales-tax-in-cents type="integer" nil="true"></sales-tax-in-cents>
44
+ <sales-tax-in-promillage type="integer">190</sales-tax-in-promillage>
45
+ <sku>wheels-43-nut-29</sku>
46
+ <updated-at type="datetime">2012-04-03T13:41:15+02:00</updated-at>
47
+ </line-item>
48
+ </line-items>
49
+ <invoice-url>https://www.caren-cares.com/invoices/06590eb9de2f2baf</invoice-url>
50
+ <payment-url>https://www.caren-cares.com/invoices/06590eb9de2f2baf/payment</payment-url>
51
+ <billing-address>
52
+ <address-line-1>Botsholsedwarsweg 12</address-line-1>
53
+ <address-line-2 nil="true"></address-line-2>
54
+ <city>Waverveen</city>
55
+ <country>Nederland</country>
56
+ <full-name>Joris de Boer</full-name>
57
+ <state-province-or-region nil="true"></state-province-or-region>
58
+ <zip>3646 AJ</zip>
59
+ </billing-address>
60
+ </invoice>
@@ -0,0 +1,147 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <invoices type="array">
3
+ <invoice>
4
+ <access-token>06590eb9de2f2baf</access-token>
5
+ <created-at type="datetime">2012-04-03T13:41:15+02:00</created-at>
6
+ <customer-email>jenny@example.com</customer-email>
7
+ <email-status>sent</email-status>
8
+ <id type="integer">17</id>
9
+ <invoiced-at type="datetime">2012-04-03T13:41:15+02:00</invoiced-at>
10
+ <paid type="boolean">true</paid>
11
+ <paid-at type="datetime">2012-04-03T13:45:48+02:00</paid-at>
12
+ <payment-method nil="true"></payment-method>
13
+ <payment-method-description nil="true"></payment-method-description>
14
+ <reference>NW-05463-12-0</reference>
15
+ <requires-account type="boolean">true</requires-account>
16
+ <requires-payment type="boolean">true</requires-payment>
17
+ <updated-at type="datetime">2012-04-03T13:45:48+02:00</updated-at>
18
+ <line-items type="array">
19
+ <line-item type="Invoice::LineItem">
20
+ <created-at type="datetime">2012-04-03T13:41:15+02:00</created-at>
21
+ <currency>EUR</currency>
22
+ <description>Wheel</description>
23
+ <discount-in-cents type="integer" nil="true"></discount-in-cents>
24
+ <discount-in-promillage type="integer" nil="true"></discount-in-promillage>
25
+ <id type="integer">28</id>
26
+ <invoice-id type="integer">17</invoice-id>
27
+ <price-in-cents type="integer">1199</price-in-cents>
28
+ <quantity type="integer">4</quantity>
29
+ <sales-tax-in-cents type="integer" nil="true"></sales-tax-in-cents>
30
+ <sales-tax-in-promillage type="integer">60</sales-tax-in-promillage>
31
+ <sku>wheels-12-nut-56</sku>
32
+ <updated-at type="datetime">2012-04-03T13:41:15+02:00</updated-at>
33
+ </line-item>
34
+ <line-item type="Invoice::LineItem">
35
+ <created-at type="datetime">2012-04-03T13:41:15+02:00</created-at>
36
+ <currency>EUR</currency>
37
+ <description>Nut</description>
38
+ <discount-in-cents type="integer" nil="true"></discount-in-cents>
39
+ <discount-in-promillage type="integer" nil="true"></discount-in-promillage>
40
+ <id type="integer">29</id>
41
+ <invoice-id type="integer">17</invoice-id>
42
+ <price-in-cents type="integer">699</price-in-cents>
43
+ <quantity type="integer">8</quantity>
44
+ <sales-tax-in-cents type="integer" nil="true"></sales-tax-in-cents>
45
+ <sales-tax-in-promillage type="integer">190</sales-tax-in-promillage>
46
+ <sku>wheels-43-nut-29</sku>
47
+ <updated-at type="datetime">2012-04-03T13:41:15+02:00</updated-at>
48
+ </line-item>
49
+ </line-items>
50
+ <invoice-url>https://www.caren-cares.com/invoices/06590eb9de2f2baf</invoice-url>
51
+ <payment-url>https://www.caren-cares.com/invoices/06590eb9de2f2baf/payment</payment-url>
52
+ <billing-address>
53
+ <address-line-1>Botsholsedwarsweg 12</address-line-1>
54
+ <address-line-2 nil="true"></address-line-2>
55
+ <city>Waverveen</city>
56
+ <country>Nederland</country>
57
+ <full-name>Joris de Boer</full-name>
58
+ <state-province-or-region nil="true"></state-province-or-region>
59
+ <zip>3646 AJ</zip>
60
+ </billing-address>
61
+ </invoice>
62
+ <invoice>
63
+ <access-token>753a857e0267c87b</access-token>
64
+ <created-at type="datetime">2012-04-03T13:41:15+02:00</created-at>
65
+ <customer-email>benny@example.com</customer-email>
66
+ <email-status>sent</email-status>
67
+ <id type="integer">18</id>
68
+ <invoiced-at type="datetime">2012-04-03T13:41:15+02:00</invoiced-at>
69
+ <paid type="boolean">true</paid>
70
+ <paid-at type="datetime">2012-04-03T13:41:44+02:00</paid-at>
71
+ <payment-method nil="true"></payment-method>
72
+ <payment-method-description nil="true"></payment-method-description>
73
+ <reference>JU-000000-12-1</reference>
74
+ <requires-account type="boolean">false</requires-account>
75
+ <requires-payment type="boolean">true</requires-payment>
76
+ <updated-at type="datetime">2012-04-03T13:41:44+02:00</updated-at>
77
+ <line-items type="array">
78
+ <line-item type="Invoice::LineItem">
79
+ <created-at type="datetime">2012-04-03T13:41:15+02:00</created-at>
80
+ <currency>EUR</currency>
81
+ <description>Bear with happy ears</description>
82
+ <discount-in-cents type="integer" nil="true"></discount-in-cents>
83
+ <discount-in-promillage type="integer">50</discount-in-promillage>
84
+ <id type="integer">30</id>
85
+ <invoice-id type="integer">18</invoice-id>
86
+ <price-in-cents type="integer">1199</price-in-cents>
87
+ <quantity type="integer" nil="true"></quantity>
88
+ <sales-tax-in-cents type="integer" nil="true"></sales-tax-in-cents>
89
+ <sales-tax-in-promillage type="integer">190</sales-tax-in-promillage>
90
+ <sku nil="true"></sku>
91
+ <updated-at type="datetime">2012-04-03T13:41:15+02:00</updated-at>
92
+ </line-item>
93
+ <line-item type="Invoice::LineItem">
94
+ <created-at type="datetime">2012-04-03T13:41:15+02:00</created-at>
95
+ <currency>EUR</currency>
96
+ <description>Bunny with carrot</description>
97
+ <discount-in-cents type="integer" nil="true"></discount-in-cents>
98
+ <discount-in-promillage type="integer">200</discount-in-promillage>
99
+ <id type="integer">31</id>
100
+ <invoice-id type="integer">18</invoice-id>
101
+ <price-in-cents type="integer">1779</price-in-cents>
102
+ <quantity type="integer" nil="true"></quantity>
103
+ <sales-tax-in-cents type="integer" nil="true"></sales-tax-in-cents>
104
+ <sales-tax-in-promillage type="integer">190</sales-tax-in-promillage>
105
+ <sku nil="true"></sku>
106
+ <updated-at type="datetime">2012-04-03T13:41:15+02:00</updated-at>
107
+ </line-item>
108
+ </line-items>
109
+ <invoice-url>https://www.caren-cares.com/invoices/753a857e0267c87b</invoice-url>
110
+ <payment-url>https://www.caren-cares.com/invoices/753a857e0267c87b/payment</payment-url>
111
+ </invoice>
112
+ <invoice>
113
+ <access-token>08d37a494927cef9</access-token>
114
+ <created-at type="datetime">2012-04-03T13:41:15+02:00</created-at>
115
+ <customer-email>marge@example.com</customer-email>
116
+ <email-status>sent</email-status>
117
+ <id type="integer">19</id>
118
+ <invoiced-at type="datetime">2012-04-03T13:41:15+02:00</invoiced-at>
119
+ <paid type="boolean">true</paid>
120
+ <paid-at type="datetime">2012-04-03T13:41:15+02:00</paid-at>
121
+ <payment-method nil="true"></payment-method>
122
+ <payment-method-description>Paid with cash at your pharmacy.</payment-method-description>
123
+ <reference nil="true"></reference>
124
+ <requires-account type="boolean">false</requires-account>
125
+ <requires-payment type="boolean">false</requires-payment>
126
+ <updated-at type="datetime">2012-04-03T13:41:15+02:00</updated-at>
127
+ <line-items type="array">
128
+ <line-item type="Invoice::LineItem">
129
+ <created-at type="datetime">2012-04-03T13:41:15+02:00</created-at>
130
+ <currency>EUR</currency>
131
+ <description nil="true"></description>
132
+ <discount-in-cents type="integer" nil="true"></discount-in-cents>
133
+ <discount-in-promillage type="integer" nil="true"></discount-in-promillage>
134
+ <id type="integer">32</id>
135
+ <invoice-id type="integer">19</invoice-id>
136
+ <price-in-cents type="integer">699</price-in-cents>
137
+ <quantity type="integer" nil="true"></quantity>
138
+ <sales-tax-in-cents type="integer" nil="true"></sales-tax-in-cents>
139
+ <sales-tax-in-promillage type="integer" nil="true"></sales-tax-in-promillage>
140
+ <sku>creme-12</sku>
141
+ <updated-at type="datetime">2012-04-03T13:41:15+02:00</updated-at>
142
+ </line-item>
143
+ </line-items>
144
+ <invoice-url>https://www.caren-cares.com/invoices/08d37a494927cef9</invoice-url>
145
+ <payment-url>https://www.caren-cares.com/invoices/08d37a494927cef9/payment</payment-url>
146
+ </invoice>
147
+ </invoices>
@@ -0,0 +1,62 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <invoices type="array">
3
+ <invoice>
4
+ <access-token>06590eb9de2f2baf</access-token>
5
+ <created-at type="datetime">2012-04-03T13:41:15+02:00</created-at>
6
+ <customer-email>jenny@example.com</customer-email>
7
+ <email-status>sent</email-status>
8
+ <id type="integer">17</id>
9
+ <invoiced-at type="datetime">2012-04-03T13:41:15+02:00</invoiced-at>
10
+ <paid type="boolean">true</paid>
11
+ <paid-at type="datetime">2012-04-03T13:45:48+02:00</paid-at>
12
+ <payment-method nil="true"></payment-method>
13
+ <payment-method-description nil="true"></payment-method-description>
14
+ <reference>NW-05463-12-0</reference>
15
+ <requires-account type="boolean">true</requires-account>
16
+ <requires-payment type="boolean">true</requires-payment>
17
+ <updated-at type="datetime">2012-04-03T13:45:48+02:00</updated-at>
18
+ <line-items type="array">
19
+ <line-item type="Invoice::LineItem">
20
+ <created-at type="datetime">2012-04-03T13:41:15+02:00</created-at>
21
+ <currency>EUR</currency>
22
+ <description>Wheel</description>
23
+ <discount-in-cents type="integer" nil="true"></discount-in-cents>
24
+ <discount-in-promillage type="integer" nil="true"></discount-in-promillage>
25
+ <id type="integer">28</id>
26
+ <invoice-id type="integer">17</invoice-id>
27
+ <price-in-cents type="integer">1199</price-in-cents>
28
+ <quantity type="integer">4</quantity>
29
+ <sales-tax-in-cents type="integer" nil="true"></sales-tax-in-cents>
30
+ <sales-tax-in-promillage type="integer">60</sales-tax-in-promillage>
31
+ <sku>wheels-12-nut-56</sku>
32
+ <updated-at type="datetime">2012-04-03T13:41:15+02:00</updated-at>
33
+ </line-item>
34
+ <line-item type="Invoice::LineItem">
35
+ <created-at type="datetime">2012-04-03T13:41:15+02:00</created-at>
36
+ <currency>EUR</currency>
37
+ <description>Nut</description>
38
+ <discount-in-cents type="integer" nil="true"></discount-in-cents>
39
+ <discount-in-promillage type="integer" nil="true"></discount-in-promillage>
40
+ <id type="integer">29</id>
41
+ <invoice-id type="integer">17</invoice-id>
42
+ <price-in-cents type="integer">699</price-in-cents>
43
+ <quantity type="integer">8</quantity>
44
+ <sales-tax-in-cents type="integer" nil="true"></sales-tax-in-cents>
45
+ <sales-tax-in-promillage type="integer">190</sales-tax-in-promillage>
46
+ <sku>wheels-43-nut-29</sku>
47
+ <updated-at type="datetime">2012-04-03T13:41:15+02:00</updated-at>
48
+ </line-item>
49
+ </line-items>
50
+ <invoice-url>https://www.caren-cares.com/invoices/06590eb9de2f2baf</invoice-url>
51
+ <payment-url>https://www.caren-cares.com/invoices/06590eb9de2f2baf/payment</payment-url>
52
+ <billing-address>
53
+ <address-line-1>Botsholsedwarsweg 12</address-line-1>
54
+ <address-line-2 nil="true"></address-line-2>
55
+ <city>Waverveen</city>
56
+ <country>Nederland</country>
57
+ <full-name>Joris de Boer</full-name>
58
+ <state-province-or-region nil="true"></state-province-or-region>
59
+ <zip>3646 AJ</zip>
60
+ </billing-address>
61
+ </invoice>
62
+ </invoices>
@@ -0,0 +1,33 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <payments type="array">
3
+ <payment>
4
+ <amount-in-cents type="integer">1898</amount-in-cents>
5
+ <auth-code nil="true"></auth-code>
6
+ <created-at type="datetime">2012-02-15T11:35:21+01:00</created-at>
7
+ <currency>EUR</currency>
8
+ <gateway>ideal</gateway>
9
+ <id type="integer">1</id>
10
+ <invoice-id type="integer">2</invoice-id>
11
+ <person-id type="integer" nil="true"></person-id>
12
+ <psp-reference>0030000006449217</psp-reference>
13
+ <refusal-reason nil="true"></refusal-reason>
14
+ <result-code nil="true"></result-code>
15
+ <status>paid</status>
16
+ <updated-at type="datetime">2012-02-15T11:35:37+01:00</updated-at>
17
+ </payment>
18
+ <payment>
19
+ <amount-in-cents type="integer">1898</amount-in-cents>
20
+ <auth-code nil="true"></auth-code>
21
+ <created-at type="datetime">2012-03-15T10:59:20+01:00</created-at>
22
+ <currency>EUR</currency>
23
+ <gateway>ideal</gateway>
24
+ <id type="integer">2</id>
25
+ <invoice-id type="integer">8</invoice-id>
26
+ <person-id type="integer" nil="true"></person-id>
27
+ <psp-reference>0030000006785038</psp-reference>
28
+ <refusal-reason nil="true"></refusal-reason>
29
+ <result-code nil="true"></result-code>
30
+ <status>failed</status>
31
+ <updated-at type="datetime">2012-03-15T10:59:24+01:00</updated-at>
32
+ </payment>
33
+ </payments>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <payments type="array">
3
+ <payment>
4
+ <amount-in-cents type="integer">1898</amount-in-cents>
5
+ <auth-code nil="true"></auth-code>
6
+ <created-at type="datetime">2012-03-15T10:59:20+01:00</created-at>
7
+ <currency>EUR</currency>
8
+ <gateway>ideal</gateway>
9
+ <id type="integer">2</id>
10
+ <invoice-id type="integer">8</invoice-id>
11
+ <person-id type="integer" nil="true"></person-id>
12
+ <psp-reference>0030000006785038</psp-reference>
13
+ <refusal-reason nil="true"></refusal-reason>
14
+ <result-code nil="true"></result-code>
15
+ <status>failed</status>
16
+ <updated-at type="datetime">2012-03-15T10:59:24+01:00</updated-at>
17
+ </payment>
18
+ </payments>
data/spec/spec_helper.rb CHANGED
@@ -24,7 +24,9 @@ RSpec::Matchers.define :convert_to_valid_caren_xml do
24
24
  hash = Hash.from_xml(instance.to_xml)
25
25
  keys = instance.as_xml.keys.map(&:to_s)
26
26
  (hash[instance.class.node_root.to_s].keys - keys).should be_empty
27
- keys.map{ |key| hash[instance.class.node_root.to_s][key].to_s == instance.send(key.to_sym).to_s }.inject(&:&)
27
+ keys.map do |key|
28
+ hash[instance.class.node_root.to_s][key].to_s == instance.send(key.to_sym).to_s
29
+ end.flatten.inject(&:&)
28
30
  end
29
31
  end
30
32
 
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Store::Address", "converting to xml" do
4
+
5
+ before do
6
+ @address_a = Caren::Store::Address.new( :full_name => "Andre Foeken" )
7
+ @address_b = Caren::Store::Address.new( :full_name => "Bart ten Brinke" )
8
+ end
9
+
10
+ it "should be able to convert an address to valid xml" do
11
+ @address_a.should convert_to_valid_caren_xml
12
+ end
13
+
14
+ it "should be able to convert an array of addresses to valid xml" do
15
+ [@address_a,@address_b].should convert_to_valid_caren_array_xml
16
+ end
17
+
18
+ end
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  describe "BillableCategory", "converting to xml" do
4
4
 
5
5
  before do
6
- @billable_category_a = Caren::BillableCategory.new( :name => "Services" )
7
- @billable_category_b = Caren::BillableCategory.new( :name => "Products" )
6
+ @billable_category_a = Caren::Store::BillableCategory.new( :name => "Services" )
7
+ @billable_category_b = Caren::Store::BillableCategory.new( :name => "Products" )
8
8
  end
9
9
 
10
10
  it "should be able to convert a product to valid xml" do
@@ -24,9 +24,9 @@ describe "BillableCategory", "REST methods" do
24
24
  billable_categories = File.read("spec/fixtures/caren_billable_categories.xml")
25
25
  billable_categories_search = File.read("spec/fixtures/caren_billable_categories_search.xml")
26
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" )
27
+ billable_category_url = Caren::Api.session.url_for( Caren::Store::BillableCategory.resource_url(1) )
28
+ billable_categories_url = Caren::Api.session.url_for( Caren::Store::BillableCategory.resource_url )
29
+ search_url = Caren::Api.session.url_for( "#{Caren::Store::BillableCategory.resource_url}?key=name&value=billables" )
30
30
 
31
31
  timestamp = DateTime.now.to_i
32
32
 
@@ -36,18 +36,18 @@ describe "BillableCategory", "REST methods" do
36
36
  end
37
37
 
38
38
  it "should be able to search for a specific billable category" do
39
- billable_categories = Caren::BillableCategory.search :name, "billables", Caren::Api.session
39
+ billable_categories = Caren::Store::BillableCategory.search :name, "billables", Caren::Api.session
40
40
  billable_categories.should have(1).things
41
41
  billable_categories.first.name.should == "Billables"
42
42
  end
43
43
 
44
44
  it "should be able to find a billable category" do
45
- billable_category = Caren::BillableCategory.find 1, Caren::Api.session
45
+ billable_category = Caren::Store::BillableCategory.find 1, Caren::Api.session
46
46
  billable_category.name.should == "Billables"
47
47
  end
48
48
 
49
49
  it "should be able to find all billable category" do
50
- billable_categories = Caren::BillableCategory.all Caren::Api.session
50
+ billable_categories = Caren::Store::BillableCategory.all Caren::Api.session
51
51
  billable_categories.should have(2).things
52
52
  billable_categories.first.name.should == "Products"
53
53
  end
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  describe "Billable", "converting to xml" do
4
4
 
5
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" )
6
+ @billable_a = Caren::Store::Billable.new( :name => "Washing", :price => 100.euros, :in_store => true, :type => "Product" )
7
+ @billable_b = Caren::Store::Billable.new( :name => "Bedpan", :price => 100.euros, :in_store => false, :type => "Product" )
8
8
  end
9
9
 
10
10
  it "should be able to convert a billable to valid xml" do
@@ -24,9 +24,9 @@ describe "Billable", "REST methods" do
24
24
  billables = File.read("spec/fixtures/caren_billables.xml")
25
25
  billable_search = File.read("spec/fixtures/caren_billables_search.xml")
26
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" )
27
+ billable_url = Caren::Api.session.url_for( Caren::Store::Billable.resource_url(1) )
28
+ billables_url = Caren::Api.session.url_for( Caren::Store::Billable.resource_url )
29
+ search_url = Caren::Api.session.url_for( "#{Caren::Store::Billable.resource_url}?key=name&value=bedpan" )
30
30
 
31
31
  timestamp = DateTime.now.to_i
32
32
 
@@ -34,30 +34,35 @@ describe "Billable", "REST methods" do
34
34
  FakeWeb.register_uri(:put, billable_url, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp) )
35
35
  FakeWeb.register_uri(:get, billables_url, :body => billables, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billables) )
36
36
  FakeWeb.register_uri(:get, billable_url, :body => billable, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billable) )
37
+ FakeWeb.register_uri(:delete, billable_url, :body => nil, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,nil) )
37
38
  FakeWeb.register_uri(:get, search_url, :body => billable_search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,billable_search) )
38
39
  end
39
40
 
40
41
  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
+ lambda{ Caren::Store::Billable.new( :id => 1, :name => "Bedpan" ).update( Caren::Api.session ) }.should_not raise_error
42
43
  end
43
44
 
44
45
  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
+ lambda{ Caren::Store::Billable.new( :id => 1 ).update_photo( "spec/fixtures/bacon.jpg", Caren::Api.session ) }.should_not raise_error
46
47
  end
47
48
 
48
49
  it "should be able to find a specific billable" do
49
- billable = Caren::Billable.find 1, Caren::Api.session
50
+ billable = Caren::Store::Billable.find 1, Caren::Api.session
50
51
  billable.name.should == "Dishwashing"
51
52
  end
53
+
54
+ it "should be able to delete a specific billable" do
55
+ lambda{ Caren::Store::Billable.new( :id => 1 ).delete(Caren::Api.session) }.should_not raise_error
56
+ end
52
57
 
53
58
  it "should be able to search for a specific product" do
54
- billables = Caren::Billable.search :name, "bedpan", Caren::Api.session
59
+ billables = Caren::Store::Billable.search :name, "bedpan", Caren::Api.session
55
60
  billables.should have(1).things
56
61
  billables.first.name.should == "bedpan"
57
62
  end
58
63
 
59
64
  it "should be able to find all billables" do
60
- billables = Caren::Billable.all Caren::Api.session
65
+ billables = Caren::Store::Billable.all Caren::Api.session
61
66
  billables.should have(2).things
62
67
  billables.first.name.should == "Dishwashing"
63
68
  end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Store::Invoice", "converting to xml" do
4
+
5
+ before do
6
+ @line_item_a = Caren::Store::LineItem.new( :price_in_cents => 1900 )
7
+ @line_item_b = Caren::Store::LineItem.new( :price_in_cents => 1499 )
8
+ @address = Caren::Store::Address.new( :full_name => "Andre Foeken")
9
+ @invoice_a = Caren::Store::Invoice.new( :reference => "NW-05463-12-A", :line_items => [@line_item_a,@line_item_b], :shipping_address => @address )
10
+ @invoice_b = Caren::Store::Invoice.new( :reference => "NW-05463-12-B", :billing_address => @address )
11
+ end
12
+
13
+ it "should be able to convert a line item to valid xml" do
14
+ # A bit nasty but it works
15
+ new_object = Caren::Store::Invoice.from_xml( @invoice_a.to_xml )
16
+ new_object.shipping_address.attributes.should == @invoice_a.shipping_address.attributes
17
+
18
+ count = 0
19
+ new_object.line_items.each do |li|
20
+ li.attributes.should == @invoice_a.line_items[count].attributes
21
+ count += 1
22
+ end
23
+
24
+ @invoice_a.attributes.delete :shipping_address
25
+ @invoice_a.attributes.delete :line_items
26
+
27
+ new_object.attributes.delete :shipping_address
28
+ new_object.attributes.delete :line_items
29
+
30
+ new_object.attributes.should == @invoice_a.attributes
31
+ end
32
+
33
+ end
34
+
35
+ describe "Store::Invoice", "REST methods" do
36
+
37
+ before do
38
+ invoice = File.read("spec/fixtures/caren_invoice.xml")
39
+ invoices = File.read("spec/fixtures/caren_invoices.xml")
40
+ invoices_search = File.read("spec/fixtures/caren_invoices_search.xml")
41
+
42
+ invoice_url = Caren::Api.session.url_for( Caren::Store::Invoice.resource_url(17) )
43
+ invoice_email_url = Caren::Api.session.url_for( "#{Caren::Store::Invoice.resource_url(17)}/email" )
44
+ invoices_url = Caren::Api.session.url_for( Caren::Store::Invoice.resource_url )
45
+ invoices_search_url = Caren::Api.session.url_for( "#{Caren::Store::Invoice.resource_url}?key=reference&value=NW-05463-12-0" )
46
+ timestamp = DateTime.now.to_i
47
+
48
+ FakeWeb.register_uri(:get, invoices_url, :body => invoices, :signature => Caren::Api.session.sign(timestamp,nil,invoices), :timestamp => timestamp )
49
+ FakeWeb.register_uri(:get, invoices_search_url, :body => invoices_search, :signature => Caren::Api.session.sign(timestamp,nil,invoices_search), :timestamp => timestamp )
50
+ FakeWeb.register_uri(:get, invoice_url, :body => invoice, :signature => Caren::Api.session.sign(timestamp,nil,invoice), :timestamp => timestamp )
51
+
52
+ FakeWeb.register_uri(:post, invoice_email_url, :status => 201, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
53
+ FakeWeb.register_uri(:post, invoices_url, :status => 201, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
54
+ FakeWeb.register_uri(:put, invoice_url, :body => invoice, :signature => Caren::Api.session.sign(timestamp,nil,invoice), :timestamp => timestamp )
55
+ FakeWeb.register_uri(:delete, invoice_url, :signature => Caren::Api.session.sign(timestamp), :timestamp => timestamp )
56
+ end
57
+
58
+ it "should be able to find all invoices" do
59
+ invoices = Caren::Store::Invoice.all Caren::Api.session
60
+ invoices.should have(3).things
61
+ invoices.first.customer_email.should == "jenny@example.com"
62
+ end
63
+
64
+ it "should be able to find one invoice" do
65
+ invoice = Caren::Store::Invoice.find 17, Caren::Api.session
66
+ invoice.customer_email.should == "jenny@example.com"
67
+ end
68
+
69
+ it "should be able to search for a specific invoice" do
70
+ billables = Caren::Store::Invoice.search :reference, "NW-05463-12-0", Caren::Api.session
71
+ billables.should have(1).things
72
+ billables.first.reference.should == "NW-05463-12-0"
73
+ end
74
+
75
+ it "should be able to create an invoice" do
76
+ lambda{ Caren::Store::Invoice.new( :reference => "JL-1" ).create(Caren::Api.session) }.should_not raise_error
77
+ end
78
+
79
+ it "should be able to update an invoice" do
80
+ lambda{ Caren::Store::Invoice.new( :id => 17, :reference => "JL-1" ).update(Caren::Api.session) }.should_not raise_error
81
+ end
82
+
83
+ it "should be able to email an invoice" do
84
+ lambda{ Caren::Store::Invoice.new( :id => 17 ).email(Caren::Api.session) }.should_not raise_error
85
+ end
86
+
87
+ it "should be able to delete an external invoice" do
88
+ lambda{ Caren::Store::Invoice.new( :id => 17 ).delete(Caren::Api.session) }.should_not raise_error
89
+ end
90
+
91
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Store::LineItem", "converting to xml" do
4
+
5
+ before do
6
+ @line_item_a = Caren::Store::LineItem.new( :price_in_cents => 1900 )
7
+ @line_item_b = Caren::Store::LineItem.new( :price_in_cents => 1499 )
8
+ end
9
+
10
+ it "should be able to convert a line item to valid xml" do
11
+ @line_item_a.should convert_to_valid_caren_xml
12
+ end
13
+
14
+ it "should be able to convert an array of line items to valid xml" do
15
+ [@line_item_a,@line_item_b].should convert_to_valid_caren_array_xml
16
+ end
17
+
18
+ end
19
+
20
+ describe "LineItem", "REST methods" do
21
+
22
+ before do
23
+ line_item_url = Caren::Api.session.url_for( Caren::Store::LineItem.resource_url(1) )
24
+ timestamp = DateTime.now.to_i
25
+ FakeWeb.register_uri(:delete, line_item_url, :body => nil, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,nil) )
26
+ end
27
+
28
+ it "should be able to delete a specific line item" do
29
+ lambda{ Caren::Store::LineItem.new(:id=>1).delete Caren::Api.session }.should_not raise_error
30
+ end
31
+
32
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Store::Payment", "REST methods" do
4
+
5
+ before do
6
+ payments = File.read("spec/fixtures/caren_payments.xml")
7
+ payments_search = File.read("spec/fixtures/caren_payments_search.xml")
8
+
9
+ payments_url = Caren::Api.session.url_for( Caren::Store::Payment.resource_url )
10
+ search_url = Caren::Api.session.url_for( "#{Caren::Store::Payment.resource_url}?key=status&value=failed" )
11
+
12
+ timestamp = DateTime.now.to_i
13
+
14
+ FakeWeb.register_uri(:get, payments_url, :body => payments, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,payments) )
15
+ FakeWeb.register_uri(:get, search_url, :body => payments_search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,payments_search) )
16
+ end
17
+
18
+ it "should be able to search for a specific billable category" do
19
+ payments_search = Caren::Store::Payment.search :status, "failed", Caren::Api.session
20
+ payments_search.should have(1).things
21
+ payments_search.first.status.should == "failed"
22
+ end
23
+
24
+ it "should be able to find all billable category" do
25
+ payments = Caren::Store::Payment.all Caren::Api.session
26
+ payments.should have(2).things
27
+ payments.first.status.should == "paid"
28
+ end
29
+
30
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caren-api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 75
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 34
10
- version: 0.4.34
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
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-10 00:00:00 Z
18
+ date: 2012-04-03 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  requirement: &id001 !ruby/object:Gem::Requirement
@@ -168,8 +168,6 @@ files:
168
168
  - init.rb
169
169
  - lib/caren-api.rb
170
170
  - lib/caren/base.rb
171
- - lib/caren/billable.rb
172
- - lib/caren/billable_category.rb
173
171
  - lib/caren/care_provider.rb
174
172
  - lib/caren/caren.rb
175
173
  - lib/caren/client.rb
@@ -180,9 +178,14 @@ files:
180
178
  - lib/caren/event_slot_container.rb
181
179
  - lib/caren/external_message.rb
182
180
  - lib/caren/link.rb
181
+ - lib/caren/store/address.rb
182
+ - lib/caren/store/billable.rb
183
+ - lib/caren/store/billable_category.rb
184
+ - lib/caren/store/invoice.rb
185
+ - lib/caren/store/line_item.rb
186
+ - lib/caren/store/payment.rb
187
+ - lib/caren/store/store.rb
183
188
  - spec/.DS_Store
184
- - spec/billable_category_spec.rb
185
- - spec/billable_spec.rb
186
189
  - spec/care_provider_spec.rb
187
190
  - spec/caren_spec.rb
188
191
  - spec/client_spec.rb
@@ -204,15 +207,26 @@ files:
204
207
  - spec/fixtures/caren_care_providers_search.xml
205
208
  - spec/fixtures/caren_external_message.xml
206
209
  - spec/fixtures/caren_external_messages.xml
210
+ - spec/fixtures/caren_invoice.xml
211
+ - spec/fixtures/caren_invoices.xml
212
+ - spec/fixtures/caren_invoices_search.xml
207
213
  - spec/fixtures/caren_link.xml
208
214
  - spec/fixtures/caren_links.xml
209
215
  - spec/fixtures/caren_links_search.xml
216
+ - spec/fixtures/caren_payments.xml
217
+ - spec/fixtures/caren_payments_search.xml
210
218
  - spec/fixtures/caren_unauthorized.xml
211
219
  - spec/fixtures/incoming.xml
212
220
  - spec/fixtures/incoming_single_object.xml
213
221
  - spec/link_spec.rb
214
222
  - spec/spec.opts
215
223
  - spec/spec_helper.rb
224
+ - spec/store/address_spec.rb
225
+ - spec/store/billable_category_spec.rb
226
+ - spec/store/billable_spec.rb
227
+ - spec/store/invoice_spec.rb
228
+ - spec/store/line_items_spec.rb
229
+ - spec/store/payment_spec.rb
216
230
  homepage: http://github.com/foeken/caren-api
217
231
  licenses:
218
232
  - MIT