youdao-translate 0.1.2 → 0.2.4

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
  SHA256:
3
- metadata.gz: 6e8870f9a4940f606bd6b74cc07a525333a8fae599c6d45716ca5c2fc75698ba
4
- data.tar.gz: 21113626913fe0e6d0e6ac8b26a5e3a18f7e94cfb728861f16f7371ef3894020
3
+ metadata.gz: feb80bb11ec674e22a2690bc87309915c052286f925d1541211de8e321ad84e9
4
+ data.tar.gz: 5dc7bcd7c18b48da50cd15940c1d2f758f07c76358a2e7eb23a49d657034b8ff
5
5
  SHA512:
6
- metadata.gz: 2dcd7e8a101bb33a090f93c0633d533f5f7452f2fa4cfea9cff312eb7389da26d42f87ac929eefe8de387999c68087a2e8cedfa192a193d8202748af38fd6c71
7
- data.tar.gz: 6a5a6d4b4cdba7c389302c247fb735892ac6035e00e901b19ebdec1fff6c460df6db5b338936ec7d9a3a3ecc0dbe107de3f32af74078f64bb2c37db075664ee3
6
+ metadata.gz: f7c5db25b2885f9b7362754573da15205ff95bd8359cc40e06223cb6b598956be197ae6483010bf3c660431042fd83a8cf52a8b1b9d57c6700258f74c424bb6c
7
+ data.tar.gz: f5a38843cc056c6fa1274f11f9e3d2751ddfd97217cb92194a7213f3f58525f8df159eaa3ec43076dab5d3eeeefe301243cd53086ca5085594b7d8078f6a865f
data/Gemfile.lock CHANGED
@@ -1,20 +1,82 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- youdao-translate (0.1.2)
4
+ youdao-translate (0.2.4)
5
+ forwardable (~> 1.3.2)
6
+ http (~> 5.0)
5
7
  singleton (~> 0.1.1)
6
8
 
7
9
  GEM
8
10
  remote: https://rubygems.org/
9
11
  specs:
12
+ addressable (2.8.0)
13
+ public_suffix (>= 2.0.2, < 5.0)
14
+ ast (2.4.2)
15
+ diff-lcs (1.5.0)
16
+ domain_name (0.5.20190701)
17
+ unf (>= 0.0.5, < 1.0.0)
18
+ ffi (1.15.5)
19
+ ffi-compiler (1.0.1)
20
+ ffi (>= 1.0.0)
21
+ rake
22
+ forwardable (1.3.2)
23
+ http (5.0.4)
24
+ addressable (~> 2.8)
25
+ http-cookie (~> 1.0)
26
+ http-form_data (~> 2.2)
27
+ llhttp-ffi (~> 0.4.0)
28
+ http-cookie (1.0.4)
29
+ domain_name (~> 0.5)
30
+ http-form_data (2.3.0)
31
+ llhttp-ffi (0.4.0)
32
+ ffi-compiler (~> 1.0)
33
+ rake (~> 13.0)
34
+ parallel (1.21.0)
35
+ parser (3.1.1.0)
36
+ ast (~> 2.4.1)
37
+ public_suffix (4.0.6)
38
+ rainbow (3.1.1)
10
39
  rake (13.0.6)
40
+ regexp_parser (2.2.1)
41
+ rexml (3.2.5)
42
+ rspec (3.11.0)
43
+ rspec-core (~> 3.11.0)
44
+ rspec-expectations (~> 3.11.0)
45
+ rspec-mocks (~> 3.11.0)
46
+ rspec-core (3.11.0)
47
+ rspec-support (~> 3.11.0)
48
+ rspec-expectations (3.11.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.11.0)
51
+ rspec-mocks (3.11.0)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.11.0)
54
+ rspec-support (3.11.0)
55
+ rubocop (1.6.1)
56
+ parallel (~> 1.10)
57
+ parser (>= 2.7.1.5)
58
+ rainbow (>= 2.2.2, < 4.0)
59
+ regexp_parser (>= 1.8, < 3.0)
60
+ rexml
61
+ rubocop-ast (>= 1.2.0, < 2.0)
62
+ ruby-progressbar (~> 1.7)
63
+ unicode-display_width (>= 1.4.0, < 2.0)
64
+ rubocop-ast (1.16.0)
65
+ parser (>= 3.1.1.0)
66
+ ruby-progressbar (1.11.0)
11
67
  singleton (0.1.1)
68
+ unf (0.1.4)
69
+ unf_ext
70
+ unf_ext (0.0.8)
71
+ unicode-display_width (1.8.0)
12
72
 
