crunchbase4 0.1.0 → 0.1.5

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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +11 -1
  3. data/CHANGELOG.md +66 -0
  4. data/Gemfile.lock +4 -1
  5. data/README.md +572 -62
  6. data/crunchbase4.gemspec +7 -6
  7. data/lib/crunchbase.rb +30 -3
  8. data/lib/crunchbase/autocompletes/client.rb +75 -0
  9. data/lib/crunchbase/client.rb +9 -40
  10. data/lib/crunchbase/config.rb +1 -1
  11. data/lib/crunchbase/deleted_entities/client.rb +69 -0
  12. data/lib/crunchbase/entities/client.rb +35 -21
  13. data/lib/crunchbase/models.rb +11 -1
  14. data/lib/crunchbase/models/acquisition.rb +61 -0
  15. data/lib/crunchbase/models/address.rb +36 -0
  16. data/lib/crunchbase/models/autocomplete_entity.rb +25 -0
  17. data/lib/crunchbase/models/concerns/entity.rb +48 -0
  18. data/lib/crunchbase/models/concerns/mappings.rb +37 -0
  19. data/lib/crunchbase/models/deleted_entity.rb +26 -0
  20. data/lib/crunchbase/models/event_appearance.rb +39 -0
  21. data/lib/crunchbase/models/fund.rb +43 -0
  22. data/lib/crunchbase/models/funding_round.rb +1 -1
  23. data/lib/crunchbase/models/ipo.rb +48 -0
  24. data/lib/crunchbase/models/job.rb +42 -0
  25. data/lib/crunchbase/models/ownership.rb +39 -0
  26. data/lib/crunchbase/models/principal.rb +112 -0
  27. data/lib/crunchbase/searches/client.rb +57 -6
  28. data/lib/crunchbase/utilities/autocomplete.rb +51 -0
  29. data/lib/crunchbase/utilities/cb_model.rb +32 -0
  30. data/lib/crunchbase/utilities/deleted_entities.rb +47 -0
  31. data/lib/crunchbase/utilities/entity_endpoints.rb +125 -0
  32. data/lib/crunchbase/utilities/request.rb +47 -8
  33. data/lib/crunchbase/utilities/response.rb +33 -12
  34. data/lib/crunchbase/utilities/search_endpoints.rb +46 -0
  35. data/lib/crunchbase/utilities/search_query_parameters.rb +64 -0
  36. data/lib/crunchbase/utilities/veriables.rb +335 -0
  37. data/lib/crunchbase/version.rb +1 -1
  38. metadata +45 -12
  39. data/lib/crunchbase/models/entity.rb +0 -28
  40. data/lib/crunchbase/searches/organization.rb +0 -52
@@ -6,11 +6,11 @@ Gem::Specification.new do |spec|
6
6
  spec.name = 'crunchbase4'
7
7
  spec.version = Crunchbase::VERSION
8
8
  spec.authors = ['Encore Shao']
9
- spec.email = ['encore.shao@gmail.com']
9
+ spec.email = ['encore@ekohe.com']
10
10
 
11
- spec.summary = 'Ruby Library for Crunchbase API Version 4.0'
12
- spec.description = 'A Ruby wrapper for Crunchbase API version 4.0, crunchbase build new API interface by GraphQL'
13
- spec.homepage = 'https://github.com/encoreshao/crunchbase4'
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. it provides easy to get the API data by each endpoint. '
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')
16
16
  spec.post_install_message = 'Thanks for installing!'
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.metadata['allowed_push_host'] = 'https://rubygems.org'
19
19
 
20
20
  spec.metadata['homepage_uri'] = spec.homepage
21
- spec.metadata['source_code_uri'] = 'https://github.com/encoreshao/crunchbase4'
22
- spec.metadata['changelog_uri'] = 'https://github.com/encoreshao/crunchbase4/CHANGELOG.md'
21
+ spec.metadata['source_code_uri'] = 'https://github.com/ekohe/crunchbase4'
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.
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ['lib']
33
33
 
34
34
  spec.add_dependency 'faraday'
35
+ spec.add_dependency 'faraday_curl'
35
36
  spec.add_dependency 'faraday_middleware'
36
37
 
37
38
  # VCR for testing APIs
@@ -3,14 +3,41 @@
3
3
  require 'crunchbase/version'
4
4
 
5
5
  require 'crunchbase/config'
6
- require 'crunchbase/utilities'
7
6
  require 'crunchbase/client'
7
+ require 'crunchbase/models'
8
8
  require 'crunchbase/entities'
9
9
  require 'crunchbase/searches'
10
- require 'crunchbase/models'
11
- require 'crunchbase/errors'
10
+ require 'crunchbase/utilities/veriables'
12
11
 
12
+ # CB v4
13
13
  module Crunchbase
14
14
  API_VERSION = 'v4'
