Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions collmex-ruby.gemspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
Gem::Specification.new do |s|
s.name = 'collmex-ruby'
s.version = '0.2.0'
s.date = '2012-07-29'
s.version = '1.2.0'
s.date = '2024-03-01'
s.summary = "A ruby api lib for collmex"
s.description = "A lib written in ruby that talks to the german accounting software collmex."
s.authors = ["Roman Lehnert"]
s.email = 'roman.lehnert@googlemail.com'
s.files = Dir['lib/**/*.rb']
s.homepage = 'https://github.com/romanlehnert/collmex-ruby'
s.license = "MIT"
s.add_development_dependency 'json', '~> 1.8.0'
s.add_development_dependency 'rspec', '~> 2.5'
s.add_dependency 'csv'
s.add_dependency 'base64'
s.add_development_dependency 'rspec'
s.add_development_dependency 'webmock'
s.add_development_dependency 'vcr'
s.test_files = Dir.glob("{spec,test}/**/*.rb")
Expand Down
3 changes: 2 additions & 1 deletion lib/collmex/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def self.line_class_exists?(class_name)
# from Collmex::Api::Line
def self.parse_line(line)
# in case the line is already an array
if line.is_a?(Array) && line.first.is_a?(String) || line.is_a?(String) && line = CSV.parse_line(line, Collmex.csv_opts)
if line.is_a?(Array) && line.first.is_a?(String) || line.is_a?(String) && line = CSV.parse_line(line, **Collmex.csv_opts)
identifyer = line.first.split(/_|-/).map { |s| s.downcase.capitalize }.join
if self.line_class_exists?(identifyer)
Collmex::Api.const_get(identifyer).new(line)
Expand Down Expand Up @@ -95,4 +95,5 @@ def self.stringify_currency(data)
require "collmex/api/sales_order_get"
require "collmex/api/accbal_get"
require "collmex/api/accbal"
require "collmex/api/cmxums"

3 changes: 3 additions & 0 deletions lib/collmex/api/cmxknd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def self.specification
{ name: :output_language , type: :integer },
{ name: :email_cc , type: :string },
{ name: :phone_2 , type: :string },
{ name: :sepa_mandate_reference, type: :string },
{ name: :sepa_mandate_signature_date, type: :date },
{ name: :dunning_block , type: :integer },
]
end
end
Expand Down
36 changes: 36 additions & 0 deletions lib/collmex/api/cmxums.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class Collmex::Api::Cmxums < Collmex::Api::Line
def self.specification
[
{ name: :_1_identifyer, type: :string, fix: "CMXUMS"}, # 1
{ name: :_2_customer_id, type: :integer},
{ name: :_3_company_id, type: :integer, default: 1},
{ name: :_4_receipt_date, type: :date },
{ name: :_5_receipt_number, type: :string }, # 5
{ name: :_6_net_value_full_tax, type: :currency },
{ name: :_7_tax_value_full_tax, type: :currency },
{ name: :_8_net_value_half_tax, type: :currency },
{ name: :_9_tax_value_half_tax, type: :currency },
{ name: :_10_net_value_inter_eu_trade, type: :currency }, # 10
{ name: :_11_net_value_export, type: :currency },
{ name: :_12_account_revenue_tax_free, type: :integer },
{ name: :_13_value_revenue_tax_free, type: :currency },
{ name: :_14_currency_code, type: :string },
{ name: :_15_contra_account, type: :integer }, # 15
{ name: :_16_receipt_type, type: :integer, default: 0 },
{ name: :_17_receipt_text, type: :string },
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit odd to me to prefix the hash keys with numbers. At least this is not the current practice in this repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well - yes when looking at it it looks odd - but when I implemented the api and I looked at the API documentation at collmex it was super hard to find the matching fields (translate to german and find the right position).

The API is CSV based and thus the index is the most important criteria to feed it right.
When using the ruby API it gets so much easier to find and use the right fields. It just feels better to have the index in place and to be safe when using the API. The descriptive name makes it then just easier to read.

{ name: :_18_payment_term, type: :integer },
{ name: :_19_account_full_tax, type: :integer },
{ name: :_20_account_half_tax, type: :integer }, # 20
{ name: :_21_reserved21, type: :string },
{ name: :_22_reserved22, type: :string },
{ name: :_23_storno, type: :integer },
{ name: :_24_final_receipt, type: :string },
{ name: :_25_revenue_type, type: :integer }, # 25
{ name: :_26_system_name, type: :string },
{ name: :_27_charge_against_receipt_number, type: :string },
{ name: :_28_cost_center, type: :string }
]
end
end


4 changes: 2 additions & 2 deletions lib/collmex/api/line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def self.hashify(data)
hash = self.default_hash
fields_spec = self.specification

if data.is_a?(Array) || data.is_a?(String) && data = CSV.parse_line(data,Collmex.csv_opts)
if data.is_a?(Array) || data.is_a?(String) && data = CSV.parse_line(data, **Collmex.csv_opts)
fields_spec.each_with_index do |field_spec, index|
if !data[index].nil? && !field_spec.has_key?(:fix)
hash[field_spec[:name]] = Collmex::Api.parse_field(data[index], field_spec[:type])
Expand Down Expand Up @@ -70,7 +70,7 @@ def to_stringified_array


def to_csv
CSV.generate_line(self.to_stringified_array, Collmex.csv_opts)
CSV.generate_line(self.to_stringified_array, **Collmex.csv_opts)
end

def to_h
Expand Down
2 changes: 1 addition & 1 deletion lib/collmex/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def execute
@raw_response[:string] = response.body.encode("UTF-8")

begin
@raw_response[:array] = CSV.parse(@raw_response[:string], Collmex.csv_opts)
@raw_response[:array] = CSV.parse(@raw_response[:string], **Collmex.csv_opts)
rescue => e
STDERR.puts "CSV.parse failed with string: #{@raw_response[:string]}" if self.debug
raise e
Expand Down
Loading