# Crunchbase Crunchbase is a ruby wrapper base on Crunchbase V4 API. It provides easy to get the API data by each endpoint. [CB-v4 doc](https://app.swaggerhub.com/apis/Crunchbase/crunchbase-enterprise_api/1.0.1) [![Gem Version](https://badge.fury.io/rb/crunchbase4.svg)](https://badge.fury.io/rb/crunchbase4) [![Build Status](https://travis-ci.org/encoreshao/crunchbase4.svg?branch=master)](https://travis-ci.org/encoreshao/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 ### Configure your API certificate ``` require 'crunchbase4' CB_CONFIG = YAML.load(File.read('crunchbase.yml')) Crunchbase.config do |c| c.user_key = CB_CONFIG['user_key'] end OR Crunchbase.config.user_key = CB_CONFIG['user_key'] ``` ## Usage ### The first step is to build an API client ``` pry(main)> client = Crunchbase::Client.new ``` ### Entity #### Get the organization data ``` 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 ``` pry(main)> response = client.person('mark-zuckerberg') => # pry(main)> response.name => "Mark Zuckerberg" pry(main)> response.permalink => "mark-zuckerberg" ``` #### Get the funding round data ``` => # 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 acquisition data ``` 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 ``` pry(main)> response = client.press_reference('0171b30e-9cf8-4ad5-8288-2993e4308e0f') => # ``` #### Get the investment data ``` pry(main)> response = client.investment('1368da0c-07b0-46ef-9a86-b518367e60d6') => # ``` ### Search * Search query parameters for each endpoint ``` { "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 ``` 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) ``` #### Search organizations by query conditions and order * Step1: Needs to build the query conditions ``` 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 ``` 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 all entities: `response.entities` - Get total count: `response.total_count` - Get entities count: `response.count` #### Search people by query conditions and order * Step1: Needs to build the query conditions ``` 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 ``` 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" 1. Example: Search in an organization by keyword ``` pry(main)> response = client.autocomplete_organizations('ekohe') => #"ekohe", :collection_ids=>"organizations"}, @count=25, @entities= [#, #, #, ...] pry(main)> response.entities pry(main)> response.count pry(main)> response.total_count ``` 2. Example: Search in an people by keyword ``` pry(main)> response = client.autocomplete_people('maxime') => #"maxime", :collection_ids=>"people"}, @count=25, @entities= [#, #, #, ...] pry(main)> response.entities pry(main)> response.count pry(main)> response.total_count ``` 2. Example: Search in an funding rounds by keyword ``` pry(main)> pry(main)> response = client.autocomplete_funding_rounds('facebook') => #"facebook", :collection_ids=>"funding_rounds"}, @count=25, @entities= [#, #, #, ...] pry(main)> response.entities pry(main)> response.count pry(main)> response.total_count ``` ## 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. ### Examples of API requests for each endpoint ``` Crunchbase.config.user_key = 'user_key' client = Crunchbase::Client.new response = client.organization('ekohe') response = client.person('mark-zuckerberg') response = client.funding_round('371c20af8aa94bcba8da0694d138f247') response = client.acquisition('7638eae9-07b7-4fc6-ad20-5d99de3ff928') 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_organizations('ekohe') response = client.autocomplete_people('encore') response = client.autocomplete_funding_rounds('facebook') ``` ## 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).