crunchbase4 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3b4fc39257c331e78bdf3f05dd4e08c96c67b34c8e0627c2c7bc5a583f5a7f6
4
- data.tar.gz: 22f753ee2a2b785247c8311fd126ef826853028c542bbae010e55a391aa59e6e
3
+ metadata.gz: d55577caf7591f6f9da599815b133401620f51137d303e9f1d56ca1a37554a30
4
+ data.tar.gz: e0b0a754d0060dd9d3f566ce3cea3f6120c3bec2c3fd9dd490d6d6c1dfdaa04c
5
5
  SHA512:
6
- metadata.gz: 13c65190a96019e452efe17a6f0173c4cc3f1cbf28ca067fc56da2c394377f5b3f48176d3c34383e242bfa25ead36a9a70156ba0c243e23381ab7c39ba9bbcfd
7
- data.tar.gz: c13e836e817f2509dac847db8c8f733eb680d0eb69e81961cab23288d9bf3190479481bd5fe9b67a1402d0f164195ba3097601a9c3a7bade0bfb78561380e2e3
6
+ metadata.gz: 740e35d9fabbf05e930aa6a3a663143b0dee43d77ccb29b2845d79836ee2891a5b9eb4a360ba03dd2087afaea6525cafefe8beb0ed299d17d375be0eddab285f
7
+ data.tar.gz: ca15245080f46ca75779e1b694842a206a1ece5107b31b9a937a5e3ae049ff0247cf74b5e390c13290b9360ab1a4678832a7f36cb3dbe07ed1cb31d67098c7c2
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
 
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+ .ruby-version
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Change Log
2
2
 
3
+ ## [0.1.9] - 2021-10-04
4
+
5
+ ### Allow to export Daily CSV bulk
6
+ - Implement new API to export daily CSV bulk. related document https://data.crunchbase.com/docs/daily-csv-export
7
+ - download_bulk: (`client.download_bulk(dir, extract: true)`)
8
+
9
+ ## [0.1.8] - 2021-02-23
10
+
11
+ ### Add new fields on funding_rounds
12
+ - Adding diversity_spotlights and pre_money_valuation on raised_funding_rounds endpoint
13
+
3
14
  ## [0.1.7] - 2020-12-02
4
15
 
5
16
  ### Improve press_reference API response for activity_entities
data/Gemfile.lock CHANGED
@@ -1,29 +1,54 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- crunchbase4 (0.1.7)
4
+ crunchbase4 (0.2.0)
5
5
  faraday
6
6
  faraday_curl
7
7
  faraday_middleware
8
+ httparty
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
11
12
  specs:
12
- addressable (2.7.0)
13
+ addressable (2.8.0)
13
14
  public_suffix (>= 2.0.2, < 5.0)
14
15
  ast (2.4.0)
15
16
  coderay (1.1.3)
16
17
  crack (0.4.3)
17
18
  safe_yaml (~> 1.0.0)
18
19
  diff-lcs (1.3)
19
- faraday (1.0.1)
20
+ faraday (1.8.0)
21
+ faraday-em_http (~> 1.0)
22
+ faraday-em_synchrony (~> 1.0)
23
+ faraday-excon (~> 1.1)
24
+ faraday-httpclient (~> 1.0.1)
25
+ faraday-net_http (~> 1.0)
26
+ faraday-net_http_persistent (~> 1.1)
27
+ faraday-patron (~> 1.0)
28
+ faraday-rack (~> 1.0)
20
29
  multipart-post (>= 1.2, < 3)
30
+ ruby2_keywords (>= 0.0.4)
31
+ faraday-em_http (1.0.0)
32
+ faraday-em_synchrony (1.0.0)
33
+ faraday-excon (1.1.0)
34
+ faraday-httpclient (1.0.1)
35
+ faraday-net_http (1.0.1)
36
+ faraday-net_http_persistent (1.2.0)
37
+ faraday-patron (1.0.0)
38
+ faraday-rack (1.0.0)
21
39
  faraday_curl (0.0.2)
