lib/crunchbase/utilities/request.rb in crunchbase4-0.1.1 vs lib/crunchbase/utilities/request.rb in crunchbase4-0.1.2
- old
+ new
@@ -11,23 +11,20 @@
module Utilities
# API Request
module Request
module_function
+ # Autocompletes endpoint
+ def get(uri, *args)
+ fetch_request(uri, *args)
+ end
+
# Entity endpoints
#
# https://app.swaggerhub.com/apis-docs/Crunchbase/crunchbase-enterprise_api/1.0.1#/Entity/get_entities_organizations__entity_id_
def entity(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.reason_phrase
+ fetch_request(uri, *args)
end
# Search endpoints
#
# https://app.swaggerhub.com/apis-docs/Crunchbase/crunchbase-enterprise_api/1.0.1#/Search/post_searches_organizations
@@ -39,13 +36,25 @@
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.reason_phrase
+ raise Error, response.body[0]['message']
end
private
+
+ 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.body['error']
+ end
def debug_mode?
Crunchbase.config.debug || false
end