Class: Rapidomize::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rapidomize/client.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, transport, app_id = nil, token = nil) ⇒ Client

Create a new client with a URI and a transport method. These parameters will be used with every payload sent through this client.

Parameters:

  • uri (String)

    URI for all payloads sent through this client.

  • transport (Rapidomize::Transports::BaseTransport)

    mode of transport. Must be a subclass of BaseTransport

  • app_id (String) (defaults to: nil)

    _(optional)_ Application id for the messages.

  • token (String) (defaults to: nil)

    _(optional)_ Token for message authorization.



20
21
22
23
24
25
# 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

Instance Attribute Details

#app_idObject

Returns the value of attribute app_id.



10
11
12
# File 'lib/rapidomize/client.rb', line 10

def app_id
  @app_id
end

#tokenObject

Returns the value of attribute token.



10
11
12
# File 'lib/rapidomize/client.rb', line 10

def token
  @token
end

#transportObject

Returns the value of attribute transport.



10
11
12
# File 'lib/rapidomize/client.rb', line 10

def transport
  @transport
end

#uriObject

Returns the value of attribute uri.



10
11
12
# File 'lib/rapidomize/client.rb', line 10

def uri
  @uri
end

Instance Method Details

#send(payload) ⇒ Net::HTTPResponse

Send the payload

Parameters:

  • payload (Hash, String, Payload)

    payload data to send

Returns:

  • (Net::HTTPResponse)

    return the response object



30
31
32
33
34
35
36
37
# 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