22
40
  faraday (>= 0.9.0)
23
- faraday_middleware (1.0.0)
41
+ faraday_middleware (1.2.0)
24
42
  faraday (~> 1.0)
25
43
  hashdiff (1.0.1)
44
+ httparty (0.20.0)
45
+ mime-types (~> 3.0)
46
+ multi_xml (>= 0.5.2)
26
47
  method_source (1.0.0)
48
+ mime-types (3.3.1)
49
+ mime-types-data (~> 3.2015)
50
+ mime-types-data (3.2021.0901)
51
+ multi_xml (0.6.0)
27
52
  multipart-post (2.1.1)
28
53
  parallel (1.19.1)
29
54
  parser (2.7.1.3)
@@ -31,11 +56,11 @@ GEM
31
56
  pry (0.13.1)
32
57
  coderay (~> 1.1)
33
58
  method_source (~> 1.0)
34
- public_suffix (4.0.5)
59
+ public_suffix (4.0.6)
35
60
  rainbow (3.0.0)
36
61
  rake (12.3.3)
37
62
  regexp_parser (1.7.0)
38
- rexml (3.2.4)
63
+ rexml (3.2.5)
39
64
  rspec (3.9.0)
40
65
  rspec-core (~> 3.9.0)
41
66
  rspec-expectations (~> 3.9.0)
@@ -61,6 +86,7 @@ GEM
61
86
  rubocop-ast (0.0.3)
62
87
  parser (>= 2.7.0.1)
63
88
  ruby-progressbar (1.10.1)
89
+ ruby2_keywords (0.0.5)
64
90
  safe_yaml (1.0.5)
65
91
  unicode-display_width (1.7.0)
66
92
  vcr (6.0.0)
@@ -82,4 +108,4 @@ DEPENDENCIES
82
108
  webmock
83
109
 
84
110
  BUNDLED WITH
85
- 2.1.4
111
+ 2.2.5
data/README.md CHANGED
@@ -26,13 +26,18 @@ Or install it yourself as:
26
26
  #### Configure your certificate for API
27
27
 
28
28
  ```ruby
29
- require 'crunchbase4'
29
+ require 'crunchbase'
30
30
 
31
- CB_CONFIG = YAML.load(File.read('crunchbase.yml'))
32
- Crunchbase.config.user_key = CB_CONFIG['user_key']
33
- Crunchbase.config.user_key = false # If you want to know the request information, can set the debug = true
31
+ config = YAML.load(File.read('spec/crunchbase.yml'))
32
+ Crunchbase.config.user_key = config['user_key']
33
+ Crunchbase.config.debug = config['debug'] || false # If you want to know the request information, can set the debug = true
34
34
  ```
35
35
 
