google_translation 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +15 -0
  2. data/README.md +34 -0
  3. data/lib/google_translation.rb +70 -0
  4. metadata +73 -0
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MmZlM2UwNGVmNjg5YTU5ZDgxNTZkMzNkYTk2MzljMjk1NzA1YWY1NA==
5
+ data.tar.gz: !binary |-
6
+ ZDQ3ZDczNTkyMGU2OTJiZWMxYWUwMDU2ZTYxNDE2YmZlMGNjMGE3ZQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ODU3YjMyNjVlNGIwOTM3MTZhZThkYjEzNzI5MDFlNTUyZGQxMmM1MGQ2ZmM5
10
+ NmU2YTE1MTJhZGEwYjI0NzFlNDAzZTgxZGVmZWM2ODE0YTE2N2RmMzJhMDE1
11
+ ZTZmYmFlOTIwYTI1ZjY3NGNkMjQ3Yjk0MTY4OGZkZDBjZTUyMzI=
12
+ data.tar.gz: !binary |-
13
+ ZWYyODFlYTgyYjVjZWFlMGIyMTIyOGRhODFkYTlmODliZTc1NzhiOGUwNDRm
14
+ MGNlYjAzMzNmZTM0M2U5YTJiNTIzYzk1MWEyZDBmYmYyZjY0YmVhNmQ5YTUy
15
+ NWNjNzYyODI4ZmRhY2QyMTEwMDQ5NGE4YzI2ZmYwYjY5ZjE1OGY=
@@ -0,0 +1,34 @@
1
+ Google Translation Client
2
+ =========================
3
+
4
+ This is a minimalistic API client for Google Translation API
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Installation is a piece of cake:
10
+
11
+ To get started, install composer in your project:
12
+
13
+ $ gem install google-translate-mini
14
+
15
+
16
+ Usage
17
+ -----
18
+
19
+ Using the Google Translation client is easy:
20
+
21
+ ``` ruby
22
+
23
+ # Translate from one language to another
24
+ client = Translate.new('YOUR API KEY')
25
+ client.translate(:source => 'en', :target => 'de', :q => @eng)
26
+
27
+ # Discover available languages
28
+ client.discover()
29
+
30
+ # Detect a language
31
+ client.detect("If wishes were fishes we'd all cast nets")
32
+
33
+
34
+ ```
@@ -0,0 +1,70 @@
1
+ require 'json'
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+
5
+ class Translate < Hash
6
+
7
+ BASE = 'https://www.googleapis.com'
8
+ PATH = '/language/translate/v2/'
9
+ AGENT = 'Mini-Goolge-Translate-Client'
10
+
11
+ attr_accessor :user_agent
12
+
13
+ # Require key at initialization
14
+ #
15
+ # @param [string] key | Goolge API key
16
+ def initialize(key)
17
+ self['key'] = key
18
+ self.user_agent = AGENT
19
+ end
20
+
21
+ # Method for tranlating
22
+ #
23
+ # @param [options]
24
+ # @option options [string] :source language to translate from
25
+ # @option options [string] :target language to translate to
26
+ # @option options [string] :q string to be translated
27
+ def translate(options={})
28
+ self.call('', options)
29
+ end
30
+
31
+ # Method for disocvering supported languages
32
+ def discover()
33
+ self.call('languages', {})
34
+ end
35
+
36
+ # Method for dectecting language of text input
37
+ #
38
+ # @param [string] text language to interpret
39
+ def detect(text)
40
+ self.call('detect', q: text.to_str)
41
+ end
42
+
43
+ # Set URL and make request
44
+ #
45
+ # @param [string] path file path for service
46
+ # @param [hash] options hash to convert into query
47
+ def call(path, options)
48
+ self.url(path, options)
49
+ resp = self.conn.get
50
+ JSON.parse(resp.body)
51
+ end
52
+
53
+ # Build Faraday connection for HTTP request
54
+ def conn
55
+ Faraday.new(:url => @url) do |c|
56
+ c.adapter Faraday.default_adapter
57
+ c.headers['User-Agent'] = self.user_agent
58
+ c.params = self
59
+ end
60
+ end
61
+
62
+ # Assemble URL and query params
63
+ #
64
+ # @param [string] path path file path for service
65
+ # @param [hash] options hash to convert into query
66
+ def url(path, options)
67
+ self.merge!(options) unless options.empty?
68
+ @url = BASE + PATH + path
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google_translation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Travis Tillotson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
41
+ description: Simple API client as an interface for Google Translation API
42
+ email: tillotson.travis@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files:
46
+ - README.md
47
+ files:
48
+ - lib/google_translation.rb
49
+ - README.md
50
+ homepage: https://github.com/Opus1no2/Google-Translation-Gem
51
+ licenses: []
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.0.4
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Mini Translation Client for Google Translate API
73
+ test_files: []