crunchbase4 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'crunchbase/version'
4
+
5
+ require 'crunchbase/config'
6
+ require 'crunchbase/utilities'
7
+ require 'crunchbase/client'
8
+ require 'crunchbase/entities'
9
+ require 'crunchbase/searches'
10
+ require 'crunchbase/models'
11
+ require 'crunchbase/errors'
12
+
13
+ module Crunchbase
14
+ API_VERSION = 'v4'
15
+ BASE_URI = "https://api.crunchbase.com/api/#{API_VERSION}/"
16
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crunchbase
4
+ # API Request
5
+ class Client
6
+ # API Parameters
7
+ #
8
+ # entity_id: UUID or permalink of desired entity
9
+ # card_id: A card to include on the resulting entity
10
+ # order: Field name with order direction (asc/desc)
11
+ # limit: Number of rows to return. Default is 100, min is 1, max is 100.
12
+ def organization(entity_id, card_id: nil)
13
+ kobject = entities('Organization', entity_id)
14
+ return kobject.fetch if card_id.nil?
15
+
16
+ kobject.cards(card_id)
17
+ end
18
+
19
+ # Fetching all cards of organization
20
+ def organization_cards(entity_id, cards: [])
21
+ entities('Organization', entity_id).fetch_cards(cards)
22
+ end
23
+
24
+ def person(entity_id, card_id: nil)
25
+ kobject = entities('Person', entity_id)
26
+ return kobject.fetch if card_id.nil?
27
+
28
+ kobject.cards(card_id)
29
+ end
30
+
31
+ # Fetching all cards of people
32
+ def person_cards(entity_id)
33
+ entities('Person', entity_id).fetch_cards
34
+ end
35
+
36
+ def searches(keyword, _scope: nil)
37
+ Crunchbase::Searches::Organization.new('name', keyword)
38
+ end
39
+
40
+ private
41
+
42
+ def entities(kclass_name, entity_id)
43
+ model_name = Kernel.const_get("Crunchbase::Models::#{kclass_name}")
44
+ Crunchbase::Entities::Client.new(entity_id, model_name)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+
5
+ # Root Crunchbase
6
+ module Crunchbase
7
+ # Config
8
+ class Config
9
+ include Singleton
10
+ attr_accessor :user_key
11
+ end
12
+
13
+ def self.config
14
+ yield Config.instance if block_given?
15
+
16
+ Config.instance
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crunchbase
4
+ # Entities API
5
+ module Entities
6
+ autoload :Client, 'crunchbase/entities/client'
7
+ end
8
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crunchbase
4
+ # Whole entities endpoints
5
+ module Entities
6
+ # Send request for entities endpoints
7
+ class Client
8
+ include ::Crunchbase::Utilities::Request
9
+
10
+ attr_reader :object
11
+
12
+ ROOT_LIST = 'entities'
13
+
14
+ def initialize(entity_id, model_name)
15
+ @entity_id = entity_id
16
+ @object = model_name.new
17
+ end
18
+
19
+ # Will include all attribute from API document
20
+ def fetch
21
+ object.parse_response(entity(
22
+ root_uri,
23
+ field_ids: object.field_ids.join(',')
24
+ ))
25
+ end
26
+
27
+ # Only include a part basis fields of endpoint
28
+ def fetch_cards(card_names = [])
29
+ object.parse_cards_response(entity(
30
+ root_uri,
31
+ field_ids: object.basis_fields.join(','),
32
+ cards: (object.full_cards & card_names).join(',')
33
+ ))
34
+ end
35
+
36
+ def cards(card_id)
37
+ object.parse_response(entity(
38
+ root_uri(name: __method__, id: card_id)
39
+ ))
40
+ end
41
+
42
+ private
43
+
44
+ def root_uri(args = {})
45
+ [
46
+ ROOT_LIST, object.class::RESOURCE_LIST,
47
+ @entity_id, args[:name], args[:id]
48
+ ].compact.join('/')
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crunchbase
4
+ class Error < StandardError; end
5
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crunchbase
4
+ # Models
5
+ module Models
6
+ autoload :Entity, 'crunchbase/models/entity'
7
+ autoload :Organization, 'crunchbase/models/organization'
8
+ autoload :Person, 'crunchbase/models/person'
9
+ autoload :FundingRound, 'crunchbase/models/funding_round'
10
+ autoload :Investment, 'crunchbase/models/investment'
11
+ autoload :PressReference, 'crunchbase/models/press_reference'
12
+ autoload :CategoryGroup, 'crunchbase/models/category_group'
13
+ autoload :Category, 'crunchbase/models/category'
14
+ end
15
+ 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
+ # Get the person data from API
7
+ class Category < Entity
8
+ RESOURCE_LIST = 'categories'
9
+
10
+ def field_ids
11
+ %w[
12
+ ] + basis_fields
13
+ end
14
+
15
+ def basis_fields
16
+ %w[
17
+ ]
18
+ end
19
+
20
+ def full_cards
21
+ %w[
22
+ ]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,33 @@
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 CategoryGroup < Entity
8
+ RESOURCE_LIST = 'category_groups'
9
+
10
+ def field_ids
11
+ %w[
12
+ categories
13
+ created_at
14
+ entity_def_id
15
+ identifier
16
+ rank
17
+ updated_at
18
+ ] + basis_fields
19
+ end
20
+
21
+ def basis_fields
22
+ %w[
23
+ uuid
24
+ name
25
+ ]
26
+ end
27
+
28
+ def full_cards
29
+ %w[]
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crunchbase
4
+ # Get the Organization data from API
5
+ module Models
6
+ # Root
7
+ class Entity
8
+ include ::Crunchbase::Utilities::Response
9
+
10
+ def fields
11
+ field_ids.map(&:to_sym)
12
+ end
13
+
14
+ def parse_response(response)
15
+ dynamic_attributes(self, field_ids, response.dig('properties'))
16
+ end
17
+
18
+ def parse_cards_response(response)
19
+ parse_response(response, response.dig('properties'))
20
+ # response.dig('cards')
21
+ end
22
+
23
+ def as_json
24
+ fields.each_with_object({}) { |item, hash| hash[item] = send(item) }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,63 @@
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 FundingRound < Entity
8
+ RESOURCE_LIST = 'funding_rounds'
9
+
10
+ def field_ids
11
+ %w[
12
+ created_at
13
+ entity_def_id
14
+ funded_organization_categories
15
+ funded_organization_description
16
+ funded_organization_funding_stage
17
+ funded_organization_funding_total
18
+ funded_organization_identifier
19
+ funded_organization_location
20
+ funded_organization_revenue_range
21
+ identifier
22
+ image_id
23
+ investor_identifiers
24
+ is_equity
25
+ lead_investor_identifiers
26
+ num_partners
27
+ num_relationships
28
+ permalink
29
+ pre_money_valuation
30
+ rank
31
+ rank_funding_round
32
+ updated_at
33
+ ] + basis_fields
34
+ end
35
+
36
+ def basis_fields
37
+ %w[
38
+ uuid
39
+ name
40
+ announced_on
41
+ closed_on
42
+ investment_stage
43
+ investment_type
44
+ money_raised
45
+ target_money_raised
46
+ num_investors
47
+ short_description
48
+ ]
49
+ end
50
+
51
+ def full_cards
52
+ %w[
53
+ investments
54
+ lead_investors
55
+ investors
56
+ organization
57
+ partners
58
+ press_references
59
+ ]
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,47 @@
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 Investment < Entity
8
+ RESOURCE_LIST = 'investments'
9
+
10
+ def field_ids
11
+ %w[
12
+ created_at
13
+ entity_def_id
14
+ identifier
15
+ investor_identifier
16
+ is_lead_investor
17
+ funding_round_identifier
18
+ updated_at
19
+ ] + basis_fields
20
+ end
21
+
22
+ def basis_fields
23
+ %w[
24
+ uuid
25
+ name
26
+ permalink
27
+ money_invested
28
+ investor_stage
29
+ investor_type
30
+ funding_round_money_raised
31
+ organization_identifier
32
+ partner_identifiers
33
+ announced_on
34
+ ]
35
+ end
36
+
37
+ def full_cards
38
+ %w[
39
+ investor
40
+ organization
41
+ funding_round
42
+ partner
43
+ ]
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,139 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crunchbase
4
+ # Get the Organization data from API
5
+ module Models
6
+ # Build Organization API
7
+ class Organization < Entity
8
+ RESOURCE_LIST = 'organizations'
9
+
10
+ def basis_fields
11
+ %w[
12
+ uuid
13
+ identifier
14
+ permalink
15
+ permalink_aliases
16
+ name
17
+ legal_name
18
+ aliases
19
+ website
20
+ linkedin
21
+ twitter
22
+ rank_org
23
+ short_description
24
+ description
25
+ rank_org_company
26
+ ]
27
+ end
28
+
29
+ def field_ids
30
+ %w[
31
+ acquirer_identifier
32
+ categories
33
+ category_groups
34
+ closed_on
35
+ company_type
36
+ contact_email
37
+ created_at
38
+ delisted_on
39
+ demo_days
40
+ entity_def_id
41
+ equity_funding_total
42
+ exited_on
43
+ facebook
44
+ facet_ids
45
+ founded_on
46
+ founder_identifiers
47
+ funding_stage
48
+ funding_total
49
+ funds_total
50
+ image_id
51
+ image_url
52
+ investor_identifiers
53
+ investor_stage
54
+ investor_type
55
+ ipo_status
56
+ last_equity_funding_total
57
+ last_equity_funding_type
58
+ last_funding_at
59
+ last_funding_total
60
+ last_funding_type
61
+ layout_id
62
+ listed_stock_symbol
63
+ location_group_identifiers
64
+ location_identifiers
65
+ num_acquisitions
66
+ num_alumni
67
+ num_articles
68
+ num_current_advisor_positions
69
+ num_current_positions
70
+ num_employees_enum
71
+ num_enrollments
72
+ num_event_appearances
73
+ num_exits
74
+ num_exits_ipo
75
+ num_founder_alumni
76
+ num_founders
77
+ num_funding_rounds
78
+ num_funds
79
+ num_investments
80
+ num_investments_funding_rounds
81
+ num_investors
82
+ num_lead_investments
83
+ num_lead_investors
84
+ num_past_positions
85
+ num_portfolio_organizations
86
+ num_relationships
87
+ num_sub_organizations
88
+ operating_status
89
+ override_layout_id
90
+ owner_identifier
91
+ phone_number
92
+ program_application_deadline
93
+ program_duration
94
+ program_type
95
+ rank_delta_d30
96
+ rank_delta_d7
97
+ rank_delta_d90
98
+ rank
99
+ rank_org_school
100
+ rank_principal
101
+ rank_principal_investor
102
+ revenue_range
103
+ school_method
104
+ school_program
105
+ school_type
106
+ status
107
+ stock_exchange_symbol
108
+ stock_symbol
109
+ updated_at
110
+ went_public_on
111
+ ] + basis_fields
112
+ end
113
+
114
+ def full_cards
115
+ %w[
116
+ raised_investments
117
+ participated_funds
118
+ child_organizations
119
+ participated_investments
120
+ investors
121
+ parent_organization
122
+ raised_funding_rounds
123
+ ipos
124
+ event_appearances
125
+ raised_funds
126
+ acquiree_acquisitions
127
+ acquirer_acquisitions
128
+ parent_ownership
129
+ jobs
130
+ founders
131
+ child_ownerships
132
+ participated_funding_rounds
133
+ press_references
134
+ headquarters_address
135
+ ]
136
+ end
137
+ end
138
+ end
139
+ end