lib/economic/proxies/creditor_proxy.rb in rconomic-0.4 vs lib/economic/proxies/creditor_proxy.rb in rconomic-0.4.1
- old
+ new
@@ -1,61 +1,14 @@
require 'economic/proxies/entity_proxy'
+require 'economic/proxies/actions/find_by_ci_number'
+require 'economic/proxies/actions/find_by_handle_with_number'
+require 'economic/proxies/actions/find_by_number'
module Economic
class CreditorProxy < EntityProxy
-
- # Fetches Creditor from API
- def find(handle)
- handle = if handle.respond_to?(:to_i)
- Entity::Handle.new(:number => handle.to_i)
- else
- Entity::Handle.new(handle)
- end
- super(handle)
- end
-
- # Returns Creditors that have the given ci_number. The Creditor objects will only be partially loaded
- def find_by_ci_number(ci_number)
- # Get a list of CreditorHandles from e-conomic
- response = session.request(entity_class.soap_action('FindByCINumber')) do
- soap.body = {
- 'ciNumber' => ci_number
- }
- end
-
- # Make sure we always have an array of handles even if the result only contains one
- handles = [response[:creditor_handle]].flatten.reject(&:blank?)
-
- # Create partial Creditor entities
- handles.collect do |handle|
- creditor = build
- creditor.partial = true
- creditor.persisted = true
- creditor.handle = handle
- creditor.number = handle[:number]
- creditor
- end
- end
-
- # Returns handle with a given number.
- def find_by_number(number)
- response = session.request(entity_class.soap_action('FindByNumber')) do
- soap.body = {
- 'number' => number
- }
- end
-
- if response == {}
- nil
- else
- creditor = build
- creditor.partial = true
- creditor.persisted = true
- creditor.handle = response
- creditor.number = response[:number].to_i
- creditor
- end
- end
+ include FindByCiNumber
+ include FindByHandleWithNumber
+ include FindByNumber
def create_simple(opts)
response = session.request(entity_class.soap_action('Create')) do
soap.body = {
'number' => opts[:number],