collmex-ruby 0.1.0 → 0.2.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/lib/collmex.rb +14 -20
- data/lib/collmex/api.rb +158 -20
- data/lib/collmex/request.rb +20 -21
- data/spec/lib/collmex/api_spec.rb +100 -57
- data/spec/lib/collmex/request_spec.rb +5 -0
- data/spec/lib/collmex_spec.rb +5 -12
- data/spec/spec_helper.rb +7 -7
- metadata +43 -7
- data/lib/collmex/api/line.rb +0 -0
- data/lib/collmex/api/lines.rb +0 -0
data/lib/collmex.rb
CHANGED
@@ -4,9 +4,20 @@ require 'collmex/request'
|
|
4
4
|
module Collmex
|
5
5
|
|
6
6
|
class << self
|
7
|
-
|
8
|
-
attr_accessor :username
|
9
|
-
|
7
|
+
|
8
|
+
attr_accessor :username, :password, :customer_id
|
9
|
+
|
10
|
+
def setup_login_data(logindata)
|
11
|
+
Collmex.username = logindata[:username]
|
12
|
+
Collmex.password = logindata[:password]
|
13
|
+
Collmex.customer_id = logindata[:customer_id]
|
14
|
+
end
|
15
|
+
|
16
|
+
def reset_login_data
|
17
|
+
Collmex.username = nil
|
18
|
+
Collmex.password = nil
|
19
|
+
Collmex.customer_id = nil
|
20
|
+
end
|
10
21
|
|
11
22
|
def csv_opts
|
12
23
|
{
|
@@ -14,22 +25,5 @@ module Collmex
|
|
14
25
|
}
|
15
26
|
end
|
16
27
|
|
17
|
-
|
18
|
-
def setup_login_data
|
19
|
-
config = YAML.load_file('config/collmex_config.yml')["development"]
|
20
|
-
Collmex.username = config["username"]
|
21
|
-
Collmex.password = config["password"]
|
22
|
-
Collmex.customer_id = config["customer_id"]
|
23
|
-
end
|
24
|
-
|
25
|
-
def reset_login_data
|
26
|
-
Collmex.username = "000000"
|
27
|
-
Collmex.password = "000000"
|
28
|
-
Collmex.customer_id = "000000"
|
29
|
-
end
|
30
28
|
end
|
31
29
|
end
|
32
|
-
|
33
|
-
Collmex.reset_login_data
|
34
|
-
|
35
|
-
|
data/lib/collmex/api.rb
CHANGED
@@ -6,7 +6,7 @@ module Collmex
|
|
6
6
|
def self.is_a_collmex_api_line_obj? obj
|
7
7
|
obj.class.name =~ /Collmex\:\:Api/
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def self.line_class_exists?(class_name)
|
11
11
|
klass = Collmex::Api.const_get(class_name)
|
12
12
|
return klass.is_a?(Class)
|
@@ -16,18 +16,18 @@ module Collmex
|
|
16
16
|
|
17
17
|
def self.parse_line(line)
|
18
18
|
if line.is_a?(Array) and line.first.is_a?(String)
|
19
|
-
identifyer = line.first.split(
|
19
|
+
identifyer = line.first.split(/_|-/).map { |s| s.downcase.capitalize }.join
|
20
20
|
if self.line_class_exists?(identifyer)
|
21
21
|
Collmex::Api.const_get(identifyer).new(line)
|
22
22
|
else
|
23
|
-
raise "Could not find a Collmex::Api::Line class for \"#{identifyer}\""
|
23
|
+
raise "Could not find a Collmex::Api::Line class for \"#{identifyer}\" (\"#{line.first}\")"
|
24
24
|
end
|
25
25
|
elsif line.is_a?(String) && parsed_line = CSV.parse_line(line, Collmex.csv_opts)
|
26
|
-
identifyer = parsed_line.first.split(
|
26
|
+
identifyer = parsed_line.first.split(/_|-/).map { |s| s.downcase.capitalize }.join
|
27
27
|
if self.line_class_exists?(identifyer)
|
28
28
|
Collmex::Api.const_get(identifyer).new(parsed_line)
|
29
29
|
else
|
30
|
-
raise "Could not find a Collmex::Api::Line class for \"#{identifyer}\""
|
30
|
+
raise "Could not find a Collmex::Api::Line class for \"#{identifyer}\" (\"#{parsed_line.first}\")"
|
31
31
|
end
|
32
32
|
else
|
33
33
|
raise "Could not parse a Collmex::Api Line from #{line.inspect}"
|
@@ -66,13 +66,13 @@ module Collmex
|
|
66
66
|
when :date then data.strftime("%Y%m%d") unless data.nil?
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def self.stringify_currency(data)
|
71
71
|
case
|
72
72
|
when data.is_a?(Integer) then sprintf("%.2f",(data.to_f / 100)).gsub('.',',')
|
73
73
|
when data.is_a?(Float) then sprintf("%.2f",(data.to_f)).gsub('.',',')
|
74
|
-
when data.is_a?(String)
|
75
|
-
int = self.parse_currency(data)
|
74
|
+
when data.is_a?(String)
|
75
|
+
int = self.parse_currency(data)
|
76
76
|
sprintf("%.2f",(int.to_f / 100)).gsub('.',',')
|
77
77
|
else data
|
78
78
|
end
|
@@ -92,7 +92,7 @@ module Collmex
|
|
92
92
|
|
93
93
|
def self.default_hash
|
94
94
|
hash = {}
|
95
|
-
self.specification.each_with_index do |field_spec, index|
|
95
|
+
self.specification.each_with_index do |field_spec, index|
|
96
96
|
if field_spec.has_key? :fix
|
97
97
|
hash[field_spec[:name]] = field_spec[:fix]
|
98
98
|
elsif field_spec.has_key? :default
|
@@ -109,21 +109,21 @@ module Collmex
|
|
109
109
|
fields_spec = self.specification
|
110
110
|
|
111
111
|
if data.is_a? Array
|
112
|
-
fields_spec.each_with_index do |field_spec, index|
|
112
|
+
fields_spec.each_with_index do |field_spec, index|
|
113
113
|
if !data[index].nil? && !field_spec.has_key?(:fix)
|
114
|
-
hash[field_spec[:name]] = Collmex::Api.parse_field(data[index], field_spec[:type])
|
114
|
+
hash[field_spec[:name]] = Collmex::Api.parse_field(data[index], field_spec[:type])
|
115
115
|
end
|
116
116
|
end
|
117
117
|
elsif data.is_a? Hash
|
118
118
|
fields_spec.each_with_index do |field_spec, index|
|
119
119
|
if data.key?(field_spec[:name]) && !field_spec.has_key?(:fix)
|
120
|
-
hash[field_spec[:name]] = Collmex::Api.parse_field(data[field_spec[:name]], field_spec[:type])
|
120
|
+
hash[field_spec[:name]] = Collmex::Api.parse_field(data[field_spec[:name]], field_spec[:type])
|
121
121
|
end
|
122
122
|
end
|
123
123
|
elsif data.is_a?(String) && parsed = CSV.parse_line(data,Collmex.csv_opts)
|
124
|
-
fields_spec.each_with_index do |field_spec, index|
|
124
|
+
fields_spec.each_with_index do |field_spec, index|
|
125
125
|
if !data[index].nil? && !field_spec.has_key?(:fix)
|
126
|
-
hash[field_spec[:name]] = Collmex::Api.parse_field(parsed[index], field_spec[:type])
|
126
|
+
hash[field_spec[:name]] = Collmex::Api.parse_field(parsed[index], field_spec[:type])
|
127
127
|
end
|
128
128
|
end
|
129
129
|
end
|
@@ -131,8 +131,8 @@ module Collmex
|
|
131
131
|
end
|
132
132
|
|
133
133
|
|
134
|
-
def initialize(arg = nil)
|
135
|
-
#puts self.class.name
|
134
|
+
def initialize(arg = nil)
|
135
|
+
#puts self.class.name
|
136
136
|
@hash = self.class.default_hash
|
137
137
|
@hash = @hash.merge(self.class.hashify(arg)) if !arg.nil?
|
138
138
|
if self.class.specification.empty? && self.class.name.to_s != "Collmex::Api::Line"
|
@@ -140,7 +140,7 @@ module Collmex
|
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
-
|
143
|
+
|
144
144
|
def to_a
|
145
145
|
array = []
|
146
146
|
self.class.specification.each do |spec|
|
@@ -188,8 +188,8 @@ module Collmex
|
|
188
188
|
def self.specification
|
189
189
|
[
|
190
190
|
{ name: :identifyer, type: :string, fix: "LOGIN" },
|
191
|
-
{ name: :username, type: :
|
192
|
-
{ name: :password, type: :
|
191
|
+
{ name: :username, type: :string },
|
192
|
+
{ name: :password, type: :string }
|
193
193
|
]
|
194
194
|
end
|
195
195
|
end
|
@@ -204,7 +204,7 @@ module Collmex
|
|
204
204
|
{ name: :title , type: :string },
|
205
205
|
{ name: :firstname , type: :string },
|
206
206
|
{ name: :lastname , type: :string },
|
207
|
-
{ name: :
|
207
|
+
{ name: :company , type: :string },
|
208
208
|
{ name: :department , type: :string },
|
209
209
|
{ name: :street , type: :string },
|
210
210
|
{ name: :zipcode , type: :string },
|
@@ -221,6 +221,7 @@ module Collmex
|
|
221
221
|
{ name: :bic , type: :string },
|
222
222
|
{ name: :bank_name , type: :string },
|
223
223
|
{ name: :vat_id , type: :string },
|
224
|
+
{ name: :ust_ldnr , type: :string },
|
224
225
|
{ name: :payment_condition, type: :integer },
|
225
226
|
{ name: :dscout_group , type: :integer },
|
226
227
|
{ name: :deliver_conditions, type: :string },
|
@@ -357,5 +358,142 @@ module Collmex
|
|
357
358
|
end
|
358
359
|
end
|
359
360
|
|
361
|
+
# Creating Orders
|
362
|
+
class Cmxord2 < Line
|
363
|
+
def self.specification
|
364
|
+
[
|
365
|
+
{name: :identifyer, type: :string, fix: "CMXORD-2"},
|
366
|
+
{name: :order_id, type: :integer},
|
367
|
+
{name: :position, type: :integer},
|
368
|
+
{name: :order, type: :integer}, # Should be left blank
|
369
|
+
{name: :company_id, type: :integer, default: 1},
|
370
|
+
{name: :customer_id, type: :integer},
|
371
|
+
{name: :customer_title, type: :string},
|
372
|
+
{name: :customer_title_2, type: :string},
|
373
|
+
{name: :customer_first_name, type: :string},
|
374
|
+
{name: :customer_name, type: :string},
|
375
|
+
{name: :customer_company, type: :string},
|
376
|
+
{name: :customer_department, type: :string},
|
377
|
+
{name: :customer_street, type: :string},
|
378
|
+
{name: :customer_zip, type: :string},
|
379
|
+
{name: :customer_place, type: :string},
|
380
|
+
{name: :customer_country, type: :string}, # ISO code (DE)
|
381
|
+
{name: :customer_phone, type: :string},
|
382
|
+
{name: :customer_phone_2, type: :string},
|
383
|
+
{name: :customer_fax, type: :string},
|
384
|
+
{name: :customer_email, type: :string},
|
385
|
+
{name: :acct, type: :string},
|
386
|
+
{name: :customer_blz, type: :string},
|
387
|
+
{name: :customer_account_holders, type: :string},
|
388
|
+
{name: :customer_iban, type: :string},
|
389
|
+
{name: :customer_bic, type: :string},
|
390
|
+
{name: :customer_bank, type: :string},
|
391
|
+
{name: :customer_ustidnr, type: :string},
|
392
|
+
{name: :reserved, type: :integer}, # Should be left blank
|
393
|
+
{name: :order_id_for_customer, type: :string},
|
394
|
+
{name: :order_date, type: :date},
|
395
|
+
{name: :price_date, type: :date},
|
396
|
+
{name: :terms_of_payment, type: :integer},
|
397
|
+
{name: :currency, type: :string}, # ISO code (EUR)
|
398
|
+
{name: :price_group, type: :integer},
|
399
|
+
{name: :discount_group, type: :integer},
|
400
|
+
{name: :closing_off, type: :integer},
|
401
|
+
{name: :discount_ground, type: :string},
|
402
|
+
{name: :confirmation_text, type: :string},
|
403
|
+
{name: :final_text, type: :string},
|
404
|
+
{name: :internal_memo, type: :string},
|
405
|
+
{name: :billing_allowed, type: :integer},
|
406
|
+
{name: :partial_deliveries_allowed, type: :integer},
|
407
|
+
{name: :deleted, type: :integer},
|
408
|
+
{name: :status, type: :integer},
|
409
|
+
{name: :language, type: :integer}, # 0 = German, 1 = English
|
410
|
+
{name: :editor, type: :integer},
|
411
|
+
{name: :mediator, type: :integer},
|
412
|
+
{name: :system_name, type: :string},
|
413
|
+
{name: :closing_off_2, type: :currency},
|
414
|
+
{name: :closing_off_2_base, type: :string},
|
415
|
+
{name: :reserved_2, type: :string}, # Should be left blank
|
416
|
+
{name: :canceled_on, type: :date},
|
417
|
+
{name: :dispatch, type: :integer},
|
418
|
+
{name: :returns, type: :currency},
|
419
|
+
{name: :collection_fee, type: :currency},
|
420
|
+
{name: :terms_of_delivery, type: :string},
|
421
|
+
{name: :additional_delivery_conditions, type: :string},
|
422
|
+
{name: :delivery_address_title, type: :string},
|
423
|
+
{name: :delivery_address_title_2, type: :string},
|
424
|
+
{name: :delivery_address_first_name, type: :string},
|
425
|
+
{name: :delivery_address_name, type: :string},
|
426
|
+
{name: :delivery_address_company, type: :string},
|
427
|
+
{name: :delivery_address_department, type: :string},
|
428
|
+
{name: :delivery_address_street, type: :string},
|
429
|
+
{name: :delivery_address_zip, type: :string},
|
430
|
+
{name: :delivery_address_place, type: :string},
|
431
|
+
{name: :delivery_address_country, type: :string}, # ISO code (DE)
|
432
|
+
{name: :delivery_address_phone, type: :string},
|
433
|
+
{name: :delivery_address_phone_2, type: :string},
|
434
|
+
{name: :delivery_address_fax, type: :string},
|
435
|
+
{name: :delivery_address_email, type: :string},
|
436
|
+
{name: :position_type, type: :integer},
|
437
|
+
{name: :product_number, type: :string},
|
438
|
+
{name: :product_description, type: :string},
|
439
|
+
{name: :unit, type: :string}, # ISO code (EUR)
|
440
|
+
{name: :quantity, type: :float},
|
441
|
+
{name: :price, type: :currency},
|
442
|
+
{name: :delivery_date, type: :date},
|
443
|
+
{name: :price_quantity, type: :float},
|
444
|
+
{name: :item_discount, type: :currency}, # In percents
|
445
|
+
{name: :position_value, type: :currency},
|
446
|
+
{name: :product, type: :integer},
|
447
|
+
{name: :tax_classification, type: :integer},
|
448
|
+
{name: :control_abroad, type: :integer},
|
449
|
+
{name: :revenue_element, type: :integer},
|
450
|
+
{name: :fully_delivered, type: :integer},
|
451
|
+
{name: :finally_settled, type: :integer}
|
452
|
+
]
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
456
|
+
class SalesOrderGet < Line
|
457
|
+
def self.specification
|
458
|
+
[
|
459
|
+
{name: :identifyer, type: :string, fix: "SALES_ORDER_GET"},
|
460
|
+
{name: :order_id, type: :string},
|
461
|
+
{name: :company_id, type: :integer},
|
462
|
+
{name: :customer_id, type: :integer},
|
463
|
+
{name: :date_from, type: :date},
|
464
|
+
{name: :date_to, type: :date},
|
465
|
+
{name: :order_id_for_customer, type: :string},
|
466
|
+
{name: :format, type: :string}, # 1 means ZIP file with PDF
|
467
|
+
{name: :changed_only, type: :integer},
|
468
|
+
{name: :system_name, type: :string},
|
469
|
+
{name: :created_by_system_only, type: :integer}, # 1 means take only records created by the "system_name"
|
470
|
+
{name: :without_stationary, type: :integer}
|
471
|
+
]
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
class AccbalGet < Line
|
476
|
+
def self.specification
|
477
|
+
[
|
478
|
+
{name: :identifyer, type: :string, fix: "ACCBAL_GET"},
|
479
|
+
{name: :company_id, type: :integer, default: 1},
|
480
|
+
{name: :fiscal_year, type: :integer, default: Date.today.year},
|
481
|
+
{name: :date_to, type: :date},
|
482
|
+
{name: :account_number, type: :integer},
|
483
|
+
{name: :account_group, type: :integer}
|
484
|
+
]
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
class AccBal < Line
|
489
|
+
def self.specification
|
490
|
+
[
|
491
|
+
{name: :identifyer, type: :string, fix: "ACC_BAL"},
|
492
|
+
{name: :account_number, type: :integer},
|
493
|
+
{name: :account_name, type: :string},
|
494
|
+
{name: :account_balance, type: :currency}
|
495
|
+
]
|
496
|
+
end
|
497
|
+
end
|
360
498
|
end
|
361
499
|
end
|
data/lib/collmex/request.rb
CHANGED
@@ -3,10 +3,8 @@ require "uri"
|
|
3
3
|
|
4
4
|
module Collmex
|
5
5
|
class Request
|
6
|
-
|
7
|
-
|
8
6
|
attr_accessor :commands, :http
|
9
|
-
|
7
|
+
attr_accessor :debug
|
10
8
|
|
11
9
|
def self.run(&block)
|
12
10
|
Request.new.tap do |request|
|
@@ -20,8 +18,7 @@ module Collmex
|
|
20
18
|
term.to_s.split("_").collect(&:capitalize).join
|
21
19
|
end
|
22
20
|
|
23
|
-
|
24
|
-
def enqueue(command, args = {})
|
21
|
+
def enqueue(command, args = {})
|
25
22
|
if command.is_a? Symbol
|
26
23
|
add_command Collmex::Api::const_get(self.class.classify(command)).new(args)
|
27
24
|
elsif Collmex::Api.is_a_collmex_api_line_obj?(command)
|
@@ -31,35 +28,34 @@ module Collmex
|
|
31
28
|
end
|
32
29
|
end
|
33
30
|
|
34
|
-
|
35
31
|
def initialize
|
36
32
|
@commands = []
|
37
33
|
@raw_response = {}
|
38
34
|
|
39
|
-
|
35
|
+
if Collmex.username.nil? || Collmex.password.nil? || Collmex.customer_id.nil?
|
36
|
+
raise "No credentials for collmex given"
|
37
|
+
else
|
38
|
+
add_command Collmex::Api::Login.new({username: Collmex.username, password: Collmex.password})
|
39
|
+
end
|
40
40
|
end
|
41
41
|
|
42
|
-
|
43
42
|
def add_command(cmd)
|
44
43
|
@commands << cmd
|
45
44
|
cmd
|
46
45
|
end
|
47
46
|
|
48
|
-
|
49
47
|
def self.uri
|
50
48
|
URI.parse "https://www.collmex.de/cgi-bin/cgi.exe\?#{Collmex.customer_id},0,data_exchange"
|
51
49
|
end
|
52
50
|
|
53
|
-
|
54
51
|
def self.header_attributes
|
55
52
|
{"Content-Type" => "text/csv"}
|
56
53
|
end
|
57
54
|
|
58
55
|
def payload
|
59
|
-
@commands.map{ |c| c.to_csv }.join
|
56
|
+
@commands.map { |c| c.to_csv }.join
|
60
57
|
end
|
61
58
|
|
62
|
-
|
63
59
|
def parse_response
|
64
60
|
@response = @raw_response[:array].map { |l| Collmex::Api.parse_line(l) }
|
65
61
|
@response
|
@@ -69,27 +65,30 @@ module Collmex
|
|
69
65
|
@raw_response
|
70
66
|
end
|
71
67
|
|
72
|
-
|
73
|
-
def response
|
68
|
+
def response
|
74
69
|
@response
|
75
70
|
end
|
76
71
|
|
77
|
-
|
78
72
|
def execute
|
79
73
|
@http = Net::HTTP.new(Collmex::Request.uri.host, Collmex::Request.uri.port)
|
80
74
|
@http.use_ssl = true
|
81
75
|
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
82
76
|
|
83
|
-
|
84
|
-
|
77
|
+
# http://www.collmex.de/faq.html#zeichensatz_import
|
78
|
+
encoded_body = payload.encode("ISO8859-1", undef: :replace) # Do not blow up on undefined characters in ISO8859-1
|
79
|
+
response = @http.request_post(Collmex::Request.uri.request_uri, encoded_body, Collmex::Request.header_attributes)
|
85
80
|
response.body.force_encoding("ISO8859-1") if response.body.encoding.to_s == "ASCII-8BIT"
|
86
81
|
|
87
82
|
@raw_response[:string] = response.body.encode("UTF-8")
|
88
|
-
@raw_response[:array] = CSV.parse(@raw_response[:string], Collmex.csv_opts)
|
89
|
-
|
90
|
-
return parse_response
|
91
|
-
end
|
92
83
|
|
84
|
+
begin
|
85
|
+
@raw_response[:array] = CSV.parse(@raw_response[:string], Collmex.csv_opts)
|
86
|
+
rescue => e
|
87
|
+
STDERR.puts "CSV.parse failed with string: #{@raw_response[:string]}" if self.debug
|
88
|
+
raise e
|
89
|
+
end
|
93
90
|
|
91
|
+
parse_response
|
92
|
+
end
|
94
93
|
end
|
95
94
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
sample_spec = [
|
3
|
+
sample_spec = [
|
4
4
|
{ name: :identifyer, type: :string, fix: "BLA" },
|
5
5
|
{ name: :b, type: :currency },
|
6
6
|
{ name: :c, type: :float },
|
@@ -26,7 +26,7 @@ describe Collmex::Api do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should succeed for a Collmex::Api Object" do
|
29
|
-
b = Collmex::Api::AccdocGet.new()
|
29
|
+
b = Collmex::Api::AccdocGet.new()
|
30
30
|
described_class.is_a_collmex_api_line_obj?(b).should be_true
|
31
31
|
end
|
32
32
|
end
|
@@ -97,7 +97,7 @@ describe Collmex::Api do
|
|
97
97
|
context "when given an invalid line" do
|
98
98
|
it "should throw an error" do
|
99
99
|
line = ["OMG", 2,3,4,5,6]
|
100
|
-
lambda { described_class.parse_line(line) }.should raise_error 'Could not find a Collmex::Api::Line class for "Omg"'
|
100
|
+
lambda { described_class.parse_line(line) }.should raise_error 'Could not find a Collmex::Api::Line class for "Omg" ("OMG")'
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
@@ -181,10 +181,10 @@ end
|
|
181
181
|
shared_examples_for "Collmex Api Command" do
|
182
182
|
|
183
183
|
describe ".hashify" do
|
184
|
-
|
184
|
+
|
185
185
|
it "should parse the fields" do
|
186
186
|
string = "BLA"
|
187
|
-
integer = 421
|
187
|
+
integer = 421
|
188
188
|
float = 123.23
|
189
189
|
currency = 200
|
190
190
|
date = Date.parse("12.10.1985")
|
@@ -199,16 +199,16 @@ shared_examples_for "Collmex Api Command" do
|
|
199
199
|
Collmex::Api.stub(:parse_field).with(anything(),:date).and_return date
|
200
200
|
|
201
201
|
tests = [
|
202
|
-
[1,2,3,4],
|
203
|
-
[1,nil,3],
|
204
|
-
[1],
|
205
|
-
{a: 1, b:nil},
|
206
|
-
{},
|
207
|
-
{c: 3},
|
208
|
-
"1;2;3",
|
209
|
-
"1;-2;3",
|
210
|
-
"1;-2,5;3",
|
211
|
-
";;3",
|
202
|
+
[1,2,3,4],
|
203
|
+
[1,nil,3],
|
204
|
+
[1],
|
205
|
+
{a: 1, b:nil},
|
206
|
+
{},
|
207
|
+
{c: 3},
|
208
|
+
"1;2;3",
|
209
|
+
"1;-2;3",
|
210
|
+
"1;-2,5;3",
|
211
|
+
";;3",
|
212
212
|
]
|
213
213
|
|
214
214
|
tests.each do |testdata|
|
@@ -217,36 +217,36 @@ shared_examples_for "Collmex Api Command" do
|
|
217
217
|
end
|
218
218
|
|
219
219
|
it "should set default values when nothing given" do
|
220
|
-
sample_default_spec = [
|
220
|
+
sample_default_spec = [
|
221
221
|
{ name: :a, type: :string, default: "fixvalue" },
|
222
222
|
{ name: :b, type: :currency, default: 899 },
|
223
223
|
{ name: :c, type: :integer, default: 10 },
|
224
224
|
{ name: :d, type: :float, default: 2.99 },
|
225
|
-
]
|
225
|
+
]
|
226
226
|
sample_default_outcome = {a: "fixvalue", b: 899, c: 10, d: 2.99}
|
227
227
|
described_class.stub(:specification).and_return sample_default_spec
|
228
228
|
described_class.hashify([]).should eql sample_default_outcome
|
229
229
|
end
|
230
230
|
|
231
231
|
it "should overwrite default values when data is given" do
|
232
|
-
sample_default_spec = [
|
232
|
+
sample_default_spec = [
|
233
233
|
{ name: :a, type: :string, default: "fixvalue" },
|
234
234
|
{ name: :b, type: :currency, default: 899 },
|
235
235
|
{ name: :c, type: :integer, default: 10 },
|
236
236
|
{ name: :d, type: :float, default: 2.99 },
|
237
|
-
]
|
237
|
+
]
|
238
238
|
sample_default_outcome = {a: "asd", b: 12, c: 1, d: 1.0}
|
239
239
|
described_class.stub(:specification).and_return sample_default_spec
|
240
240
|
described_class.hashify({a: "asd", b: 12, c: 1, d: 1}).should eql sample_default_outcome
|
241
241
|
end
|
242
242
|
|
243
243
|
it "should ignore given values for fix-value-fields" do
|
244
|
-
sample_fix_spec = [
|
244
|
+
sample_fix_spec = [
|
245
245
|
{ name: :a, type: :string, fix: "fixvalue" },
|
246
246
|
{ name: :b, type: :currency, fix: 899 },
|
247
247
|
{ name: :c, type: :integer, fix: 10 },
|
248
248
|
{ name: :d, type: :float, fix: 2.99 },
|
249
|
-
]
|
249
|
+
]
|
250
250
|
sample_fix_outcome = {a: "fixvalue", b: 899, c: 10, d: 2.99}
|
251
251
|
described_class.stub(:specification).and_return sample_fix_spec
|
252
252
|
described_class.hashify([]).should eql sample_fix_outcome
|
@@ -314,7 +314,7 @@ shared_examples_for "Collmex Api Command" do
|
|
314
314
|
end
|
315
315
|
|
316
316
|
describe "#to_h" do
|
317
|
-
it "should return the hash" do
|
317
|
+
it "should return the hash" do
|
318
318
|
h = { first: 1, second: 2 }
|
319
319
|
subject.instance_variable_set(:@hash, h)
|
320
320
|
subject.to_h.should eql h
|
@@ -332,29 +332,29 @@ shared_examples_for "Collmex Api Command" do
|
|
332
332
|
end
|
333
333
|
|
334
334
|
describe Collmex::Api::Line do
|
335
|
-
it_behaves_like "Collmex Api Command"
|
335
|
+
it_behaves_like "Collmex Api Command"
|
336
336
|
end
|
337
337
|
|
338
338
|
describe Collmex::Api::Login do
|
339
|
-
subject { Collmex::Api::Login.new({:username =>
|
340
|
-
it_behaves_like "Collmex Api Command"
|
341
|
-
spec =
|
339
|
+
subject { Collmex::Api::Login.new({:username => "012", :password => "34"}) }
|
340
|
+
it_behaves_like "Collmex Api Command"
|
341
|
+
spec =
|
342
342
|
[
|
343
343
|
{ name: :identifyer, type: :string, fix: "LOGIN" },
|
344
|
-
{ name: :username, type: :
|
345
|
-
{ name: :password, type: :
|
344
|
+
{ name: :username, type: :string },
|
345
|
+
{ name: :password, type: :string }
|
346
346
|
]
|
347
347
|
|
348
|
-
specify { described_class.specification.should eql spec }
|
348
|
+
specify { described_class.specification.should eql spec }
|
349
349
|
|
350
|
-
output = ["LOGIN",
|
350
|
+
output = ["LOGIN", "012", "34"]
|
351
351
|
specify { subject.to_a.should eql output }
|
352
352
|
end
|
353
353
|
|
354
354
|
describe Collmex::Api::CustomerGet do
|
355
|
-
it_behaves_like "Collmex Api Command"
|
355
|
+
it_behaves_like "Collmex Api Command"
|
356
356
|
|
357
|
-
spec =
|
357
|
+
spec =
|
358
358
|
[
|
359
359
|
{ name: :identifyer , type: :string , fix: "CUSTOMER_GET" },
|
360
360
|
{ name: :id , type: :integer },
|
@@ -371,19 +371,19 @@ describe Collmex::Api::CustomerGet do
|
|
371
371
|
{ name: :inactive , type: :integer },
|
372
372
|
]
|
373
373
|
|
374
|
-
specify { described_class.specification.should eql spec }
|
374
|
+
specify { described_class.specification.should eql spec }
|
375
375
|
|
376
376
|
subject { described_class.new( {:customer_id => 9999} ) }
|
377
377
|
|
378
|
-
output = ["CUSTOMER_GET", nil, 1, "", nil, "", nil, nil, nil, nil, nil, "", nil]
|
378
|
+
output = ["CUSTOMER_GET", nil, 1, "", nil, "", nil, nil, nil, nil, nil, "", nil]
|
379
379
|
|
380
380
|
specify { subject.to_a.should eql output }
|
381
381
|
end
|
382
382
|
|
383
383
|
describe Collmex::Api::AccdocGet do
|
384
|
-
it_behaves_like "Collmex Api Command"
|
384
|
+
it_behaves_like "Collmex Api Command"
|
385
385
|
|
386
|
-
spec =
|
386
|
+
spec =
|
387
387
|
[
|
388
388
|
{ name: :identifyer , type: :string , fix: "ACCDOC_GET" },
|
389
389
|
{ name: :company_id , type: :integer , default: 1 },
|
@@ -406,7 +406,7 @@ describe Collmex::Api::AccdocGet do
|
|
406
406
|
|
407
407
|
|
408
408
|
|
409
|
-
specify { described_class.specification.should eql spec }
|
409
|
+
specify { described_class.specification.should eql spec }
|
410
410
|
|
411
411
|
subject { described_class.new( {id: 1} ) }
|
412
412
|
|
@@ -415,11 +415,33 @@ describe Collmex::Api::AccdocGet do
|
|
415
415
|
specify { subject.to_a.should eql output }
|
416
416
|
end
|
417
417
|
|
418
|
+
describe Collmex::Api::AccbalGet do
|
419
|
+
it_behaves_like "Collmex Api Command"
|
420
|
+
|
421
|
+
spec =
|
422
|
+
[
|
423
|
+
{name: :identifyer, type: :string, fix: "ACCBAL_GET"},
|
424
|
+
{name: :company_id, type: :integer, default: 1},
|
425
|
+
{name: :fiscal_year, type: :integer, default: Date.today.year},
|
426
|
+
{name: :date_to, type: :date},
|
427
|
+
{name: :account_number, type: :integer},
|
428
|
+
{name: :account_group, type: :integer}
|
429
|
+
]
|
430
|
+
|
431
|
+
specify { described_class.specification.should eql spec }
|
418
432
|
|
419
|
-
|
433
|
+
subject { described_class.new( {id: 1} ) }
|
434
|
+
|
435
|
+
output = ["ACCBAL_GET", 1, Date.today.year, nil, nil, nil]
|
420
436
|
|
421
|
-
|
422
|
-
|
437
|
+
specify { subject.to_a.should eql output }
|
438
|
+
end
|
439
|
+
|
440
|
+
|
441
|
+
describe Collmex::Api::Cmxknd do
|
442
|
+
|
443
|
+
it_behaves_like "Collmex Api Command"
|
444
|
+
spec =
|
423
445
|
[
|
424
446
|
{ name: :identifyer , type: :string , fix: "CMXKND" },
|
425
447
|
{ name: :customer_id , type: :integer },
|
@@ -428,7 +450,7 @@ describe Collmex::Api::Cmxknd do
|
|
428
450
|
{ name: :title , type: :string },
|
429
451
|
{ name: :firstname , type: :string },
|
430
452
|
{ name: :lastname , type: :string },
|
431
|
-
{ name: :
|
453
|
+
{ name: :company , type: :string },
|
432
454
|
{ name: :department , type: :string },
|
433
455
|
{ name: :street , type: :string },
|
434
456
|
{ name: :zipcode , type: :string },
|
@@ -445,6 +467,7 @@ describe Collmex::Api::Cmxknd do
|
|
445
467
|
{ name: :bic , type: :string },
|
446
468
|
{ name: :bank_name , type: :string },
|
447
469
|
{ name: :vat_id , type: :string },
|
470
|
+
{ name: :ust_ldnr , type: :string },
|
448
471
|
{ name: :payment_condition, type: :integer },
|
449
472
|
{ name: :dscout_group , type: :integer },
|
450
473
|
{ name: :deliver_conditions, type: :string },
|
@@ -466,21 +489,21 @@ describe Collmex::Api::Cmxknd do
|
|
466
489
|
{ name: :phone_2 , type: :string },
|
467
490
|
]
|
468
491
|
|
469
|
-
specify { described_class.specification.should eql spec }
|
492
|
+
specify { described_class.specification.should eql spec }
|
470
493
|
|
471
494
|
subject { described_class.new( {id: 1} ) }
|
472
495
|
|
473
|
-
output = ["CMXKND", nil, 1, "", "", "", "", "", "", "", "", "", "", nil, "", "", "", "", "", "", "", "", "", "", nil, nil, "", "", nil, "", nil, "", nil, "", nil, "", nil, nil, nil, "", nil, "", ""]
|
496
|
+
output = ["CMXKND", nil, 1, "", "", "", "", "", "", "", "", "", "", nil, "", "", "", "", "", "", "", "", "", "", "", nil, nil, "", "", nil, "", nil, "", nil, "", nil, "", nil, nil, nil, "", nil, "", ""]
|
474
497
|
|
475
498
|
specify { subject.to_a.should eql output }
|
476
499
|
end
|
477
500
|
|
478
501
|
|
479
|
-
describe Collmex::Api::Message do
|
502
|
+
describe Collmex::Api::Message do
|
480
503
|
|
481
|
-
it_behaves_like "Collmex Api Command"
|
504
|
+
it_behaves_like "Collmex Api Command"
|
482
505
|
|
483
|
-
spec =
|
506
|
+
spec =
|
484
507
|
[
|
485
508
|
{ name: :identifyer , type: :string , fix: "MESSAGE" },
|
486
509
|
{ name: :type , type: :string },
|
@@ -489,25 +512,25 @@ describe Collmex::Api::Message do
|
|
489
512
|
{ name: :line , type: :integer },
|
490
513
|
]
|
491
514
|
|
492
|
-
specify { described_class.specification.should eql spec }
|
515
|
+
specify { described_class.specification.should eql spec }
|
493
516
|
|
494
517
|
subject { described_class.new( ) }
|
495
518
|
|
496
519
|
output = ["MESSAGE", "", nil, "", nil]
|
497
520
|
|
498
521
|
specify { subject.to_a.should eql output }
|
499
|
-
|
522
|
+
|
500
523
|
context "success" do
|
501
524
|
subject { described_class.new(type: "S") }
|
502
|
-
specify do
|
503
|
-
subject.success?.should eql true
|
504
|
-
subject.result.should eql :success
|
525
|
+
specify do
|
526
|
+
subject.success?.should eql true
|
527
|
+
subject.result.should eql :success
|
505
528
|
end
|
506
529
|
end
|
507
530
|
|
508
531
|
context "warning" do
|
509
532
|
subject { described_class.new(type: "W") }
|
510
|
-
specify do
|
533
|
+
specify do
|
511
534
|
subject.success?.should eql false
|
512
535
|
subject.result.should eql :warning
|
513
536
|
end
|
@@ -515,7 +538,7 @@ describe Collmex::Api::Message do
|
|
515
538
|
|
516
539
|
context "error" do
|
517
540
|
subject { described_class.new(type: "E") }
|
518
|
-
specify do
|
541
|
+
specify do
|
519
542
|
subject.success?.should eql false
|
520
543
|
subject.result.should eql :error
|
521
544
|
end
|
@@ -523,7 +546,7 @@ describe Collmex::Api::Message do
|
|
523
546
|
|
524
547
|
context "undefined" do
|
525
548
|
subject { described_class.new() }
|
526
|
-
specify do
|
549
|
+
specify do
|
527
550
|
subject.success?.should eql false
|
528
551
|
subject.result.should eql :undefined
|
529
552
|
end
|
@@ -535,9 +558,9 @@ end
|
|
535
558
|
|
536
559
|
describe Collmex::Api::Accdoc do # fixme ACCDOC
|
537
560
|
|
538
|
-
it_behaves_like "Collmex Api Command"
|
561
|
+
it_behaves_like "Collmex Api Command"
|
539
562
|
|
540
|
-
spec =
|
563
|
+
spec =
|
541
564
|
[
|
542
565
|
{ name: :identifyer , type: :string , fix: "ACCDOC" },
|
543
566
|
{ name: :company_id , type: :integer , default: 1 },
|
@@ -569,7 +592,7 @@ describe Collmex::Api::Accdoc do # fixme ACCDOC
|
|
569
592
|
|
570
593
|
|
571
594
|
|
572
|
-
specify { described_class.specification.should eql spec }
|
595
|
+
specify { described_class.specification.should eql spec }
|
573
596
|
|
574
597
|
subject { described_class.new( {id: 1} ) }
|
575
598
|
|
@@ -579,4 +602,24 @@ describe Collmex::Api::Accdoc do # fixme ACCDOC
|
|
579
602
|
end
|
580
603
|
|
581
604
|
|
605
|
+
describe Collmex::Api::AccBal do
|
606
|
+
|
607
|
+
it_behaves_like "Collmex Api Command"
|
608
|
+
|
609
|
+
spec =
|
610
|
+
[
|
611
|
+
{name: :identifyer, type: :string, fix: "ACC_BAL"},
|
612
|
+
{name: :account_number, type: :integer},
|
613
|
+
{name: :account_name, type: :string},
|
614
|
+
{name: :account_balance, type: :currency}
|
615
|
+
]
|
616
|
+
|
617
|
+
specify { described_class.specification.should eql spec }
|
618
|
+
|
619
|
+
subject { described_class.new( {id: 1} ) }
|
620
|
+
|
621
|
+
output = ["ACC_BAL", nil, "", nil]
|
622
|
+
|
623
|
+
specify { subject.to_a.should eql output }
|
624
|
+
end
|
582
625
|
|
@@ -29,6 +29,11 @@ describe Collmex::Request do
|
|
29
29
|
|
30
30
|
describe "#initialize" do
|
31
31
|
|
32
|
+
it "should raise an error if no credentials given" do
|
33
|
+
Collmex.reset_login_data
|
34
|
+
lambda { Collmex::Request.new }.should raise_error "No credentials for collmex given"
|
35
|
+
end
|
36
|
+
|
32
37
|
it "should add the Login command to its own queue" do
|
33
38
|
request = Collmex::Request.new
|
34
39
|
request.commands.count.should eql 1
|
data/spec/lib/collmex_spec.rb
CHANGED
@@ -15,11 +15,7 @@ end
|
|
15
15
|
describe "CollmexIntegration" do
|
16
16
|
|
17
17
|
before(:each) do
|
18
|
-
Collmex.setup_login_data
|
19
|
-
end
|
20
|
-
|
21
|
-
after(:each) do
|
22
|
-
Collmex.reset_login_data
|
18
|
+
Collmex.setup_login_data({username: 4109488, password: 6642111, customer_id: 112249})
|
23
19
|
end
|
24
20
|
|
25
21
|
it "should work with the long form" do
|
@@ -33,21 +29,18 @@ describe "CollmexIntegration" do
|
|
33
29
|
VCR.use_cassette('standard_request') do
|
34
30
|
request.execute
|
35
31
|
end
|
36
|
-
|
37
|
-
|
38
32
|
end
|
39
33
|
|
40
34
|
it "should work with the block form" do
|
41
35
|
|
42
|
-
# ap Collmex::Api::AccdocGet.new("ASDASD;2;2")
|
43
|
-
|
44
36
|
request = Collmex::Request.run do
|
45
37
|
enqueue :customer_get, id: 9999
|
46
38
|
end
|
39
|
+
|
40
|
+
VCR.use_cassette('standard_request') do
|
41
|
+
request.response.last.success?.should eql true
|
42
|
+
end
|
47
43
|
|
48
|
-
#ap request.response
|
49
|
-
|
50
|
-
request.response.last.success?.should eql true
|
51
44
|
end
|
52
45
|
end
|
53
46
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,22 +1,23 @@
|
|
1
|
-
require
|
1
|
+
require "rspec"
|
2
2
|
require "awesome_print"
|
3
3
|
require "vcr"
|
4
4
|
|
5
5
|
RSpec.configure do |config|
|
6
|
-
|
7
6
|
config.color_enabled = true
|
8
7
|
config.filter_run :focus => true
|
9
8
|
config.run_all_when_everything_filtered = true
|
10
9
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
10
|
|
12
11
|
config.before(:each) do
|
13
|
-
|
12
|
+
Collmex.setup_login_data({username: "8866413", password: "2291502", customer_id: "104156"})
|
14
13
|
end
|
15
14
|
|
15
|
+
config.after(:each) do
|
16
|
+
Collmex.reset_login_data
|
17
|
+
end
|
16
18
|
end
|
17
19
|
|
18
|
-
|
19
|
-
def timed(name)
|
20
|
+
def timed(name)
|
20
21
|
start = Time.now
|
21
22
|
puts "\n[STARTED: #{name}]"
|
22
23
|
yield if block_given?
|
@@ -24,10 +25,9 @@ def timed(name)
|
|
24
25
|
puts "[FINISHED: #{name} in #{(finish - start) * 1000} milliseconds]"
|
25
26
|
end
|
26
27
|
|
27
|
-
|
28
28
|
VCR.configure do |c|
|
29
29
|
c.allow_http_connections_when_no_cassette = true
|
30
|
-
c.cassette_library_dir =
|
30
|
+
c.cassette_library_dir = "spec/fixtures/vcr_cassettes"
|
31
31
|
c.hook_into :webmock
|
32
32
|
end
|
33
33
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: collmex-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-07-29 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,15 +21,50 @@ dependencies:
|
|
21
21
|
version: '2.5'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.5'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: webmock
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: vcr
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
25
62
|
description: A lib written in ruby that talks to the german accounting software collmex.
|
26
63
|
email: roman.lehnert@googlemail.com
|
27
64
|
executables: []
|
28
65
|
extensions: []
|
29
66
|
extra_rdoc_files: []
|
30
67
|
files:
|
31
|
-
- lib/collmex/api/line.rb
|
32
|
-
- lib/collmex/api/lines.rb
|
33
68
|
- lib/collmex/api.rb
|
34
69
|
- lib/collmex/request.rb
|
35
70
|
- lib/collmex.rb
|
@@ -38,7 +73,8 @@ files:
|
|
38
73
|
- spec/lib/collmex_spec.rb
|
39
74
|
- spec/spec_helper.rb
|
40
75
|
homepage: https://github.com/romanlehnert/collmex-ruby
|
41
|
-
licenses:
|
76
|
+
licenses:
|
77
|
+
- MIT
|
42
78
|
post_install_message:
|
43
79
|
rdoc_options: []
|
44
80
|
require_paths:
|
@@ -57,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
93
|
version: '0'
|
58
94
|
requirements: []
|
59
95
|
rubyforge_project:
|
60
|
-
rubygems_version: 1.8.
|
96
|
+
rubygems_version: 1.8.25
|
61
97
|
signing_key:
|
62
98
|
specification_version: 3
|
63
99
|
summary: A ruby api lib for collmex
|
data/lib/collmex/api/line.rb
DELETED
File without changes
|
data/lib/collmex/api/lines.rb
DELETED
File without changes
|