economic-rest 0.1.9 → 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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +1 -1
- data/lib/economic/base.rb +41 -46
- data/lib/economic/delivery.rb +10 -0
- data/lib/economic/layout.rb +5 -0
- data/lib/economic/notes.rb +7 -0
- data/lib/economic/order.rb +9 -9
- data/lib/economic/orders/drafts_repo.rb +6 -4
- data/lib/economic/orders/sent_repo.rb +6 -4
- data/lib/economic/payment_terms.rb +8 -0
- data/lib/economic/pdf.rb +5 -0
- data/lib/economic/project.rb +5 -0
- data/lib/economic/recipient.rb +8 -0
- data/lib/economic/references.rb +5 -0
- data/lib/economic/rest.rb +12 -0
- data/lib/economic/rest/version.rb +1 -1
- data/lib/economic/vat_zone.rb +5 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 708eea9e22edcc7c7ebdb0d619bcc7a61e088209ee0da3db606db8aeda83cd75
|
4
|
+
data.tar.gz: e7acc224d6e5f1dada3be67e7cc9f505b2a90c057140a3eb1f6b150d22367114
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b968674ace73f8c88f64d066e55819aa79800a2fba25bc600c5b490bc9ad6773ac32ba985635c5fecf4903d7239fd0d4497b1b979bfbb72a571455dcefb6b7a7
|
7
|
+
data.tar.gz: ebaef0843aabde82c6160a84565a440181a95f4d3115b711bdeb449f11598df4dee4a404a7eef6a3d9b677a96c32f4f33fab0801e5340248ce410e7fa350f513
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/lib/economic/base.rb
CHANGED
@@ -5,13 +5,17 @@ module Economic
|
|
5
5
|
end
|
6
6
|
|
7
7
|
class << self
|
8
|
-
attr_reader :attributes
|
8
|
+
attr_reader :attributes, :relations
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.add_attribute(name)
|
12
12
|
(@attributes ||= []).push(name)
|
13
13
|
end
|
14
14
|
|
15
|
+
def self.add_relation(name, fields)
|
16
|
+
(@relations ||= []).push(name: name, fields: fields)
|
17
|
+
end
|
18
|
+
|
15
19
|
def self.field(name, id: false, model: nil)
|
16
20
|
economic_cased_attibute_name = name.to_s
|
17
21
|
attr_accessor economic_cased_attibute_name
|
@@ -27,48 +31,49 @@ module Economic
|
|
27
31
|
end
|
28
32
|
|
29
33
|
def self.relation(name, fields:)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
alias_method snake_case(name), name
|
34
|
+
economic_cased_attibute_name = name.to_s
|
35
|
+
add_relation economic_cased_attibute_name, fields
|
36
|
+
attr_reader economic_cased_attibute_name
|
37
|
+
alias_method snake_case(economic_cased_attibute_name), economic_cased_attibute_name
|
36
38
|
end
|
37
39
|
|
38
40
|
def values_based_on_hash(hash)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
warn "unassigned k #{k} in #{self.class.name}" unless %w[layout self soap metaData].include? k
|
41
|
+
@internal_hash = hash || {}
|
42
|
+
|
43
|
+
self.class.attributes.each do |field_name|
|
44
|
+
public_send("#{field_name}=", @internal_hash[field_name])
|
45
|
+
end
|
46
|
+
|
47
|
+
if self.class.relations
|
48
|
+
self.class.relations.each do |relation_hash|
|
49
|
+
name = relation_hash[:name]
|
50
|
+
related_model = model_class(name).new(@internal_hash[name])
|
51
|
+
|
52
|
+
instance_variable_set("@#{name}", related_model)
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
56
|
-
def to_h(
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
def to_h(only_fields: [])
|
58
|
+
return_hash = {}
|
59
|
+
|
60
|
+
self.class.attributes.each do |field_name|
|
61
|
+
next if only_fields.any? && !only_fields.include?(field_name.to_sym)
|
62
|
+
|
63
|
+
return_hash[field_name] = public_send(field_name) if public_send(field_name)
|
62
64
|
end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
|
66
|
+
if self.class.relations
|
67
|
+
self.class.relations.each do |relation_hash|
|
68
|
+
relation_name = relation_hash[:name]
|
69
|
+
relation_fields = relation_hash[:fields]
|
70
|
+
|
71
|
+
relation_data = public_send(relation_name).to_h(only_fields: relation_fields)
|
72
|
+
|
73
|
+
return_hash[relation_name] = relation_data unless relation_data.empty?
|
68
74
|
end
|
69
|
-
return limited_hash
|
70
75
|
end
|
71
|
-
|
76
|
+
return_hash
|
72
77
|
end
|
73
78
|
|
74
79
|
def dirty?
|
@@ -78,13 +83,6 @@ module Economic
|
|
78
83
|
false
|
79
84
|
end
|
80
85
|
|
81
|
-
def save
|
82
|
-
if dirty?
|
83
|
-
response = repo.save(self)
|
84
|
-
values_based_on_hash(JSON.parse(response.body))
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
86
|
def self.snake_case(camel_cased)
|
89
87
|
camel_cased.to_s.gsub(/::/, '/')
|
90
88
|
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
@@ -101,12 +99,9 @@ module Economic
|
|
101
99
|
def repo
|
102
100
|
Object.const_get("#{self.class}Repo")
|
103
101
|
end
|
104
|
-
end
|
105
|
-
end
|
106
102
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
self
|
103
|
+
def model_class(name)
|
104
|
+
Object.const_get('Economic::' + name.slice(0, 1).capitalize + name.slice(1..-1))
|
105
|
+
end
|
111
106
|
end
|
112
107
|
end
|
data/lib/economic/order.rb
CHANGED
@@ -17,14 +17,14 @@ module Economic
|
|
17
17
|
field :roundingAmount
|
18
18
|
field :vatAmount
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
relation :customer, fields: [:customerNumber]
|
21
|
+
# relation :delivery, fields: []
|
22
|
+
# relation :notes, fields: []
|
23
|
+
relation :paymentTerms, fields: [:paymentTermsNumber]
|
24
|
+
# relation :pdf, fields: []
|
25
|
+
# relation :project, fields: []
|
26
|
+
relation :recipient, fields: [:name]
|
27
|
+
# relation :references, fields: []
|
28
|
+
relation :layout, fields: [:layoutNumber]
|
29
29
|
end
|
30
30
|
end
|
@@ -4,10 +4,12 @@ module Economic
|
|
4
4
|
def self.send(model)
|
5
5
|
url = ''
|
6
6
|
url << URL
|
7
|
-
url << '
|
8
|
-
url << '/
|
9
|
-
response = RestClient.post(url, model.to_h.to_json, headers)
|
10
|
-
|
7
|
+
url << 'orders'
|
8
|
+
url << '/drafts'
|
9
|
+
response = RestClient.post(url, model.to_h.to_json, headers) do |response, _request, _result|
|
10
|
+
response
|
11
|
+
end
|
12
|
+
test_response(response)
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -4,10 +4,12 @@ module Economic
|
|
4
4
|
def self.send(model)
|
5
5
|
url = ''
|
6
6
|
url << URL
|
7
|
-
url << '
|
8
|
-
url << '/
|
9
|
-
response = RestClient.post(url, model.to_h.to_json, headers)
|
10
|
-
|
7
|
+
url << 'orders'
|
8
|
+
url << '/sent'
|
9
|
+
response = RestClient.post(url, model.to_h.to_json, headers) do |response, _request, _result|
|
10
|
+
response
|
11
|
+
end
|
12
|
+
test_response(response)
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
data/lib/economic/pdf.rb
ADDED
data/lib/economic/rest.rb
CHANGED
@@ -3,6 +3,18 @@ require 'rest-client'
|
|
3
3
|
|
4
4
|
require 'economic/base_repo'
|
5
5
|
require 'economic/base'
|
6
|
+
|
7
|
+
require 'economic/vat_zone'
|
8
|
+
|
9
|
+
require 'economic/delivery'
|
10
|
+
require 'economic/layout'
|
11
|
+
require 'economic/notes'
|
12
|
+
require 'economic/payment_terms'
|
13
|
+
require 'economic/pdf'
|
14
|
+
require 'economic/project'
|
15
|
+
require 'economic/recipient'
|
16
|
+
require 'economic/references'
|
17
|
+
|
6
18
|
require 'economic/customer_repo'
|
7
19
|
require 'economic/customer'
|
8
20
|
require 'economic/product_repo'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: economic-rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Klogborg
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,18 +102,27 @@ files:
|
|
102
102
|
- lib/economic/base_repo.rb
|
103
103
|
- lib/economic/customer.rb
|
104
104
|
- lib/economic/customer_repo.rb
|
105
|
+
- lib/economic/delivery.rb
|
105
106
|
- lib/economic/journal.rb
|
106
107
|
- lib/economic/journal_repo.rb
|
108
|
+
- lib/economic/layout.rb
|
109
|
+
- lib/economic/notes.rb
|
107
110
|
- lib/economic/order.rb
|
108
111
|
- lib/economic/orders/archived_repo.rb
|
109
112
|
- lib/economic/orders/drafts_repo.rb
|
110
113
|
- lib/economic/orders/repo.rb
|
111
114
|
- lib/economic/orders/sent_repo.rb
|
115
|
+
- lib/economic/payment_terms.rb
|
116
|
+
- lib/economic/pdf.rb
|
112
117
|
- lib/economic/product.rb
|
113
118
|
- lib/economic/product_repo.rb
|
119
|
+
- lib/economic/project.rb
|
120
|
+
- lib/economic/recipient.rb
|
121
|
+
- lib/economic/references.rb
|
114
122
|
- lib/economic/rest.rb
|
115
123
|
- lib/economic/rest/version.rb
|
116
124
|
- lib/economic/session.rb
|
125
|
+
- lib/economic/vat_zone.rb
|
117
126
|
- lib/economic/voucher.rb
|
118
127
|
homepage: https://bitbucket.org/traels/economic-rest
|
119
128
|
licenses:
|