youdao-fanyi 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,7 +6,7 @@ This is a [Youdao Fanyi][YoudaoFanyi] API wrapper written in Ruby.
6
6
  ## Pre Job ##
7
7
  Before coding, you should go to [Youdao Fanyi API][YoudaoFanyiAPI] for an API key.
8
8
 
9
- **Caution**: Each key can only request less than 1000 times per hour.
9
+ **Caution**: Each key can request less than 1000 times per hour.
10
10
 
11
11
  ## Example ##
12
12
 
@@ -28,7 +28,7 @@ Before coding, you should go to [Youdao Fanyi API][YoudaoFanyiAPI] for an API ke
28
28
 
29
29
  Here is an ***xml*** sample:
30
30
 
31
- http://fanyi.youdao.com/fanyiapi.do?keyfrom=<keyfrom>&key=<key>&type=data&doctype=xml&version=1.1&q=这里是有道翻译API
31
+ http://fanyi.youdao.com/fanyiapi.do?keyfrom=<keyfrom>&key=<key>&type=data&doctype=xml&version=1.1&q=这里是有道翻译API
32
32
 
33
33
  <?xml version="1.0" encoding="UTF-8"?>
34
34
  <youdao-fanyi>
@@ -42,7 +42,7 @@ http://fanyi.youdao.com/fanyiapi.do?keyfrom=<keyfrom>&key=<key>&type=data&doctyp
42
42
 
43
43
  Here is a ***json*** sample:
44
44
 
45
- http://fanyi.youdao.com/fanyiapi.do?keyfrom=<keyfrom>&key=<key>&type=data&doctype=json&version=1.1&q=翻译
45
+ http://fanyi.youdao.com/fanyiapi.do?keyfrom=<keyfrom>&key=<key>&type=data&doctype=json&version=1.1&q=翻译
46
46
 
47
47
  {
48
48
  "errorCode":0
@@ -66,7 +66,7 @@ http://fanyi.youdao.com/fanyiapi.do?keyfrom=<keyfrom>&key=<key>&type=data&doctyp
66
66
 
67
67
  Here is a ***jsonp*** sample:
68
68
 
69
- http://fanyi.youdao.com/fanyiapi.do?keyfrom=<keyfrom>&key=<key>&type=data&doctype=jsonp&callback=show&version=1.1&q=API
69
+ http://fanyi.youdao.com/fanyiapi.do?keyfrom=<keyfrom>&key=<key>&type=data&doctype=jsonp&callback=show&version=1.1&q=API
70
70
 
71
71
  show({
72
72
  "errorCode":0
@@ -87,7 +87,7 @@ http://fanyi.youdao.com/fanyiapi.do?keyfrom=<keyfrom>&key=<key>&type=data&doctyp
87
87
  });
88
88
 
89
89
  ## Contributors ##
90
- * ZHANG Hailong (https://github.com/zhhailon)
90
+ * ZHANG Hailong [https://github.com/zhhailon]
91
91
 
92
92
 
93
93
  [YoudaoFanyi]: http://fanyi.youdao.com "Youdao Fanyi"
@@ -2,21 +2,28 @@ require 'crack'
2
2
 
3
3
  module YoudaoFanyi
4
4
  class Result
5
- attr_reader :error_code, :query, :translation, :explains,
6
- :web_explains
5
+ attr_reader :error_code, :query, :translation, :explains, :web_explains
7
6
 
8
7
  def initialize(xml_data)
9
8
  data = parse(xml_data)["youdao_fanyi"]
9
+ return if data.nil?
10
10
  @error_code = data["errorCode"]
11
11
  @query = data["query"]
12
- @translation = data["translation"]["paragraph"]
13
- @explains = data["basic"]["explains"]["ex"]
14
- @web_explains = data["web"]["explain"]
12
+ @translation = data["translation"]["paragraph"] unless data["translation"].nil?
13
+ unless data.nil?
14
+ unless data["basic"].nil?
15
+ unless data["basic"]["explains"].nil?
16
+ @explains = data["basic"]["explains"]["ex"]
17
+ end
18
+ end
19
+ end
20
+ @web_explains = data["web"]["explain"] unless data["web"].nil?
15
21
  end
16
22
 
17
23
  private
18
- def parse(xml)
19
- Crack::XML.parse(xml)
20
- end
24
+ def parse(xml)
25
+ Crack::XML.parse(xml)
26
+ end
21
27
  end
22
- end
28
+ end
29
+
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'youdao-fanyi'
3
- s.version = "0.0.1"
3
+ s.version = "0.0.2"
4
4
  s.authors = ["ZHANG Hailong"]
5
- s.date = '2011-12-01'
5
+ s.date = '2012-04-01'
6
6
  s.summary = 'Youdao Fanyi (Translation) API Wrapper'
7
7
  s.description = 'A gem to wrap the Youdao Fanyi (fanyi.youdao.com) API. "fanyi" is "translation" in Chinese.'
8
8
  s.email = 'zhhailon@gmail.com'
@@ -18,3 +18,4 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.add_dependency('crack', [">= 0"])
20
20
  end
21
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: youdao-fanyi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-01 00:00:00.000000000Z
12
+ date: 2012-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: crack
16
- requirement: &74031110 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,12 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *74031110
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  description: A gem to wrap the Youdao Fanyi (fanyi.youdao.com) API. "fanyi" is "translation"
26
31
  in Chinese.
27
32
  email: zhhailon@gmail.com
@@ -56,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
61
  version: '0'
57
62
  requirements: []
58
63
  rubyforge_project:
59
- rubygems_version: 1.8.11
64
+ rubygems_version: 1.8.21
60
65
  signing_key:
61
66
  specification_version: 3
62
67
  summary: Youdao Fanyi (Translation) API Wrapper