Class: RelayGrid::Client
- Inherits:
-
Object
- Object
- RelayGrid::Client
- Defined in:
- lib/relaygrid/client.rb
Overview
The entry point for every API call. Holds one Faraday connection and hands out the resource objects.
client = RelayGrid::Client.new # global configuration
client = RelayGrid::Client.new(api_key: "sk_other") # per-client override
Instances are frozen once built, so a single client is safe to share across threads.
Constant Summary collapse
- IDEMPOTENT_METHODS =
Requests that may be replayed without changing server state.
notifyis deliberately absent: a blind retry sends the recipient a second real notification. See README ("Retries and idempotency"). %i[get head options].freeze
- RETRIABLE_STATUSES =
[429, 500, 502, 503, 504].freeze
- RETRIABLE_EXCEPTIONS =
[ Faraday::ConnectionFailed, Faraday::TimeoutError, # Required for RETRIABLE_STATUSES to have any effect: faraday-retry signals # a retriable status by raising this, and only retries exceptions listed # here. Leaving it out silently disables status-based retries. Faraday::RetriableResponse, ].freeze
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #channel_tokens ⇒ Object
- #delete(path) ⇒ Object
- #deliveries ⇒ Object
- #get(path, params: {}) ⇒ Object
-
#initialize(configuration = nil, **overrides) ⇒ Client
constructor
A new instance of Client.
- #message_templates ⇒ Object
- #messages ⇒ Object
- #notifications ⇒ Object
-
#notify(**kwargs) ⇒ Object
Send a notification -- the one call the whole gem exists for.
- #patch(path, body: {}) ⇒ Object
- #post(path, body: {}) ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(configuration = nil, **overrides) ⇒ Client
Returns a new instance of Client.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/relaygrid/client.rb', line 35 def initialize(configuration = nil, **overrides) base = configuration || RelayGrid.configuration @configuration = base.merge(overrides).validate! # Built up front so the frozen instance never has to memoize lazily. @connection = build_connection @resources = {} freeze end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
33 34 35 |
# File 'lib/relaygrid/client.rb', line 33 def configuration @configuration end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
92 93 94 |
# File 'lib/relaygrid/client.rb', line 92 def connection @connection end |
Instance Method Details
#channel_tokens ⇒ Object
62 63 64 |
# File 'lib/relaygrid/client.rb', line 62 def channel_tokens resource(:channel_tokens) { Resources::ChannelTokens.new(self) } end |
#delete(path) ⇒ Object
88 89 90 |
# File 'lib/relaygrid/client.rb', line 88 def delete(path) request(:delete, path) end |
#deliveries ⇒ Object
50 51 52 |
# File 'lib/relaygrid/client.rb', line 50 def deliveries resource(:deliveries) { Resources::Deliveries.new(self) } end |
#get(path, params: {}) ⇒ Object
76 77 78 |
# File 'lib/relaygrid/client.rb', line 76 def get(path, params: {}) request(:get, path, params: params) end |
#message_templates ⇒ Object
66 67 68 |
# File 'lib/relaygrid/client.rb', line 66 def resource(:message_templates) { Resources::MessageTemplates.new(self) } end |
#messages ⇒ Object
54 55 56 |
# File 'lib/relaygrid/client.rb', line 54 def resource(:messages) { Resources::Messages.new(self) } end |
#notifications ⇒ Object
46 47 48 |
# File 'lib/relaygrid/client.rb', line 46 def notifications resource(:notifications) { Resources::Notifications.new(self) } end |
#notify(**kwargs) ⇒ Object
Send a notification -- the one call the whole gem exists for. See Resources::Notifications#notify.
72 73 74 |
# File 'lib/relaygrid/client.rb', line 72 def notify(**kwargs) notifications.notify(**kwargs) end |
#patch(path, body: {}) ⇒ Object
84 85 86 |
# File 'lib/relaygrid/client.rb', line 84 def patch(path, body: {}) request(:patch, path, body: body) end |
#post(path, body: {}) ⇒ Object
80 81 82 |
# File 'lib/relaygrid/client.rb', line 80 def post(path, body: {}) request(:post, path, body: body) end |