An open API service indexing awesome lists of open source software.

https://github.com/ekohe/crunchbase4

A Ruby Library for CrunchBase API v4
https://github.com/ekohe/crunchbase4

api-service crunchbase crunchbase-api ekohe json-data ruby rubyonrails

Last synced: 8 months ago
JSON representation

A Ruby Library for CrunchBase API v4

Awesome Lists containing this project

README

          

# Crunchbase4

Crunchbase4 is a ruby wrapper based on Crunchbase V4 API, it provides easy to get the API data by each endpoint. [Crunchbase Enterprise API, 2021-07-16](https://app.swaggerhub.com/apis/Crunchbase/crunchbase-enterprise_api/1.0.3)

[![Gem Version](https://badge.fury.io/rb/crunchbase4.svg)](https://badge.fury.io/rb/crunchbase4)
[![Build Status](https://travis-ci.org/ekohe/crunchbase4.svg?branch=master)](https://travis-ci.org/ekohe/crunchbase4)

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'crunchbase4', github: 'ekohe/crunchbase4'
```

And then execute:

$ bundle install

Or install it yourself as:

$ gem install crunchbase4

## Getting Started

#### Crunchbase API Infos

- Title: Crunchbase Enterprise API
- Last Updated Date: 2021-07-16
- Servers URL: https://api.crunchbase.com/api/v4
- API Reference doc: https://data.crunchbase.com/docs
- Tags
- Autocomplete
- Deleted Entities
- Entity
- Search

#### Configure your certificate for API

```ruby
require 'crunchbase'

config = YAML.load(File.read('spec/crunchbase.yml'))
Crunchbase.config.user_key = config['user_key']
Crunchbase.config.debug = config['debug'] || false # If you want to know the request information, can set the debug = true
```

#### If you want to use it in Rails Application, simple way to create a file `crunchbase.rb` in `config/initializers`

- and put the above info(https://github.com/ekohe/crunchbase4#configure-your-certificate-for-api) into the new file

## Usage

#### Class: `Client` for API

```
pry(main)> client = Crunchbase::Client.new
```

#### API request for endpoint we completed

- [Entity](https://github.com/ekohe/crunchbase4#entity)
- Organization
- fields
- cards: [raised_investments, participated_funds, child_organizations, participated_investments, investors, parent_organization, raised_funding_rounds, ipos, event_appearances, raised_funds, acquiree_acquisitions, acquirer_acquisitions, parent_ownership, jobs, founders, child_ownerships, participated_funding_rounds, press_references, headquarters_address]
- Person
- fields
- FundingRound
- fields
- [Searches](https://github.com/ekohe/crunchbase4#search)
- [Autocompletes](https://github.com/ekohe/crunchbase4#autocompletes)
- [Deleted Entities](https://github.com/ekohe/crunchbase4#deleted-entities)

```ruby

response = client.organization('ekohe')
ipos = client.organization('ekohe', card_id: 'ipos')
fund = client.organization('ekohe', card_id: 'fund')
ownership = client.organization('ekohe', card_id: 'ownership')
founders = client.organization('ekohe', card_id: 'founders')
investors = client.organization('ekohe', card_id: 'investors')
jobs = client.organization('ekohe', card_id: 'jobs')
headquarters_address = client.organization('ekohe', card_id: 'headquarters_address')
top_2_press_references = client.organization('ekohe', card_id: 'press_references', limit: 2)

response = client.organization(
'facebook', card_id: 'participated_funding_rounds',
limit: 5,
order: 'announced_on:desc',
after_id: '3cdfcecd-5377-439b-acab-cefcf6fe21a5'
)

response = client.person('mark-zuckerberg')
response = client.person('mark-zuckerberg', card_id: 'participated_investments')
response = client.funding_round('3cdfcecd-5377-439b-acab-cefcf6fe21a5')
response = client.funding_round('3cdfcecd-5377-439b-acab-cefcf6fe21a5', card_id: 'investors')
response = client.acquisition('7638eae9-07b7-4fc6-ad20-5d99de3ff928')
response = client.fund('aeaac12b-df56-7039-40f9-f1992f88e20e')
response = client.ownership('4506d9ce-85d3-4a8f-89cd-07a225359d55')

response.as_json

client.search_organizations(query_data)
client.search_people(query_data)
client.search_funding_rounds(query_data)
client.recent_updates({
scope_name: 'organization',
field_ids: %w[name website permalink],
date: '2020-05-05',
limit: 100
})

response = client.autocomplete('ekohe')
response = client.autocomplete('ekohe', collection_ids: 'organizations')
response = client.autocomplete('ekohe', collection_ids: 'organizations', limit: 3)
response = client.autocomplete('encore', collection_ids: 'people')
response = client.autocomplete('facebook', collection_ids: 'funding_rounds')
response = client.autocomplete('facebook', collection_ids: 'press_references')

response = client.deledeted_entities(collection_ids: 'organizations')
response = client.deledeted_entities(collection_ids: 'people')
response = client.deledeted_entities(collection_ids: 'funding_rounds')
```

#### Module: Utils

* We return all the original data from CrunchBase without any conversion. So you want to use the converted data, you can use this tool to convert.

```ruby
pry(main)> Crunchbase::Utils.constants
=> [:QUERY_OPERATORS,
:COMPANY_TYPES,
:FACET_IDS,
:IPO_STATUS,
:FUNDING_STAGES,
:FUNDING_TYPES,
:CURRENCY_ENUM,
:DATE_PRECISIONS,
:LAYOUT_IDS,
:NUM_EMPLOYEES_ENUM,
:OPERATING_STATUS,
:PROGRAM_TYPES,
:REVENUE_RANGES,
:SCHOOL_METHODS,
:SCHOOL_TYPES,
:STATUS,
:STOCK_EXCHANGE_SYMBOLS]
pry(main)> Crunchbase::Utils::COMPANY_TYPES
=> {"for_profit"=>"For Profit", "non_profit"=>"Non-profit"}
```

### Entity

#### Get the organization data

```ruby
pry(main)> response = client.organization('ekohe')
=> #
pry(main)> response.name
=> "Ekohe"
pry(main)> response.permalink
=> "ekohe"
```

Or, if you want to use json data, please call `response.as_json` in your project.

##### Get the person data

```ruby
pry(main)> response = client.person('mark-zuckerberg')
=> #
pry(main)> response.name
=> "Mark Zuckerberg"
pry(main)> response.permalink
=> "mark-zuckerberg"
```

##### Get the funding round data

```ruby
pry(main)> response = client.funding_round('371c20af-8aa9-4bcb-a8da-0694d138f247')
=> #
pry(main)> response.name
=> "Secondary Market - Facebook"
pry(main)> response.uuid
=> "371c20af-8aa9-4bcb-a8da-0694d138f247"
```
##### Get the fund data

```ruby
pry(main)> response = client.fund('aeaac12b-df56-7039-40f9-f1992f88e20e')
=> #
pry(main)> response.name
=> "The News Integrity Initiative Fund I"
pry(main)> response.uuid
=> "aeaac12b-df56-7039-40f9-f1992f88e20e"
```

##### Get the acquisition data

```ruby
pry(main)> response = client.acquisition('7638eae9-07b7-4fc6-ad20-5d99de3ff928')
=> #
pry(main)> response.uuid
=> "7638eae9-07b7-4fc6-ad20-5d99de3ff928"
pry(main)> response.acquiree_funding_total
=> 150949998
```

##### Get the press reference data

```ruby
pry(main)> response = client.press_reference('0171b30e-9cf8-4ad5-8288-2993e4308e0f')
=> #,
#,
#,
#,
#],
@author=nil,
@created_at="2020-06-05T17:41:10Z",
@entity_def_id="press_reference",
@identifier=["0171b30e-9cf8-4ad5-8288-2993e4308e0f", "Jio Platforms to receive $1.2b from Abu Dhabi’s sovereign investment firm"],
@posted_on="2020-06-05",
@publisher="Tech in Asia",
@thumbnail_url="https://cdn.techinasia.com/wp-content/uploads/2016/07/Flickr_-_World_Economic_Forum_-_Ambani.jpg",
@title="Jio Platforms to receive $1.2b from Abu Dhabi’s sovereign investment firm",
@updated_at="2020-06-05T17:41:10Z",
@url="https://ift.tt/3cByFh1",
@uuid="0171b30e-9cf8-4ad5-8288-2993e4308e0f">
```

##### Get the investment data

```ruby
pry(main)> response = client.investment('1368da0c-07b0-46ef-9a86-b518367e60d6')
=> #
```

##### Get the ownership data

```ruby
pry(main)> response = client.ownership('4506d9ce-85d3-4a8f-89cd-07a225359d55')
=> #
pry(main)> response.name
=> "Facebook owns Instagram"
pry(main)> response.uuid
=> "4506d9ce-85d3-4a8f-89cd-07a225359d55"
```

### Search

* Search query parameters for each endpoint

```ruby
{
"field_ids": [],
"query": [],
"order": [],
"limit": 0
}
```

##### Get the latest updated entities

Allow user using the method `recent_updates(args)` to get recent updates for each endpoint on searches

* Example to get recent updated organizations

```ruby
args = {
scope_name: 'organization', # must
date: '2020-05-05', # must
field_ids: %w[name website permalink], # default %[uuid created_at updated_at]
sort: 'desc' # default `desc`
before_id: 'uuid' # optional
after_id: 'uuid' # optional
}

response = client.recent_updates(args)

args = {
scope_name: 'press_reference', # must
from_date: '2020-05-05', # optional
to_date: '2020-05-05', # optional
field_ids: %w[title posted_on publisher], # default %[uuid created_at updated_at]
sort: 'desc' # default `desc`
before_id: 'uuid' # optional
after_id: 'uuid' # optional
}

response = client.recent_updates(args)
```

##### Search organizations by query conditions and order

* building the query conditions

```ruby
query_data = {
'field_ids' => %w[
name
website
uuid
short_description
company_type
],
'order' => [
{
'field_id' => 'company_type',
'sort' => 'asc'
}
],
'query' => [
{
'type' => 'predicate',
'field_id' => 'funding_total',
'operator_id' => 'between',
'values' => [
{
'value' => 1_000_000,
'currency' => 'usd'
},
{
'value' => 10_000_000,
'currency' => 'usd'
}
]
},
{
'type' => 'predicate',
'field_id' => 'facet_ids',
'operator_id' => 'includes',
'values' => %w[company investor]
}
],
'limit' => 4
}
```

* Use `client` to send a request and parse response

```ruby
pry(main)> response = client.search_organizations(query_data)
=> #["name", "website", "uuid", "short_description", "company_type"],
"order"=>[{"field_id"=>"company_type", "sort"=>"asc"}],
"query"=>
[{"type"=>"predicate", "field_id"=>"funding_total", "operator_id"=>"between", "values"=>[{"value"=>1000000, "currency"=>"usd"}, {"value"=>10000000, "currency"=>"usd"}]},
{"type"=>"predicate", "field_id"=>"facet_ids", "operator_id"=>"includes", "values"=>["company", "investor"]}],
"limit"=>4},
@count=4,
@entities=
[#,
#,
#,
#],
@entity_type="organization",
@kclass_name=Crunchbase::Models::Organization,
@total_count=44871>
```

- Get entities: response.entities
- Get total count: response.total_count
- Get entities count: response.count

##### Search people by query conditions and order

* building the query conditions

```ruby
query_data = {
'field_ids' => %w[
first_name
last_name
uuid
permalink
name
],
'order' => [
{
'field_id' => 'last_name',
'sort' => 'asc',
'nulls' => 'last'
}
],
'query' => [
{
'type' => 'predicate',
'field_id' => 'first_name',
'operator_id' => 'contains',
'values' => [
'Maxime'
]
},
{
'type' => 'predicate',
'field_id' => 'last_name',
'operator_id' => 'contains',
'values' => [
'Guilbot'
]
}
],
'limit' => 5
}
```

* Use `client` to send a request and parse response

```ruby
pry(main)> response = client.search_people(query_data)
=> #["first_name", "last_name", "uuid", "permalink", "name"],
"order"=>[{"field_id"=>"last_name", "sort"=>"asc", "nulls"=>"last"}],
"query"=>
[{"type"=>"predicate", "field_id"=>"first_name", "operator_id"=>"contains", "values"=>["Maxime"]}, {"type"=>"predicate", "field_id"=>"last_name", "operator_id"=>"contains", "values"=>["Guilbot"]}],
"limit"=>5},
@count=1,
@entities=[#],
@entity_type="person",
@kclass_name=Crunchbase::Models::Person,
@total_count=1>
pry(main)> response.entities
=> [#]
pry(main)> response.total_count
=> 1
```

### Autocompletes

##### Allow users to filter by keyword from these endpoints

Search by keyword has been supported in "Organization", "People" and "Fund Round"

* Search in an organization by keyword

```ruby
pry(main)> response = client.autocomplete('ekohe', collection_ids: 'organizations')
=> #"ekohe", :collection_ids=>"organizations"},
@count=25,
@entities=
[#,
#,
#,
...]
pry(main)> response.entities
pry(main)> response.count
pry(main)> response.total_count
```

* Search in an people by keyword

```ruby
pry(main)> response = client.autocomplete('maxime', collection_ids: 'people')
=> #"maxime", :collection_ids=>"people"},
@count=25,
@entities=
[#,
#,
#,
...]
pry(main)> response.entities
pry(main)> response.count
pry(main)> response.total_count
```

* Search in an funding rounds by keyword

```ruby
pry(main)> response = client.autocomplete('facebook', collection_ids: 'funding_rounds')
=> #"facebook", :collection_ids=>"funding_rounds"},
@count=25,
@entities=
[#,
#,
#,
...]
pry(main)> response.entities
pry(main)> response.count
pry(main)> response.total_count
```

### Deleted Entities

* Get deleted entities by collection_ids

```ruby
pry(main)> response = client.deleted_entities
=> #"organizations"},
@count=1000,
@entities=
[#,
#,
#,
#,
#,
#,
#,
#,
#,
#,
#,
#,
#,
....]
pry(main)> response.entities
pry(main)> response.count
pry(main)> response.total_count

# Get deleted people and funding rounds
pry(main)> response = client.deleted_entities(collection_ids: 'people')
pry(main)> response = client.deleted_entities(collection_ids: 'funding_rounds')
```

### Daily CSV Export

* https://api.crunchbase.com/bulk/v4/bulk_export.tar.gz?user_key=user_key

```ruby
pry(main)> response = client.download_bulk(dir, extract: true)
```

After running the download operation, you will see `bulk_export.tar.gz` in your provided folder.

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

## Changelog

If you want to know what update, please check the [Changelog](https://github.com/ekohe/crunchbase4/blob/master/CHANGELOG.md).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ekohe/crunchbase4. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected.

To see all contributors from https://github.com/ekohe/crunchbase4/graphs/contributors

## License

Crunchbase is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

## Code of Conduct

Everyone interacting in the Crunchbase project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ekohe/crunchbase4/blob/master/CODE_OF_CONDUCT.md).