Module: Pipedrive::Fields::ClassMethods
- Defined in:
- lib/pipedrive/fields.rb
Instance Method Summary collapse
-
#api_version ⇒ Object
override the default version with the one provided.
- #fields ⇒ Object
-
#fields_api_version ⇒ Object
Fields-specific API version.
-
#use_fields_version(version) ⇒ Object
Set version specifically for fields operations.
Instance Method Details
#api_version ⇒ Object
override the default version with the one provided
19 20 21 22 23 24 |
# File 'lib/pipedrive/fields.rb', line 19 def api_version return @version if @version # Fall back to original Request module logic if no version override super end |
#fields ⇒ Object
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 |
# File 'lib/pipedrive/fields.rb', line 31 def fields url = fields_url || "#{class_name.downcase}Fields" data = [] start = 0 request_more_fields = true while request_more_fields response = fields_request(:get, url, start: start) data.concat(response.dig(:data)) # Check wether there are more fields to bring = response.dig(:additional_data, :pagination) request_more_fields = &.fetch(:more_items_in_collection, false) start = [:next_start] if request_more_fields end # return a hash prefilled with # the fields hash and name parameterized # and the original array of fields (schema) dicc = data.reduce({}) do |fields_dicc, field| # snakify the name 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 |
#fields_api_version ⇒ Object
Fields-specific API version
27 28 29 |
# File 'lib/pipedrive/fields.rb', line 27 def fields_api_version @fields_version || api_version end |
#use_fields_version(version) ⇒ Object
Set version specifically for fields operations
14 15 16 |
# File 'lib/pipedrive/fields.rb', line 14 def use_fields_version(version) @fields_version = version end |