Module: YoudaoFanyi

Defined in:
lib/youdao-fanyi/config.rb,
lib/youdao-fanyi.rb,
lib/youdao-fanyi/result.rb,
lib/youdao-fanyi/request.rb

Overview

require ‘open-uri’

Defined Under Namespace

Modules: Config Classes: Request, Result, YoudaoFanyiError

Class Method Summary collapse

Class Method Details

.search_json(q) ⇒ Object

Query a word or sentence. Param: q The query word or sentence. Return: A String of doctype JSON.



14
15
16
17
18
19
20
21
# File 'lib/youdao-fanyi.rb', line 14

def self.search_json(q)
  if q.is_a?(String) && q.length > 0 && q.length <= 200
    Request.get(q, :json)
  else
    puts "The query must be a String and its length should "+
         "be between 1 to 200."
  end
end

.search_jsonp(q) ⇒ Object

Query a word or sentence. Param: q The query word or sentence. Return: A String of doctype JSONP.



38
39
40
41
42
43
44
45
# File 'lib/youdao-fanyi.rb', line 38

def self.search_jsonp(q)
  if q.is_a?(String) && q.length > 0 && q.length <= 200
    Request.get(q, :jsonp)
  else
    puts "The query must be a String and its length should "+
         "be between 1 to 200."
  end
end

.search_result_obj(q) ⇒ Object

Query a word or sentence. Param: q The query word or sentence. Return: A YoudaoFanyi::Result object.



50
51
52
53
54
55
56
57
# File 'lib/youdao-fanyi.rb', line 50

def self.search_result_obj(q)
  if q.is_a?(String) && q.length > 0 && q.length <= 200
    Result.new(search_xml(q))
  else
    puts "The query must be a String and its length should "+
         "be between 1 to 200."
  end
end

.search_xml(q) ⇒ Object

Query a word or sentence. Param: q The query word or sentence. Return: A String of doctype XML.



26
27
28
29
30
31
32
33
# File 'lib/youdao-fanyi.rb', line 26

def self.search_xml(q)
  if q.is_a?(String) && q.length > 0 && q.length <= 200
    Request.get(q, :xml)
  else
    puts "The query must be a String and its length should "+
         "be between 1 to 200."
  end
end