lib/crunchbase/utilities/search_query_parameters.rb in crunchbase4-0.2.1 vs lib/crunchbase/utilities/search_query_parameters.rb in crunchbase4-0.2.2
- old
+ new
@@ -9,10 +9,11 @@
# https://app.swaggerhub.com/apis-docs/Crunchbase/crunchbase-enterprise_api/1.0.1#/Search/post_searches_people
#
# Search Query Parameters
#
+ # order_field_id: sort field, default field will be updated_at
# field_ids: array of field_id strings
# Fields to include as columns in the search result entities
# query: Search query to perform on the designated entity
# order: (field_id, sort, nulls)
# Order in which the search results should be returned
@@ -23,32 +24,24 @@
# before_id should be the uuid of the first item in the current page. May not be provided simultaneously with after_id.
# after_id: string($uuid)
# Used to paginate search results to the next page.
# after_id should be the uuid of the last item in the current page. May not be provided simultaneously with before_id.
def query_parameters(args)
+ order_field_id = args[:order_field_id] || 'updated_at'
+
params = {
- 'field_ids' => %w[
- uuid
- created_at
- updated_at
- ] + (args[:field_ids] || []).uniq,
- 'order' => [
- {
- 'field_id' => 'updated_at',
- 'sort' => (args[:sort] || 'desc'),
- 'nulls' => 'last'
- }
- ],
+ 'field_ids' => default_field_ids + (args[:field_ids] || []).uniq,
+ 'order' => [{ 'field_id' => order_field_id, 'sort' => (args[:sort] || 'desc'), 'nulls' => 'last' }],
'limit' => args[:limit] || 1000
}
unless args[:date].nil?
params.merge!(
'query' => [
{
'type' => 'predicate',
- 'field_id' => 'updated_at',
+ 'field_id' => order_field_id,
'operator_id' => 'gte',
'values' => [
args[:date]
]
}
@@ -56,9 +49,17 @@
)
end
params.merge!('before_id' => args[:before_id]) unless args[:before_id].nil?
params.merge!('after_id' => args[:after_id]) unless args[:after_id].nil?
params
+ end
+
+ def default_field_ids
+ @default_field_ids ||= %w[
+ uuid
+ created_at
+ updated_at
+ ]
end
end
end
end