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
|
# File 'lib/pipedrive/fields.rb', line 13
def fields
url = fields_url || "#{class_name.downcase}Fields"
data = []
start = 0
request_more_fields = true
while request_more_fields
response = request(:get, url, start: start)
data.concat(response.dig(:data))
metadata = response.dig(:additional_data, :pagination)
request_more_fields = metadata&.fetch(:more_items_in_collection, false)
start = metadata[:next_start] if request_more_fields
end
dicc = data.reduce({}) do |fields_dicc, field|
snake_name = field.dig(:name).gsub(/\w+/).reduce([]) do |words, c|
words << c.downcase
end.join("_")
fields_dicc.merge(
field.dig(:key).to_sym => snake_name.to_sym
)
end
[dicc, data]
end
|