Module: RelayGrid

Defined in:
lib/relaygrid.rb,
lib/relaygrid/event.rb,
lib/relaygrid/client.rb,
lib/relaygrid/errors.rb,
lib/relaygrid/version.rb,
lib/relaygrid/delivery.rb,
lib/relaygrid/webhooks.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,
lib/relaygrid/resources/webhook_endpoints.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, Webhooks Classes: APIError, AuthenticationError, Client, Configuration, ConfigurationError, ConnectionError, Delivery, Error, Event, LimitExceededError, NotFoundError, SendResult, ServerError, SignatureVerificationError, TemplateNotFoundError, TimeoutError, TimeoutWaitingForDeliveries, UserNotFoundError, ValidationError, WebsocketClient

Constant Summary collapse

VERSION =

Returns:

  • (String)
"0.2.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



36
37
38
# File 'lib/relaygrid.rb', line 36

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.clientRelayGrid::Client

The default client, built from the global configuration.

Returns:



51
52
53
# File 'lib/relaygrid.rb', line 51

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:



42
43
44
45
46
# File 'lib/relaygrid.rb', line 42

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

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

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



59
60
61
# File 'lib/relaygrid.rb', line 59

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

.reset!Object

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



72
73
74
75
# File 'lib/relaygrid.rb', line 72

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:



67
68
69
# File 'lib/relaygrid.rb', line 67

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