Class: Cent::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/cent/http.rb

Overview

Cent::HTTP

Holds request call and response handling logic

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection:) ⇒ HTTP

Returns a new instance of HTTP.

Parameters:

  • connection (Faraday::Connection)

    HTTP Connection object



28
29
30
# File 'lib/cent/http.rb', line 28

def initialize(connection:)
  @connection = connection
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



24
25
26
# File 'lib/cent/http.rb', line 24

def connection
  @connection
end

Instance Method Details

#post(body: nil) ⇒ Hash

Perform POST request to centrifugo API

Parameters:

  • body (Hash) (defaults to: nil)

    Request body(non serialized)

Returns:

  • (Hash)

    Parsed response body

Raises:



39
40
41
42
43
44
45
# File 'lib/cent/http.rb', line 39

def post(body: nil)
  response = connection.post(nil, body)

  raise ResponseError.new(**response.body['error'].transform_keys(&:to_sym)) if response.body.key?('error')

  response.body
end