ably-pubsub-core 0.0.1.pre → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ably/auth.rb +5 -5
- data/lib/ably/exceptions.rb +5 -0
- data/lib/ably/internal.rb +115 -0
- data/lib/ably/logger.rb +3 -3
- data/lib/ably/models/channel_details.rb +1 -1
- data/lib/ably/models/channel_metrics.rb +1 -1
- data/lib/ably/models/channel_occupancy.rb +1 -1
- data/lib/ably/models/channel_state_change.rb +7 -7
- data/lib/ably/models/channel_status.rb +1 -1
- data/lib/ably/models/cipher_params.rb +1 -1
- data/lib/ably/models/connection_details.rb +2 -2
- data/lib/ably/models/connection_state_change.rb +6 -6
- data/lib/ably/models/http_paginated_response.rb +3 -3
- data/lib/ably/models/message.rb +69 -2
- data/lib/ably/models/message_operation.rb +53 -0
- data/lib/ably/models/paginated_result.rb +2 -2
- data/lib/ably/models/presence_message.rb +1 -1
- data/lib/ably/models/protocol_message.rb +14 -1
- data/lib/ably/models/publish_result.rb +32 -0
- data/lib/ably/models/stats.rb +41 -84
- data/lib/ably/models/update_delete_result.rb +32 -0
- data/lib/ably/modules/ably.rb +13 -12
- data/lib/ably/modules/channels_collection.rb +1 -1
- data/lib/ably/modules/http_helpers.rb +11 -11
- data/lib/ably/{rest → pubsub/http}/channel/push_channel.rb +3 -3
- data/lib/ably/pubsub/http/channel.rb +284 -0
- data/lib/ably/pubsub/http/channels.rb +49 -0
- data/lib/ably/pubsub/http/client.rb +738 -0
- data/lib/ably/pubsub/http/middleware/encoder.rb +51 -0
- data/lib/ably/pubsub/http/middleware/exceptions.rb +55 -0
- data/lib/ably/pubsub/http/middleware/external_exceptions.rb +26 -0
- data/lib/ably/pubsub/http/middleware/fail_if_unsupported_mime_type.rb +24 -0
- data/lib/ably/pubsub/http/middleware/logger.rb +60 -0
- data/lib/ably/pubsub/http/middleware/parse_json.rb +29 -0
- data/lib/ably/pubsub/http/middleware/parse_message_pack.rb +45 -0
- data/lib/ably/pubsub/http/presence.rb +117 -0
- data/lib/ably/{rest → pubsub/http}/push/admin.rb +5 -5
- data/lib/ably/{rest → pubsub/http}/push/channel_subscriptions.rb +1 -1
- data/lib/ably/{rest → pubsub/http}/push/device_registrations.rb +1 -1
- data/lib/ably/pubsub/http/push.rb +27 -0
- data/lib/ably/pubsub/http.rb +38 -0
- data/lib/ably/pubsub/realtime/auth.rb +285 -0
- data/lib/ably/{realtime → pubsub/realtime}/channel/channel_manager.rb +2 -2
- data/lib/ably/{realtime → pubsub/realtime}/channel/channel_properties.rb +5 -5
- data/lib/ably/{realtime → pubsub/realtime}/channel/channel_state_machine.rb +2 -2
- data/lib/ably/{realtime → pubsub/realtime}/channel/publisher.rb +9 -4
- data/lib/ably/{realtime → pubsub/realtime}/channel/push_channel.rb +2 -2
- data/lib/ably/pubsub/realtime/channel.rb +545 -0
- data/lib/ably/pubsub/realtime/channels.rb +92 -0
- data/lib/ably/{realtime → pubsub/realtime}/client/incoming_message_dispatcher.rb +43 -8
- data/lib/ably/{realtime → pubsub/realtime}/client/outgoing_message_dispatcher.rb +2 -2
- data/lib/ably/pubsub/realtime/client.rb +372 -0
- data/lib/ably/{realtime → pubsub/realtime}/connection/connection_manager.rb +6 -6
- data/lib/ably/{realtime → pubsub/realtime}/connection/connection_state_machine.rb +2 -2
- data/lib/ably/{realtime → pubsub/realtime}/connection/websocket_transport.rb +1 -1
- data/lib/ably/pubsub/realtime/connection.rb +724 -0
- data/lib/ably/{realtime → pubsub/realtime}/models/nil_channel.rb +3 -3
- data/lib/ably/{realtime → pubsub/realtime}/presence/members_map.rb +2 -2
- data/lib/ably/{realtime → pubsub/realtime}/presence/presence_manager.rb +3 -3
- data/lib/ably/{realtime → pubsub/realtime}/presence/presence_state_machine.rb +2 -2
- data/lib/ably/{realtime → pubsub/realtime}/presence.rb +23 -23
- data/lib/ably/{realtime → pubsub/realtime}/push/admin.rb +8 -8
- data/lib/ably/{realtime → pubsub/realtime}/push/channel_subscriptions.rb +6 -6
- data/lib/ably/{realtime → pubsub/realtime}/push/device_registrations.rb +6 -6
- data/lib/ably/pubsub/realtime/push.rb +27 -0
- data/lib/ably/pubsub/realtime/recovery_key_context.rb +38 -0
- data/lib/ably/pubsub/realtime.rb +58 -0
- data/lib/ably/pubsub.rb +11 -0
- data/lib/ably/version.rb +2 -2
- data/lib/ably.rb +6 -2
- metadata +50 -46
- data/lib/ably/models/stats_types.rb +0 -107
- data/lib/ably/realtime/auth.rb +0 -283
- data/lib/ably/realtime/channel.rb +0 -440
- data/lib/ably/realtime/channels.rb +0 -71
- data/lib/ably/realtime/client.rb +0 -363
- data/lib/ably/realtime/connection.rb +0 -738
- data/lib/ably/realtime/push.rb +0 -25
- data/lib/ably/realtime/recovery_key_context.rb +0 -36
- data/lib/ably/realtime.rb +0 -60
- data/lib/ably/rest/channel.rb +0 -194
- data/lib/ably/rest/channels.rb +0 -47
- data/lib/ably/rest/client.rb +0 -727
- data/lib/ably/rest/middleware/encoder.rb +0 -49
- data/lib/ably/rest/middleware/exceptions.rb +0 -53
- data/lib/ably/rest/middleware/external_exceptions.rb +0 -24
- data/lib/ably/rest/middleware/fail_if_unsupported_mime_type.rb +0 -22
- data/lib/ably/rest/middleware/logger.rb +0 -58
- data/lib/ably/rest/middleware/parse_json.rb +0 -27
- data/lib/ably/rest/middleware/parse_message_pack.rb +0 -43
- data/lib/ably/rest/presence.rb +0 -113
- data/lib/ably/rest/push.rb +0 -25
- data/lib/ably/rest.rb +0 -40
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
module Ably::Models
|
|
2
|
-
class Stats
|
|
3
|
-
# StatsStruct is a basic Struct like class that allows methods to be defined
|
|
4
|
-
# on the class that will be retuned co-erced objects from the underlying hash used to
|
|
5
|
-
# initialize the object.
|
|
6
|
-
#
|
|
7
|
-
# This class provides a concise way to create classes that have fixed attributes and types
|
|
8
|
-
#
|
|
9
|
-
# @example
|
|
10
|
-
# class MessageCount < StatsStruct
|
|
11
|
-
# coerce_attributes :count, :data, into: Integer
|
|
12
|
-
# end
|
|
13
|
-
#
|
|
14
|
-
# @api private
|
|
15
|
-
#
|
|
16
|
-
class StatsStruct
|
|
17
|
-
class << self
|
|
18
|
-
def coerce_attributes(*attributes)
|
|
19
|
-
options = attributes.pop
|
|
20
|
-
raise ArgumentError, 'Expected attribute into: within options hash' unless options.kind_of?(Hash) && options[:into]
|
|
21
|
-
|
|
22
|
-
@type_klass = options[:into]
|
|
23
|
-
setup_attribute_methods attributes
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def type_klass
|
|
27
|
-
@type_klass
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
private
|
|
31
|
-
def setup_attribute_methods(attributes)
|
|
32
|
-
attributes.each do |attr|
|
|
33
|
-
define_method(attr) do
|
|
34
|
-
# Lazy load the co-erced value only when accessed
|
|
35
|
-
unless instance_variable_defined?("@#{attr}")
|
|
36
|
-
instance_variable_set "@#{attr}", self.class.type_klass.new(hash[attr.to_sym])
|
|
37
|
-
end
|
|
38
|
-
instance_variable_get("@#{attr}")
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
attr_reader :hash
|
|
45
|
-
|
|
46
|
-
def initialize(hash)
|
|
47
|
-
@hash = hash || {}
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# IntegerDefaultZero will always return an Integer object and will default to value 0 unless truthy
|
|
52
|
-
#
|
|
53
|
-
# @api private
|
|
54
|
-
#
|
|
55
|
-
class IntegerDefaultZero
|
|
56
|
-
def self.new(value)
|
|
57
|
-
(value && value.to_i) || 0
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# MessageCount contains aggregate counts for messages and data transferred
|
|
62
|
-
#
|
|
63
|
-
# @spec TS5a, TS5b
|
|
64
|
-
#
|
|
65
|
-
class MessageCount < StatsStruct
|
|
66
|
-
coerce_attributes :count, :data, into: IntegerDefaultZero
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
# RequestCount contains aggregate counts for requests made
|
|
70
|
-
#
|
|
71
|
-
# @spec TS8a, TS8b, TS8c
|
|
72
|
-
#
|
|
73
|
-
class RequestCount < StatsStruct
|
|
74
|
-
coerce_attributes :succeeded, :failed, :refused, into: IntegerDefaultZero
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# ResourceCount contains aggregate data for usage of a resource in a specific scope
|
|
78
|
-
#
|
|
79
|
-
class ResourceCount < StatsStruct
|
|
80
|
-
coerce_attributes :opened, :peak, :mean, :min, :refused, into: IntegerDefaultZero
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
# ConnectionTypes contains a breakdown of summary stats data for different (TLS vs non-TLS) connection types
|
|
84
|
-
#
|
|
85
|
-
# @spec TS4a, TS4b, TS4c
|
|
86
|
-
#
|
|
87
|
-
class ConnectionTypes < StatsStruct
|
|
88
|
-
coerce_attributes :tls, :plain, :all, into: ResourceCount
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
# MessageTypes contains a breakdown of summary stats data for different (message vs presence) message types
|
|
92
|
-
#
|
|
93
|
-
# @spec TS6a, TS6b, TS6c
|
|
94
|
-
#
|
|
95
|
-
class MessageTypes < StatsStruct
|
|
96
|
-
coerce_attributes :messages, :presence, :all, into: MessageCount
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
# MessageTraffic contains a breakdown of summary stats data for traffic over various transport types
|
|
100
|
-
#
|
|
101
|
-
# @spec TS7a, TS7b, TS7c, TS7d
|
|
102
|
-
#
|
|
103
|
-
class MessageTraffic < StatsStruct
|
|
104
|
-
coerce_attributes :realtime, :rest, :webhook, :all, into: MessageTypes
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|
data/lib/ably/realtime/auth.rb
DELETED
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
require 'ably/auth'
|
|
2
|
-
|
|
3
|
-
module Ably
|
|
4
|
-
module Realtime
|
|
5
|
-
# Auth is responsible for authentication with {https://www.ably.com Ably} using basic or token authentication
|
|
6
|
-
# This {Ably::Realtime::Auth Realtime::Auth} class wraps the {Ably::Auth Synchronous Ably::Auth} class in an EventMachine friendly way using Deferrables for all IO. See {Ably::Auth Ably::Auth} for more information
|
|
7
|
-
#
|
|
8
|
-
# Find out more about Ably authentication at: https://www.ably.com/docs/general/authentication/
|
|
9
|
-
#
|
|
10
|
-
# @!attribute [r] client_id
|
|
11
|
-
# (see Ably::Auth#client_id)
|
|
12
|
-
# @!attribute [r] current_token_details
|
|
13
|
-
# (see Ably::Auth#current_token_details)
|
|
14
|
-
# @!attribute [r] token
|
|
15
|
-
# (see Ably::Auth#token)
|
|
16
|
-
# @!attribute [r] key
|
|
17
|
-
# (see Ably::Auth#key)
|
|
18
|
-
# @!attribute [r] key_name
|
|
19
|
-
# (see Ably::Auth#key_name)
|
|
20
|
-
# @!attribute [r] key_secret
|
|
21
|
-
# (see Ably::Auth#key_secret)
|
|
22
|
-
# @!attribute [r] options
|
|
23
|
-
# (see Ably::Auth#options)
|
|
24
|
-
# @!attribute [r] token_params
|
|
25
|
-
# (see Ably::Auth#options)
|
|
26
|
-
# @!attribute [r] using_basic_auth?
|
|
27
|
-
# (see Ably::Auth#using_basic_auth?)
|
|
28
|
-
# @!attribute [r] using_token_auth?
|
|
29
|
-
# (see Ably::Auth#using_token_auth?)
|
|
30
|
-
# @!attribute [r] token_renewable?
|
|
31
|
-
# (see Ably::Auth#token_renewable?)
|
|
32
|
-
# @!attribute [r] authentication_security_requirements_met?
|
|
33
|
-
# (see Ably::Auth#authentication_security_requirements_met?)
|
|
34
|
-
#
|
|
35
|
-
class Auth
|
|
36
|
-
extend Forwardable
|
|
37
|
-
include Ably::Modules::AsyncWrapper
|
|
38
|
-
|
|
39
|
-
def_delegators :auth_sync, :client_id
|
|
40
|
-
def_delegators :auth_sync, :token_client_id_allowed?, :configure_client_id, :client_id_validated?
|
|
41
|
-
def_delegators :auth_sync, :can_assume_client_id?, :has_client_id?
|
|
42
|
-
def_delegators :auth_sync, :current_token_details, :token
|
|
43
|
-
def_delegators :auth_sync, :key, :key_name, :key_secret, :options, :auth_options, :token_params
|
|
44
|
-
def_delegators :auth_sync, :using_basic_auth?, :using_token_auth?
|
|
45
|
-
def_delegators :auth_sync, :token_renewable?, :authentication_security_requirements_met?
|
|
46
|
-
def_delegators :client, :logger
|
|
47
|
-
def_delegators :client, :connection
|
|
48
|
-
|
|
49
|
-
def initialize(client)
|
|
50
|
-
@client = client
|
|
51
|
-
@auth_sync = client.rest_client.auth
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# For new connections, ensures valid auth credentials are present for the library instance. This may rely on an already-known and valid token, and will obtain a new token if necessary.
|
|
55
|
-
# If a connection is already established, the connection will be upgraded with a new token
|
|
56
|
-
#
|
|
57
|
-
# In the event that a new token request is made, the provided options are used
|
|
58
|
-
#
|
|
59
|
-
# @param (see Ably::Auth#authorize)
|
|
60
|
-
# @option (see Ably::Auth#authorize)
|
|
61
|
-
#
|
|
62
|
-
# @return [Ably::Util::SafeDeferrable]
|
|
63
|
-
# @yield [Ably::Models::TokenDetails]
|
|
64
|
-
#
|
|
65
|
-
# @example
|
|
66
|
-
# # will issue a simple token request using basic auth
|
|
67
|
-
# client = Ably::Rest::Client.new(key: 'key.id:secret')
|
|
68
|
-
# client.auth.authorize do |token_details|
|
|
69
|
-
# token_details #=> Ably::Models::TokenDetails
|
|
70
|
-
# end
|
|
71
|
-
#
|
|
72
|
-
def authorize(token_params = nil, auth_options = nil, &success_callback)
|
|
73
|
-
Ably::Util::SafeDeferrable.new(logger).tap do |authorize_method_deferrable|
|
|
74
|
-
# Wrap the sync authorize method and wait for the result from the deferrable
|
|
75
|
-
async_wrap do
|
|
76
|
-
authorize_sync(token_params, auth_options)
|
|
77
|
-
end.tap do |auth_operation|
|
|
78
|
-
# Authorize operation succeeded and we have a new token, now let's perform inline authentication
|
|
79
|
-
auth_operation.callback do |token|
|
|
80
|
-
case connection.state.to_sym
|
|
81
|
-
when :initialized, :disconnected, :suspended, :closed, :closing, :failed
|
|
82
|
-
connection.connect
|
|
83
|
-
when :connected
|
|
84
|
-
perform_inline_auth token
|
|
85
|
-
when :connecting
|
|
86
|
-
# Fail all current connection attempts and try again with the new token, see #RTC8b
|
|
87
|
-
connection.manager.release_and_establish_new_transport
|
|
88
|
-
else
|
|
89
|
-
logger.fatal { "Auth#authorize: unsupported state #{connection.state}" }
|
|
90
|
-
authorize_method_deferrable.fail Ably::Exceptions::InvalidState.new("Unsupported state #{connection.state} for Auth#authorize")
|
|
91
|
-
next
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
# Indicate success or failure based on response from realtime, see #RTC8b1
|
|
95
|
-
auth_deferrable_resolved = false
|
|
96
|
-
|
|
97
|
-
connection.unsafe_once(:connected, :update) do
|
|
98
|
-
auth_deferrable_resolved = true
|
|
99
|
-
authorize_method_deferrable.succeed token
|
|
100
|
-
end
|
|
101
|
-
connection.unsafe_once(:suspended, :closed, :failed) do |state_change|
|
|
102
|
-
auth_deferrable_resolved = true
|
|
103
|
-
authorize_method_deferrable.fail state_change.reason
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
# Authorize failed, likely due to auth_url or auth_callback failing
|
|
108
|
-
auth_operation.errback do |error|
|
|
109
|
-
client.connection.transition_state_machine :failed, reason: error if error.kind_of?(Ably::Exceptions::IncompatibleClientId)
|
|
110
|
-
authorize_method_deferrable.fail error
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
# Call the block provided to this method upon success of this deferrable
|
|
115
|
-
authorize_method_deferrable.callback do |token|
|
|
116
|
-
yield token if block_given?
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
# @deprecated Use {#authorize} instead
|
|
122
|
-
def authorise(*args, &block)
|
|
123
|
-
logger.warn { "Auth#authorise is deprecated and will be removed in 1.0. Please use Auth#authorize instead" }
|
|
124
|
-
authorize(*args, &block)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
# Synchronous version of {#authorize}. See {Ably::Auth#authorize} for method definition
|
|
128
|
-
# Please note that authorize_sync will however not upgrade the current connection's token as this requires
|
|
129
|
-
# an synchronous operation to send the new authentication details to Ably over a realtime connection
|
|
130
|
-
#
|
|
131
|
-
# @param (see Ably::Auth#authorize)
|
|
132
|
-
# @option (see Ably::Auth#authorize)
|
|
133
|
-
# @return [Ably::Models::TokenDetails]
|
|
134
|
-
#
|
|
135
|
-
def authorize_sync(token_params = nil, auth_options = nil)
|
|
136
|
-
@authorization_in_flight = true
|
|
137
|
-
auth_sync.authorize(token_params, auth_options)
|
|
138
|
-
ensure
|
|
139
|
-
@authorization_in_flight = false
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
# @api private
|
|
143
|
-
def authorization_in_flight?
|
|
144
|
-
@authorization_in_flight
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
# @deprecated Use {#authorize_sync} instead
|
|
148
|
-
def authorise_sync(*args)
|
|
149
|
-
logger.warn { "Auth#authorise_sync is deprecated and will be removed in 1.0. Please use Auth#authorize_sync instead" }
|
|
150
|
-
authorize_sync(*args)
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
# Request a {Ably::Models::TokenDetails} which can be used to make authenticated token based requests
|
|
154
|
-
#
|
|
155
|
-
# @param (see Ably::Auth#request_token)
|
|
156
|
-
# @option (see Ably::Auth#request_token)
|
|
157
|
-
#
|
|
158
|
-
# @return [Ably::Util::SafeDeferrable]
|
|
159
|
-
# @yield [Ably::Models::TokenDetails]
|
|
160
|
-
#
|
|
161
|
-
# @example
|
|
162
|
-
# # simple token request using basic auth
|
|
163
|
-
# client = Ably::Rest::Client.new(key: 'key.id:secret')
|
|
164
|
-
# client.auth.request_token do |token_details|
|
|
165
|
-
# token_details #=> Ably::Models::TokenDetails
|
|
166
|
-
# end
|
|
167
|
-
#
|
|
168
|
-
def request_token(token_params = {}, auth_options = {}, &success_callback)
|
|
169
|
-
async_wrap(success_callback) do
|
|
170
|
-
request_token_sync(token_params, auth_options)
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
# Synchronous version of {#request_token}. See {Ably::Auth#request_token} for method definition
|
|
175
|
-
# @param (see Ably::Auth#authorize)
|
|
176
|
-
# @option (see Ably::Auth#authorize)
|
|
177
|
-
# @return [Ably::Models::TokenDetails]
|
|
178
|
-
#
|
|
179
|
-
def request_token_sync(token_params = {}, auth_options = {})
|
|
180
|
-
auth_sync.request_token(token_params, auth_options)
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
# Creates and signs a token request that can then subsequently be used by any client to request a token
|
|
184
|
-
#
|
|
185
|
-
# @param (see Ably::Auth#create_token_request)
|
|
186
|
-
# @option (see Ably::Auth#create_token_request)
|
|
187
|
-
#
|
|
188
|
-
# @return [Ably::Util::SafeDeferrable]
|
|
189
|
-
# @yield [Models::TokenRequest]
|
|
190
|
-
#
|
|
191
|
-
# @example
|
|
192
|
-
# client.auth.create_token_request({ ttl: 3600 }, id: 'asd.asd') do |token_request|
|
|
193
|
-
# token_request #=> Ably::Models::TokenRequest
|
|
194
|
-
# end
|
|
195
|
-
def create_token_request(token_params = {}, auth_options = {}, &success_callback)
|
|
196
|
-
async_wrap(success_callback) do
|
|
197
|
-
create_token_request_sync(token_params, auth_options)
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
# Synchronous version of {#create_token_request}. See {Ably::Auth#create_token_request} for method definition
|
|
202
|
-
# @param (see Ably::Auth#authorize)
|
|
203
|
-
# @option (see Ably::Auth#authorize)
|
|
204
|
-
# @return [Ably::Models::TokenRequest]
|
|
205
|
-
#
|
|
206
|
-
def create_token_request_sync(token_params = {}, auth_options = {})
|
|
207
|
-
auth_sync.create_token_request(token_params, auth_options)
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
# Auth header string used in HTTP requests to Ably
|
|
211
|
-
# Will reauthorize implicitly if required and capable
|
|
212
|
-
#
|
|
213
|
-
# @return [Ably::Util::SafeDeferrable]
|
|
214
|
-
# @yield [String] HTTP authentication value used in HTTP_AUTHORIZATION header
|
|
215
|
-
#
|
|
216
|
-
def auth_header(&success_callback)
|
|
217
|
-
async_wrap(success_callback) do
|
|
218
|
-
auth_header_sync
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
# Synchronous version of {#auth_header}. See {Ably::Auth#auth_header} for method definition
|
|
223
|
-
# @return [String] HTTP authentication value used in HTTP_AUTHORIZATION header
|
|
224
|
-
#
|
|
225
|
-
def auth_header_sync
|
|
226
|
-
auth_sync.auth_header
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
def client_id_for_request_sync
|
|
230
|
-
auth_sync.client_id_for_request
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
# Auth params used in URI endpoint for Realtime connections
|
|
234
|
-
# Will reauthorize implicitly if required and capable
|
|
235
|
-
#
|
|
236
|
-
# @return [Ably::Util::SafeDeferrable]
|
|
237
|
-
# @yield [Hash] Auth params for a new Realtime connection
|
|
238
|
-
#
|
|
239
|
-
def auth_params(&success_callback)
|
|
240
|
-
fail_callback = lambda do |error, deferrable|
|
|
241
|
-
logger.error { "Failed to authenticate: #{error}" }
|
|
242
|
-
if error.kind_of?(Ably::Exceptions::BaseAblyException)
|
|
243
|
-
# Use base exception if it exists carrying forward the status codes
|
|
244
|
-
deferrable.fail Ably::Exceptions::AuthenticationFailed.new(error.message, nil, nil, error)
|
|
245
|
-
else
|
|
246
|
-
deferrable.fail Ably::Exceptions::AuthenticationFailed.new(error.message, 500, Ably::Exceptions::Codes::CLIENT_CONFIGURED_AUTHENTICATION_PROVIDER_REQUEST_FAILED)
|
|
247
|
-
end
|
|
248
|
-
end
|
|
249
|
-
async_wrap(success_callback, fail_callback) do
|
|
250
|
-
auth_params_sync
|
|
251
|
-
end
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
# Synchronous version of {#auth_params}. See {Ably::Auth#auth_params} for method definition
|
|
255
|
-
# @return [Hash] Auth params for a new Realtime connection
|
|
256
|
-
#
|
|
257
|
-
def auth_params_sync
|
|
258
|
-
auth_sync.auth_params
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
private
|
|
262
|
-
# The synchronous Auth class instanced by the Rest client
|
|
263
|
-
# @return [Ably::Auth]
|
|
264
|
-
def auth_sync
|
|
265
|
-
@auth_sync
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
def client
|
|
269
|
-
@client
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
# Sends an AUTH ProtocolMessage on the existing connection triggering
|
|
273
|
-
# an inline AUTH process, see #RTC8a
|
|
274
|
-
def perform_inline_auth(token)
|
|
275
|
-
logger.debug { "Performing inline AUTH with Ably using token #{token}" }
|
|
276
|
-
connection.send_protocol_message(
|
|
277
|
-
action: Ably::Models::ProtocolMessage::ACTION.Auth.to_i,
|
|
278
|
-
auth: { access_token: token.token }
|
|
279
|
-
)
|
|
280
|
-
end
|
|
281
|
-
end
|
|
282
|
-
end
|
|
283
|
-
end
|