@@ -30,8 +30,8 @@ class Client
3030 #
3131 # @param [string] api_key your application api_key
3232 # @param [string] api_secret your application secret
33- # @param [string]
34- # @param [hash] options extra options
33+ # @param [float] timeout the timeout for the http requests
34+ # @param [hash] options extra options such as base_url
3535 #
3636 # @example initialized the client with a timeout setting
3737 # StreamChat::Client.new('my_key', 'my_secret', 3.0)
@@ -54,6 +54,19 @@ def initialize(api_key = '', api_secret = '', timeout = 6.0, **options)
5454 end
5555 end
5656
57+ # initializes a Stream Chat API Client from STREAM_KEY and STREAM_SECRET
58+ # environmental variables.
59+ def self . from_env
60+ Client . new ( ENV [ 'STREAM_KEY' ] , ENV [ 'STREAM_SECRET' ] )
61+ end
62+
63+ # Sets the underlying Faraday http client.
64+ #
65+ # @param [client] an instance of Faraday::Connection
66+ def set_http_client ( client )
67+ @conn = client
68+ end
69+
5770 def create_token ( user_id , exp = nil , iat = nil )
5871 payload = { user_id : user_id }
5972 payload [ 'exp' ] = exp unless exp . nil?
@@ -526,10 +539,9 @@ def make_http_request(method, relative_url, params: nil, data: nil)
526539 headers = get_default_headers
527540 headers [ 'Authorization' ] = @auth_token
528541 headers [ 'stream-auth-type' ] = 'jwt'
529- url = [ @base_url , relative_url ] . join ( '/' )
530542 params = { } if params . nil?
531543 params = ( get_default_params . merge ( params ) . sort_by { |k , _v | k . to_s } ) . to_h
532- url = "#{ url } ?#{ URI . encode_www_form ( params ) } "
544+ url = "#{ relative_url } ?#{ URI . encode_www_form ( params ) } "
533545
534546 body = data . to_json if %w[ patch post put ] . include? method . to_s
535547
0 commit comments