13
73
  PLATFORMS
14
74
  x86_64-darwin-19
15
75
 
16
76
  DEPENDENCIES
17
77
  rake (~> 13.0)
78
+ rspec (~> 3.7)
79
+ rubocop (~> 1.6.1)
18
80
  youdao-translate!
19
81
 
20
82
  BUNDLED WITH
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2021 hfpp2012
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -23,15 +23,25 @@ Or install it yourself as:
23
23
  ## Usage
24
24
 
25
25
  ```ruby
26
- Translate::Youdao.get("hello")
26
+ Youdao::Translate.get("hello")
27
27
 
28
- Translate::Youdao.get("hello", from: "zh-CHS", to: "ja")
28
+ Youdao::Translate.get("hello", from: "zh-CHS", to: "ja")
29
29
 
30
- Translate::Youdao.get("hello", to: "ko")
30
+ Youdao::Translate.get("hello", to: "ko")
31
31
 
32
- Translate::Youdao.instance.get("hello")
32
+ Youdao::Translate.instance.get("hello")
33
33
 
34
- Translate::Youdao.instance.get("hello", from: "zh-CHS", to: "ja")
34
+ Youdao::Translate.instance.get("hello", from: "zh-CHS", to: "ja")
35
+ ```
36
+
37
+ ## Test
38
+
39
+ ```
40
+ rspec -f d
41
+ ```
42
+
43
+ ```
44
+ bundle exec rubocop .
35
45
  ```
36
46
 
37
47
  ## Contributing
data/Rakefile CHANGED
@@ -1,4 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- task default: %i[]
3
+ require 'bundler/gem_tasks'
4
+ # task default: %i[]
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:rspec)
8
+ task default: :rspec
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Youdao
4
- module Translate
5
- VERSION = "0.1.2"
4
+ class Translate
5
+ VERSION = '0.2.4'
6
6
  end
7
7
  end
@@ -1,11 +1,67 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "translate/version"
4
- require_relative "translate/youdao"
3
+ require_relative 'translate/version'
4
+ require 'singleton'
5
+ require 'forwardable'
6
+ require 'http'
5
7
 
6
8
  module Youdao
7
- module Translate
8
- class Error < StandardError; end
9
- # Your code goes here...
9
+ class Translate
10
+ include Singleton
11
+
12
+ URL = 'https://aidemo.youdao.com/trans'
13
+
14
+ class << self
15
+ extend Forwardable
16
+ delegate %i[get] => :instance
17
+ end
18
+
19
+ # Get a tranlsated string
20
+ #
21
+ # @example
22
+ # Youdao::Translate.get("hello")
23
+ #
24
+ # Youdao::Translate.get("hello", from: "zh-CHS", to: "ja")
25
+ #
26
+ # Youdao::Translate.get("hello", to: "ko")
27
+ #
28
+ # Youdao::Translate.instance.get("hello")
29
+ #
30
+ # Youdao::Translate.instance.get("hello", from: "zh-CHS", to: "ja")
31
+ #
32
+ # @param [String] content
33
+ # the content you want to translate
34
+ # @param [String] from
35
+ # the language from
36
+ #
37
+ # @param [String] to
38
+ # the language translate to
39
+ #
40
+ # @api public
41
+
42
+ def get(content, options = {})
43
+ @content = content
44
+
45
+ form = payload.merge(options)
46
+
47
+ res = HTTP.post(URL, form: form)
48
+ result = res.parse :json
49
+
50
+ result['translation'].first
51
+ rescue StandardError
52
+ nil
53
+ end
54
+
55
+ private
56
+
57
+ attr_accessor :content
58
+
59
+ def payload
60
+ {
61
+ q: content,
62
+ from: 'auto',
63
+ to: 'en'
64
+ }
65
+ end
10
66
  end
11
67
  end
@@ -1,32 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/youdao/translate/version"
3
+ require_relative 'lib/youdao/translate/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "youdao-translate"
6
+ spec.name = 'youdao-translate'
7
7
  spec.version = Youdao::Translate::VERSION
8
- spec.authors = ["hfpp2012"]
9
- spec.email = ["hfpp2012@gmail.com"]
8
+ spec.authors = ['hfpp2012']
9
+ spec.email = ['hfpp2012@gmail.com']
10
10
 
11
- spec.summary = "Translate using youdao"
12
- spec.description = "Translate using youdao"
13
- spec.homepage = "https://gitlab.com/suifeng2012/youdao-tranlsate"
14
- spec.required_ruby_version = ">= 2.6.0"
11
+ spec.summary = 'Translate using youdao'
12
+ spec.description = 'Translate using youdao'
13
+ spec.homepage = 'https://gitlab.qiuzhi99.com/hfpp2012/youdao-tranlsate'
14
+ spec.required_ruby_version = '>= 2.6.0'
15
15
 
