Module: RelayGrid

Defined in:
lib/relaygrid.rb,
lib/relaygrid/client.rb,
lib/relaygrid/errors.rb,
lib/relaygrid/version.rb,
lib/relaygrid/delivery.rb,
lib/relaygrid/send_result.rb,
lib/relaygrid/configuration.rb,
lib/relaygrid/resources/users.rb,
lib/relaygrid/websocket_client.rb,
lib/relaygrid/resources/messages.rb,
lib/relaygrid/resources/deliveries.rb,
lib/relaygrid/resources/notifications.rb,
lib/relaygrid/resources/channel_tokens.rb,
lib/relaygrid/resources/message_templates.rb,
sig/relaygrid.rbs

Overview

Ruby client for the RelayGrid / RelayGrid notification API.

RelayGrid.configure do |config|
config.api_key  = ENV["RELAYGRID_API_KEY"]
config.base_url = ENV.fetch("RELAYGRID_BASE_URL", "https://relaygrid.dev")
end

result = RelayGrid.client.notify(
user:       { id: "user-123", first_name: "Ada", last_name: "Lovelace" },
template:   "order_shipped",
attributes: { order_number: "1042" }
)

Defined Under Namespace

Modules: Resources Classes: APIError, AuthenticationError, Client, Configuration, ConfigurationError, ConnectionError, Delivery, Error, LimitExceededError, NotFoundError, SendResult, ServerError, TemplateNotFoundError, TimeoutError, TimeoutWaitingForDeliveries, UserNotFoundError, ValidationError, WebsocketClient

Constant Summary collapse

VERSION =

Returns:

  • (String)
"0.1.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



33
34
35
# File 'lib/relaygrid.rb', line 33

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.clientRelayGrid::Client

The default client, built from the global configuration.

Returns:



48
49
50
# File 'lib/relaygrid.rb', line 48

def client
  @client ||= Client.new(configuration)
end

.configure {|configuration| ... } ⇒ Object

Set the process-wide defaults. The cached default client is dropped so the next call picks the new settings up (clients are frozen and never mutate).

Yields:



39
40
41
42
43
# File 'lib/relaygrid.rb', line 39

def configure
  yield(configuration)
  @client = nil
  configuration
end

.notify(**kwargs) ⇒ RelayGrid::SendResult

Send a notification with the default client. See Resources::Notifications#notify.



56
57
58
# File 'lib/relaygrid.rb', line 56

def notify(**kwargs)
  client.notify(**kwargs)
end

.reset!Object

Drop the global configuration and cached client. Intended for test suites.



69
70
71
72
# File 'lib/relaygrid.rb', line 69

def reset!
  @configuration = Configuration.new
  @client = nil
end

.websocket(user_id:, **options) ⇒ RelayGrid::WebsocketClient

A realtime subscriber for one recipient's messages.

Parameters:

  • user_id (String)

    your identifier for the user

Returns:



64
65
66
# File 'lib/relaygrid.rb', line 64

def websocket(user_id:, **options)
  WebsocketClient.new(user_id: user_id, client: client, **options)
end