Class: Crunchbase::Model::BatchSearch

Inherits:
Entity
  • Object
show all
Includes:
Enumerable
Defined in:
lib/crunchbase/model/batch_search.rb

Instance Attribute Summary collapse

Attributes inherited from Entity

#type_name, #uuid

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

#convert_date!, #date_keys, #fetch, #instance_multi_relationship_objects, #instance_relationships_object, #instance_timestamps, #one_to_many, #one_to_one, #parse_hash_items, #property_keys, #relationship_lists, #set_relationships_object, #set_variables, #setup_relationships_data!, #special_relationship, #verify_item?

Methods included from Request::Client

#api, #array_from_list, #funding_rounds_lists, #get, #list, #organization_lists, #parsing_from_list, #person_lists, #total_items_from_list

Constructor Details

#initialize(json) ⇒ BatchSearch

Returns a new instance of BatchSearch.



12
13
14
15
16
# File 'lib/crunchbase/model/batch_search.rb', line 12

def initialize(json)
  @results = []

  populate_results(json)
end

Instance Attribute Details

#resultsObject (readonly) Also known as: items

Returns the value of attribute results.



8
9
10
# File 'lib/crunchbase/model/batch_search.rb', line 8

def results
  @results
end

Class Method Details

.batch_search(requests) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/crunchbase/model/batch_search.rb', line 29

def self.batch_search(requests)
  raise ConfigurationException, 'Invalid argument. Please pass in an array as an argument' unless requests.is_a?(Array)
  raise InvalidRequestException, "Too many requests(#{requests.length}) in batch, max allowed 10" if requests.length > 10
  raise MissingParamsException, 'Missing :type or :uuid parameter in some requests' if requests.any? { |request| !request.key?(:type) || !request.key?(:uuid) }
  return [] if requests.empty?

  BatchSearch.new API.batch_search(requests)
end

Instance Method Details

#populate_results(json) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/crunchbase/model/batch_search.rb', line 18

def populate_results(json)
  @results = []

  @results = json['items'].map do |r|
    next Error.new(r['error']) if r.key?('error')

    kclass = kclass_name(r['type'])
    kclass.new(r)
  end
end