16
- spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = spec.homepage
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = spec.homepage
18
18
 
19
19
  # Specify which files should be added to the gem when it is released.
20
20
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
- `git ls-files -z`.split("\x0").reject do |f|
23
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
24
- end
25
- end
26
- spec.require_paths = ["lib"]
21
+ spec.files = `git ls-files`.split($/)
22
+ spec.files -= spec.files.grep(%r{^(doc/|\.|spec/)}) + %w[CHANGES.md Gemfile]
23
+ spec.require_paths = ['lib']
27
24
 
28
25
  # Uncomment to register a new dependency of your gem
29
- spec.add_dependency "singleton", "~> 0.1.1"
26
+ spec.add_dependency 'forwardable', '~> 1.3.2'
27
+ spec.add_dependency 'http', '~> 5.0'
28
+ spec.add_dependency 'singleton', '~> 0.1.1'
29
+ spec.add_development_dependency 'rspec', '~> 3.7'
30
+ spec.add_development_dependency 'rubocop', '~> 1.6.1'
30
31
 
31
32
  # For more information and examples about making a new gem, check out our
32
33
  # guide at: https://bundler.io/guides/creating_gem.html
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: youdao-translate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - hfpp2012
@@ -10,6 +10,34 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2022-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: forwardable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: singleton
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +52,34 @@ dependencies:
24
52
  - - "~>"
25
53
  - !ruby/object:Gem::Version
26
54
  version: 0.1.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.6.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.6.1
27
83
  description: Translate using youdao
28
84
  email:
29
85
  - hfpp2012@gmail.com
@@ -31,19 +87,18 @@ executables: []
31
87
  extensions: []
32
88
  extra_rdoc_files: []
33
89
  files:
34
- - Gemfile
35
90
  - Gemfile.lock
91
+ - LICENSE.txt
36
92
  - README.md
37
93
  - Rakefile
38
94
  - lib/youdao/translate.rb
39
95
  - lib/youdao/translate/version.rb
40
- - lib/youdao/translate/youdao.rb
41
96
  - youdao-translate.gemspec
42
- homepage: https://gitlab.com/suifeng2012/youdao-tranlsate
97
+ homepage: https://gitlab.qiuzhi99.com/hfpp2012/youdao-tranlsate
43
98
  licenses: []
44
99
  metadata:
45
- homepage_uri: https://gitlab.com/suifeng2012/youdao-tranlsate
46
- source_code_uri: https://gitlab.com/suifeng2012/youdao-tranlsate
100
+ homepage_uri: https://gitlab.qiuzhi99.com/hfpp2012/youdao-tranlsate
101
+ source_code_uri: https://gitlab.qiuzhi99.com/hfpp2012/youdao-tranlsate
47
102
  post_install_message:
48
103
  rdoc_options: []
49
104
  require_paths:
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in youdao-translate.gemspec
6
- gemspec
7
-
8
- gem "rake", "~> 13.0"
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Translate
4
- class Youdao
5
- include Singleton
6
-
7
- URL = "https://aidemo.youdao.com/trans"
8
-
9
- class << self
10
- extend Forwardable
11
- delegate %i[get] => :instance
12
- end
13
-
14
- # Get a tranlsated string
15
- #
16
- # @example
17
- # Translate::Youdao.get("hello")
18
- #
19
- # Translate::Youdao.get("hello", from: "zh-CHS", to: "ja")
20
- #
21
- # Translate::Youdao.get("hello", to: "ko")
22
- #
23
- # Translate::Youdao.instance.get("hello")
24
- #
25
- # Translate::Youdao.instance.get("hello", from: "zh-CHS", to: "ja")
26
- #
27
- # @param [String] content
28
- # the content you want to translate
29
- # @param [String] from
30
- # the language from
31
- #
32
- # @param [String] to
33
- # the language translate to
34
- #
35
- # @api public
36
-
37
- def get(content, options={})
38
- @content = content
39
-
40
- form = payload.merge(options)
41
-
42
- res = HTTP.post(URL, form: form)
43
- result = res.parse :json
44
-
45
- result["translation"].first
46
- rescue StandardError
47
- nil
48
- end
49
-
50
- private
51
-
52
- attr_accessor :content
53
-
54
- def payload
55
- {
56
- q: content,
57
- from: "auto",
58
- to: "en"
59
- }
60
- end
61
- end
62
- end
63
-