Class: Transfluent::Api

Inherits:
Object
  • Object
show all
Includes:
ApiHelper, TransfluentFileApi, TransfluentTextApi
Defined in:
lib/transfluent/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TransfluentFileApi

#file_read, #file_save, #file_status, #file_translate

Methods included from TransfluentTextApi

#add_text, #add_texts, #text_orders, #text_translated?, #texts_translate

Methods included from ApiHelper

#api_uri, #execute_get, #execute_post, #parse_response, #symbolize_array, #symbolize_hash

Constructor Details

#initialize(default_settings = {}) ⇒ Api

Creates a new instance if Transfluent Api

Parameters:

  • default_settings (Hash) (defaults to: {})

    default settings for some calls

Options Hash (default_settings):

  • auth_token (String)

    your auth token

  • group (String)

    default text group

  • language (Transfluent::Language)

    default text and file source language



21
22
23
24
25
26
27
28
# 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

Instance Attribute Details

#auth_tokenstring

The authentication token associated with this instance

Returns:

  • (string)


13
14
15
# File 'lib/transfluent/api.rb', line 13

def auth_token
  @auth_token
end

Instance Method Details

#authenticate(email, password) ⇒ string

Authenticate against the backend

Parameters:

  • email (string)

    Email address

  • password (string)

    Your password

Returns:

  • (string)

    authentication token



74
75
76
77
78
79
80
# 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_groupstring

Get the default text group

Returns:

  • (string)


33
34
35
# File 'lib/transfluent/api.rb', line 33

def default_group
  @defaults[:group]
end

#default_group=(value) ⇒ Object

Set the default text group

Parameters:

  • value (string)

    new default group for texts



40
41
42
# File 'lib/transfluent/api.rb', line 40

def default_group=(value)
  @defaults[:group] = value
end

#default_languageTransfluent::Language

Get the default language



47
48
49
# File 'lib/transfluent/api.rb', line 47

def default_language
  @defaults[:language]
end

#default_language=(value) ⇒ Object

Set the default language

Parameters:



54
55
56
# File 'lib/transfluent/api.rb', line 54

def default_language=(value)
  @defaults[:language] = value
end

#hello(world) ⇒ string

Echoes back the parameter prepended with Hello

Parameters:

  • world (string)

     any text

Returns:

  • (string)

    “Hello ” + world



62
63
64
65
66
# File 'lib/transfluent/api.rb', line 62

def hello world
  response = Net::HTTP.get(api_uri("/hello/" + world))
  
  parse_response response
end