sendregning 0.1.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -21
- data/.rubocop.yml +23 -0
- data/.rubocop_todo.yml +0 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +93 -0
- data/README.md +49 -0
- data/lib/sendregning.rb +15 -8
- data/lib/sendregning/client.rb +73 -104
- data/lib/sendregning/invoice.rb +96 -145
- data/lib/sendregning/invoice_parser.rb +47 -0
- data/lib/sendregning/invoice_serializer.rb +59 -0
- data/lib/sendregning/line.rb +42 -57
- data/lib/sendregning/line_serializer.rb +16 -0
- data/lib/sendregning/version.rb +5 -0
- data/lib/sendregning/xml_serializer.rb +36 -0
- data/sendregning.gemspec +22 -56
- metadata +88 -101
- data/.document +0 -5
- data/README.rdoc +0 -47
- data/Rakefile +0 -56
- data/VERSION +0 -1
- data/test/helper.rb +0 -10
- data/test/test_sendregning.rb +0 -7
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sendregning
|
4
|
+
class InvoiceParser
|
5
|
+
class << self
|
6
|
+
def parse(response, invoice = Sendregning::Invoice.new)
|
7
|
+
new(response, invoice).parse
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(response, invoice)
|
12
|
+
@response = response
|
13
|
+
@invoice = invoice
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse
|
17
|
+
attributes = @response["invoices"]["invoice"]
|
18
|
+
|
19
|
+
# Flatten optional and shipment attributes
|
20
|
+
%w[optional shipment].each do |section|
|
21
|
+
if attributes.key?(section)
|
22
|
+
attributes = attributes.merge(attributes[section])
|
23
|
+
attributes.delete(section)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
lines = attributes["lines"]["line"]
|
28
|
+
attributes.delete("lines")
|
29
|
+
|
30
|
+
@invoice.update(stringify_hash(attributes))
|
31
|
+
@invoice.lines = lines.map do |l|
|
32
|
+
Sendregning::Line.new(stringify_hash(l))
|
33
|
+
end
|
34
|
+
@invoice
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def stringify_hash(hash)
|
40
|
+
new_hash = {}
|
41
|
+
hash.each do |key, value|
|
42
|
+
new_hash[key] = value.to_s
|
43
|
+
end
|
44
|
+
new_hash
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sendregning
|
4
|
+
class InvoiceSerializer < Sendregning::XmlSerializer
|
5
|
+
def build
|
6
|
+
builder.invoices do |invoices|
|
7
|
+
invoices.invoice do |invoice|
|
8
|
+
invoice.name item.name
|
9
|
+
invoice.zip item.zip
|
10
|
+
invoice.city item.city
|
11
|
+
|
12
|
+
lines(invoice)
|
13
|
+
optional_attributes(invoice)
|
14
|
+
shipment_attributes(invoice)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def lines(invoice)
|
22
|
+
if item.lines.any?
|
23
|
+
invoice.lines do |line_builder|
|
24
|
+
item.lines.each { |l| l.to_xml(builder: line_builder) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def optional_attributes(invoice)
|
30
|
+
if item.optional.any?
|
31
|
+
invoice.optional do |optional|
|
32
|
+
item.optional.each do |key, value|
|
33
|
+
key = key.to_sym
|
34
|
+
if value.is_a?(Date) || value.is_a?(Time)
|
35
|
+
value = value.strftime("%d.%m.%y")
|
36
|
+
end
|
37
|
+
optional.tag! key, value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def shipment_attributes(invoice)
|
44
|
+
if item.shipment.any?
|
45
|
+
invoice.shipment do |shipment|
|
46
|
+
shipment.text! item.shipment_mode
|
47
|
+
item.shipment.each do |key, values|
|
48
|
+
key = key.to_sym
|
49
|
+
next if key == :shipment
|
50
|
+
|
51
|
+
shipment.tag! key do |emails|
|
52
|
+
Array(values).each { |v| emails.email v }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/sendregning/line.rb
CHANGED
@@ -1,59 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Sendregning
|
4
|
+
class Line
|
5
|
+
# Quantity, as decimal. Example: '7,5'
|
6
|
+
attr_accessor :qty
|
7
|
+
|
8
|
+
# Product code. String, max length: 9
|
9
|
+
attr_accessor :prodCode
|
10
|
+
|
11
|
+
# Description. String, max length: 75
|
12
|
+
attr_accessor :desc
|
13
|
+
|
14
|
+
# Price per unit in decimal. Example: '250,00'
|
15
|
+
attr_accessor :unitPrice
|
16
|
+
|
17
|
+
# Discount in percentage as decimal. Optional, defaults to 0
|
18
|
+
attr_accessor :discount
|
19
|
+
|
20
|
+
# Tax rate. Valid rates are: '0', '8', '13' and '25'. Default: '25'
|
21
|
+
attr_accessor :tax
|
22
|
+
|
23
|
+
attr_accessor :itemNo, :lineTaxAmount, :lineTotal
|
24
|
+
|
25
|
+
def initialize(new_attributes = {})
|
26
|
+
self.attributes = new_attributes
|
27
|
+
end
|
28
|
+
|
29
|
+
# Renders line to XML
|
30
|
+
def to_xml(options = {})
|
31
|
+
LineSerializer.build(self, options)
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
2
35
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
attr_accessor :desc
|
13
|
-
|
14
|
-
# Price per unit in decimal. Example: '250,00'
|
15
|
-
attr_accessor :unitPrice
|
16
|
-
|
17
|
-
# Discount in percentage as decimal. Optional, defaults to 0
|
18
|
-
attr_accessor :discount
|
19
|
-
|
20
|
-
# Tax rate. Valid rates are: '0', '8', '13' and '25'. Default: '25'
|
21
|
-
attr_accessor :tax
|
22
|
-
|
23
|
-
attr_accessor :itemNo, :lineTaxAmount, :lineTotal
|
24
|
-
|
25
|
-
def initialize(new_attributes={})
|
26
|
-
self.attributes = new_attributes
|
27
|
-
end
|
28
|
-
|
29
|
-
# Renders line to XML
|
30
|
-
def to_xml(options={})
|
31
|
-
if options[:builder]
|
32
|
-
xml = options[:builder]
|
33
|
-
else
|
34
|
-
xml = Builder::XmlMarkup.new(:indent=>2)
|
35
|
-
xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
|
36
|
-
end
|
37
|
-
xml.line do |line|
|
38
|
-
line.qty self.qty if @qty
|
39
|
-
line.prodCode self.prodCode if @prodCode
|
40
|
-
line.desc self.desc if @desc
|
41
|
-
line.unitPrice self.unitPrice if @unitPrice
|
42
|
-
line.discount self.discount if @discount
|
43
|
-
line.tax self.tax if @tax
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
protected
|
48
|
-
|
49
|
-
def attributes=(attributes={})
|
50
|
-
attributes.each do |key, value|
|
51
|
-
set_method = "#{key.to_s}=".to_sym
|
52
|
-
self.send(set_method, value) if self.respond_to?(set_method)
|
53
|
-
end
|
54
|
-
attributes
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
36
|
+
def attributes=(attributes = {})
|
37
|
+
attributes.each do |key, value|
|
38
|
+
set_method = "#{key}=".to_sym
|
39
|
+
send(set_method, value) if respond_to?(set_method)
|
40
|
+
end
|
41
|
+
attributes
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sendregning
|
4
|
+
class LineSerializer < Sendregning::XmlSerializer
|
5
|
+
def build
|
6
|
+
builder.line do |line|
|
7
|
+
line.qty item.qty if item.qty
|
8
|
+
line.prodCode item.prodCode if item.prodCode
|
9
|
+
line.desc item.desc if item.desc
|
10
|
+
line.unitPrice item.unitPrice if item.unitPrice
|
11
|
+
line.discount item.discount if item.discount
|
12
|
+
line.tax item.tax if item.tax
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sendregning
|
4
|
+
class XmlSerializer
|
5
|
+
class << self
|
6
|
+
def build(item, options = {})
|
7
|
+
builder = options[:builder] || xml_builder
|
8
|
+
new(item, builder).build
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def xml_builder
|
14
|
+
xml = Builder::XmlMarkup.new(indent: 2)
|
15
|
+
xml.instruct! :xml, version: "1.0", encoding: "UTF-8"
|
16
|
+
xml
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(item, builder)
|
21
|
+
@item = item
|
22
|
+
@builder = builder
|
23
|
+
end
|
24
|
+
|
25
|
+
def build
|
26
|
+
raise("XmlSerializer is an abstract class, subclass and overwrite " \
|
27
|
+
"the build method")
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
attr_reader :builder
|
33
|
+
|
34
|
+
attr_reader :item
|
35
|
+
end
|
36
|
+
end
|
data/sendregning.gemspec
CHANGED
@@ -1,63 +1,29 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path("lib", __dir__)
|
4
|
+
require "sendregning/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
7
|
+
s.name = "sendregning"
|
8
|
+
s.version = Sendregning::VERSION
|
9
|
+
s.summary = "Ruby client for the SendRegning Web Service"
|
10
|
+
s.description = "Ruby client for the SendRegning Web Service"
|
11
|
+
s.authors = ["Inge Jørgensen"]
|
12
|
+
s.email = "inge@elektronaut.no"
|
13
|
+
s.homepage = "https://github.com/elektronaut/sendregning"
|
14
|
+
s.license = "MIT"
|
15
|
+
s.required_ruby_version = Gem::Requirement.new(">= 1.9.3")
|
9
16
|
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.
|
13
|
-
|
14
|
-
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"lib/sendregning.rb",
|
27
|
-
"lib/sendregning/client.rb",
|
28
|
-
"lib/sendregning/invoice.rb",
|
29
|
-
"lib/sendregning/line.rb",
|
30
|
-
"sendregning.gemspec",
|
31
|
-
"test/helper.rb",
|
32
|
-
"test/test_sendregning.rb"
|
33
|
-
]
|
34
|
-
s.homepage = %q{http://github.com/elektronaut/sendregning}
|
35
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map do |f|
|
20
|
+
File.basename(f)
|
21
|
+
end
|
36
22
|
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version = %q{1.3.7}
|
38
|
-
s.summary = %q{Ruby client for the SendRegning Web Service}
|
39
|
-
s.test_files = [
|
40
|
-
"test/helper.rb",
|
41
|
-
"test/test_sendregning.rb"
|
42
|
-
]
|
43
23
|
|
44
|
-
|
45
|
-
|
46
|
-
|
24
|
+
s.add_runtime_dependency "builder", "~> 3.1"
|
25
|
+
s.add_runtime_dependency "httmultiparty", "~> 0.3"
|
26
|
+
s.add_runtime_dependency "httparty", "~> 0.13"
|
47
27
|
|
48
|
-
|
49
|
-
s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
|
50
|
-
s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
|
51
|
-
s.add_runtime_dependency(%q<multipart-post>, [">= 1.0.1"])
|
52
|
-
else
|
53
|
-
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
54
|
-
s.add_dependency(%q<builder>, [">= 2.1.2"])
|
55
|
-
s.add_dependency(%q<multipart-post>, [">= 1.0.1"])
|
56
|
-
end
|
57
|
-
else
|
58
|
-
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
59
|
-
s.add_dependency(%q<builder>, [">= 2.1.2"])
|
60
|
-
s.add_dependency(%q<multipart-post>, [">= 1.0.1"])
|
61
|
-
end
|
28
|
+
s.add_development_dependency "rake"
|
62
29
|
end
|
63
|
-
|
metadata
CHANGED
@@ -1,128 +1,115 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendregning
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 1
|
10
|
-
version: 0.1.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.2
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
13
|
-
-
|
6
|
+
authors:
|
7
|
+
- Inge Jørgensen
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
date: 2020-06-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: builder
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.1'
|
20
|
+
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httmultiparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.3'
|
35
34
|
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: builder
|
39
35
|
prerelease: false
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httparty
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.13'
|
51
48
|
type: :runtime
|
52
|
-
version_requirements: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: multipart-post
|
55
49
|
prerelease: false
|
56
|
-
|
57
|
-
|
58
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.13'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
59
|
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
69
|
description: Ruby client for the SendRegning Web Service
|
70
|
-
email: inge@
|
70
|
+
email: inge@elektronaut.no
|
71
71
|
executables: []
|
72
|
-
|
73
72
|
extensions: []
|
74
|
-
|
75
|
-
|
76
|
-
-
|
77
|
-
-
|
78
|
-
|
79
|
-
-
|
80
|
-
- .
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- ".gitignore"
|
76
|
+
- ".rubocop.yml"
|
77
|
+
- ".rubocop_todo.yml"
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
81
80
|
- LICENSE
|
82
|
-
- README.
|
83
|
-
- Rakefile
|
84
|
-
- VERSION
|
81
|
+
- README.md
|
85
82
|
- lib/sendregning.rb
|
86
83
|
- lib/sendregning/client.rb
|
87
84
|
- lib/sendregning/invoice.rb
|
85
|
+
- lib/sendregning/invoice_parser.rb
|
86
|
+
- lib/sendregning/invoice_serializer.rb
|
88
87
|
- lib/sendregning/line.rb
|
88
|
+
- lib/sendregning/line_serializer.rb
|
89
|
+
- lib/sendregning/version.rb
|
90
|
+
- lib/sendregning/xml_serializer.rb
|
89
91
|
- sendregning.gemspec
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
licenses: []
|
95
|
-
|
92
|
+
homepage: https://github.com/elektronaut/sendregning
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
96
|
post_install_message:
|
97
|
-
rdoc_options:
|
98
|
-
|
99
|
-
require_paths:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
100
99
|
- lib
|
101
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
-
|
103
|
-
requirements:
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
104
102
|
- - ">="
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
version: "0"
|
110
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
-
none: false
|
112
|
-
requirements:
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 1.9.3
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
113
107
|
- - ">="
|
114
|
-
- !ruby/object:Gem::Version
|
115
|
-
|
116
|
-
segments:
|
117
|
-
- 0
|
118
|
-
version: "0"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
119
110
|
requirements: []
|
120
|
-
|
121
|
-
rubyforge_project:
|
122
|
-
rubygems_version: 1.3.7
|
111
|
+
rubygems_version: 3.1.2
|
123
112
|
signing_key:
|
124
|
-
specification_version:
|
113
|
+
specification_version: 4
|
125
114
|
summary: Ruby client for the SendRegning Web Service
|
126
|
-
test_files:
|
127
|
-
- test/helper.rb
|
128
|
-
- test/test_sendregning.rb
|
115
|
+
test_files: []
|