crunchbase4 0.1.1 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +5 -0
- data/CHANGELOG.md +66 -0
- data/Gemfile.lock +1 -1
- data/README.md +392 -40
- data/crunchbase4.gemspec +2 -2
- data/lib/crunchbase.rb +30 -1
- data/lib/crunchbase/autocompletes/client.rb +75 -0
- data/lib/crunchbase/client.rb +4 -0
- data/lib/crunchbase/deleted_entities/client.rb +69 -0
- data/lib/crunchbase/entities/client.rb +24 -12
- data/lib/crunchbase/models.rb +10 -1
- data/lib/crunchbase/models/address.rb +36 -0
- data/lib/crunchbase/models/autocomplete_entity.rb +25 -0
- data/lib/crunchbase/models/concerns/entity.rb +53 -0
- data/lib/crunchbase/models/concerns/mappings.rb +37 -0
- data/lib/crunchbase/models/deleted_entity.rb +26 -0
- data/lib/crunchbase/models/event_appearance.rb +39 -0
- data/lib/crunchbase/models/fund.rb +43 -0
- data/lib/crunchbase/models/ipo.rb +48 -0
- data/lib/crunchbase/models/job.rb +42 -0
- data/lib/crunchbase/models/organization.rb +9 -0
- data/lib/crunchbase/models/ownership.rb +39 -0
- data/lib/crunchbase/models/principal.rb +112 -0
- data/lib/crunchbase/utilities/autocomplete.rb +51 -0
- data/lib/crunchbase/utilities/deleted_entities.rb +47 -0
- data/lib/crunchbase/utilities/entity_endpoints.rb +58 -24
- data/lib/crunchbase/utilities/request.rb +28 -11
- data/lib/crunchbase/utilities/response.rb +1 -1
- data/lib/crunchbase/utilities/search_endpoints.rb +22 -0
- data/lib/crunchbase/utilities/search_query_parameters.rb +64 -0
- data/lib/crunchbase/utilities/veriables.rb +335 -0
- data/lib/crunchbase/version.rb +1 -1
- metadata +23 -7
- data/lib/crunchbase/models/entity.rb +0 -32
data/crunchbase4.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ['encore@ekohe.com']
|
10
10
|
|
11
11
|
spec.summary = 'Crunchbase is a ruby wrapper base on Crunchbase V4 API'
|
12
|
-
spec.description = 'Crunchbase is a ruby wrapper base on Crunchbase V4 API.
|
12
|
+
spec.description = 'Crunchbase is a ruby wrapper base on Crunchbase V4 API. it provides easy to get the API data by each endpoint. '
|
13
13
|
spec.homepage = 'https://github.com/ekohe/crunchbase4'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.metadata['homepage_uri'] = spec.homepage
|
21
21
|
spec.metadata['source_code_uri'] = 'https://github.com/ekohe/crunchbase4'
|
22
|
-
spec.metadata['changelog_uri'] = 'https://github.com/ekohe/crunchbase4/CHANGELOG.md'
|
22
|
+
spec.metadata['changelog_uri'] = 'https://github.com/ekohe/crunchbase4/blob/master/CHANGELOG.md'
|
23
23
|
|
24
24
|
# Specify which files should be added to the gem when it is released.
|
25
25
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
data/lib/crunchbase.rb
CHANGED
@@ -4,11 +4,40 @@ require 'crunchbase/version'
|
|
4
4
|
|
5
5
|
require 'crunchbase/config'
|
6
6
|
require 'crunchbase/client'
|
7
|
+
require 'crunchbase/models'
|
7
8
|
require 'crunchbase/entities'
|
8
9
|
require 'crunchbase/searches'
|
9
|
-
require 'crunchbase/
|
10
|
+
require 'crunchbase/utilities/veriables'
|
10
11
|
|
12
|
+
# CB v4
|
11
13
|
module Crunchbase
|
12
14
|
API_VERSION = 'v4'
|
13
15
|
BASE_URI = "https://api.crunchbase.com/api/#{API_VERSION}/"
|
16
|
+
|
17
|
+
# Defined Veriables for the data Category or Types
|
18
|
+
#
|
19
|
+
# Crunchbase::Utils.constants => [
|
20
|
+
# :OPERATING_STATUS,
|
21
|
+
# :PROGRAM_TYPES,
|
22
|
+
# :REVENUE_RANGES,
|
23
|
+
# :COMPANY_TYPES,
|
24
|
+
# :FACET_IDS,
|
25
|
+
# :SCHOOL_METHODS,
|
26
|
+
# :IPO_STATUS,
|
27
|
+
# :FUNDING_STAGES,
|
28
|
+
# :CURRENCY_ENUM,
|
29
|
+
# :DATE_PRECISIONS,
|
30
|
+
# :LAYOUT_IDS,
|
31
|
+
# :NUM_EMPLOYEES_ENUM,
|
32
|
+
# :FUNDING_TYPES,
|
33
|
+
# :SCHOOL_TYPES,
|
34
|
+
# :QUERY_OPERATORS,
|
35
|
+
# :STATUS,
|
36
|
+
# :STOCK_EXCHANGE_SYMBOLS
|
37
|
+
# ]
|
38
|
+
#
|
39
|
+
# Crunchbase::Utils::NUM_EMPLOYEES_ENUM
|
40
|
+
class Utils
|
41
|
+
include Utilities::Veriables
|
42
|
+
end
|
14
43
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../utilities/request'
|
4
|
+
require_relative '../utilities/cb_model'
|
5
|
+
|
6
|
+
module Crunchbase
|
7
|
+
# autocompletes endpoints
|
8
|
+
module Autocompletes
|
9
|
+
# Send request for autocompletes endpoint
|
10
|
+
#
|
11
|
+
# API doc:
|
12
|
+
# https://app.swaggerhub.com/apis-docs/Crunchbase/crunchbase-enterprise_api/1.0.1#/Autocomplete/get_autocompletes
|
13
|
+
class Client
|
14
|
+
include ::Crunchbase::Utilities::Request
|
15
|
+
include ::Crunchbase::Utilities::CbModel
|
16
|
+
|
17
|
+
attr_accessor :total_count, :count, :entities, :conditions, :entity_type
|
18
|
+
|
19
|
+
ROOT_LIST = 'autocompletes'
|
20
|
+
LIMIT = 25
|
21
|
+
|
22
|
+
def initialize(raw_data)
|
23
|
+
@conditions = raw_data
|
24
|
+
@entity_type = 'autocomplete_entity'
|
25
|
+
end
|
26
|
+
|
27
|
+
# Will include all attribute from API document
|
28
|
+
def autocompletes
|
29
|
+
wrapping_autocomplete_entities!(
|
30
|
+
get(
|
31
|
+
ROOT_LIST,
|
32
|
+
autocompletes_parameters
|
33
|
+
)
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def wrapping_autocomplete_entities!(response)
|
40
|
+
query_results = search_results(response.dig('entities'))
|
41
|
+
|
42
|
+
self.total_count = response['count']
|
43
|
+
self.entities = query_results
|
44
|
+
self.count = query_results.size
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
# One item of organization
|
49
|
+
#
|
50
|
+
# {
|
51
|
+
# "facet_ids"=>
|
52
|
+
# ["siftery", "apptopia", "company", "rank", "builtwith", "bombora", "similarweb"],
|
53
|
+
# "identifier"=>
|
54
|
+
# {
|
55
|
+
# "uuid"=>"9fe491b2-b6a1-5c87-0f4d-226dd0cc97a9",
|
56
|
+
# "value"=>"Ekohe",
|
57
|
+
# "image_id"=>"v1500646625/zhionn8nlgbkz4lj7ilz.png",
|
58
|
+
# "permalink"=>"ekohe",
|
59
|
+
# "entity_def_id"=>"organization"
|
60
|
+
# },
|
61
|
+
# "short_description"=>
|
62
|
+
# "Creating cutting-edge, useful technical solutions to move you forward -- we deliver on the promise of AI."
|
63
|
+
# }
|
64
|
+
def search_results(entities)
|
65
|
+
entities.each_with_object([]) do |entity, objects|
|
66
|
+
objects << cbobject.parse_response(entity)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def autocompletes_parameters
|
71
|
+
@conditions.merge(limit: @conditions[:limit] || LIMIT)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/crunchbase/client.rb
CHANGED
@@ -2,11 +2,15 @@
|
|
2
2
|
|
3
3
|
require_relative 'utilities/entity_endpoints'
|
4
4
|
require_relative 'utilities/search_endpoints'
|
5
|
+
require_relative 'utilities/autocomplete'
|
6
|
+
require_relative 'utilities/deleted_entities'
|
5
7
|
|
6
8
|
module Crunchbase
|
7
9
|
# API Request
|
8
10
|
class Client
|
9
11
|
include Utilities::EntityEndpoints
|
10
12
|
include Utilities::SearchEndpoints
|
13
|
+
include Utilities::Autocomplete
|
14
|
+
include Utilities::DeletedEntities
|
11
15
|
end
|
12
16
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../utilities/request'
|
4
|
+
require_relative '../utilities/cb_model'
|
5
|
+
|
6
|
+
module Crunchbase
|
7
|
+
# Retrieve deleted entities
|
8
|
+
module DeletedEntities
|
9
|
+
# Send request for deleted_entities endpoint
|
10
|
+
class Client
|
11
|
+
include ::Crunchbase::Utilities::Request
|
12
|
+
include ::Crunchbase::Utilities::CbModel
|
13
|
+
|
14
|
+
attr_accessor :total_count, :count, :entities, :conditions, :entity_type
|
15
|
+
|
16
|
+
ROOT_LIST = 'deleted_entities'
|
17
|
+
LIMIT = 1000
|
18
|
+
|
19
|
+
def initialize(raw_data)
|
20
|
+
@conditions = raw_data
|
21
|
+
@entity_type = 'deleted_entity'
|
22
|
+
end
|
23
|
+
|
24
|
+
# Will include all attribute from API document
|
25
|
+
def deleted_entities
|
26
|
+
wrapping_deleted_entities!(
|
27
|
+
deleted(
|
28
|
+
ROOT_LIST,
|
29
|
+
deleted_entities_parameters
|
30
|
+
)
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def wrapping_deleted_entities!(response)
|
37
|
+
query_results = search_results(response)
|
38
|
+
|
39
|
+
self.total_count = response.size
|
40
|
+
self.entities = query_results
|
41
|
+
self.count = query_results.size
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
# One item of organization
|
46
|
+
#
|
47
|
+
# {
|
48
|
+
# "identifier"=>
|
49
|
+
# {
|
50
|
+
# "uuid"=>"9fe491b2-b6a1-5c87-0f4d-226dd0cc97a9",
|
51
|
+
# "value"=>"Ekohe",
|
52
|
+
# "image_id"=>"v1500646625/zhionn8nlgbkz4lj7ilz.png",
|
53
|
+
# "permalink"=>"ekohe",
|
54
|
+
# "entity_def_id"=>"organization"
|
55
|
+
# },
|
56
|
+
# "deleted_at"=> string($date-time)
|
57
|
+
# }
|
58
|
+
def search_results(entities)
|
59
|
+
entities.each_with_object([]) do |entity, objects|
|
60
|
+
objects << cbobject.parse_response(entity)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def deleted_entities_parameters
|
65
|
+
@conditions.merge(limit: @conditions[:limit] || LIMIT)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -6,7 +6,7 @@ require_relative '../utilities/cb_model'
|
|
6
6
|
module Crunchbase
|
7
7
|
# Whole entities endpoints
|
8
8
|
module Entities
|
9
|
-
#
|
9
|
+
# using Crunchbase's Entity Lookup API endpoints
|
10
10
|
class Client
|
11
11
|
include ::Crunchbase::Utilities::Request
|
12
12
|
include ::Crunchbase::Utilities::CbModel
|
@@ -21,32 +21,44 @@ module Crunchbase
|
|
21
21
|
# Will include all attribute from API document
|
22
22
|
def fetch
|
23
23
|
cbobject.parse_response(entity(
|
24
|
-
|
24
|
+
entity_request_uri,
|
25
25
|
field_ids: cbobject.field_ids.join(',')
|
26
26
|
))
|
27
27
|
end
|
28
28
|
|
29
29
|
# Only include a part basis fields of endpoint
|
30
30
|
def fetch_cards(card_names = [])
|
31
|
-
cbobject.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
cbobject.parse_response(entity(
|
32
|
+
entity_request_uri,
|
33
|
+
field_ids: cbobject.basis_fields.join(','),
|
34
|
+
cards: (cbobject.full_cards & card_names).join(',')
|
35
|
+
), cbobject.basis_fields, card_names)
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
# Auto combine the card num field to request field_ids
|
39
|
+
#
|
40
|
+
# Example: if card_id is investors, will auto add num_investors
|
41
|
+
def cards(card_id, **args)
|
42
|
+
raise Crunchbase::Error, 'Invalid card_id' unless cbobject.full_cards.include?(card_id)
|
43
|
+
|
44
|
+
field_ids = cbobject.basis_fields.concat(cbobject.card_num_field(card_id))
|
45
|
+
|
46
|
+
request_args = args.merge(
|
47
|
+
field_ids: field_ids.join(','),
|
48
|
+
card_field_ids: cbobject.model_mappings[card_id].new.field_ids.join(',')
|
49
|
+
)
|
39
50
|
cbobject.parse_response(entity(
|
40
|
-
|
41
|
-
|
51
|
+
entity_request_uri(name: __method__, card_id: card_id),
|
52
|
+
request_args
|
53
|
+
), field_ids, [card_id])
|
42
54
|
end
|
43
55
|
|
44
56
|
private
|
45
57
|
|
46
|
-
def
|
58
|
+
def entity_request_uri(**args)
|
47
59
|
[
|
48
60
|
ROOT_LIST, kclass_name::RESOURCE_LIST,
|
49
|
-
@entity_id, args[:name], args[:
|
61
|
+
@entity_id, args[:name], args[:card_id]
|
50
62
|
].compact.join('/')
|
51
63
|
end
|
52
64
|
end
|
data/lib/crunchbase/models.rb
CHANGED
@@ -3,7 +3,9 @@
|
|
3
3
|
module Crunchbase
|
4
4
|
# Models
|
5
5
|
module Models
|
6
|
-
autoload :Entity, 'crunchbase/models/entity'
|
6
|
+
autoload :Entity, 'crunchbase/models/concerns/entity'
|
7
|
+
autoload :AutocompleteEntity, 'crunchbase/models/autocomplete_entity'
|
8
|
+
autoload :DeletedEntity, 'crunchbase/models/deleted_entity'
|
7
9
|
autoload :Organization, 'crunchbase/models/organization'
|
8
10
|
autoload :Person, 'crunchbase/models/person'
|
9
11
|
autoload :FundingRound, 'crunchbase/models/funding_round'
|
@@ -12,5 +14,12 @@ module Crunchbase
|
|
12
14
|
autoload :PressReference, 'crunchbase/models/press_reference'
|
13
15
|
autoload :CategoryGroup, 'crunchbase/models/category_group'
|
14
16
|
autoload :Category, 'crunchbase/models/category'
|
17
|
+
autoload :Ipo, 'crunchbase/models/ipo'
|
18
|
+
autoload :Fund, 'crunchbase/models/fund'
|
19
|
+
autoload :Ownership, 'crunchbase/models/ownership'
|
20
|
+
autoload :EventAppearance, 'crunchbase/models/event_appearance'
|
21
|
+
autoload :Principal, 'crunchbase/models/principal'
|
22
|
+
autoload :Job, 'crunchbase/models/job'
|
23
|
+
autoload :Address, 'crunchbase/models/address'
|
15
24
|
end
|
16
25
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Crunchbase
|
4
|
+
# Get the Entities data from API
|
5
|
+
module Models
|
6
|
+
# Get the person data from API
|
7
|
+
class Address < Entity
|
8
|
+
RESOURCE_LIST = 'addresses'
|
9
|
+
|
10
|
+
def field_ids
|
11
|
+
%w[
|
12
|
+
created_at
|
13
|
+
entity_def_id
|
14
|
+
updated_at
|
15
|
+
] + basis_fields
|
16
|
+
end
|
17
|
+
|
18
|
+
def basis_fields
|
19
|
+
%w[
|
20
|
+
uuid
|
21
|
+
name
|
22
|
+
postal_code
|
23
|
+
street_1
|
24
|
+
street_2
|
25
|
+
identifier
|
26
|
+
location_identifiers
|
27
|
+
]
|
28
|
+
end
|
29
|
+
|
30
|
+
def full_cards
|
31
|
+
%w[
|
32
|
+
]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Crunchbase
|
4
|
+
# Get the Entities data from API
|
5
|
+
module Models
|
6
|
+
# For AutocompleteEntity
|
7
|
+
class AutocompleteEntity < Entity
|
8
|
+
def field_ids
|
9
|
+
basis_fields
|
10
|
+
end
|
11
|
+
|
12
|
+
def basis_fields
|
13
|
+
%w[
|
14
|
+
identifier
|
15
|
+
facet_ids
|
16
|
+
short_description
|
17
|
+
]
|
18
|
+
end
|
19
|
+
|
20
|
+
def parse_response(response)
|
21
|
+
dynamic_attributes(self, field_ids, response)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../utilities/response'
|
4
|
+
require_relative './mappings'
|
5
|
+
|
6
|
+
module Crunchbase
|
7
|
+
# Get the Organization data from API
|
8
|
+
module Models
|
9
|
+
# Root
|
10
|
+
class Entity
|
11
|
+
include ::Crunchbase::Utilities::Response
|
12
|
+
include Mappings
|
13
|
+
|
14
|
+
def fields
|
15
|
+
field_ids.concat(custom_fields).map(&:to_sym)
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_response(response, request_field_ids = [], cards = [])
|
19
|
+
extract_fields = (request_field_ids.empty? ? field_ids : request_field_ids)
|
20
|
+
|
21
|
+
dynamic_attributes(self, extract_fields, response.dig('properties'))
|
22
|
+
setup_relationships(self, cards, response.dig('cards'))
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def setup_relationships(object, request_card_ids, response_cards)
|
27
|
+
request_card_ids.each do |card_id|
|
28
|
+
card_data = response_cards.dig(card_id)
|
29
|
+
card_model = model_mappings[card_id]
|
30
|
+
card_objects = if card_data.is_a?(Array)
|
31
|
+
card_data.each_with_object([]) do |data, objects|
|
32
|
+
new_card_instance = card_model.new
|
33
|
+
objects << dynamic_attributes(new_card_instance, new_card_instance.basis_fields, data)
|
34
|
+
end
|
35
|
+
else
|
36
|
+
card_data.nil? ? nil : dynamic_attributes(card_model.new, extract_fields, data)
|
37
|
+
end
|
38
|
+
|
39
|
+
dynamic_define_method(object, card_id, card_objects)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def as_json
|
44
|
+
fields.each_with_object({}) { |item, hash| hash[item] = send(item) }
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def custom_fields
|
49
|
+
[]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Crunchbase
|
4
|
+
# Get the Organization data from API
|
5
|
+
module Models
|
6
|
+
# Build card mappings
|
7
|
+
module Mappings
|
8
|
+
def model_mappings
|
9
|
+
{
|
10
|
+
'investments' => Investment,
|
11
|
+
'raised_investments' => Investment,
|
12
|
+
'participated_investments' => Investment,
|
13
|
+
'participated_funds' => Fund,
|
14
|
+
'raised_funds' => Fund,
|
15
|
+
'child_organizations' => Organization,
|
16
|
+
'parent_organization' => Organization,
|
17
|
+
'investors' => Principal,
|
18
|
+
'raised_funding_rounds' => FundingRound,
|
19
|
+
'participated_funding_rounds' => FundingRound,
|
20
|
+
'ipos' => Ipo,
|
21
|
+
'event_appearances' => EventAppearance,
|
22
|
+
'acquiree_acquisitions' => Acquisition,
|
23
|
+
'parent_ownership' => Ownership,
|
24
|
+
'child_ownerships' => Ownership,
|
25
|
+
'jobs' => Job,
|
26
|
+
'founders' => Person,
|
27
|
+
'press_references' => PressReference,
|
28
|
+
'headquarters_address' => Address
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def card_num_field(card_id)
|
33
|
+
field_ids & ["num_#{card_id}"]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|