Class: SocketServ

Inherits:
Object
  • Object
show all
Defined in:
lib/socket_serv.rb,
lib/socket_serv/version.rb

Defined Under Namespace

Modules: RailsHelper Classes: Client, Engine

Constant Summary collapse

VERSION =
"0.1.1"
API_VERSION =
"v1"

Class Method Summary collapse

Class Method Details

.base_uriObject



7
8
9
# File 'lib/socket_serv.rb', line 7

def self.base_uri
  ENV["SOCKETSERV_API_URL"] || "www.socketserv.com:443"
end

.configure(&block) ⇒ Object



20
21
22
# File 'lib/socket_serv.rb', line 20

def self.configure(&block)
  block.yield self
end

.mint_token(client_id = nil, client_secret = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/socket_serv.rb', line 24

def self.mint_token(client_id=nil, client_secret=nil)
  client_secret ||= ENV["SOCKETSERV_APP_SECRET"]
  client_id     ||= ENV["SOCKETSERV_APP_ID"]

  payload = {
    iss: "Application:#{client_id}",
    iat: Time.now.to_i,
    exp: 1.week.from_now.to_i
  }

  JWT.encode(payload, client_secret, "HS256")
end

.websocket_uriObject



11
12
13
14
15
16
17
18
# File 'lib/socket_serv.rb', line 11

def self.websocket_uri
  if base_uri =~ /:443$/
    uri = base_uri.gsub(/:443$/, '')
    "wss://#{uri}/ws"
  else
    "ws://#{uri}/ws"
  end
end