get_google_translate 0.1.1 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f27c32d1dd744eebaa9ea32ecf0f1abfdb43d36
4
- data.tar.gz: 166f7aabcfbd62b7188257a174f88828e60f5d63
3
+ metadata.gz: 8e3a68876a230f818031b9bcbf512e0cfbae00de
4
+ data.tar.gz: 081821613a4623af5686614b6e95e50435489100
5
5
  SHA512:
6
- metadata.gz: 98ce27017fbdb474f5e8e8ac600c17b9f7057bcb500cf19f4758e07516fe2fa2800e3d5b736fbad564e2dbf6807f13972403728973294f253bbc48ef8c79c8d9
7
- data.tar.gz: a0a97aba352437cc39c5ac9a04e838083c1f0096d0d50f8c12ee175bf91e802bef185ca2bf88396759ed2dcdc003c296a097b056456c71a48d3cf03f423c8af7
6
+ metadata.gz: 3f2a2b4a088ba1e686da8c9787759a1279f79c9d737a123b457ac9b0a255a565ae9c78b54b37ff98c198c3443a5e2dfd00429009318d58e9416b1794af72b6dd
7
+ data.tar.gz: 636212097f43d90686db6e4146ec4da4fb085c40664359f9caaa01abd46a8a91bd8e3252168a69081ef1b7bb9def9bd9d764912e0953a9bf746b279a8936c408
data/README.md CHANGED
@@ -4,6 +4,11 @@ Welcome to your new gem! In this directory, you'll find the files you need to be
4
4
 
5
5
  TODO: Delete this and the text above, and describe your gem
6
6
 
7
+ ## Before Installation
8
+
9
+ Due to Google API payment issue, You have to appy Public API access Key from Google. https://console.developers.google.com
10
+ After you can use this gem with key.
11
+
7
12
  ## Installation
8
13
 
9
14
  Add this line to your application's Gemfile:
@@ -22,11 +27,11 @@ Or install it yourself as:
22
27
 
23
28
  ## Usage
24
29
 
25
- GetGoogleTranslate::Translate.new(soure, target, text)
30
+ GetGoogleTranslate::Translate.new(key, soure, target, text)
26
31
 
27
32
  example:
28
33
 
29
- GetGoogleTranslate::Translate.new('en', 'ja', "How's the weather today in Tokyo!!")
34
+ GetGoogleTranslate::Translate.new('AIzaSyAULB3hd-LiCaCHRRvZp_-AJUjoAm2jlJE', 'en', 'ja', "How's the weather today in Tokyo!!")
30
35
 
31
36
  どのように天気は東京で、今日です!
32
37
 
@@ -38,5 +43,5 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
38
43
 
39
44
  ## Contributing
40
45
 
41
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/get_google_translate. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jct808/get_google_translate. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
42
47
 
@@ -5,9 +5,9 @@ require 'json'
5
5
  module GetGoogleTranslate
6
6
 
7
7
  class Translate
8
- def self.new(source, target, text)
8
+ def self.new(key, source, target, text)
9
9
  # Generate Key From Google API console
10
- client = Google::APIClient.new(:key => "AIzaSyBWXUwP2HvBOY_mmMWxmtx-l092eqXXf7E",
10
+ client = Google::APIClient.new(:key => key,
11
11
  :application_name => "getGoogleTranslate", :application_version => 1, :authorization => nil )
12
12
 
13
13
  # Catch Exception if there is something wrong
@@ -25,8 +25,15 @@ module GetGoogleTranslate
25
25
  # Encoding translate Context
26
26
  result.body.force_encoding("UTF-8")
27
27
  # Get only translateText from query result
28
- translatedText = JSON.parse(result.body)
29
- return translatedText["data"]["translations"][0]["translatedText"]
28
+ translatedText = JSON.parse(result.body)
29
+
30
+ # Check it does return a error from google server
31
+ if translatedText["error"] != nil
32
+ return translatedText["error"]["message"]
33
+ else
34
+ return translatedText["data"]["translations"][0]["translatedText"]
35
+ end
36
+
30
37
  rescue Exception => e
31
38
  # Output the error message
32
39
  return "Error: #{e}"
@@ -1,3 +1,3 @@
1
1
  module GetGoogleTranslate
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: get_google_translate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Tai
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-12 00:00:00.000000000 Z
11
+ date: 2015-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler