Class: FanyiAPI::Strategies::Youdao
- Defined in:
- lib/fanyi_api/strategies/youdao.rb
Instance Method Summary collapse
- #api_url ⇒ Object
-
#initialize(params = {}) ⇒ Youdao
constructor
A new instance of Youdao.
- #query_key ⇒ Object
- #request_url ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Youdao
Returns a new instance of Youdao.
6 7 8 9 10 11 12 13 |
# File 'lib/fanyi_api/strategies/youdao.rb', line 6 def initialize(params={}) @options = { host: "http://fanyi.youdao.com/openapi.do", version: "1.1", doctype: "json", type: "data" }.merge(params) end |
Instance Method Details
#api_url ⇒ Object
15 16 17 |
# File 'lib/fanyi_api/strategies/youdao.rb', line 15 def api_url @api_url ||= "#{@options[:host]}?type=#{@options[:type]}&doctype=#{@options[:doctype]}&version=#{@options[:version]}" end |
#query_key ⇒ Object
26 27 28 |
# File 'lib/fanyi_api/strategies/youdao.rb', line 26 def query_key :q end |
#request_url ⇒ Object
19 20 21 22 23 24 |
# File 'lib/fanyi_api/strategies/youdao.rb', line 19 def request_url raise InvalidKey, "Key is not provided!" \ if @options[:keyfrom].nil? || @options[:key].nil? @request_url ||= api_url + "&keyfrom=" + @options[:keyfrom] + "&key=" + @options[:key] end |