Class: Unbabel::Client

Inherits:
Object
  • Object
show all
Includes:
LanguangePair, Tone, Topic, Translation
Defined in:
lib/unbabel/client.rb

Constant Summary collapse

TEST_MODE =
ENV['UNBABEL_SANDBOX'] == 'true'
SANDBOX =
'http://sandbox.unbabel.com/tapi/v2'
ENDPOINT =
TEST_MODE ? SANDBOX : 'https://unbabel.com/tapi/v2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Translation

#find, #request_translation, #translations

Methods included from Tone

#tones

Methods included from Topic

#topics

Methods included from LanguangePair

#language_pairs

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:



15
16
17
18
19
20
21
22
23
# File 'lib/unbabel/client.rb', line 15

def initialize(options = {})
  @username = options[:username]
  @token    = options[:token]

  yield(self) if block_given?
  validate_credentials!
  Unirest.default_header('Content-Type', 'application/json')
  Unirest.default_header('Authorization', "ApiKey #{@username}:#{@token}")
end

Instance Attribute Details

#tokenObject

Returns the value of attribute token.



12
13
14
# File 'lib/unbabel/client.rb', line 12

def token
  @token
end

#usernameObject

Returns the value of attribute username.



12
13
14
# File 'lib/unbabel/client.rb', line 12

def username
  @username
end

Instance Method Details

#credentialsObject



25
26
27
28
29
30
# File 'lib/unbabel/client.rb', line 25

def credentials
  {
    username: username,
    token:    token
  }
end

#credentials?Boolean

Returns:



32
33
34
# File 'lib/unbabel/client.rb', line 32

def credentials?
  credentials.values.all?
end