Class: Sockudo::Client
Constant Summary collapse
- DEFAULT_CONNECT_TIMEOUT =
CONFIGURATION ##
5- DEFAULT_SEND_TIMEOUT =
5- DEFAULT_RECEIVE_TIMEOUT =
5- DEFAULT_KEEP_ALIVE_TIMEOUT =
30- DEFAULT_CLUSTER =
'mt1'
Instance Attribute Summary collapse
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#base_id ⇒ Object
readonly
Returns the value of attribute base_id.
-
#connect_timeout ⇒ Object
writeonly
Sets the attribute connect_timeout.
-
#encryption_master_key ⇒ Object
Returns the value of attribute encryption_master_key.
-
#host ⇒ Object
Returns the value of attribute host.
-
#http_proxy ⇒ Object
Returns the value of attribute http_proxy.
-
#keep_alive_timeout ⇒ Object
writeonly
Sets the attribute keep_alive_timeout.
-
#key ⇒ Object
Returns the value of attribute key.
-
#port ⇒ Object
Returns the value of attribute port.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
-
#publish_serial ⇒ Object
readonly
Returns the value of attribute publish_serial.
-
#receive_timeout ⇒ Object
writeonly
Sets the attribute receive_timeout.
-
#scheme ⇒ Object
Returns the value of attribute scheme.
-
#secret ⇒ Object
Returns the value of attribute secret.
-
#send_timeout ⇒ Object
writeonly
Sets the attribute send_timeout.
Class Method Summary collapse
-
.from_env(key = 'SOCKUDO_URL') ⇒ Object
Loads the configuration from an url in the environment.
-
.from_url(url) ⇒ Object
Loads the configuration from a url.
Instance Method Summary collapse
-
#activate_device(device, options = {}) ⇒ Object
Activate or create a push device registration with admin scope.
-
#append_message(channel_name, message_serial, params = {}) ⇒ Object
Apply a mutable-message append.
-
#authenticate(channel_name, socket_id, custom_data = nil) ⇒ Hash
Generate the expected response for an authentication endpoint.
-
#authenticate_user(socket_id, user_data) ⇒ Hash
Generate the expected response for a user authentication endpoint.
- #authentication_token ⇒ Object
-
#cancel_scheduled_push(publish_id) ⇒ Object
Cancel a scheduled publish.
-
#channel(channel_name) ⇒ Channel
(also: #[])
Return a convenience channel object by name that delegates operations on a channel.
-
#channel_history(channel_name, params = {}) ⇒ Hash
Request durable history for a specific channel.
-
#channel_info(channel_name, params = {}) ⇒ Hash
Request info for a specific channel.
-
#channel_presence_history(channel_name, params = {}) ⇒ Hash
Request presence history for a specific presence channel.
-
#channel_presence_snapshot(channel_name, params = {}) ⇒ Hash
Request a reconstructed presence snapshot for a specific presence channel.
-
#channel_users(channel_name, params = {}) ⇒ Hash
Request info for users of a presence channel.
-
#channels(params = {}) ⇒ Hash
Request a list of occupied channels from the API.
- #cluster=(cluster) ⇒ Object
-
#create_device_activation(device, options = {}) ⇒ Object
Alias of activate_device.
-
#delete(path, params = {}, headers = {}) ⇒ Object
DELETE arbitrary REST API resource using a synchronous http client.
-
#delete_annotation(channel_name, message_serial, annotation_serial, params = {}) ⇒ Object
Delete an annotation from a versioned message.
-
#delete_channel_push_subscriptions(params = {}, device_identity_token = nil) ⇒ Object
Delete push channel subscriptions.
-
#delete_device_registration(device_id, device_identity_token = nil) ⇒ Object
Delete a push device registration.
-
#delete_message(channel_name, message_serial, params = {}) ⇒ Object
Apply a mutable-message delete.
- #em_http_client(uri) ⇒ Object
-
#encrypted=(boolean) ⇒ Object
Configure whether Sockudo API calls should be made over SSL (default false).
- #encrypted? ⇒ Boolean
-
#encryption_master_key_base64=(str) ⇒ Object
Set an encryption_master_key to use with private-encrypted channels from a base64 encoded string.
-
#get(path, params = {}, headers = {}) ⇒ Hash
GET arbitrary REST API resource using a synchronous http client.
-
#get_async(path, params = {}, headers = {}) ⇒ Object
GET arbitrary REST API resource using an asynchronous http client.
-
#get_device_registration(device_id, device_identity_token = nil) ⇒ Object
Get a push device registration.
-
#get_message(channel_name, message_serial, params = {}) ⇒ Object
Request the latest visible version of a mutable message.
-
#get_message_versions(channel_name, message_serial, params = {}) ⇒ Object
Request preserved versions of a mutable message.
-
#get_publish_status(publish_id) ⇒ Object
Get the status for a publish id.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#list_annotations(channel_name, message_serial, params = {}) ⇒ Object
List raw annotation events for a versioned message.
-
#list_channel_push_subscription_channels(params = {}) ⇒ Object
List subscribed channels with cursor pagination.
-
#list_channel_push_subscriptions(params = {}, device_identity_token = nil) ⇒ Object
List push channel subscriptions with cursor pagination.
-
#list_device_registrations(params = {}) ⇒ Object
List push device registrations with cursor pagination.
-
#list_push_credentials(params = {}) ⇒ Object
List stored push provider credentials with cursor pagination.
-
#post(path, params = {}, headers = {}) ⇒ Object
POST arbitrary REST API resource using a synchronous http client.
-
#post_async(path, params = {}, headers = {}) ⇒ Object
POST arbitrary REST API resource using an asynchronous http client.
-
#post_push_delivery_status(event) ⇒ Object
Submit a provider delivery status event.
-
#publish_annotation(channel_name, message_serial, params = {}) ⇒ Object
Publish an annotation for a versioned message.
-
#publish_push(request) ⇒ Object
Publish push asynchronously by default.
-
#publish_push_batch(requests) ⇒ Object
Publish a batch of push notifications asynchronously by default.
-
#publish_push_direct(request) ⇒ Object
Alias of publish_push.
-
#put_push_credential(provider, credential) ⇒ Object
Store or update a provider credential payload.
-
#remove_device_registrations_by_client(client_id) ⇒ Object
Delete all device registrations for a client identifier.
-
#resource(path) ⇒ Object
INTERACT WITH THE API ##.
-
#schedule_push(request) ⇒ Object
Schedule a push publish; requires notBeforeMs in the request.
- #sync_http_client ⇒ Object
-
#timeout=(value) ⇒ Object
Convenience method to set all timeouts to the same value (in seconds).
-
#trigger(channels, event_name, data, params = {}) ⇒ Hash
Trigger an event on one or more channels.
-
#trigger_async(channels, event_name, data, params = {}) ⇒ Object
Trigger an event on one or more channels asynchronously.
-
#trigger_batch(*events) ⇒ Hash
Trigger multiple events at the same time.
-
#trigger_batch_async(*events) ⇒ Object
Trigger multiple events asynchronously.
-
#update_device_registration(device, device_identity_token) ⇒ Object
Update a push device registration with push-subscribe scope.
-
#update_message(channel_name, message_serial, params = {}) ⇒ Object
Apply a mutable-message update.
-
#upsert_channel_push_subscription(subscription, device_identity_token = nil) ⇒ Object
Upsert a push channel subscription.
- #url(path = nil) ⇒ Object
-
#url=(url) ⇒ Object
Configure Sockudo connection by providing a url rather than specifying scheme, key, secret, and app_id separately.
-
#webhook(request) ⇒ Object
Convenience method for creating a new WebHook instance for validating and extracting info from a received WebHook.
Methods included from Utils
#_authentication_string, #validate_socket_id
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sockudo/client.rb', line 34 def initialize( = {}) @scheme = 'https' @port = [:port] || 443 if .key?(:encrypted) warn '[DEPRECATION] `encrypted` is deprecated and will be removed in the next major version. Use `use_tls` instead.' end if [:use_tls] == false || [:encrypted] == false @scheme = 'http' @port = [:port] || 80 end @app_id = [:app_id] @key = [:key] @secret = [:secret] @auto_idempotency_key = .fetch(:auto_idempotency_key, true) @base_id = Base64.urlsafe_encode64(SecureRandom.random_bytes(12), padding: false) @publish_serial = 0 @max_retries = 3 @host = [:host] @host ||= "api-#{[:cluster]}.sockudo.com" unless [:cluster].nil? || [:cluster].empty? @host ||= "api-#{DEFAULT_CLUSTER}.sockudo.com" @encryption_master_key = Base64.strict_decode64([:encryption_master_key_base64]) if [:encryption_master_key_base64] @http_proxy = [:http_proxy] # Default timeouts @connect_timeout = DEFAULT_CONNECT_TIMEOUT @send_timeout = DEFAULT_SEND_TIMEOUT @receive_timeout = DEFAULT_RECEIVE_TIMEOUT @keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT end |
Instance Attribute Details
#app_id ⇒ Object
Returns the value of attribute app_id.
9 10 11 |
# File 'lib/sockudo/client.rb', line 9 def app_id @app_id end |
#base_id ⇒ Object (readonly)
Returns the value of attribute base_id.
10 11 12 |
# File 'lib/sockudo/client.rb', line 10 def base_id @base_id end |
#connect_timeout=(value) ⇒ Object (writeonly)
Sets the attribute connect_timeout
11 12 13 |
# File 'lib/sockudo/client.rb', line 11 def connect_timeout=(value) @connect_timeout = value end |
#encryption_master_key ⇒ Object
Returns the value of attribute encryption_master_key.
9 10 11 |
# File 'lib/sockudo/client.rb', line 9 def encryption_master_key @encryption_master_key end |
#host ⇒ Object
Returns the value of attribute host.
9 10 11 |
# File 'lib/sockudo/client.rb', line 9 def host @host end |
#http_proxy ⇒ Object
Returns the value of attribute http_proxy.
10 11 12 |
# File 'lib/sockudo/client.rb', line 10 def http_proxy @http_proxy end |
#keep_alive_timeout=(value) ⇒ Object (writeonly)
Sets the attribute keep_alive_timeout
11 12 13 |
# File 'lib/sockudo/client.rb', line 11 def keep_alive_timeout=(value) @keep_alive_timeout = value end |
#key ⇒ Object
Returns the value of attribute key.
9 10 11 |
# File 'lib/sockudo/client.rb', line 9 def key @key end |
#port ⇒ Object
Returns the value of attribute port.
9 10 11 |
# File 'lib/sockudo/client.rb', line 9 def port @port end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
10 11 12 |
# File 'lib/sockudo/client.rb', line 10 def proxy @proxy end |
#publish_serial ⇒ Object (readonly)
Returns the value of attribute publish_serial.
10 11 12 |
# File 'lib/sockudo/client.rb', line 10 def publish_serial @publish_serial end |
#receive_timeout=(value) ⇒ Object (writeonly)
Sets the attribute receive_timeout
11 12 13 |
# File 'lib/sockudo/client.rb', line 11 def receive_timeout=(value) @receive_timeout = value end |
#scheme ⇒ Object
Returns the value of attribute scheme.
9 10 11 |
# File 'lib/sockudo/client.rb', line 9 def scheme @scheme end |
#secret ⇒ Object
Returns the value of attribute secret.
9 10 11 |
# File 'lib/sockudo/client.rb', line 9 def secret @secret end |
#send_timeout=(value) ⇒ Object (writeonly)
Sets the attribute send_timeout
11 12 13 |
# File 'lib/sockudo/client.rb', line 11 def send_timeout=(value) @send_timeout = value end |
Class Method Details
.from_env(key = 'SOCKUDO_URL') ⇒ Object
Loads the configuration from an url in the environment
22 23 24 25 |
# File 'lib/sockudo/client.rb', line 22 def self.from_env(key = 'SOCKUDO_URL') url = ENV[key] || raise(ConfigurationError, key) from_url(url) end |
.from_url(url) ⇒ Object
Loads the configuration from a url
28 29 30 31 32 |
# File 'lib/sockudo/client.rb', line 28 def self.from_url(url) client = new client.url = url client end |
Instance Method Details
#activate_device(device, options = {}) ⇒ Object
Activate or create a push device registration with admin scope
377 378 379 380 |
# File 'lib/sockudo/client.rb', line 377 def activate_device(device, = {}) post(push_path('/deviceRegistrations'), device, push_headers('push-admin', nil, rotate_device_identity_token: [:rotate_device_identity_token])) end |
#append_message(channel_name, message_serial, params = {}) ⇒ Object
Apply a mutable-message append
341 342 343 |
# File 'lib/sockudo/client.rb', line 341 def (channel_name, , params = {}) post("/channels/#{channel_name}/messages/#{}/append", params) end |
#authenticate(channel_name, socket_id, custom_data = nil) ⇒ Hash
Generate the expected response for an authentication endpoint. See sockudo.com/docs/channels/server_api/authorizing-users for details.
566 567 568 569 570 571 572 573 574 575 |
# File 'lib/sockudo/client.rb', line 566 def authenticate(channel_name, socket_id, custom_data = nil) channel_instance = channel(channel_name) r = channel_instance.authenticate(socket_id, custom_data) if channel_name.match(/^private-encrypted-/) r[:shared_secret] = Base64.strict_encode64( channel_instance.shared_secret(encryption_master_key) ) end r end |
#authenticate_user(socket_id, user_data) ⇒ Hash
Generate the expected response for a user authentication endpoint. See sockudo.com/docs/authenticating_users for details.
593 594 595 596 597 598 599 600 |
# File 'lib/sockudo/client.rb', line 593 def authenticate_user(socket_id, user_data) validate_user_data(user_data) custom_data = MultiJson.encode(user_data) auth = authentication_string(socket_id, custom_data) { auth: auth, user_data: custom_data } end |
#authentication_token ⇒ Object
71 72 73 74 75 76 |
# File 'lib/sockudo/client.rb', line 71 def authentication_token raise ConfigurationError, :key unless @key raise ConfigurationError, :secret unless @secret Pusher::Signature::Token.new(@key, @secret) end |
#cancel_scheduled_push(publish_id) ⇒ Object
Cancel a scheduled publish
475 476 477 |
# File 'lib/sockudo/client.rb', line 475 def cancel_scheduled_push(publish_id) delete(push_path("/scheduled/#{publish_id}"), {}, push_headers('push-admin')) end |
#channel(channel_name) ⇒ Channel Also known as: []
Return a convenience channel object by name that delegates operations on a channel. No API request is made.
238 239 240 |
# File 'lib/sockudo/client.rb', line 238 def channel(channel_name) Channel.new(nil, channel_name, self) end |
#channel_history(channel_name, params = {}) ⇒ Hash
288 289 290 |
# File 'lib/sockudo/client.rb', line 288 def channel_history(channel_name, params = {}) get("/channels/#{channel_name}/history", params) end |
#channel_info(channel_name, params = {}) ⇒ Hash
271 272 273 |
# File 'lib/sockudo/client.rb', line 271 def channel_info(channel_name, params = {}) get("/channels/#{channel_name}", params) end |
#channel_presence_history(channel_name, params = {}) ⇒ Hash
302 303 304 |
# File 'lib/sockudo/client.rb', line 302 def channel_presence_history(channel_name, params = {}) get("/channels/#{channel_name}/presence/history", params) end |
#channel_presence_snapshot(channel_name, params = {}) ⇒ Hash
316 317 318 |
# File 'lib/sockudo/client.rb', line 316 def channel_presence_snapshot(channel_name, params = {}) get("/channels/#{channel_name}/presence/history/snapshot", params) end |
#channel_users(channel_name, params = {}) ⇒ Hash
372 373 374 |
# File 'lib/sockudo/client.rb', line 372 def channel_users(channel_name, params = {}) get("/channels/#{channel_name}/users", params) end |
#channels(params = {}) ⇒ Hash
Request a list of occupied channels from the API
GET /apps//channels
255 256 257 |
# File 'lib/sockudo/client.rb', line 255 def channels(params = {}) get('/channels', params) end |
#cluster=(cluster) ⇒ Object
134 135 136 137 138 |
# File 'lib/sockudo/client.rb', line 134 def cluster=(cluster) cluster = DEFAULT_CLUSTER if cluster.nil? || cluster.empty? @host = "api-#{cluster}.sockudo.com" end |
#create_device_activation(device, options = {}) ⇒ Object
Alias of activate_device
383 384 385 |
# File 'lib/sockudo/client.rb', line 383 def create_device_activation(device, = {}) activate_device(device, ) end |
#delete(path, params = {}, headers = {}) ⇒ Object
DELETE arbitrary REST API resource using a synchronous http client. All request signing is handled automatically.
206 207 208 |
# File 'lib/sockudo/client.rb', line 206 def delete(path, params = {}, headers = {}) resource(path).delete(params, headers) end |
#delete_annotation(channel_name, message_serial, annotation_serial, params = {}) ⇒ Object
Delete an annotation from a versioned message
351 352 353 |
# File 'lib/sockudo/client.rb', line 351 def delete_annotation(channel_name, , annotation_serial, params = {}) delete("/channels/#{channel_name}/messages/#{}/annotations/#{annotation_serial}", params) end |
#delete_channel_push_subscriptions(params = {}, device_identity_token = nil) ⇒ Object
Delete push channel subscriptions
427 428 429 430 |
# File 'lib/sockudo/client.rb', line 427 def delete_channel_push_subscriptions(params = {}, device_identity_token = nil) capability = device_identity_token ? 'push-subscribe' : 'push-admin' delete(push_path('/channelSubscriptions'), params, push_headers(capability, device_identity_token)) end |
#delete_device_registration(device_id, device_identity_token = nil) ⇒ Object
Delete a push device registration
404 405 406 407 |
# File 'lib/sockudo/client.rb', line 404 def delete_device_registration(device_id, device_identity_token = nil) capability = device_identity_token ? 'push-subscribe' : 'push-admin' delete(push_path("/deviceRegistrations/#{device_id}"), {}, push_headers(capability, device_identity_token)) end |
#delete_message(channel_name, message_serial, params = {}) ⇒ Object
Apply a mutable-message delete
336 337 338 |
# File 'lib/sockudo/client.rb', line 336 def (channel_name, , params = {}) post("/channels/#{channel_name}/messages/#{}/delete", params) end |
#em_http_client(uri) ⇒ Object
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
# File 'lib/sockudo/client.rb', line 615 def em_http_client(uri) unless defined?(EventMachine) && EventMachine.reactor_running? raise Error, 'In order to use async calling you must be running inside an eventmachine loop' end require 'em-http' unless defined?(EventMachine::HttpRequest) connection_opts = { connect_timeout: @connect_timeout, inactivity_timeout: @receive_timeout } if defined?(@proxy) proxy_opts = { host: @proxy[:host], port: @proxy[:port] } proxy_opts[:authorization] = [@proxy[:user], @proxy[:password]] if @proxy[:user] connection_opts[:proxy] = proxy_opts end EventMachine::HttpRequest.new(uri, connection_opts) end |
#encrypted=(boolean) ⇒ Object
Configure whether Sockudo API calls should be made over SSL (default false)
124 125 126 127 128 |
# File 'lib/sockudo/client.rb', line 124 def encrypted=(boolean) @scheme = boolean ? 'https' : 'http' # Configure port if it hasn't already been configured @port = boolean ? 443 : 80 end |
#encrypted? ⇒ Boolean
130 131 132 |
# File 'lib/sockudo/client.rb', line 130 def encrypted? @scheme == 'https' end |
#encryption_master_key_base64=(str) ⇒ Object
Set an encryption_master_key to use with private-encrypted channels from a base64 encoded string.
150 151 152 |
# File 'lib/sockudo/client.rb', line 150 def encryption_master_key_base64=(str) @encryption_master_key = str ? Base64.strict_decode64(str) : nil end |
#get(path, params = {}, headers = {}) ⇒ Hash
GET arbitrary REST API resource using a synchronous http client. All request signing is handled automatically.
178 179 180 |
# File 'lib/sockudo/client.rb', line 178 def get(path, params = {}, headers = {}) resource(path).get(params, headers) end |
#get_async(path, params = {}, headers = {}) ⇒ Object
GET arbitrary REST API resource using an asynchronous http client. All request signing is handled automatically.
When the eventmachine reactor is running, the em-http-request gem is used; otherwise an async request is made using httpclient. See README for details and examples.
194 195 196 |
# File 'lib/sockudo/client.rb', line 194 def get_async(path, params = {}, headers = {}) resource(path).get_async(params, headers) end |
#get_device_registration(device_id, device_identity_token = nil) ⇒ Object
Get a push device registration
398 399 400 401 |
# File 'lib/sockudo/client.rb', line 398 def get_device_registration(device_id, device_identity_token = nil) capability = device_identity_token ? 'push-subscribe' : 'push-admin' get(push_path("/deviceRegistrations/#{device_id}"), {}, push_headers(capability, device_identity_token)) end |
#get_message(channel_name, message_serial, params = {}) ⇒ Object
Request the latest visible version of a mutable message
321 322 323 |
# File 'lib/sockudo/client.rb', line 321 def (channel_name, , params = {}) get("/channels/#{channel_name}/messages/#{}", params) end |
#get_message_versions(channel_name, message_serial, params = {}) ⇒ Object
Request preserved versions of a mutable message
326 327 328 |
# File 'lib/sockudo/client.rb', line 326 def (channel_name, , params = {}) get("/channels/#{channel_name}/messages/#{}/versions", params) end |
#get_publish_status(publish_id) ⇒ Object
Get the status for a publish id
470 471 472 |
# File 'lib/sockudo/client.rb', line 470 def get_publish_status(publish_id) get(push_path("/publish/#{publish_id}/status"), {}, push_headers('push-admin')) end |
#list_annotations(channel_name, message_serial, params = {}) ⇒ Object
List raw annotation events for a versioned message
356 357 358 |
# File 'lib/sockudo/client.rb', line 356 def list_annotations(channel_name, , params = {}) get("/channels/#{channel_name}/messages/#{}/annotations", params) end |
#list_channel_push_subscription_channels(params = {}) ⇒ Object
List subscribed channels with cursor pagination
433 434 435 |
# File 'lib/sockudo/client.rb', line 433 def list_channel_push_subscription_channels(params = {}) get(push_path('/channelSubscriptions/channels'), params, push_headers('push-admin')) end |
#list_channel_push_subscriptions(params = {}, device_identity_token = nil) ⇒ Object
List push channel subscriptions with cursor pagination
421 422 423 424 |
# File 'lib/sockudo/client.rb', line 421 def list_channel_push_subscriptions(params = {}, device_identity_token = nil) capability = device_identity_token ? 'push-subscribe' : 'push-admin' get(push_path('/channelSubscriptions'), params, push_headers(capability, device_identity_token)) end |
#list_device_registrations(params = {}) ⇒ Object
List push device registrations with cursor pagination
393 394 395 |
# File 'lib/sockudo/client.rb', line 393 def list_device_registrations(params = {}) get(push_path('/deviceRegistrations'), params, push_headers('push-admin')) end |
#list_push_credentials(params = {}) ⇒ Object
List stored push provider credentials with cursor pagination
438 439 440 |
# File 'lib/sockudo/client.rb', line 438 def list_push_credentials(params = {}) get(push_path('/credentials'), params, push_headers('push-admin')) end |
#post(path, params = {}, headers = {}) ⇒ Object
POST arbitrary REST API resource using a synchronous http client. Works identially to get method, but posts params as JSON in post body.
200 201 202 |
# File 'lib/sockudo/client.rb', line 200 def post(path, params = {}, headers = {}) resource(path).post(params, headers) end |
#post_async(path, params = {}, headers = {}) ⇒ Object
POST arbitrary REST API resource using an asynchronous http client. Works identially to get_async method, but posts params as JSON in post body.
213 214 215 |
# File 'lib/sockudo/client.rb', line 213 def post_async(path, params = {}, headers = {}) resource(path).post_async(params, headers) end |
#post_push_delivery_status(event) ⇒ Object
Submit a provider delivery status event
480 481 482 |
# File 'lib/sockudo/client.rb', line 480 def post_push_delivery_status(event) post(push_path('/deliveryStatus'), event, push_headers('push-admin')) end |
#publish_annotation(channel_name, message_serial, params = {}) ⇒ Object
Publish an annotation for a versioned message
346 347 348 |
# File 'lib/sockudo/client.rb', line 346 def publish_annotation(channel_name, , params = {}) post("/channels/#{channel_name}/messages/#{}/annotations", params) end |
#publish_push(request) ⇒ Object
Publish push asynchronously by default
448 449 450 |
# File 'lib/sockudo/client.rb', line 448 def publish_push(request) post(push_path('/publish'), request.merge(sync: false), push_headers('push-admin')) end |
#publish_push_batch(requests) ⇒ Object
Publish a batch of push notifications asynchronously by default
458 459 460 |
# File 'lib/sockudo/client.rb', line 458 def publish_push_batch(requests) post(push_path('/batch/publish'), requests.map { |request| request.merge(sync: false) }, push_headers('push-admin')) end |
#publish_push_direct(request) ⇒ Object
Alias of publish_push
453 454 455 |
# File 'lib/sockudo/client.rb', line 453 def publish_push_direct(request) publish_push(request) end |
#put_push_credential(provider, credential) ⇒ Object
Store or update a provider credential payload
443 444 445 |
# File 'lib/sockudo/client.rb', line 443 def put_push_credential(provider, credential) post(push_path("/credentials/#{provider}"), credential, push_headers('push-admin')) end |
#remove_device_registrations_by_client(client_id) ⇒ Object
Delete all device registrations for a client identifier
410 411 412 |
# File 'lib/sockudo/client.rb', line 410 def remove_device_registrations_by_client(client_id) delete(push_path('/deviceRegistrations'), { clientId: client_id }, push_headers('push-admin')) end |
#resource(path) ⇒ Object
INTERACT WITH THE API ##
156 157 158 |
# File 'lib/sockudo/client.rb', line 156 def resource(path) Resource.new(self, path) end |
#schedule_push(request) ⇒ Object
Schedule a push publish; requires notBeforeMs in the request
463 464 465 466 467 |
# File 'lib/sockudo/client.rb', line 463 def schedule_push(request) raise Sockudo::Error, 'scheduled push requires notBeforeMs' unless request.key?(:notBeforeMs) || request.key?('notBeforeMs') publish_push(request) end |
#sync_http_client ⇒ Object
603 604 605 606 607 608 609 610 611 612 |
# File 'lib/sockudo/client.rb', line 603 def sync_http_client require 'httpclient' @sync_http_client ||= HTTPClient.new(@http_proxy).tap do |c| c.connect_timeout = @connect_timeout c.send_timeout = @send_timeout c.receive_timeout = @receive_timeout c.keep_alive_timeout = @keep_alive_timeout end end |
#timeout=(value) ⇒ Object
Convenience method to set all timeouts to the same value (in seconds). For more control, use the individual writers.
142 143 144 145 146 |
# File 'lib/sockudo/client.rb', line 142 def timeout=(value) @connect_timeout = value @send_timeout = value @receive_timeout = value end |
#trigger(channels, event_name, data, params = {}) ⇒ Hash
Trigger an event on one or more channels
POST /apps//events
500 501 502 503 504 |
# File 'lib/sockudo/client.rb', line 500 def trigger(channels, event_name, data, params = {}) params = inject_auto_idempotency_key(params) body, headers = trigger_params_with_headers(channels, event_name, data, params) post_with_retry('/events', body, headers) end |
#trigger_async(channels, event_name, data, params = {}) ⇒ Object
Trigger an event on one or more channels asynchronously. For parameters see #trigger
527 528 529 530 531 |
# File 'lib/sockudo/client.rb', line 527 def trigger_async(channels, event_name, data, params = {}) params = inject_auto_idempotency_key(params) body, headers = trigger_params_with_headers(channels, event_name, data, params) post_async('/events', body, headers) end |
#trigger_batch(*events) ⇒ Hash
Trigger multiple events at the same time
POST /apps//batch_events
518 519 520 521 522 |
# File 'lib/sockudo/client.rb', line 518 def trigger_batch(*events) flat_events = events.flatten inject_auto_idempotency_keys_batch!(flat_events) post_with_retry('/batch_events', trigger_batch_params(flat_events)) end |
#trigger_batch_async(*events) ⇒ Object
Trigger multiple events asynchronously. For parameters see #trigger_batch
536 537 538 539 540 |
# File 'lib/sockudo/client.rb', line 536 def trigger_batch_async(*events) flat_events = events.flatten inject_auto_idempotency_keys_batch!(flat_events) post_async('/batch_events', trigger_batch_params(flat_events)) end |
#update_device_registration(device, device_identity_token) ⇒ Object
Update a push device registration with push-subscribe scope
388 389 390 |
# File 'lib/sockudo/client.rb', line 388 def update_device_registration(device, device_identity_token) post(push_path('/deviceRegistrations'), device, push_headers('push-subscribe', device_identity_token)) end |
#update_message(channel_name, message_serial, params = {}) ⇒ Object
Apply a mutable-message update
331 332 333 |
# File 'lib/sockudo/client.rb', line 331 def (channel_name, , params = {}) post("/channels/#{channel_name}/messages/#{}/update", params) end |
#upsert_channel_push_subscription(subscription, device_identity_token = nil) ⇒ Object
Upsert a push channel subscription
415 416 417 418 |
# File 'lib/sockudo/client.rb', line 415 def upsert_channel_push_subscription(subscription, device_identity_token = nil) capability = device_identity_token ? 'push-subscribe' : 'push-admin' post(push_path('/channelSubscriptions'), subscription, push_headers(capability, device_identity_token)) end |
#url(path = nil) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/sockudo/client.rb', line 79 def url(path = nil) raise ConfigurationError, :app_id unless @app_id URI::Generic.build({ scheme: @scheme, host: @host, port: @port, path: "/apps/#{@app_id}#{path}" }) end |
#url=(url) ⇒ Object
Configure Sockudo connection by providing a url rather than specifying scheme, key, secret, and app_id separately.
96 97 98 99 100 101 102 103 104 |
# File 'lib/sockudo/client.rb', line 96 def url=(url) uri = URI.parse(url) @scheme = uri.scheme @app_id = uri.path.split('/').last @key = uri.user @secret = uri.password @host = uri.host @port = uri.port end |