Method: MuxRuby::ApiClient#call_api
- Defined in:
- lib/mux_ruby/api_client.rb
#call_api(http_method, path, opts = {}) ⇒ Array<(Object, Integer, Hash)>
Call an API with given options.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/mux_ruby/api_client.rb', line 49 def call_api(http_method, path, opts = {}) request = build_request(http_method, path, opts) response = request.run if @config.debugging @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n" end unless response.success? if response.timed_out? fail ApiError.new('Connection timed out') elsif response.code == 0 # Errors from libcurl will be made visible here fail ApiError.new(:code => 0, :message => response.) elsif response.code == 401 fail UnauthorizedError.new(:code => response.code, :response_headers => response.headers, :response_body => response.body, :message => response.) elsif response.code == 403 fail ForbiddenError.new(:code => response.code, :response_headers => response.headers, :response_body => response.body, :message => response.) elsif response.code == 404 fail NotFoundError.new(:code => response.code, :response_headers => response.headers, :response_body => response.body, :message => response.) elsif response.code == 429 fail TooManyRequestsError.new(:code => response.code, :response_headers => response.headers, :response_body => response.body, :message => response.) elsif response.code.between?(400, 499) fail ClientError.new(:code => response.code, :response_headers => response.headers, :response_body => response.body, :message => response.) elsif response.code.between?(500, 599) fail ServiceError.new(:code => response.code, :response_headers => response.headers, :response_body => response.body, :message => response.) else fail ApiError.new(:code => response.code, :response_headers => response.headers, :response_body => response.body, :message => response.) end end if opts[:return_type] data = deserialize(response, opts[:return_type]) else data = nil end return data, response.code, response.headers end |