youdao-translate 0.1.1 → 0.2.3

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: 14b880c3136bc5a5d7dc563c34311a7ca42ad43578e531c7f8e1c659f71f743d
4
- data.tar.gz: 71b74ca9391969249cc1c769ae7c70688448f4d254bb1fa5f31a4953b0e1aacf
3
+ metadata.gz: 7c2bc74e9913af570e2fb78fa18f960d5154af71f1c0e5d50c0eb814cb7f2fba
4
+ data.tar.gz: 5ce0b7319e8b754a9f050a39665fd449525232796059f4570bf9d47ad8bae3eb
5
5
  SHA512:
6
- metadata.gz: 6ad1e262b2291ada6cfcef173a4d29906bbf0e4137f3dc1a7c942c3ce1a84ddbc5ac3fbc0156c8b8079a18b343bd5a2b576748e983b7aae78093afc4ed1dcea0
7
- data.tar.gz: 10d41438b1a8fee4e84b10cf87c36f2a2d28a9e481d5af1f317c4bb3c53fad0727a0c19fdfb08f55c4d71a7d275e1f13e15555fe36e805ef0fcc2584362acc79
6
+ metadata.gz: 7e84ad4bc3a91178b8a5204bcdffc2de93581a1b09953c3e0fa93464661a3335f9671558f8aefb38502ff1896b3de8d436c8b428bb2e21d10eb8260f9acc651f
7
+ data.tar.gz: e6e00fbb435d5490f887f898e22ebbca33d2957bdcea665fa457a0c7c85cbef8b3ba08e74655c97d1cb1672bfbbe8765c256d12d91027152344ec549baa69b25
data/Gemfile.lock CHANGED
@@ -1,18 +1,82 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- youdao-translate (0.1.1)
4
+ youdao-translate (0.2.3)
5
+ forwardable (~> 1.3.2)
6
+ http (~> 5.0)
7
+ singleton (~> 0.1.1)
5
8
 
6
9
  GEM
7
10
  remote: https://rubygems.org/
8
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)
9
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)
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)
10
72
 
11
73
  PLATFORMS
12
74
  x86_64-darwin-19
13
75
 
14
76
  DEPENDENCIES
15
77
  rake (~> 13.0)
78
+ rspec (~> 3.7)
79
+ rubocop (~> 1.6.1)
16
80
  youdao-translate!
17
81
 
18
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,23 +23,27 @@ 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
- ## Development
37
+ ## Test
38
38
 
39
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+ ```
40
+ rspec -f d
41
+ ```
40
42
 
41
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+ ```
44
+ bundle exec rubocop .
45
+ ```
42
46
 
43
47
  ## Contributing
44
48
 
45
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/youdao-translate.
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.1.1"
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,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.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 "example-gem", "~> 1.0"
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.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - hfpp2012
@@ -9,7 +9,77 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2022-03-09 00:00:00.000000000 Z
12
- dependencies: []
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'
41
+ - !ruby/object:Gem::Dependency
42
+ name: singleton
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
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
13
83
  description: Translate using youdao
14
84
  email:
15
85
  - hfpp2012@gmail.com
@@ -17,13 +87,12 @@ executables: []
17
87
  extensions: []
18
88
  extra_rdoc_files: []
19
89
  files:
20
- - Gemfile
21
90
  - Gemfile.lock
91
+ - LICENSE.txt
22
92
  - README.md
23
93
  - Rakefile
24
94
  - lib/youdao/translate.rb
25
95
  - lib/youdao/translate/version.rb
26
- - lib/youdao/translate/youdao.rb
27
96
  - youdao-translate.gemspec
28
97
  homepage: https://gitlab.com/suifeng2012/youdao-tranlsate
29
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,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
-