keppler_watson 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36316aff24d38bac1061dcec23a7d9bb4cdcbf96767697b103b763da4ee7b418
4
- data.tar.gz: fc9af314a6f4f895e8e9aa0e0c4876ed04c9e8f80d1cc3a07f8e2526ed581eb4
3
+ metadata.gz: 38e1dd708454952d2b6160c359d4f27ffee04f1347da1b929d02c6992b4f7e65
4
+ data.tar.gz: d4e3f158e59a4e8562060caa02e573dc3e02b76a43980ed022c5f76026fa3e43
5
5
  SHA512:
6
- metadata.gz: 40d6cec70a71c88f2ebf7df332285eafb542f7b5260ac4f7de40228d2a40c65ba458bf0530d80e610bcc0dc31dfae456410704b2b8ab8a7173c1e6925ad4295d
7
- data.tar.gz: 9a1ad45cab5c0eb81366dd0e514faecb3b492ea868346dd07da1b1fd1aeb0d505e942fb288cb27ead5271822981eceb478d0494d112b10b666fd33a017e8fc9c
6
+ metadata.gz: 4c67170e607e67bc9e3d0956440f311f0d32aad7a14f85790f0b3ba3bde6bd8f35678cf6bca0368b885332621ff447b7596722459e4713648afbacd6a97c5ff5
7
+ data.tar.gz: e6aa3792cb3fb1b58821fbab95f15fb43d18cd7a0cc243cee4f3b31930bc3d9d6ab5a2dafa92f8627fef97104b6f8be5fb2ffb254d9096d4f23e4d0afe8e3252
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ keppler_watson (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.5.0)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 1.16)
16
+ keppler_watson!
17
+ rake (~> 10.0)
18
+
19
+ BUNDLED WITH
20
+ 1.16.2
@@ -2,6 +2,7 @@ require "keppler_watson/version"
2
2
  require "keppler_watson/visual_recognition"
3
3
  require "keppler_watson/natural_lenguage"
4
4
  require "keppler_watson/personality_insights"
5
+ require "keppler_watson/language_translator"
5
6
 
6
7
  module KepplerWatson
7
8
 
@@ -0,0 +1,48 @@
1
+ require "keppler_watson/version"
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'byebug'
5
+
6
+ module KepplerWatson
7
+ # Your code goes here...
8
+ class LanguageTraslator
9
+
10
+ def initialize(params)
11
+ @api_key = params[:api_key]
12
+ @version = params[:version]
13
+ end
14
+
15
+ def translate(text, model_id="es-en")
16
+ params = { text: text, model_id: model_id }
17
+ api_post(:translate, params)
18
+ end
19
+
20
+ def identify(text)
21
+ api_post(:identify, text)
22
+ end
23
+
24
+ private
25
+
26
+ def api_url
27
+ 'https://gateway.watsonplatform.net/language-translator/api/v3'
28
+ end
29
+
30
+ def api_post(action, params)
31
+ uri = URI.parse("#{api_url}/#{action.to_s}?version=#{@version}")
32
+ request = Net::HTTP::Post.new(uri)
33
+ if action.eql?(:translate)
34
+ request['Content-Type'] = "application/json"
35
+ request.body = params.to_json
36
+ else
37
+ request['Content-Type'] = "text/plain"
38
+ request.body = params.to_json
39
+ end
40
+ request.basic_auth("apikey", @api_key.to_s)
41
+ req_options = { use_ssl: uri.scheme == "https", }
42
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
43
+ http.request(request)
44
+ end
45
+ JSON.parse(response.body, object_class: OpenStruct)
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module KepplerWatson
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keppler_watson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - luprz
@@ -48,6 +48,7 @@ files:
48
48
  - ".gitignore"
49
49
  - CODE_OF_CONDUCT.md
50
50
  - Gemfile
51
+ - Gemfile.lock
51
52
  - LICENSE.txt
52
53
  - README.md
53
54
  - Rakefile
@@ -55,6 +56,7 @@ files:
55
56
  - bin/setup
56
57
  - keppler_watson.gemspec
57
58
  - lib/keppler_watson.rb
59
+ - lib/keppler_watson/language_translator.rb
58
60
  - lib/keppler_watson/natural_lenguage.rb
59
61
  - lib/keppler_watson/personality_insights.rb
60
62
  - lib/keppler_watson/version.rb