Class: Rubycent::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycent/query.rb

Overview

Rubycent::Query

Centrifugo API request configuration and execution

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Query

Returns a new instance of Query.

Parameters:

  • client (Rubycent::Client)

    Rubycent client that contains all the configuration



18
19
20
# File 'lib/rubycent/query.rb', line 18

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



13
14
15
# File 'lib/rubycent/query.rb', line 13

def client
  @client
end

Instance Method Details

#execute(method, data) ⇒ Hash

Perform centrifugo API call

Parameters:

  • method (String)

    Centrifugo command, represents centrifugo actions such as ‘publish’, ‘broadcast’, e.t.c.

  • data (Hash)

    Any data that will be sent as command parameters

Returns:

  • (Hash)

    Parser request responce

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rubycent/query.rb', line 34

def execute(method, data)
  body = dump_body(method, data)

  params = {
    timeout: client.timeout,
    open_timeout: client.open_timeout
  }

  headers = build_headers(client.api_key)
  endpoint = build_endpoint(client.host, client.port, client.scheme.to_s)

  Rubycent::Request.new(endpoint, params, body, headers).post
end