Class: Lymbix::Base
- Inherits:
-
Object
- Object
- Lymbix::Base
- Defined in:
- lib/lymbix/base.rb
Overview
The Base class is the most used class in the Lymbix gem. It incorporates all the methods used to tonalize.
To begin using the base class, you must authenticate using one of the authenticate methods and store the results in a variable. On a successful authentication, you can start calling tonalize methods immediatly.
Instance Attribute Summary collapse
-
#auth_key ⇒ Object
The user’s authentication key.
-
#error_messages ⇒ Object
Error messages that were caught during the authentication.
Instance Method Summary collapse
-
#flag_response(phrase, api_method_requested, api_version, callback_url = nil) ⇒ Object
Flags a phrase to be re-evaluated.
-
#initialize(auth_key) ⇒ Base
constructor
API Version.
-
#tonalize(article, return_fields = [], accept_type = "application/json") ⇒ Object
Tonalizes text using version 2.1 of ToneAPI.
-
#tonalize_article(article, accept_type = "application/json") ⇒ Object
Tonalizes text using version 2.0 of ToneAPI.
-
#tonalize_detailed(article, return_fields = [], accept_type = "application/json") ⇒ Object
Tonalizes article using version 2.1 of ToneAPI.
-
#tonalize_multiple(articles, return_fields = [], accept_type = "application/json") ⇒ Object
Tonalizes mutliple articles using version 2.1 of ToneAPI.
Constructor Details
#initialize(auth_key) ⇒ Base
API Version
18 19 20 |
# File 'lib/lymbix/base.rb', line 18 def initialize(auth_key) @auth_key = auth_key end |
Instance Attribute Details
#auth_key ⇒ Object
The user’s authentication key
13 14 15 |
# File 'lib/lymbix/base.rb', line 13 def auth_key @auth_key end |
#error_messages ⇒ Object
Error messages that were caught during the authentication
15 16 17 |
# File 'lib/lymbix/base.rb', line 15 def @error_messages end |
Instance Method Details
#flag_response(phrase, api_method_requested, api_version, callback_url = nil) ⇒ Object
Flags a phrase to be re-evaluated
52 53 54 55 |
# File 'lib/lymbix/base.rb', line 52 def flag_response(phrase, api_method_requested, api_version, callback_url = nil) @version = 2.1 response = request(:post, 'flag_response', {:phrase => phrase, :api_method_requested => api_method_requested, :api_version => api_version, :callback_url => callback_url}).data end |
#tonalize(article, return_fields = [], accept_type = "application/json") ⇒ Object
Tonalizes text using version 2.1 of ToneAPI
23 24 25 26 27 |
# File 'lib/lymbix/base.rb', line 23 def tonalize(article, return_fields = [], accept_type = "application/json") @version = 2.1 accept_type == "application/xml" ? return_fields = return_fields_xml(return_fields) : return_fields = return_fields_json(return_fields) response = request(:post, 'tonalize',{:article => article, :return_fields => return_fields}, {:accept => accept_type}).data end |
#tonalize_article(article, accept_type = "application/json") ⇒ Object
Tonalizes text using version 2.0 of ToneAPI
30 31 32 33 |
# File 'lib/lymbix/base.rb', line 30 def tonalize_article(article, accept_type = "application/json") @version = 2.0 response = request(:post, 'tonalize_article',{:article => article}, {:accept => accept_type}).data end |
#tonalize_detailed(article, return_fields = [], accept_type = "application/json") ⇒ Object
Tonalizes article using version 2.1 of ToneAPI. With the return_fields param you can now specify which field to get back from the API. The detailed response includes the tonalization data for the article and all sentences found in the article
45 46 47 48 49 |
# File 'lib/lymbix/base.rb', line 45 def tonalize_detailed(article, return_fields = [], accept_type = "application/json") @version = 2.1 accept_type == "application/xml" ? return_fields = return_fields_xml(return_fields) : return_fields = return_fields_json(return_fields) response = request(:post, 'tonalize_detailed',{:article => article, :return_fields => return_fields}, {:accept => accept_type}).data end |
#tonalize_multiple(articles, return_fields = [], accept_type = "application/json") ⇒ Object
Tonalizes mutliple articles using version 2.1 of ToneAPI. With the return_fields param you can now specify which field to get back from the API.
36 37 38 39 40 41 |
# File 'lib/lymbix/base.rb', line 36 def tonalize_multiple(articles, return_fields = [], accept_type = "application/json") @version = 2.1 accept_type == "application/xml" ? return_fields = return_fields_xml(return_fields) : return_fields = return_fields_json(return_fields) accept_type == "application/xml" ? articles = articles_xml(articles) : articles = articles_json(articles) response = request(:post, 'tonalize_multiple',{:articles => articles, :return_fields => return_fields}, {:accept => accept_type}).data end |