class Rapidomize::Client

A client object is a simplification of the message sending process. It merely abstract the Message creation process by automatically creating messages and assign payloads and URIs to them. A transport method is still needed for the delivery process.

Attributes

app_id[RW]
token[RW]
transport[RW]
uri[RW]

Public Class Methods

new(uri, transport, app_id = nil, token = nil) click to toggle source

Create a new client with a URI and a transport method. These parameters will be used with every payload sent through this client. @param uri [String] URI for all payloads sent through this client. @param transport [Rapidomize::Transports::BaseTransport] mode of transport.

Must be a subclass of BaseTransport

@param app_id [String] _(optional)_ Application id for the messages. @param token [String] _(optional)_ Token for message authorization.

# File lib/rapidomize/client.rb, line 20
def initialize(uri, transport, app_id = nil, token = nil)
  @uri = URI(uri)
  @transport = transport
  @app_id = app_id
  @token = token
end

Public Instance Methods

send(payload) click to toggle source

Send the payload @param payload [Hash, String, Payload] payload data to send @return [Net::HTTPResponse] return the response object

# File lib/rapidomize/client.rb, line 30
def send(payload)
  pl = Payload.create(payload)
  msg = Message.new(@uri, pl)
  msg.app_id = @app_id unless @app_id.nil?
  msg.token = @token unless @token.nil?

  @transport.deliver(msg)
end