shvets-google_translate 0.5.7 → 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -11,4 +11,9 @@
11
11
 
12
12
  == Version 0.5.7
13
13
 
14
- * Removing text duplication for help
14
+ * Removing text duplication from help
15
+
16
+ == Version 0.5.8
17
+
18
+ * Merging changes from bragi: removing warnings, adding exceptions
19
+
data/Rakefile CHANGED
@@ -39,7 +39,7 @@ end
39
39
  desc "Run gem code locally"
40
40
  task :"run:gem" do
41
41
  command = "bin/translate " + ENV['params']
42
- puts ruby "#{command}"
42
+ puts ruby("#{command}")
43
43
  end
44
44
 
45
45
  desc "test gem compatibility with github"
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{google_translate}
5
- s.version = "0.5.7"
5
+ s.version = "0.5.8"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
 
@@ -19,35 +19,41 @@ module Google
19
19
  end
20
20
 
21
21
  class Translator
22
+ class MissingFromLanguage < Exception; end
23
+ class MissingToLanguage < Exception; end
24
+ class MissingTextLanguage < Exception; end
25
+ class TranslateServerIsDown < Exception; end
26
+ class InvalidResponse < Exception; end
27
+ class MissingText < Exception; end
28
+ class MissingTestText < MissingText; end
29
+
22
30
  URL_STRING = "http://ajax.googleapis.com/ajax/services/language/"
23
31
  URL2_STRING = "http://translate.google.com"
24
32
 
25
33
  def translate(from, to, from_text, options={})
26
- raise Exception.new :missing_from_language if from.nil?
27
- raise Exception.new :missing_to_language if to.nil?
28
- raise Exception.new :missing_text if from_text.nil?
34
+ raise(MissingFromLanguage) if from.nil?
35
+ raise(MissingToLanguage) if to.nil?
36
+ raise(MissingTextLanguage) if from_text.nil?
29
37
 
30
38
  request = URL_STRING + "translate?v=1.0&langpair=#{from}%7C#{to}&q=" + CGI.escape(from_text)
31
39
 
32
40
  begin
33
41
  response = call_service(request, [:response_status, :response_details, :response_data])
34
42
 
35
- raise Exception.new :translate_server_is_down if response.empty?
43
+ raise(TranslateServerIsDown) if response.empty?
36
44
 
37
- raise Exception.new response[:response_details] if response[:response_status] != 200 # success
45
+ raise(InvalidResponse, response[:response_details]) if response[:response_status] != 200 # success
38
46
 
39
47
  to_text = response[:response_data]['translatedText']
40
48
 
41
- # to_text = encode_text(to_text) if to == :ru
42
-
43
49
  (options[:html]) ? CGI.unescapeHTML(to_text) : to_text
44
50
  rescue OpenURI::HTTPError
45
- raise Exception.new :translate_server_is_down
51
+ raise(TranslateServerIsDown)
46
52
  end
47
53
  end
48
54
 
49
- def detect_language test_text
50
- raise Exception.new :missing_test_text if test_text.nil?
55
+ def detect_language(test_text)
56
+ raise(MissingTestText) if test_text.nil?
51
57
 
52
58
  request = URL_STRING + "detect?v=1.0&q=" + CGI.escape(test_text)
53
59
 
@@ -55,13 +61,11 @@ module Google
55
61
  response = call_service(request, [:response_data])
56
62
  response_data = response[:response_data]
57
63
 
58
- raise Exception.new :translate_server_is_down if response.empty?
59
- #raise Exception.new :unreliable_detection if !response_data['isReliable']
64
+ raise(TranslateServerIsDown) if response.empty?
60
65
 
61
66
  response_data
62
- #
63
67
  rescue OpenURI::HTTPError
64
- raise Exception.new :translate_server_is_down
68
+ raise(TranslateServerIsDown)
65
69
  end
66
70
  end
67
71
 
@@ -44,7 +44,7 @@ module Google
44
44
  end
45
45
 
46
46
  it "should return unreliable flag if language is not recognized" do
47
- @translator.detect_language("azafretmkldt")['isReliable'].should be false
47
+ @translator.detect_language("azafretmkldt")['isReliable'].should be_false
48
48
  end
49
49
 
50
50
  it "should return list of supportd languages" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shvets-google_translate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shvets