class Unbabel::Client

Constants

ENDPOINT
SANDBOX
TEST_MODE

Attributes

token[RW]
username[RW]

Public Class Methods

new(options = {}) { |self| ... } click to toggle source
# 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

Public Instance Methods

credentials() click to toggle source
# File lib/unbabel/client.rb, line 25
def credentials
  {
    username: username,
    token:    token
  }
end
credentials?() click to toggle source
# File lib/unbabel/client.rb, line 32
def credentials?
  credentials.values.all?
end

Private Instance Methods

validate_credentials!() click to toggle source

 Ensures that all necessary credentials  are set during configuration.

# File lib/unbabel/client.rb, line 39
def validate_credentials!
  credentials.each do |credential, value|
    next if !value.nil? && value.is_a?(String)
    fail(ArgumentError.new("Invalid #{credential}, it's value: #{value.inspect} must be a string."))
  end
end