lib/eventline/client.rb
# Execute an HTTP request on the connection.
#
# @param request [HTTPRequest] the HTTP request to execute
#
# @raise [RequestError] if the server not responds with 2xx status.
# @raise [SocketError]
# @raise [Timeout::Error]
#
# @return [String, Hash]
Execute an HTTP request on the connection.
Execute an HTTP request on the connection .
def call(request)
      request.content_type = "application/json"
      request.content_length = request.body.to_s.bytesize
      request["Accept"] = "application/json"
      request["User-Agent"] = "Eventline/1.0 (platform; ruby) eventline-sdk"
      request["Authorization"] = "Bearer #{@token}"
      request["X-Eventline-Project-Id"] = @project_id
      response = @mut.synchronize do
        @conn.request(request)
      end
      data = if response.content_type == "application/json"
        begin
          JSON.parse(response.body)
        rescue
          raise(
            RequestError.new(
              response.code.to_i,
              "invalid_json",
              response.body,
              "invalid json body"
            )
          )
        end
      else
        response.body
      end
      if response.code.to_i < 200 || response.code.to_i >= 300
        if response.content_type == "application/json"
          raise(
            RequestError.new(
              response.code.to_i,
              data.fetch("code", "unknown_error"),
              data.fetch("data", {}),
              data.fetch("error")
            )
          )
        else
          raise(
            RequestError.new(
              response.code.to_i,
              "invalid_json",
              response.body,
              "invalid json body"
            )
          )
        end
      end
      data
    end
def call ( request ) request . content_type = "application/json" request . content_length = request . body . to_s . bytesize request [ "Accept" ] = "application/json" request [ "User-Agent" ] = "Eventline/1.0 (platform; ruby) eventline-sdk" request [ "Authorization" ] = "Bearer #{@token}" request [ "X-Eventline-Project-Id" ] = @project_id response = @mut . synchronize do @conn . request ( request ) end data = if response . content_type == "application/json" begin JSON . parse ( response . body ) rescue raise ( RequestError . new ( response . code . to_i , "invalid_json" , response . body , "invalid json body" ) ) end else response . body end if response . code . to_i < 200 || response . code . to_i >= 300 if response . content_type == "application/json" raise ( RequestError . new ( response . code . to_i , data . fetch ( "code" , "unknown_error" ) , data . fetch ( "data" , { } ) , data . fetch ( "error" ) ) ) else raise ( RequestError . new ( response . code . to_i , "invalid_json" , response . body , "invalid json body" ) ) end end data end
Execute an HTTP request on the connection.
Execute an HTTP request on the connection .
None
String, Hash
[RequestError] if the server not responds with 2xx status.
[ RequestError ] if the server not responds with 2xx status .
None
None
request
the HTTP request to execute
the HTTP request to execute