lib/cubits/connection.rb
def request(method, path, encoded_data)
      Cubits.logger.warn 'Connecting to Cubits using insecure connection!' if insecure?
      url = URI.join(Cubits.base_url, path)
      params = {}
      http = HTTP.with(cubits_headers(path, encoded_data))
      if method == :get
        url.query = encoded_data unless encoded_data.empty?
      else
        http = http.with('Content-Type' => CONTENT_TYPE)
        params[:body] = encoded_data
      end
      params[:ssl_context] = ssl_context unless insecure?
      Cubits.logger.debug "> #{method.to_s.upcase}: #{url}"
      response = http.send(method, url, params)
      Cubits.logger.debug "< #{response.code} #{response.reason}"
      begin
        body = JSON.parse(response.body)
      rescue JSON::ParserError => e
        raise ConnectionError, "Failed to parse response: #{e}"
      end
      return body if (200...300).include?(response.status)
      respond_with_error(response.code, body['message'])
    end
# Sends a request to the API
#
Sends a request to the API
Sends a request to the API
def request(method, path, encoded_data)
      Cubits.logger.warn 'Connecting to Cubits using insecure connection!' if insecure?
      url = URI.join(Cubits.base_url, path)
      params = {}
      http = HTTP.with(cubits_headers(path, encoded_data))
      if method == :get
        url.query = encoded_data unless encoded_data.empty?
      else
        http = http.with('Content-Type' => CONTENT_TYPE)
        params[:body] = encoded_data
      end
      params[:ssl_context] = ssl_context unless insecure?
      Cubits.logger.debug "> #{method.to_s.upcase}: #{url}"
      response = http.send(method, url, params)
      Cubits.logger.debug "< #{response.code} #{response.reason}"
      begin
        body = JSON.parse(response.body)
      rescue JSON::ParserError => e
        raise ConnectionError, "Failed to parse response: #{e}"
      end
      return body if (200...300).include?(response.status)
      respond_with_error(response.code, body['message'])
    end
def request ( method , path , encoded_data ) Cubits . logger . warn 'Connecting to Cubits using insecure connection!' if insecure? url = URI . join ( Cubits . base_url , path ) params = { } http = HTTP . with ( cubits_headers ( path , encoded_data ) ) if method == :get url . query = encoded_data unless encoded_data . empty? else http = http . with ( 'Content-Type' => CONTENT_TYPE ) params [ :body ] = encoded_data end params [ :ssl_context ] = ssl_context unless insecure? Cubits . logger . debug "> #{method.to_s.upcase}: #{url}" response = http . send ( method , url , params ) Cubits . logger . debug "< #{response.code} #{response.reason}" begin body = JSON . parse ( response . body ) rescue JSON :: ParserError => e raise ConnectionError , "Failed to parse response: #{e}" end return body if ( 200 ... 300 ) . include? ( response . status ) respond_with_error ( response . code , body [ 'message' ] ) end
Sends a request to the API
Sends a request to the API
method
path
encoded_data