Class: WatsonLanguage::ActiveMethod::Base

Inherits:
Extra
  • Object
show all
Includes:
Generators::LanguageRequest
Defined in:
lib/watson-language-translator/active_method/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Generators::LanguageRequest

#base_url_request, #json_parser, #rest_client_api

Methods inherited from Extra

add_response_field, #result

Constructor Details

#initialize(text = nil, options = {}) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
14
# File 'lib/watson-language-translator/active_method/base.rb', line 7

def initialize(text = nil, options={})
  @text = text
  @username = WatsonLanguage.username
  @password = WatsonLanguage.password
  @options = options
  @http_method = fetch_http_method
  @json_result = request
end

Instance Attribute Details

#http_methodObject

Returns the value of attribute http_method.



5
6
7
# File 'lib/watson-language-translator/active_method/base.rb', line 5

def http_method
  @http_method
end

#json_resultObject

Returns the value of attribute json_result.



5
6
7
# File 'lib/watson-language-translator/active_method/base.rb', line 5

def json_result
  @json_result
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/watson-language-translator/active_method/base.rb', line 5

def options
  @options
end

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/watson-language-translator/active_method/base.rb', line 5

def password
  @password
end

#textObject

Returns the value of attribute text.



5
6
7
# File 'lib/watson-language-translator/active_method/base.rb', line 5

def text
  @text
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/watson-language-translator/active_method/base.rb', line 5

def username
  @username
end

Instance Method Details

#fetch_http_methodObject



26
27
28
29
30
31
32
33
34
# File 'lib/watson-language-translator/active_method/base.rb', line 26

def fetch_http_method
  if @options[:http_method]
    result = options[:http_method]
    @options.delete(:http_method)
  else
    result = "get"
  end
  return result.to_sym
end

#params_addressableObject



20
21
22
23
24
# File 'lib/watson-language-translator/active_method/base.rb', line 20

def params_addressable
  uri = Addressable::URI.new
  uri.query_values = @options
  uri.query
end

#requestObject



16
17
18
# File 'lib/watson-language-translator/active_method/base.rb', line 16

def request
  json_parser(endpoint)
end