Class: Layer::Client::REST

Inherits:
Layer::Client show all
Defined in:
lib/layer/client/rest.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Layer::Client

configure, #delete, #get, #head, normalize_id, #options, #patch, #post, #put

Constructor Details

#initialize(app_id = self.class.app_id, &block) ⇒ REST


18
19
20
21
22
# File 'lib/layer/client/rest.rb', line 18

def initialize(app_id = self.class.app_id, &block)
  @app_id = self.class.normalize_id(app_id)
  @block = block
  authenticate
end

Instance Attribute Details

#app_idObject (readonly)

Returns the value of attribute app_id


16
17
18
# File 'lib/layer/client/rest.rb', line 16

def app_id
  @app_id
end

#blockObject (readonly)

Returns the value of attribute block


16
17
18
# File 'lib/layer/client/rest.rb', line 16

def block
  @block
end

#tokenObject (readonly)

Returns the value of attribute token


16
17
18
# File 'lib/layer/client/rest.rb', line 16

def token
  @token
end

Class Method Details

.authenticate(app_id, nonce = nil) ⇒ Object


5
6
7
8
9
10
11
12
13
14
# File 'lib/layer/client/rest.rb', line 5

def self.authenticate(app_id, nonce = nil)
  client = Layer::Client.new

  nonce ||= client.post('/nonces')['nonce']

  identity_token = yield(nonce)

  response = client.post('/sessions', { identity_token: identity_token, app_id: app_id })
  response['session_token']
end