Class: Cnvrg::API_V2
Defined Under Namespace
Classes: CnvrgAPIError
Constant Summary collapse
- ENDPOINT_VERSION =
'v2'
Constants inherited from API
Class Method Summary collapse
Methods inherited from API
display_error, get_api, parse_version
Class Method Details
.endpoint_uri ⇒ Object
7 8 9 10 |
# File 'lib/cnvrg/api_v2.rb', line 7 def self.endpoint_uri api = get_api() return "#{api}/#{Cnvrg::API_V2::ENDPOINT_VERSION}" end |
.request(resource, method = 'GET', data = {}, parse_request = true) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cnvrg/api_v2.rb', line 12 def self.request(resource, method = 'GET', data = {}, parse_request = true) resource = URI::encode resource n = Netrc.read if n['cnvrg.io'].nil? puts 'You\'re not logged in' puts 'Please log in via `cnvrg login`' return end _, pass = n[Cnvrg::Helpers.netrc_domain] conn = Faraday.new endpoint_uri, :ssl => {:verify => !!Helpers.is_verify_ssl} conn.headers['Auth-Token'] = pass conn.headers['Authorization'] = "CAPI #{pass}" conn.headers['User-Agent'] = Cnvrg::API::USER_AGENT conn.headers['Content-Type'] = "application/json" conn..timeout = 420 conn..open_timeout = 180 20.times do begin response = send_request conn, resource, method, data Cnvrg::API.parse_version response is_response_success response if parse_request return JSON.parse(response.body) else return response.body end rescue CnvrgAPIError => e raise e rescue => e Cnvrg::Logger.log_error e sleep 0.5 retry end end rescue CnvrgAPIError => e Cnvrg::Logger.log_error e raise e rescue SignalException return false rescue => e Cnvrg::Logger.log_error e return nil end |