/
companies.rb
216 lines (198 loc) · 8.21 KB
/
companies.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# frozen_string_literal: true
module PapierkramApi
module V1
module Endpoints
module Contact
# This class is responsible for all the API calls related to banking bank connections.
class Companies < PapierkramApi::V1::Endpoints::Base
def find_by(id:)
http_get("#{@url_api_path}/contact/companies/#{id}")
end
def all(page: 1,
page_size: 100,
order_by: nil,
order_direction: nil)
query = {
page: page,
page_size: page_size
}
query[:order_by] = order_by if order_by
query[:order_direction] = order_direction if order_direction
http_get("#{@url_api_path}/contact/companies", query)
end
def create_supplier( # rubocop:disable Metrics/ParameterLists, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
name:,
phone: nil,
fax: nil,
email: nil,
delivery_method: nil,
ust_idnr: nil,
website: nil,
twitter: nil,
postal_street: nil,
postal_city: nil,
postal_zip: nil,
postal_country: nil,
physical_street: nil,
physical_city: nil,
physical_zip: nil,
physical_country: nil,
bank_blz: nil,
bank_institute: nil,
bank_account_no: nil,
bank_bic: nil,
bank_iban: nil,
notes: nil,
color: nil
)
body = {}
body[:contact_type] = 'supplier'
body[:name] = name
body[:phone] = phone if phone
body[:fax] = fax if fax
body[:email] = email if email
body[:delivery_method] = delivery_method if delivery_method
body[:ust_idnr] = ust_idnr if ust_idnr
body[:website] = website if website
body[:twitter] = twitter if twitter
body[:postal_street] = postal_street if postal_street
body[:postal_city] = postal_city if postal_city
body[:postal_zip] = postal_zip if postal_zip
body[:postal_country] = postal_country if postal_country
body[:physical_street] = physical_street if physical_street
body[:physical_city] = physical_city if physical_city
body[:physical_zip] = physical_zip if physical_zip
body[:physical_country] = physical_country if physical_country
body[:bank_blz] = bank_blz if bank_blz
body[:bank_institute] = bank_institute if bank_institute
body[:bank_account_no] = bank_account_no if bank_account_no
body[:bank_bic] = bank_bic if bank_bic
body[:bank_iban] = bank_iban if bank_iban
body[:notes] = notes if notes
body[:color] = color if color
http_post("#{@url_api_path}/contact/companies", body)
end
def create_customer( # rubocop:disable Metrics/ParameterLists, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
name:,
phone: nil,
fax: nil,
email: nil,
delivery_method: nil,
ust_idnr: nil,
website: nil,
twitter: nil,
postal_street: nil,
postal_city: nil,
postal_zip: nil,
postal_country: nil,
physical_street: nil,
physical_city: nil,
physical_zip: nil,
physical_country: nil,
bank_blz: nil,
bank_institute: nil,
bank_account_no: nil,
bank_bic: nil,
bank_iban: nil,
notes: nil,
color: nil
)
body = {}
body[:contact_type] = 'customer'
body[:name] = name
body[:phone] = phone if phone
body[:fax] = fax if fax
body[:email] = email if email
body[:delivery_method] = delivery_method if delivery_method
body[:ust_idnr] = ust_idnr if ust_idnr
body[:website] = website if website
body[:twitter] = twitter if twitter
body[:postal_street] = postal_street if postal_street
body[:postal_city] = postal_city if postal_city
body[:postal_zip] = postal_zip if postal_zip
body[:postal_country] = postal_country if postal_country
body[:physical_street] = physical_street if physical_street
body[:physical_city] = physical_city if physical_city
body[:physical_zip] = physical_zip if physical_zip
body[:physical_country] = physical_country if physical_country
body[:bank_blz] = bank_blz if bank_blz
body[:bank_institute] = bank_institute if bank_institute
body[:bank_account_no] = bank_account_no if bank_account_no
body[:bank_bic] = bank_bic if bank_bic
body[:bank_iban] = bank_iban if bank_iban
body[:notes] = notes if notes
body[:color] = color if color
http_post("#{@url_api_path}/contact/companies", body)
end
def update_by( # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/ParameterLists
id:,
name: nil,
contact_type: nil,
phone: nil,
fax: nil,
email: nil,
website: nil,
twitter: nil,
ust_idnr: nil,
delivery_method: nil,
postal_street: nil,
postal_zip: nil,
postal_city: nil,
postal_country: nil,
physical_street: nil,
physical_zip: nil,
physical_city: nil,
physical_country: nil,
bank_account_no: nil,
bank_blz: nil,
bank_institute: nil,
bank_bic: nil,
bank_iban: nil,
notes: nil,
color: nil
)
raise ArgumentError, 'id must be an Integer' unless id.is_a?(Integer)
body = {}
body[:name] = name if name
body[:contact_type] = contact_type if contact_type
body[:phone] = phone if phone
body[:fax] = fax if fax
body[:email] = email if email
body[:website] = website if website
body[:twitter] = twitter if twitter
body[:ust_idnr] = ust_idnr if ust_idnr
body[:delivery_method] = delivery_method if delivery_method
body[:postal_street] = postal_street if postal_street
body[:postal_zip] = postal_zip if postal_zip
body[:postal_city] = postal_city if postal_city
body[:postal_country] = postal_country if postal_country
body[:physical_street] = physical_street if physical_street
body[:physical_zip] = physical_zip if physical_zip
body[:physical_city] = physical_city if physical_city
body[:physical_country] = physical_country if physical_country
body[:bank_account_no] = bank_account_no if bank_account_no
body[:bank_blz] = bank_blz if bank_blz
body[:bank_institute] = bank_institute if bank_institute
body[:bank_bic] = bank_bic if bank_bic
body[:bank_iban] = bank_iban if bank_iban
body[:notes] = notes if notes
body[:color] = color if color
http_put("#{@url_api_path}/contact/companies/#{id}", body)
end
def delete_by(id:)
raise ArgumentError, 'id must be an Integer' unless id.is_a?(Integer)
http_delete("#{@url_api_path}/contact/companies/#{id}")
end
def archive_by(id:)
raise ArgumentError, 'id must be an Integer' unless id.is_a?(Integer)
http_post("#{@url_api_path}/contact/companies/#{id}/archive")
end
def unarchive_by(id:)
raise ArgumentError, 'id must be an Integer' unless id.is_a?(Integer)
http_post("#{@url_api_path}/contact/companies/#{id}/unarchive")
end
end
end
end
end
end