sogou-translate 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 400d1624c45bb65108fad47c120b0d51a153a8cd
4
+ data.tar.gz: 7827a09e4bf332c4a208b0ba0f976a15328d3aaa
5
+ SHA512:
6
+ metadata.gz: 3d8bbe4f745b4c7a1760487f8a6c9570e691287dcbdfaaec89999b68eab64f915881cdaebf1efbece647bb0349c9b1a04c3324fe461815819401472a164c4bee
7
+ data.tar.gz: dec457ff4cf45c6bb390d4a8825566140b3c373085f79352ab962b0d7fb5c407b2630f70b23c88f256f9a0d63cdd29344478727858b46d0a310c05090fa9a6f8
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in sogou-translate.gemspec
6
+ gemspec
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sogou-translate (0.1.0)
5
+ http (~> 3.3.0)
6
+ thor (~> 0.20.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.5.2)
12
+ public_suffix (>= 2.0.2, < 4.0)
13
+ domain_name (0.5.20180417)
14
+ unf (>= 0.0.5, < 1.0.0)
15
+ http (3.3.0)
16
+ addressable (~> 2.3)
17
+ http-cookie (~> 1.0)
18
+ http-form_data (~> 2.0)
19
+ http_parser.rb (~> 0.6.0)
20
+ http-cookie (1.0.3)
21
+ domain_name (~> 0.5)
22
+ http-form_data (2.1.1)
23
+ http_parser.rb (0.6.0)
24
+ public_suffix (3.0.2)
25
+ rake (10.5.0)
26
+ thor (0.20.0)
27
+ unf (0.1.4)
28
+ unf_ext
29
+ unf_ext (0.0.7.5)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ bundler (~> 1.16)
36
+ rake (~> 10.0)
37
+ sogou-translate!
38
+
39
+ BUNDLED WITH
40
+ 1.16.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Jiadeng Ruan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ .PHONY: dev-test
2
+
3
+ dev-test:
4
+ gem build sogou-translate.gemspec && gem install pkg/sogou-translate-0.1.0.gem && sogou translate
@@ -0,0 +1,40 @@
1
+ # Sogou::Translate
2
+ Sogou translation API and CLI tool.
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'sogou-translate'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install sogou-translate
19
+
20
+ ## Usage
21
+
22
+ ```
23
+ sogou translate TEXT
24
+ ```
25
+
26
+ API `Sogou::Translate.translate(text)`
27
+
28
+ ## Development
29
+
30
+ 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.
31
+
32
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sogou-translate.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sogou/translate"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "sogou/translate/cli"
4
+
5
+ Sogou::Translate::CLI.start(ARGV)
@@ -0,0 +1,7 @@
1
+ require "sogou/translate/version"
2
+ require "sogou/translate/get"
3
+
4
+ module Sogou
5
+ module Translate
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ require 'thor'
2
+ require "sogou/translate/get"
3
+
4
+ def red(text)
5
+ code = 31
6
+ return "\e[#{code}m#{text}\033[0m"
7
+ end
8
+
9
+
10
+ def green(text)
11
+ code = 32
12
+ return "\e[#{code}m#{text}\033[0m"
13
+ end
14
+
15
+
16
+ module Sogou
17
+ module Translate
18
+ class CLI < Thor
19
+ desc "trans TEXT", "translate TEXT"
20
+ def translate(text='文章本天成,妙手偶得之')
21
+ js = Sogou::Translate.translate(text)
22
+ puts " #{green("From")}: #{js['translate']['from']}"
23
+ puts " #{green("To")}: #{js['translate']['to']}"
24
+ puts " #{green("Text")}: #{js['translate']['text']}"
25
+ puts "#{green("Result")}: #{js['translate']['dit']}"
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ require "http"
2
+
3
+
4
+ module Sogou
5
+ module Translate
6
+ @API_BASE = "https://fanyi.sogou.com/reventondc/translate"
7
+
8
+ def self.translate(text)
9
+ res = HTTP.post(@API_BASE, :form => {
10
+ :from => "auto",
11
+ :text => text,
12
+ }).body.to_s
13
+ rv = JSON.parse(res)
14
+ return rv
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module Sogou
2
+ module Translate
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "sogou/translate/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sogou-translate"
8
+ spec.version = Sogou::Translate::VERSION
9
+ spec.authors = ["weaming"]
10
+ spec.email = ["garden.yuen@gmail.com"]
11
+
12
+ spec.summary = "sogou-translate"
13
+ spec.description = "sogou-translate through web api"
14
+ spec.homepage = "https://github.com/weaming/sogou-translate"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "bin"
32
+ spec.executables = ['sogou']
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_dependency "http", "~> 3.3.0"
38
+ spec.add_dependency "thor", "~> 0.20.0"
39
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sogou-translate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - weaming
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: http
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.3.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.20.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.20.0
69
+ description: sogou-translate through web api
70
+ email:
71
+ - garden.yuen@gmail.com
72
+ executables:
73
+ - sogou
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - Makefile
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - bin/sogou
87
+ - lib/sogou/translate.rb
88
+ - lib/sogou/translate/cli.rb
89
+ - lib/sogou/translate/get.rb
90
+ - lib/sogou/translate/version.rb
91
+ - sogou-translate.gemspec
92
+ homepage: https://github.com/weaming/sogou-translate
93
+ licenses:
94
+ - MIT
95
+ metadata:
96
+ allowed_push_host: https://rubygems.org
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.6.14
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: sogou-translate
117
+ test_files: []