36
+ #### If you want to use it in Rails Application, simple way to create a file `crunchbase.rb` in `config/initializers`
37
+
38
+ - and put the above info(https://github.com/ekohe/crunchbase4#configure-your-certificate-for-api) into the new file
39
+
40
+
36
41
  ## Usage
37
42
 
38
43
  #### Class: `Client` for API
@@ -711,6 +716,17 @@ pry(main)> response = client.deleted_entities(collection_ids: 'people')
711
716
  pry(main)> response = client.deleted_entities(collection_ids: 'funding_rounds')
712
717
  ```
713
718
 
719
+ ### Daily CSV Export
720
+
721
+ * https://api.crunchbase.com/bulk/v4/bulk_export.tar.gz?user_key=user_key
722
+
723
+
724
+ ```ruby
725
+ pry(main)> response = client.download_bulk(dir, extract: true)
726
+ ```
727
+
728
+ After running the download operation, you will see `bulk_export.tar.gz` in your provided folder.
729
+
714
730
  ## Development
715
731
 
716
732
  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.
data/crunchbase4.gemspec CHANGED
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.add_dependency 'faraday'
35
35
  spec.add_dependency 'faraday_curl'
36
36
  spec.add_dependency 'faraday_middleware'
37
+ spec.add_dependency 'httparty'
37
38
 
38
39
  # VCR for testing APIs
39
40
  spec.add_development_dependency 'vcr'
@@ -4,6 +4,7 @@ require_relative 'utilities/entity_endpoints'
4
4
  require_relative 'utilities/search_endpoints'
5
5
  require_relative 'utilities/autocomplete'
6
6
  require_relative 'utilities/deleted_entities'
7
+ require_relative 'utilities/downloads'
7
8
 
8
9
  module Crunchbase
9
10
  # API Request
@@ -12,5 +13,6 @@ module Crunchbase
12
13
  include Utilities::SearchEndpoints
13
14
  include Utilities::Autocomplete
14
15
  include Utilities::DeletedEntities
16
+ include Utilities::Downloads
15
17
  end
16
18
  end
@@ -7,7 +7,7 @@ module Crunchbase
7
7
  # Config
8
8
  class Config
9
9
  include Singleton
10
- attr_accessor :user_key, :debug
10
+ attr_accessor :user_key, :bulk_url, :debug
11
11
  end
12
12
 
13
13
  def self.config
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+
5
+ module Crunchbase
6
+ # Zip file downloads endpoints
7
+ module Downloads
8
+ # using Crunchbase's downloads API endpoints
9
+ class Client
10
+ include HTTParty
11
+ # Will spit out all request details to the console
12
+ debug_output $stdout
13
+
14
+ def download_bulk(dir, extract: false)
15
+ FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
16
+ dist_path = Pathname.new(dir).join File.basename(bulk_url)
17
+
18
+ download(bulk_url, dist_path) unless File.exist?(dist_path)
19
+ system "tar xfz #{dist_path} -C #{dir}" if extract
20
+
21
+ dist_path
22
+ end
23
+
24
+ private
25
+
26
+ def bulk_url
27
+ Crunchbase.config.bulk_url || [API_DOMAIN, "/bulk/#{API_VERSION}/bulk_export.tar.gz"].join
28
+ end
29
+
30
+ def download(url, dist_path)
31
+ File.open(dist_path, 'w') do |file|
32
+ file.binmode
33
+ request(url, stream_body: true) do |buffer|
34
+ file.write(buffer)
35
+ end
36
+ end
37
+ end
38
+
39
+ def request(url, options = {}, &block)
40
+ default_options = { query: { user_key: Crunchbase.config.user_key } }
41
+ options.merge!(default_options)
42
+
43
+ response = self.class.get(url, options, &block)
44
+ response.content_type.match?(/json/) ? JSON.parse(response.body) : response
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crunchbase
4
+ # Downloads
5
+ module Downloads
6
+ autoload :Client, 'crunchbase/downloads/client'
7
+ end
8
+ end
@@ -30,7 +30,7 @@ module Crunchbase
30
30
  card_objects = if card_data.is_a?(Array)
31
31
  card_data.each_with_object([]) do |data, objects|
32
32
  new_card_instance = card_model.new
33
- objects << dynamic_attributes(new_card_instance, new_card_instance.basis_fields, data)
33
+ objects << dynamic_attributes(new_card_instance, new_card_instance.field_ids, data)
34
34
  end
35
35
  else
36
36
  card_data.nil? ? nil : dynamic_attributes(card_model.new, extract_fields, data)
@@ -18,6 +18,7 @@ module Crunchbase
18
18
  funded_organization_identifier
19
19
  funded_organization_location
20
20
  funded_organization_revenue_range
21
+ funded_organization_diversity_spotlights
21
22
  identifier
22
23
  image_id
23
24
  investor_identifiers
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../downloads/client'
4
+
5
+ module Crunchbase
6
+ # Utilities
7
+ module Utilities
8
+ # Daily csv export
9
+ module Downloads
10
+ def download_bulk(dir, extract: false)
11
+ Crunchbase::Downloads::Client.new.download_bulk(dir, extract: extract)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -44,9 +44,11 @@ module Crunchbase
44
44
  faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
45
45
  end.post(uri, args)
46
46
 
47
- return response.body if response.status == 200
47
+ resp_body = response.body
48
+ resp_status = response.status
49
+ return resp_body if resp_status == 200
48
50
 
49
- raise Error, response.body[0]['message']
51
+ raise Error, resp_body.is_a?(Array) ? resp_body[0]['message'] : resp_body['error']
50
52
  end
51
53
 
52
54
  private
@@ -58,9 +60,11 @@ module Crunchbase
58
60
  faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode?
59
61
  end.get(uri, *args)
60
62
 
61
- return response.body if response.status == 200
63
+ resp_body = response.body
64
+ resp_status = response.status
65
+ return resp_body if resp_status == 200
62
66
 
63
- raise Error, response.status == 400 ? response.body[0]['message'] : response.body['error']
67
+ raise Error, resp_body.is_a?(Array) ? resp_body[0]['message'] : resp_body['error']
64
68
  end
65
69
 
66
70
  def debug_mode?
@@ -52,15 +52,18 @@ module Crunchbase
52
52
  %w[identifier]
53
53
  end
54
54
 
55
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
55
56
  def field_value(name, data)
56
57
  value = data.dig(name)
57
58
 
58
59
  return value if value.nil? || value.is_a?(String)
59
60
  return parse_items(value, name) if value.is_a?(Array) && value[0].is_a?(Hash) && value[0].keys.include?('value')
61
+ return value.dig('value_usd') if value.is_a?(Hash) && value.keys.include?('value_usd')
60
62
  return value.dig('value') if value.is_a?(Hash) && value.keys.include?('value')
61
63
 
62
64
  value
63
65
  end
66
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
64
67
 
65
68
  def parse_items(items, field_name)
66
69
  return items.collect { |e| e.dig('value') } unless field_name == 'activity_entities'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Crunchbase
4
- VERSION = '0.1.7'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/crunchbase.rb CHANGED
@@ -7,12 +7,14 @@ require 'crunchbase/client'
7
7
  require 'crunchbase/models'
8
8
  require 'crunchbase/entities'
9
9
  require 'crunchbase/searches'
10
+ require 'crunchbase/downloads'
10
11
  require 'crunchbase/utilities/veriables'
11
12
 
12
13
  # CB v4
13
14
  module Crunchbase
14
15
  API_VERSION = 'v4'
15
- BASE_URI = "https://api.crunchbase.com/api/#{API_VERSION}/"
16
+ API_DOMAIN = 'https://api.crunchbase.com'
17
+ BASE_URI = "#{API_DOMAIN}/api/#{API_VERSION}/"
16
18
 
17
19
  # Defined Veriables for the data Category or Types
18
20
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crunchbase4
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Encore Shao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-02 00:00:00.000000000 Z
11
+ date: 2022-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: vcr
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +150,8 @@ files:
136
150
  - lib/crunchbase/client.rb
137
151
  - lib/crunchbase/config.rb
138
152
  - lib/crunchbase/deleted_entities/client.rb
153
+ - lib/crunchbase/downloads.rb
154
+ - lib/crunchbase/downloads/client.rb
139
155
  - lib/crunchbase/entities.rb
140
156
  - lib/crunchbase/entities/client.rb
141
157
  - lib/crunchbase/errors.rb
@@ -165,6 +181,7 @@ files:
165
181
  - lib/crunchbase/utilities/autocomplete.rb
166
182
  - lib/crunchbase/utilities/cb_model.rb
167
183
  - lib/crunchbase/utilities/deleted_entities.rb
184
+ - lib/crunchbase/utilities/downloads.rb
168
185
  - lib/crunchbase/utilities/entity_endpoints.rb
169
186
  - lib/crunchbase/utilities/request.rb
170
187
  - lib/crunchbase/utilities/response.rb