youdao-translate 0.2.2 → 0.2.3

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: 14a0c61d17890153d3b6e83697df4ec1e676ce8f7978fcade612b500b1d369b5
4
- data.tar.gz: ded30bd18af8139eb95ebd7a3c9d26a3cb89eca7479d7286d3c7adc5894d755c
3
+ metadata.gz: 7c2bc74e9913af570e2fb78fa18f960d5154af71f1c0e5d50c0eb814cb7f2fba
4
+ data.tar.gz: 5ce0b7319e8b754a9f050a39665fd449525232796059f4570bf9d47ad8bae3eb
5
5
  SHA512:
6
- metadata.gz: 619bb13ad5f82b16256e1cd4bbae2fb8973cae3a626eb76918c1955603e631c98e8c16eb337a24ec380b6ffb8cd18f2e5461edf8503a3a89aabcee8dffd3cb97
7
- data.tar.gz: c9931210cb2d176ea7c94c2ef0b39bacff48f75dd9015155f4e71c16f779464d8263f205b89d8ae84bab659e1542d42b94bb3c128b6d6395b30689ddcfed6197
6
+ metadata.gz: 7e84ad4bc3a91178b8a5204bcdffc2de93581a1b09953c3e0fa93464661a3335f9671558f8aefb38502ff1896b3de8d436c8b428bb2e21d10eb8260f9acc651f
7
+ data.tar.gz: e6e00fbb435d5490f887f898e22ebbca33d2957bdcea665fa457a0c7c85cbef8b3ba08e74655c97d1cb1672bfbbe8765c256d12d91027152344ec549baa69b25
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- youdao-translate (0.2.2)
4
+ youdao-translate (0.2.3)
5
5
  forwardable (~> 1.3.2)
6
6
  http (~> 5.0)
7
7
  singleton (~> 0.1.1)
@@ -11,6 +11,7 @@ GEM
11
11
  specs:
12
12
  addressable (2.8.0)
13
13
  public_suffix (>= 2.0.2, < 5.0)
14
+ ast (2.4.2)
14
15
  diff-lcs (1.5.0)
15
16
  domain_name (0.5.20190701)
16
17
  unf (>= 0.0.5, < 1.0.0)
@@ -30,8 +31,14 @@ GEM
30
31
  llhttp-ffi (0.4.0)
31
32
  ffi-compiler (~> 1.0)
32
33
  rake (~> 13.0)
34
+ parallel (1.21.0)
35
+ parser (3.1.1.0)
36
+ ast (~> 2.4.1)
33
37
  public_suffix (4.0.6)
38
+ rainbow (3.1.1)
34
39
  rake (13.0.6)
40
+ regexp_parser (2.2.1)
41
+ rexml (3.2.5)
35
42
  rspec (3.11.0)
36
43
  rspec-core (~> 3.11.0)
37
44
  rspec-expectations (~> 3.11.0)
@@ -45,10 +52,23 @@ GEM
45
52
  diff-lcs (>= 1.2.0, < 2.0)
46
53
  rspec-support (~> 3.11.0)
47
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)
48
67
  singleton (0.1.1)
49
68
  unf (0.1.4)
50
69
  unf_ext
51
70
  unf_ext (0.0.8)
71
+ unicode-display_width (1.8.0)
52
72
 
53
73
  PLATFORMS
54
74
  x86_64-darwin-19
@@ -56,6 +76,7 @@ PLATFORMS
56
76
  DEPENDENCIES
57
77
  rake (~> 13.0)
58
78
  rspec (~> 3.7)
79
+ rubocop (~> 1.6.1)
59
80
  youdao-translate!
60
81
 
61
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,15 @@ 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
35
  ```
36
36
 
37
37
  ## Test
@@ -40,6 +40,10 @@ Translate::Youdao.instance.get("hello", from: "zh-CHS", to: "ja")
40
40
  rspec -f d
41
41
  ```
42
42
 
43
+ ```
44
+ bundle exec rubocop .
45
+ ```
46
+
43
47
  ## Contributing
44
48
 
45
49
  Bug reports and pull requests are welcome on GitHub at https://gitlab.com/suifeng2012/youdao-translate.
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.2.2"
4
+ class Translate
5
+ VERSION = '0.2.3'
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,35 +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.com/suifeng2012/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"
30
- spec.add_dependency "http", "~> 5.0"
31
- spec.add_dependency "forwardable", "~> 1.3.2"
26
+ spec.add_dependency 'forwardable', '~> 1.3.2'
27
+ spec.add_dependency 'http', '~> 5.0'
28
+ spec.add_dependency 'singleton', '~> 0.1.1'
32
29
  spec.add_development_dependency 'rspec', '~> 3.7'
30
+ spec.add_development_dependency 'rubocop', '~> 1.6.1'
33
31
 
34
32
  # For more information and examples about making a new gem, check out our
35
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.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - hfpp2012
@@ -11,19 +11,19 @@ cert_chain: []
11
11
  date: 2022-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: singleton
14
+ name: forwardable
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.1
19
+ version: 1.3.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.1
26
+ version: 1.3.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: http
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '5.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: forwardable
42
+ name: singleton
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.3.2
47
+ version: 0.1.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.3.2
54
+ version: 0.1.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
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
69
83
  description: Translate using youdao
70
84
  email:
71
85
  - hfpp2012@gmail.com
@@ -73,13 +87,12 @@ executables: []
73
87
  extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
76
- - Gemfile
77
90
  - Gemfile.lock
91
+ - LICENSE.txt
78
92
  - README.md
79
93
  - Rakefile
80
94
  - lib/youdao/translate.rb
81
95
  - lib/youdao/translate/version.rb
82
- - lib/youdao/translate/youdao.rb
83
96
  - youdao-translate.gemspec
84
97
  homepage: https://gitlab.com/suifeng2012/youdao-tranlsate
85
98
  licenses: []
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,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'singleton'
4
- require 'forwardable'
5
- require 'http'
6
-
7
- module Translate
8
- class Youdao
9
- include Singleton
10
-
11
- URL = "https://aidemo.youdao.com/trans"
12
-
13
- class << self
14
- extend Forwardable
15
- delegate %i[get] => :instance
16
- end
17
-
18
- # Get a tranlsated string
19
- #
20
- # @example
21
- # Translate::Youdao.get("hello")
22
- #
23
- # Translate::Youdao.get("hello", from: "zh-CHS", to: "ja")
24
- #
25
- # Translate::Youdao.get("hello", to: "ko")
26
- #
27
- # Translate::Youdao.instance.get("hello")
28
- #
29
- # Translate::Youdao.instance.get("hello", from: "zh-CHS", to: "ja")
30
- #
31
- # @param [String] content
32
- # the content you want to translate
33
- # @param [String] from
34
- # the language from
35
- #
36
- # @param [String] to
37
- # the language translate to
38
- #
39
- # @api public
40
-
41
- def get(content, options={})
42
- @content = content
43
-
44
- form = payload.merge(options)
45
-
46
- res = HTTP.post(URL, form: form)
47
- result = res.parse :json
48
-
49
- result["translation"].first
50
- rescue StandardError
51
- nil
52
- end
53
-
54
- private
55
-
56
- attr_accessor :content
57
-
58
- def payload
59
- {
60
- q: content,
61
- from: "auto",
62
- to: "en"
63
- }
64
- end
65
- end
66
- end
67
-