Class: DolphinKit::YoudaoService
- Inherits:
-
Object
- Object
- DolphinKit::YoudaoService
- Defined in:
- lib/dolphin_kit/services/youdao_service.rb
Constant Summary collapse
- BASE_URL =
'https://fanyi.youdao.com'
Instance Method Summary collapse
- #call(text:) ⇒ Object
-
#initialize(keyfrom: nil, key: nil, endpoint: nil) ⇒ YoudaoService
constructor
A new instance of YoudaoService.
Constructor Details
#initialize(keyfrom: nil, key: nil, endpoint: nil) ⇒ YoudaoService
Returns a new instance of YoudaoService.
5 6 7 8 |
# File 'lib/dolphin_kit/services/youdao_service.rb', line 5 def initialize(keyfrom: nil, key: nil, endpoint: nil) @endpoint = "#{BASE_URL}/openapi.do" @keyfrom, @key = keyfrom, key end |
Instance Method Details
#call(text:) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dolphin_kit/services/youdao_service.rb', line 10 def call(text:) response = HTTP.get(@endpoint, params: build_params(text)) result = JSON.parse(response.body) if (code = result['errorCode'].to_i) > 0 @failure = FAILURES[code] else @failure = nil end result end |