class Transfluent::Api

Attributes

auth_token[RW]

The authentication token associated with this instance

@return [string]

Public Class Methods

new(default_settings = {}) click to toggle source

Creates a new instance if Transfluent Api

@param [Hash] default_settings default settings for some calls @option default_settings [String] auth_token your auth token @option default_settings [String] group default text group @option default_settings [Transfluent::Language] language default text and file source language

# File lib/transfluent/api.rb, line 21
def initialize default_settings = {}
  @auth_token = default_settings[:auth_token]
  @defaults = default_settings

  if @defaults.has_key? :api_root
    @_ROOT_URL = @defaults.delete :api_root
  end
end

Public Instance Methods

authenticate(email, password) click to toggle source

Authenticate against the backend

@param [string] email Email address @param [string] password Your password

@return [string] authentication token

# File lib/transfluent/api.rb, line 74
def authenticate email, password
  uri = api_uri('authenticate')
  uri.query = URI.encode_www_form({'email' => email, 'password' => password})
  response = parse_response(Net::HTTP.get(uri))
  
  @auth_token = response[:token].to_s 
end
default_group() click to toggle source

Get the default text group

@return [string]

# File lib/transfluent/api.rb, line 33
def default_group
  @defaults[:group]
end
default_group=(value) click to toggle source

Set the default text group

@param [string] value new default group for texts

# File lib/transfluent/api.rb, line 40
def default_group=(value)
  @defaults[:group] = value
end
default_language() click to toggle source

Get the default language

@return [Transfluent::Language]

# File lib/transfluent/api.rb, line 47
def default_language
  @defaults[:language]
end
default_language=(value) click to toggle source

Set the default language

@param [Transfluent::Language] value new default language for texts

# File lib/transfluent/api.rb, line 54
def default_language=(value)
  @defaults[:language] = value
end
hello(world) click to toggle source

Echoes back the parameter prepended with Hello

@param world [string] any text @return [string] “Hello ” + world

# File lib/transfluent/api.rb, line 62
def hello world
  response = Net::HTTP.get(api_uri("/hello/" + world))
  
  parse_response response
end