class Rubycent::Query
Centrifugo API request configuration and execution
Attributes
client[R]
Public Class Methods
new(client)
click to toggle source
@param client [Rubycent::Client]
Rubycent client that contains all the configuration
# File lib/rubycent/query.rb, line 18 def initialize(client) @client = client end
Public Instance Methods
execute(method, data)
click to toggle source
Perform centrifugo API call
@param method [String]
Centrifugo command, represents centrifugo actions such as 'publish', 'broadcast', e.t.c.
@param data [Hash]
Any data that will be sent as command parameters
@return [Hash] Parser request responce
@raise [Rubycent::Error, Rubycent::NetworkError
, Rubycent::RequestError
, Rubycent::ResponseError]
# 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
Private Instance Methods
build_endpoint(host, port, scheme)
click to toggle source
# File lib/rubycent/query.rb, line 54 def build_endpoint(host, port, scheme) ::URI::Generic.build(scheme: scheme, host: host, port: port, path: '/api').to_s end
build_headers(api_key)
click to toggle source
# File lib/rubycent/query.rb, line 58 def build_headers(api_key) { 'Content-Type' => 'application/json', 'Authorization' => "apikey #{api_key}" } end
dump_body(method, params)
click to toggle source
# File lib/rubycent/query.rb, line 50 def dump_body(method, params) MultiJson.dump(method: method, params: params) end