crunchbase4 0.1.2 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +45 -6
- data/Gemfile.lock +1 -1
- data/README.md +297 -78
- data/crunchbase4.gemspec +2 -2
- data/lib/crunchbase.rb +1 -1
- data/lib/crunchbase/autocompletes/client.rb +2 -2
- data/lib/crunchbase/deleted_entities/client.rb +69 -0
- data/lib/crunchbase/entities/client.rb +24 -12
- data/lib/crunchbase/models.rb +8 -1
- data/lib/crunchbase/models/address.rb +36 -0
- data/lib/crunchbase/models/concerns/entity.rb +54 -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/job.rb +42 -0
- data/lib/crunchbase/models/organization.rb +10 -0
- data/lib/crunchbase/models/ownership.rb +39 -0
- data/lib/crunchbase/models/principal.rb +112 -0
- data/lib/crunchbase/utilities/autocomplete.rb +5 -20
- data/lib/crunchbase/utilities/deleted_entities.rb +33 -1
- data/lib/crunchbase/utilities/entity_endpoints.rb +52 -28
- data/lib/crunchbase/utilities/request.rb +10 -2
- data/lib/crunchbase/utilities/response.rb +20 -1
- data/lib/crunchbase/utilities/veriables.rb +1 -1
- data/lib/crunchbase/version.rb +1 -1
- metadata +16 -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
@@ -26,7 +26,7 @@ module Crunchbase
|
|
26
26
|
|
27
27
|
# Will include all attribute from API document
|
28
28
|
def autocompletes
|
29
|
-
|
29
|
+
wrapping_autocomplete_entities!(
|
30
30
|
get(
|
31
31
|
ROOT_LIST,
|
32
32
|
autocompletes_parameters
|
@@ -36,7 +36,7 @@ module Crunchbase
|
|
36
36
|
|
37
37
|
private
|
38
38
|
|
39
|
-
def
|
39
|
+
def wrapping_autocomplete_entities!(response)
|
40
40
|
query_results = search_results(response.dig('entities'))
|
41
41
|
|
42
42
|
self.total_count = response['count']
|
@@ -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,8 +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
7
|
autoload :AutocompleteEntity, 'crunchbase/models/autocomplete_entity'
|
8
|
+
autoload :DeletedEntity, 'crunchbase/models/deleted_entity'
|
8
9
|
autoload :Organization, 'crunchbase/models/organization'
|
9
10
|
autoload :Person, 'crunchbase/models/person'
|
10
11
|
autoload :FundingRound, 'crunchbase/models/funding_round'
|
@@ -14,5 +15,11 @@ module Crunchbase
|
|
14
15
|
autoload :CategoryGroup, 'crunchbase/models/category_group'
|
15
16
|
autoload :Category, 'crunchbase/models/category'
|
16
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'
|
17
24
|
end
|
18
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,54 @@
|
|
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
|
+
|
49
|
+
def custom_fields
|
50
|
+
[]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
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
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Crunchbase
|
4
|
+
# Get the Entities data from API
|
5
|
+
module Models
|
6
|
+
# For AutocompleteEntity
|
7
|
+
class DeletedEntity < Entity
|
8
|
+
def field_ids
|
9
|
+
basis_fields
|
10
|
+
end
|
11
|
+
|
12
|
+
def basis_fields
|
13
|
+
%w[
|
14
|
+
uuid
|
15
|
+
entity_def_id
|
16
|
+
deleted_at
|
17
|
+
identifier
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_response(response)
|
22
|
+
dynamic_attributes(self, field_ids, response)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Crunchbase
|
4
|
+
# Get the Entities data from API
|
5
|
+
module Models
|
6
|
+
# Get the EventAppearances data from API
|
7
|
+
class EventAppearance < Entity
|
8
|
+
RESOURCE_LIST = 'event_appearances'
|
9
|
+
|
10
|
+
def field_ids
|
11
|
+
%w[
|
12
|
+
created_at
|
13
|
+
updated_at
|
14
|
+
entity_def_id
|
15
|
+
event_identifier
|
16
|
+
event_location_identifiers
|
17
|
+
participant_identifier
|
18
|
+
] + basis_fields
|
19
|
+
end
|
20
|
+
|
21
|
+
def basis_fields
|
22
|
+
%w[
|
23
|
+
appearance_type
|
24
|
+
identifier
|
25
|
+
name
|
26
|
+
permalink
|
27
|
+
short_description
|
28
|
+
event_starts_on
|
29
|
+
uuid
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
def full_cards
|
34
|
+
%w[
|
35
|
+
]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Crunchbase
|
4
|
+
# Get the Entities data from API
|
5
|
+
module Models
|
6
|
+
# Get the Fund data from API
|
7
|
+
class Fund < Entity
|
8
|
+
RESOURCE_LIST = 'funds'
|
9
|
+
|
10
|
+
def field_ids
|
11
|
+
%w[
|
12
|
+
created_at
|
13
|
+
entity_def_id
|
14
|
+
image_id
|
15
|
+
investor_identifiers
|
16
|
+
num_investors
|
17
|
+
owner_identifier
|
18
|
+
short_description
|
19
|
+
started_on
|
20
|
+
updated_at
|
21
|
+
] + basis_fields
|
22
|
+
end
|
23
|
+
|
24
|
+
def basis_fields
|
25
|
+
%w[
|
26
|
+
uuid
|
27
|
+
name
|
28
|
+
announced_on
|
29
|
+
money_raised
|
30
|
+
permalink
|
31
|
+
]
|
32
|
+
end
|
33
|
+
|
34
|
+
def full_cards
|
35
|
+
%w[
|
36
|
+
investors
|
37
|
+
owner
|
38
|
+
press_references
|
39
|
+
]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|