rconomic 0.5.0 → 0.5.1
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.
- checksums.yaml +6 -14
- data/.travis.yml +0 -1
- data/Gemfile +0 -1
- data/lib/economic/account.rb +3 -5
- data/lib/economic/cash_book.rb +1 -1
- data/lib/economic/cash_book_entry.rb +92 -94
- data/lib/economic/creditor.rb +1 -1
- data/lib/economic/creditor_contact.rb +15 -17
- data/lib/economic/creditor_entry.rb +0 -1
- data/lib/economic/current_invoice.rb +32 -35
- data/lib/economic/current_invoice_line.rb +14 -2
- data/lib/economic/debtor.rb +60 -37
- data/lib/economic/debtor_contact.rb +26 -20
- data/lib/economic/endpoint.rb +72 -0
- data/lib/economic/entity/handle.rb +35 -21
- data/lib/economic/entity/mapper.rb +41 -0
- data/lib/economic/entity.rb +58 -34
- data/lib/economic/invoice.rb +15 -2
- data/lib/economic/proxies/account_proxy.rb +2 -3
- data/lib/economic/proxies/actions/find_by_ci_number.rb +4 -2
- data/lib/economic/proxies/actions/find_by_date_interval.rb +0 -1
- data/lib/economic/proxies/actions/find_by_name.rb +5 -1
- data/lib/economic/proxies/cash_book_entry_proxy.rb +1 -1
- data/lib/economic/proxies/entity_proxy.rb +15 -8
- data/lib/economic/session.rb +27 -31
- data/lib/rconomic/version.rb +1 -1
- data/rconomic.gemspec +1 -5
- data/spec/economic/cash_book_entry_spec.rb +27 -5
- data/spec/economic/cash_book_spec.rb +6 -6
- data/spec/economic/creditor_contact_spec.rb +24 -15
- data/spec/economic/creditor_spec.rb +9 -9
- data/spec/economic/current_invoice_line_spec.rb +7 -7
- data/spec/economic/current_invoice_spec.rb +82 -33
- data/spec/economic/debtor_contact_spec.rb +25 -15
- data/spec/economic/debtor_entry_spec.rb +3 -3
- data/spec/economic/debtor_spec.rb +49 -15
- data/spec/economic/endpoint_spec.rb +71 -0
- data/spec/economic/entity/handle_spec.rb +42 -49
- data/spec/economic/entity/mapper_spec.rb +54 -0
- data/spec/economic/entity_spec.rb +78 -72
- data/spec/economic/entry_spec.rb +3 -3
- data/spec/economic/invoice_spec.rb +37 -18
- data/spec/economic/proxies/actions/find_by_name_spec.rb +15 -12
- data/spec/economic/proxies/cash_book_entry_proxy_spec.rb +26 -24
- data/spec/economic/proxies/cash_book_proxy_spec.rb +23 -21
- data/spec/economic/proxies/creditor_contact_proxy_spec.rb +12 -16
- data/spec/economic/proxies/creditor_entry_proxy_spec.rb +18 -14
- data/spec/economic/proxies/creditor_proxy_spec.rb +23 -26
- data/spec/economic/proxies/current_invoice_line_proxy_spec.rb +17 -20
- data/spec/economic/proxies/current_invoice_proxy_spec.rb +38 -41
- data/spec/economic/proxies/debtor_contact_proxy_spec.rb +12 -15
- data/spec/economic/proxies/debtor_entry_proxy_spec.rb +18 -14
- data/spec/economic/proxies/debtor_proxy_spec.rb +31 -34
- data/spec/economic/proxies/entry_proxy_spec.rb +26 -22
- data/spec/economic/proxies/invoice_proxy_spec.rb +18 -21
- data/spec/economic/session_spec.rb +57 -44
- data/spec/fixtures/{spec_entity_create_from_data → account_create_from_data}/success.xml +5 -5
- data/spec/fixtures/{spec_entity_delete → account_delete}/success.xml +1 -1
- data/spec/fixtures/{spec_entity_get_data → account_get_data}/success.xml +5 -5
- data/spec/fixtures/{spec_entity_update_from_data → account_update_from_data}/success.xml +5 -5
- data/spec/fixtures/cash_book_entry_create_creditor_invoice/success.xml +2 -2
- data/spec/fixtures/cash_book_entry_create_creditor_payment/success.xml +2 -2
- data/spec/fixtures/creditor_contact_create_from_data/success.xml +10 -0
- data/spec/fixtures/debtor_contact_create_from_data/success.xml +10 -0
- data/spec/fixtures/debtor_create_from_data/success.xml +57 -0
- data/spec/spec_helper.rb +10 -104
- data/spec/support/api_requests.rb +20 -0
- data/spec/support/factories.rb +65 -0
- data/spec/support/fixtures.rb +9 -0
- metadata +27 -31
@@ -18,7 +18,16 @@ module Economic
|
|
18
18
|
# contact.name = 'John Appleseed'
|
19
19
|
# contact.save
|
20
20
|
class DebtorContact < Entity
|
21
|
-
has_properties :id,
|
21
|
+
has_properties :id,
|
22
|
+
:debtor_handle,
|
23
|
+
:name,
|
24
|
+
:number,
|
25
|
+
:telephone_number,
|
26
|
+
:email,
|
27
|
+
:comments,
|
28
|
+
:external_id,
|
29
|
+
:is_to_receive_email_copy_of_order,
|
30
|
+
:is_to_receive_email_copy_of_invoice
|
22
31
|
|
23
32
|
def debtor
|
24
33
|
return nil if debtor_handle.nil?
|
@@ -36,29 +45,26 @@ module Economic
|
|
36
45
|
end
|
37
46
|
|
38
47
|
def handle
|
39
|
-
@handle
|
48
|
+
@handle || Handle.new({:id => @id})
|
40
49
|
end
|
41
50
|
|
42
51
|
protected
|
43
52
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
return data
|
53
|
+
# Returns the field rules to use when mapping to SOAP data
|
54
|
+
def fields
|
55
|
+
[
|
56
|
+
["Handle", :handle, Proc.new { |v| v.to_hash }, :required],
|
57
|
+
["Id", :handle, Proc.new { |v| v.id }, :required],
|
58
|
+
["DebtorHandle", :debtor, Proc.new { |v| v.handle.to_hash }],
|
59
|
+
["Name", :name, nil, :required],
|
60
|
+
["Number", :number],
|
61
|
+
["TelephoneNumber", :telephone_number],
|
62
|
+
["Email", :email],
|
63
|
+
["Comments", :comments],
|
64
|
+
["ExternalId", :external_id],
|
65
|
+
["IsToReceiveEmailCopyOfOrder", :is_to_receive_email_copy_of_order, Proc.new { |v| v || false }, :required],
|
66
|
+
["IsToReceiveEmailCopyOfInvoice", :is_to_receive_email_copy_of_invoice, Proc.new { |v| v || false }, :required]
|
67
|
+
]
|
60
68
|
end
|
61
|
-
|
62
69
|
end
|
63
|
-
|
64
70
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Economic::Endpoint models the actual SOAP endpoint at E-conomic.
|
2
|
+
#
|
3
|
+
# This is where all knowledge of SOAP actions and requests exists.
|
4
|
+
class Economic::Endpoint
|
5
|
+
|
6
|
+
# Invokes soap_action on the API endpoint with the given data.
|
7
|
+
#
|
8
|
+
# Returns a Hash with the resulting response from the endpoint as a Hash.
|
9
|
+
#
|
10
|
+
# If you need access to more details from the unparsed SOAP response, supply
|
11
|
+
# a block to `call`. A Savon::Response will be yielded to the block.
|
12
|
+
def call(soap_action, data = nil, cookies = nil)
|
13
|
+
# set_client_headers(headers)
|
14
|
+
|
15
|
+
response = request(soap_action, data, cookies)
|
16
|
+
|
17
|
+
if block_given?
|
18
|
+
yield response
|
19
|
+
else
|
20
|
+
extract_result_from_response(response, soap_action)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns a Savon::Client to connect to the e-conomic endpoint
|
25
|
+
#
|
26
|
+
# Cached on class-level to avoid loading the big WSDL file more than once (can
|
27
|
+
# take several hundred megabytes of RAM after a while...)
|
28
|
+
def client
|
29
|
+
@@client ||= Savon.client do
|
30
|
+
wsdl File.expand_path(File.join(File.dirname(__FILE__), "economic.wsdl"))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns the E-conomic API action name to call
|
35
|
+
def soap_action_name(entity_class, action)
|
36
|
+
[
|
37
|
+
class_name_without_modules(entity_class),
|
38
|
+
action.to_s
|
39
|
+
].collect(&:snakecase).join("_").intern
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def class_name_without_modules(entity_class)
|
45
|
+
class_name = entity_class.to_s
|
46
|
+
class_name.split('::').last
|
47
|
+
end
|
48
|
+
|
49
|
+
def extract_result_from_response(response, soap_action)
|
50
|
+
response = response.to_hash
|
51
|
+
|
52
|
+
response_key = "#{soap_action}_response".intern
|
53
|
+
result_key = "#{soap_action}_result".intern
|
54
|
+
|
55
|
+
if response[response_key] && response[response_key][result_key]
|
56
|
+
response[response_key][result_key]
|
57
|
+
else
|
58
|
+
{}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def request(soap_action, data, cookies)
|
63
|
+
locals = {}
|
64
|
+
locals[:message] = data if data && !data.empty?
|
65
|
+
locals[:cookies] = cookies if cookies && !cookies.empty?
|
66
|
+
|
67
|
+
client.call(
|
68
|
+
soap_action,
|
69
|
+
locals
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
@@ -1,13 +1,29 @@
|
|
1
1
|
class Economic::Entity
|
2
2
|
class Handle
|
3
|
-
attr_accessor :id, :id1, :id2, :number, :serial_number
|
4
|
-
|
5
3
|
def self.build(options)
|
6
4
|
return options if options.is_a?(Handle)
|
7
5
|
return nil if options.nil?
|
8
6
|
new(options)
|
9
7
|
end
|
10
8
|
|
9
|
+
def self.id_properties
|
10
|
+
{
|
11
|
+
:code => 'Code',
|
12
|
+
:id => 'Id',
|
13
|
+
:id1 => 'Id1',
|
14
|
+
:id2 => 'Id2',
|
15
|
+
:number => 'Number',
|
16
|
+
:serial_number => 'SerialNumber',
|
17
|
+
:vat_code => 'VatCode'
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.supported_keys
|
22
|
+
id_properties.keys
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_accessor *supported_keys
|
26
|
+
|
11
27
|
# Returns true if Handle hasn't been initialized with any values yet. This
|
12
28
|
# usually happens when the handle is constructed for an entity whose id
|
13
29
|
# properties (id, number, etc) haven't been set yet.
|
@@ -19,26 +35,26 @@ class Economic::Entity
|
|
19
35
|
verify_sanity_of_arguments!(hash)
|
20
36
|
hash = prepare_hash_argument(hash) unless hash.is_a?(self.class)
|
21
37
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
38
|
+
[:code, :vat_code].each do |key|
|
39
|
+
instance_variable_set("@#{key}", hash[key]) if hash[key]
|
40
|
+
end
|
41
|
+
[:id, :id1, :id2, :number, :serial_number].each do |key|
|
42
|
+
instance_variable_set("@#{key}", hash[key].to_i) if hash[key]
|
43
|
+
end
|
27
44
|
end
|
28
45
|
|
29
46
|
def to_hash(only_keys = id_properties.keys)
|
30
47
|
only_keys = [only_keys].flatten
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
hash
|
48
|
+
only_keys.each_with_object({}) do |key, hash|
|
49
|
+
property = id_properties[key]
|
50
|
+
value = self.send(key)
|
51
|
+
next if value.blank?
|
52
|
+
hash[property] = value
|
53
|
+
end
|
38
54
|
end
|
39
55
|
|
40
56
|
def [](key)
|
41
|
-
{
|
57
|
+
instance_variable_get("@#{key}")
|
42
58
|
end
|
43
59
|
|
44
60
|
def ==(other)
|
@@ -49,13 +65,14 @@ class Economic::Entity
|
|
49
65
|
self.id == other.id && self.number == other.number && self.id1 == other.id1 && self.id2 == other.id2
|
50
66
|
end
|
51
67
|
|
52
|
-
|
68
|
+
private
|
53
69
|
|
54
70
|
def id_properties
|
55
|
-
|
71
|
+
self.class.id_properties
|
56
72
|
end
|
57
73
|
|
58
|
-
# Raises exceptions if hash doesn't contain values we can use to construct a
|
74
|
+
# Raises exceptions if hash doesn't contain values we can use to construct a
|
75
|
+
# new handle
|
59
76
|
def verify_sanity_of_arguments!(hash)
|
60
77
|
return if hash.is_a?(self.class)
|
61
78
|
|
@@ -66,9 +83,6 @@ class Economic::Entity
|
|
66
83
|
if hash.respond_to?(:keys)
|
67
84
|
unknown_keys = hash.keys - id_properties.keys - id_properties.values
|
68
85
|
raise ArgumentError.new("Unknown keys in handle: #{unknown_keys.inspect}") unless unknown_keys.empty?
|
69
|
-
|
70
|
-
not_to_iable = hash.select { |k, v| !v.respond_to?(:to_i) }
|
71
|
-
raise ArgumentError.new("All values must respond to to_i. #{not_to_iable.inspect} didn't") unless not_to_iable.empty?
|
72
86
|
end
|
73
87
|
end
|
74
88
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Economic
|
2
|
+
# Entity::Mapper provides a generic way of building SOAP data structures for
|
3
|
+
# entities.
|
4
|
+
#
|
5
|
+
# Based on an Entity and a set of rules that define the fields to map to, it
|
6
|
+
# returns a Hash named and ordered properly, ready for passing to the
|
7
|
+
# endpoint as SOAP data.
|
8
|
+
class Entity::Mapper
|
9
|
+
attr_reader :entity, :fields
|
10
|
+
|
11
|
+
def initialize(entity, fields = [])
|
12
|
+
@entity = entity
|
13
|
+
@fields = fields
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_hash
|
17
|
+
data = {}
|
18
|
+
|
19
|
+
fields.each do |field, method, formatter, required|
|
20
|
+
value = entity.send(method)
|
21
|
+
present = present?(value)
|
22
|
+
|
23
|
+
if present || required
|
24
|
+
value = formatter.call(value) if formatter
|
25
|
+
data[field] = value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
return data
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def present?(value)
|
35
|
+
!(
|
36
|
+
(value.respond_to?(:blank?) && value.blank?) ||
|
37
|
+
(value.respond_to?(:empty?) && value.empty?)
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/economic/entity.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
require 'economic/endpoint'
|
1
2
|
require 'economic/entity/handle'
|
3
|
+
require 'economic/entity/mapper'
|
2
4
|
|
3
5
|
module Economic
|
4
6
|
class Entity
|
@@ -16,27 +18,51 @@ module Economic
|
|
16
18
|
@default_values || {}
|
17
19
|
end
|
18
20
|
|
21
|
+
# Create a setter method for property that converts its input to a Handle
|
22
|
+
def handle_writer(property)
|
23
|
+
define_method "#{property}=" do |value|
|
24
|
+
value = Economic::Entity::Handle.new(value) if value
|
25
|
+
instance_variable_set("@#{property}", value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
19
29
|
def properties_not_triggering_full_load
|
20
30
|
[:id, :number, :handle]
|
21
31
|
end
|
22
32
|
|
33
|
+
# Create a property getter that loads the full Entity from the API if
|
34
|
+
# necessary
|
35
|
+
def property_reader(property)
|
36
|
+
define_method "#{property}" do
|
37
|
+
value = instance_variable_get("@#{property}")
|
38
|
+
if value.nil? && partial? && persisted?
|
39
|
+
instance_variable_get("@#{property}")
|
40
|
+
else
|
41
|
+
value
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Create a property setter for property
|
47
|
+
def property_writer(property)
|
48
|
+
if property.to_s.end_with?("_handle")
|
49
|
+
handle_writer property
|
50
|
+
else
|
51
|
+
# Just use regular writers
|
52
|
+
attr_writer property
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
23
56
|
def has_properties(*properties)
|
24
57
|
@properties = properties
|
25
58
|
properties.each do |property|
|
59
|
+
# Create a getter for property
|
26
60
|
unless properties_not_triggering_full_load.include?(property)
|
27
|
-
|
28
|
-
define_method "#{property}" do
|
29
|
-
value = instance_variable_get("@#{property}")
|
30
|
-
if value.nil? && partial? && persisted?
|
31
|
-
instance_variable_get("@#{property}")
|
32
|
-
else
|
33
|
-
value
|
34
|
-
end
|
35
|
-
end
|
61
|
+
property_reader property
|
36
62
|
end
|
37
63
|
|
38
|
-
#
|
39
|
-
|
64
|
+
# Create a setter for property
|
65
|
+
property_writer property
|
40
66
|
end
|
41
67
|
end
|
42
68
|
|
@@ -51,14 +77,8 @@ module Economic
|
|
51
77
|
Economic.const_get(proxy_class_name)
|
52
78
|
end
|
53
79
|
|
54
|
-
# Returns
|
55
|
-
|
56
|
-
class_name = self.name
|
57
|
-
class_name_without_modules = class_name.split('::').last
|
58
|
-
"#{class_name_without_modules.snakecase}_#{action.to_s.snakecase}".intern
|
59
|
-
end
|
60
|
-
|
61
|
-
# Returns a symbol based on the name of the entity. Used to request and read data responses.
|
80
|
+
# Returns a symbol based on the name of the entity. Used to request and
|
81
|
+
# read data responses.
|
62
82
|
#
|
63
83
|
# Entity.key #=> :entity
|
64
84
|
# CurrentInvoice.key #=> :current_invoice
|
@@ -71,7 +91,7 @@ module Economic
|
|
71
91
|
end
|
72
92
|
|
73
93
|
def handle
|
74
|
-
@handle
|
94
|
+
@handle || Handle.build({:number => @number, :id => @id})
|
75
95
|
end
|
76
96
|
|
77
97
|
def handle=(handle)
|
@@ -92,13 +112,15 @@ module Economic
|
|
92
112
|
self.partial = false
|
93
113
|
self.persisted = true
|
94
114
|
end
|
95
|
-
|
96
|
-
# Returns the number of Entity. This does not trigger a load from the API
|
115
|
+
|
116
|
+
# Returns the number of Entity. This does not trigger a load from the API
|
117
|
+
# even if Entity is partial
|
97
118
|
def number
|
98
119
|
@number
|
99
120
|
end
|
100
121
|
|
101
|
-
# Returns the id of Entity. This does not trigger a load from the API even
|
122
|
+
# Returns the id of Entity. This does not trigger a load from the API even
|
123
|
+
# if Entity is partial
|
102
124
|
def id
|
103
125
|
@id
|
104
126
|
end
|
@@ -114,9 +136,9 @@ module Economic
|
|
114
136
|
!!@partial
|
115
137
|
end
|
116
138
|
|
117
|
-
# Returns a proxy for entities of the current class. For example if called
|
118
|
-
# Economic::Debtor it returns an instance of Economic::DebtorProxy
|
119
|
-
# owner.
|
139
|
+
# Returns a proxy for entities of the current class. For example if called
|
140
|
+
# on an Economic::Debtor it returns an instance of Economic::DebtorProxy
|
141
|
+
# with the Debtors session as owner.
|
120
142
|
def proxy
|
121
143
|
self.class.proxy.new(session)
|
122
144
|
end
|
@@ -157,7 +179,7 @@ module Economic
|
|
157
179
|
self.handle == other.handle && other.is_a?(self.class)
|
158
180
|
end
|
159
181
|
|
160
|
-
|
182
|
+
protected
|
161
183
|
|
162
184
|
def create_or_update
|
163
185
|
if persisted?
|
@@ -202,16 +224,19 @@ module Economic
|
|
202
224
|
|
203
225
|
# Returns Hash with the data structure to send to the API
|
204
226
|
def build_soap_data
|
205
|
-
|
227
|
+
Entity::Mapper.new(self, fields).to_hash
|
206
228
|
end
|
207
229
|
|
208
|
-
|
209
|
-
|
210
|
-
session.request(soap_action_name(action), data)
|
230
|
+
def fields
|
231
|
+
raise NotImplementedError, "Subclasses of Economic::Entity must implement `fields`"
|
211
232
|
end
|
212
233
|
|
213
|
-
|
214
|
-
|
234
|
+
# Requests an action from the API endpoint
|
235
|
+
def request(action, data = nil)
|
236
|
+
session.request(
|
237
|
+
Endpoint.new.soap_action_name(self.class, action),
|
238
|
+
data
|
239
|
+
)
|
215
240
|
end
|
216
241
|
|
217
242
|
def class_name
|
@@ -224,5 +249,4 @@ module Economic
|
|
224
249
|
end
|
225
250
|
end
|
226
251
|
end
|
227
|
-
|
228
252
|
end
|
data/lib/economic/invoice.rb
CHANGED
@@ -2,7 +2,20 @@ require 'economic/entity'
|
|
2
2
|
|
3
3
|
module Economic
|
4
4
|
class Invoice < Entity
|
5
|
-
has_properties :number,
|
5
|
+
has_properties :number,
|
6
|
+
:net_amount,
|
7
|
+
:vat_amount,
|
8
|
+
:due_date,
|
9
|
+
:debtor_handle,
|
10
|
+
:debtor_name,
|
11
|
+
:debtor_name,
|
12
|
+
:debtor_address,
|
13
|
+
:debtor_postal_code,
|
14
|
+
:debtor_city,
|
15
|
+
:debtor_country,
|
16
|
+
:debtor_ean,
|
17
|
+
:attention_handle,
|
18
|
+
:heading
|
6
19
|
|
7
20
|
def attention
|
8
21
|
return nil if attention_handle.nil?
|
@@ -49,7 +62,7 @@ module Economic
|
|
49
62
|
# end
|
50
63
|
def pdf
|
51
64
|
response = request(:get_pdf, {
|
52
|
-
|
65
|
+
"invoiceHandle" => handle.to_hash
|
53
66
|
})
|
54
67
|
|
55
68
|
Base64.decode64(response)
|
@@ -6,15 +6,14 @@ module Economic
|
|
6
6
|
response = request('FindByName', {
|
7
7
|
'name' => name
|
8
8
|
})
|
9
|
-
|
9
|
+
|
10
10
|
handle = response[:account_handle]
|
11
|
-
|
11
|
+
|
12
12
|
entity = build(response)
|
13
13
|
entity.name = name
|
14
14
|
entity.number = handle[:number]
|
15
15
|
entity.persisted = true
|
16
16
|
entity
|
17
|
-
|
18
17
|
end
|
19
18
|
end
|
20
19
|
end
|
@@ -1,12 +1,14 @@
|
|
1
1
|
module FindByCiNumber
|
2
|
-
# Returns Debtors that have the given ci_number. The Debtor objects will only
|
2
|
+
# Returns Debtors that have the given ci_number. The Debtor objects will only
|
3
|
+
# be partially loaded
|
3
4
|
def find_by_ci_number(ci_number)
|
4
5
|
# Get a list of handles from e-conomic
|
5
6
|
response = request(:find_by_ci_number, {
|
6
7
|
'ciNumber' => ci_number
|
7
8
|
})
|
8
9
|
|
9
|
-
# Make sure we always have an array of handles even if the result only
|
10
|
+
# Make sure we always have an array of handles even if the result only
|
11
|
+
# contains one
|
10
12
|
handle_key = "#{entity_class_name.downcase}_handle".intern
|
11
13
|
handles = [response[handle_key]].flatten.reject(&:blank?)
|
12
14
|
|
@@ -7,6 +7,7 @@ module Economic
|
|
7
7
|
def initialize(caller, name)
|
8
8
|
@caller = caller
|
9
9
|
@name = name
|
10
|
+
@session = caller.session
|
10
11
|
end
|
11
12
|
|
12
13
|
def call
|
@@ -45,7 +46,10 @@ module Economic
|
|
45
46
|
end
|
46
47
|
|
47
48
|
def request(action, data)
|
48
|
-
@
|
49
|
+
@session.request(
|
50
|
+
Endpoint.new.soap_action_name(@caller.entity_class, action),
|
51
|
+
data
|
52
|
+
)
|
49
53
|
end
|
50
54
|
|
51
55
|
def response
|
@@ -4,7 +4,7 @@ module Economic
|
|
4
4
|
class CashBookEntryProxy < EntityProxy
|
5
5
|
def all
|
6
6
|
entity_hash = session.request(
|
7
|
-
|
7
|
+
Endpoint.new.soap_action_name(CashBook, :get_entries),
|
8
8
|
{"cashBookHandle" => owner.handle.to_hash}
|
9
9
|
)
|
10
10
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
1
3
|
module Economic
|
2
4
|
class EntityProxy
|
3
5
|
class << self
|
@@ -73,7 +75,8 @@ module Economic
|
|
73
75
|
self.class.entity_class_name
|
74
76
|
end
|
75
77
|
|
76
|
-
# Fetches Entity data from API and returns an Entity initialized with that
|
78
|
+
# Fetches Entity data from API and returns an Entity initialized with that
|
79
|
+
# data added to Proxy
|
77
80
|
def find(handle)
|
78
81
|
handle = Entity::Handle.new(handle)
|
79
82
|
entity_hash = get_data(handle)
|
@@ -98,18 +101,14 @@ module Economic
|
|
98
101
|
end
|
99
102
|
alias :<< :append
|
100
103
|
|
101
|
-
|
102
|
-
def request(action, data = nil)
|
103
|
-
session.request(entity_class.soap_action_name(action), data)
|
104
|
-
end
|
105
|
-
|
106
|
-
protected
|
104
|
+
protected
|
107
105
|
|
108
106
|
def items
|
109
107
|
@items
|
110
108
|
end
|
111
109
|
|
112
|
-
# Fetches all data for the given handles. Returns Array with hashes of
|
110
|
+
# Fetches all data for the given handles. Returns Array with hashes of
|
111
|
+
# entity data
|
113
112
|
def get_data_array(handles)
|
114
113
|
return [] unless handles && handles.any?
|
115
114
|
|
@@ -122,5 +121,13 @@ module Economic
|
|
122
121
|
def initialize_properties_with_values_from_owner(entity)
|
123
122
|
entity
|
124
123
|
end
|
124
|
+
|
125
|
+
# Requests an action from the API endpoint
|
126
|
+
def request(action, data = nil)
|
127
|
+
session.request(
|
128
|
+
Endpoint.new.soap_action_name(entity_class, action),
|
129
|
+
data
|
130
|
+
)
|
131
|
+
end
|
125
132
|
end
|
126
133
|
end
|