module Smartling::Auth
Methods for authenticating a Smartling
user with the API.
Constants
- Error
- Failed
- Token
Attributes
access_token[R]
refresh_token[R]
user_id[R]
user_secret[R]
Public Instance Methods
authenticate() { |token| ... }
click to toggle source
# File lib/smartling/auth.rb, line 11 def authenticate refresh_token! if access_token&.expired? && refresh_token&.valid? authenticate! unless access_token&.valid? token = access_token.to_s return token unless block_given? yield token end
authenticate!()
click to toggle source
# File lib/smartling/auth.rb, line 32 def authenticate! path = '/auth-api/v2/authenticate' payload = { userIdentifier: user_id, userSecret: user_secret }.to_json headers = { 'Content-Type' => 'application/json' } resp = self.class.post(path, headers: headers, body: payload) resp = HipsterHash[resp.parsed_response].response raise(Failed, resp) unless resp.code == 'SUCCESS' self.tokens = resp.data true end
refresh_token!()
click to toggle source
# File lib/smartling/auth.rb, line 21 def refresh_token! path = '/auth-api/v2/authenticate/refresh' headers = { 'Content-Type' => 'application/json' } payload = { refreshToken: refresh_token.to_s }.to_json resp = self.class.post(path, headers: headers, query: payload) resp = HipsterHash[resp.parsed_response].response raise(Failed, resp) unless resp.code == 'SUCCESS' self.tokens = resp.data true end
tokens=(data)
click to toggle source
# File lib/smartling/auth.rb, line 43 def tokens=(data) @access_token = Token.new(data.accessToken, data.expiresIn) @refresh_token = Token.new(data.refreshToken, data.refreshExpiresIn) end