module Crunchbase::Utilities::Request
Key Reminder
entity_id must be provided in the request entity_id can be the uuid or the permalink of the entity you can pass your API key in the request's header if you do not want to pass the API key in the URL
Public Instance Methods
deleted(uri, *args)
click to toggle source
# File lib/crunchbase/utilities/request.rb, line 25 def deleted(uri, *args) fetch_request(uri, *args) end
entity(uri, *args)
click to toggle source
Entity endpoints
https://app.swaggerhub.com/apis-docs/Crunchbase/crunchbase-enterprise_api/1.0.1#/Entity/get_entities_organizations__entity_id_
# File lib/crunchbase/utilities/request.rb, line 32 def entity(uri, *args) fetch_request(uri, *args) end
get(uri, *args)
click to toggle source
Autocompletes
endpoint
# File lib/crunchbase/utilities/request.rb, line 21 def get(uri, *args) fetch_request(uri, *args) end
search(uri, args)
click to toggle source
Search endpoints
https://app.swaggerhub.com/apis-docs/Crunchbase/crunchbase-enterprise_api/1.0.1#/Search/post_searches_organizations
# File lib/crunchbase/utilities/request.rb, line 39 def search(uri, args) response = Faraday.new(url: BASE_URI, headers: post_headers) do |faraday| faraday.adapter Faraday.default_adapter faraday.response :json faraday.request :curl, ::Logger.new(STDOUT), :warn if debug_mode? faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode? end.post(uri, args) return response.body if response.status == 200 raise Error, response.body[0]['message'] end
Private Instance Methods
debug_mode?()
click to toggle source
# File lib/crunchbase/utilities/request.rb, line 66 def debug_mode? Crunchbase.config.debug || false end
fetch_request(uri, *args)
click to toggle source
# File lib/crunchbase/utilities/request.rb, line 54 def fetch_request(uri, *args) response = Faraday.new(url: BASE_URI, headers: headers) do |faraday| faraday.adapter Faraday.default_adapter faraday.response :json faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode? end.get(uri, *args) return response.body if response.status == 200 raise Error, response.status == 400 ? response.body[0]['message'] : response.body['error'] end
headers()
click to toggle source
# File lib/crunchbase/utilities/request.rb, line 76 def headers { 'X-cb-user-key' => Crunchbase.config.user_key } end
post_headers()
click to toggle source
# File lib/crunchbase/utilities/request.rb, line 70 def post_headers headers.merge( 'Content-Type' => 'application/json' ) end