15
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
16
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
@@ -1,47 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'utilities/entity_endpoints'
4
+ require_relative 'utilities/search_endpoints'
5
+ require_relative 'utilities/autocomplete'
6
+ require_relative 'utilities/deleted_entities'
7
+
3
8
  module Crunchbase
4
9
  # API Request
5
10
  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
11
+ include Utilities::EntityEndpoints
12
+ include Utilities::SearchEndpoints
13
+ include Utilities::Autocomplete
14
+ include Utilities::DeletedEntities
46
15
  end
47
16
  end
@@ -7,7 +7,7 @@ module Crunchbase
7
7
  # Config
8
8
  class Config
9
9
  include Singleton
10
- attr_accessor :user_key
10
+ attr_accessor :user_key, :debug
11
11
  end
12
12
 
13
13
  def self.config
@@ -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
@@ -1,50 +1,64 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../utilities/request'
4
+ require_relative '../utilities/cb_model'
5
+
3
6
  module Crunchbase
4
7
  # Whole entities endpoints
5
8
  module Entities
6
- # Send request for entities endpoints
9
+ # using Crunchbase's Entity Lookup API endpoints
7
10
  class Client
8
11
  include ::Crunchbase::Utilities::Request
9
-
10
- attr_reader :object
12
+ include ::Crunchbase::Utilities::CbModel
11
13
 
12
14
  ROOT_LIST = 'entities'
13
15
 
14
- def initialize(entity_id, model_name)
16
+ def initialize(entity_id, entity_type)
15
17
  @entity_id = entity_id
16
- @object = model_name.new
18
+ @entity_type = entity_type
17
19
  end
18
20
 
19
21
  # Will include all attribute from API document
20
22
  def fetch
21
- object.parse_response(entity(
22
- root_uri,
23
- field_ids: object.field_ids.join(',')
24
- ))
23
+ cbobject.parse_response(entity(
24
+ entity_request_uri,
25
+ field_ids: cbobject.field_ids.join(',')
26
+ ))
25
27
  end
26
28
 
27
29
  # Only include a part basis fields of endpoint
28
30
  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
- ))
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)
34
36
  end
35
37
 
36
- def cards(card_id)
37
- object.parse_response(entity(
38
- root_uri(name: __method__, id: card_id)
39
- ))
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
+ )
50
+ cbobject.parse_response(entity(
51
+ entity_request_uri(name: __method__, card_id: card_id),
52
+ request_args
53
+ ), field_ids, [card_id])
40
54
  end
41
55
 
42
56
  private
43
57
 
44
- def root_uri(args = {})
58
+ def entity_request_uri(**args)
45
59
  [
46
- ROOT_LIST, object.class::RESOURCE_LIST,
47
- @entity_id, args[:name], args[:id]
60
+ ROOT_LIST, kclass_name::RESOURCE_LIST,
61
+ @entity_id, args[:name], args[:card_id]
48
62
  ].compact.join('/')
49
63
  end
50
64
  end
@@ -3,13 +3,23 @@
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
+ autoload :Acquisition, 'crunchbase/models/acquisition'
10
13
  autoload :Investment, 'crunchbase/models/investment'
11
14
  autoload :PressReference, 'crunchbase/models/press_reference'
12
15
  autoload :CategoryGroup, 'crunchbase/models/category_group'
13
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'
14
24
  end
15
25
  end
@@ -0,0 +1,61 @@
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 Acquisition < Entity
8
+ RESOURCE_LIST = 'acquisitions'
9
+
10
+ def field_ids
11
+ %w[
12
+ acquiree_categories
13
+ acquiree_last_funding_type
14
+ acquiree_locations
15
+ acquiree_num_funding_rounds
16
+ acquiree_revenue_range
17
+ acquiree_short_description
18
+ acquirer_categories
19
+ acquirer_funding_total
20
+ acquirer_identifier
21
+ acquirer_locations
22
+ acquirer_num_funding_rounds
23
+ acquirer_short_description
24
+ created_at
25
+ disposition_of_acquired
26
+ entity_def_id
27
+ num_relationships
28
+ rank
29
+ rank_acquisition
30
+ status
31
+ terms
32
+ updated_at
33
+ ] + basis_fields
34
+ end
35
+
36
+ def basis_fields
37
+ %w[
38
+ uuid
39
+ permalink
40
+ identifier
41
+ announced_on
42
+ completed_on
43
+ acquisition_type
44
+ price
45
+ short_description
46
+ acquiree_funding_total
47
+ acquiree_identifier
48
+ acquirer_revenue_range
49
+ ]
50
+ end
51
+
52
+ def full_cards
53
+ %w[
54
+ acquiree_organization
55
+ acquirer_organization
56
+ press_references
57
+ ]
58
+ end
59
+ end
60
+ end
61
+ end