itranslate4 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/templates/translate.rb +3 -4
- data/lib/translate/version.rb +1 -1
- data/lib/translate.rb +37 -32
- data/test/dummy/config/initializers/translate.rb +3 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9476114e1b1b829c17f2271737b4388a016b07d8
|
4
|
+
data.tar.gz: f292a2723607172b1b3382325d6b0652d457fb86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ddb8248f37bdf7cc7bbc3e429df23e9122d9d463f8a03c9624e19eb9e3cc4f93c4c715dd77cd421ac5b8beb11f650365be2271316b1c28e52fc71d943b009fb
|
7
|
+
data.tar.gz: 89f5e3ba7bd94a7be94e889eb8b88e3e23ad9035b29ac2fc7817dfb19f09e7994379375632168e9a7963a76cfbbdc5234877c7e112060006291b5e6acefcee38
|
data/lib/templates/translate.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
TranslateApi=Translate::Itranslate4.configure(options)
|
1
|
+
Itranslate4.configure do |config|
|
2
|
+
config.key = '' #Need add you Api key
|
3
|
+
end
|
data/lib/translate/version.rb
CHANGED
data/lib/translate.rb
CHANGED
@@ -1,48 +1,53 @@
|
|
1
1
|
require 'rest-client'
|
2
2
|
|
3
|
-
module
|
3
|
+
module Itranslate4
|
4
4
|
SERVICE_URL='http://itranslate4.eu/api/'
|
5
|
-
|
6
|
-
class Itranslate4
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
6
|
+
class << self
|
7
|
+
attr_accessor :configuration
|
8
|
+
end
|
12
9
|
|
13
|
-
|
14
|
-
|
10
|
+
def self.configure
|
11
|
+
self.configuration ||= Configuration.new
|
12
|
+
yield(configuration)
|
13
|
+
end
|
14
|
+
|
15
|
+
class Configuration
|
16
|
+
attr_accessor :key
|
17
|
+
def initialize
|
18
|
+
|
15
19
|
end
|
20
|
+
end
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
def self.send_request(method, url, params={})
|
23
|
+
response = RestClient::Request.execute(method: method, url: url, headers: {params: params})
|
24
|
+
self.parse_response(response)
|
25
|
+
rescue => e
|
26
|
+
self.parse_response(e.response)
|
27
|
+
end
|
23
28
|
|
24
|
-
|
25
|
-
|
26
|
-
|
29
|
+
def self.parse_response(response)
|
30
|
+
{ code: response.code, body: response.body.empty? ? '' : JSON.parse(response.body, symbolize_names: true) }
|
31
|
+
end
|
27
32
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
def self.translate(src, trg, dat='',rid=nil)
|
34
|
+
Itranslate4.send_request :get, "#{SERVICE_URL}/Translate?auth=#{Itranslate4.configuration.key}",
|
35
|
+
{src: src, trg:trg, dat: dat, rid:rid}.as_json
|
36
|
+
end
|
32
37
|
|
33
|
-
|
34
|
-
|
35
|
-
|
38
|
+
def self.languages
|
39
|
+
Itranslate4.send_request :get, "#{SERVICE_URL}/GetLanguages?auth=#{Itranslate4.configuration.key}"
|
40
|
+
end
|
36
41
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
42
|
+
def self.get_routes(src, trg)
|
43
|
+
Itranslate4.send_request :get, "#{SERVICE_URL}/GetRoutes?auth=#{Itranslate4.configuration.key}",
|
44
|
+
{src: src, trg:trg}.as_json
|
45
|
+
end
|
41
46
|
|
42
|
-
|
43
|
-
|
44
|
-
end
|
47
|
+
def self.get_providers
|
48
|
+
Itranslate4.send_request :get, "#{SERVICE_URL}/GetProviders?auth=#{Itranslate4.configuration.key}"
|
45
49
|
end
|
50
|
+
|
46
51
|
|
47
52
|
|
48
53
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
TranslateApi=Translate::Itranslate4.configure(options)
|
1
|
+
Itranslate4.configure do |config|
|
2
|
+
config.key = '' #Need add you Api key
|
3
|
+
end
|