Class: Transfluent::Api
- Inherits:
-
Object
- Object
- Transfluent::Api
- Includes:
- ApiHelper, TransfluentFileApi, TransfluentTextApi
- Defined in:
- lib/transfluent/api.rb
Instance Attribute Summary collapse
-
#auth_token ⇒ string
The authentication token associated with this instance.
Instance Method Summary collapse
-
#authenticate(email, password) ⇒ string
Authenticate against the backend.
-
#default_group ⇒ string
Get the default text group.
-
#default_group=(value) ⇒ Object
Set the default text group.
-
#default_language ⇒ Transfluent::Language
Get the default language.
-
#default_language=(value) ⇒ Object
Set the default language.
-
#hello(world) ⇒ string
Echoes back the parameter prepended with Hello.
-
#initialize(default_settings = {}) ⇒ Api
constructor
Creates a new instance if Transfluent Api.
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
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_token ⇒ string
The authentication token associated with this instance
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
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_group ⇒ string
Get the default text group
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
40 41 42 |
# File 'lib/transfluent/api.rb', line 40 def default_group=(value) @defaults[:group] = value end |
#default_language ⇒ Transfluent::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
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
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 |