geekdict 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2469553df77ddbe3664fb8a8a2edd965741b727d
4
+ data.tar.gz: 7484c1ac4f61feabee89183636dc64b8ca0aa269
5
+ SHA512:
6
+ metadata.gz: 49f8ed1feae8dbe3deb945963d84110841a585ec0a70ef223663f5844888e616b841df9f4fead7f4e49fbcb8628788db9313340c7546f66d5c92595ea591974f
7
+ data.tar.gz: a9dd8b1af171b4af7ccfa43e18389e55fcef10ae5f3de9b776f835e06e98a3c2ec6bee13a6e504d127c11af0e9a6e4f1518d41d91c17ff1513e9416bb7a3b14c
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ coverage
6
+ *.swp
7
+ .idea/*
8
+ .DS_Store
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify dependencies in geekdict.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ Geek Dict
2
+ ---------
3
+ A command line tool for translation.
4
+
5
+ ## Commands
6
+
7
+ #### Translate a word
8
+ ```
9
+ $dict t hello
10
+ 你好
11
+ ```
12
+
13
+ #### List all my new works
14
+ ```
15
+ $dict list
16
+ ```
17
+
18
+ #### Set target language
19
+ ```
20
+ $dict settings --lang chinese
21
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc 'Run specs'
5
+
6
+ RSpec::Core::RakeTask.new do |t|
7
+ t.rspec_opts = %w(--color)
8
+ end
data/bin/geekdict ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'geekdict'
4
+ require 'geekdict/cli'
5
+
6
+ GeekDict::CLI.start(ARGV)
data/geekdict.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "geekdict/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "geekdict"
7
+ s.version = GeekDict::VERSION
8
+ s.authors = ["Bruce Li"]
9
+ s.email = ["wbinglee@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{A command line tool for translation.}
12
+ s.description = %q{A command line tool for translation.}
13
+
14
+ s.rubyforge_project = "geekdict"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "rake"
22
+ s.add_development_dependency "rspec", "~> 2.13.0"
23
+
24
+ s.add_runtime_dependency "thor", "~> 0.19.1"
25
+ s.add_runtime_dependency "httpclient", "~> 2.4.0"
26
+
27
+ end
@@ -0,0 +1,18 @@
1
+ require "thor"
2
+
3
+ module GeekDict
4
+
5
+ class CLI < Thor
6
+
7
+ desc "t", "Translate a word"
8
+ option :lang, :aliases=>'-l'
9
+ def t(word)
10
+ result = GeekDict::Youdao.translate word
11
+ output = result.join "\n"
12
+ puts output
13
+ output
14
+ end
15
+
16
+ end
17
+ end
18
+
File without changes
@@ -0,0 +1,3 @@
1
+ module GeekDict
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ require 'httpclient'
2
+ require 'json'
3
+
4
+ require 'geekdict/youdao/config'
5
+
6
+ module GeekDict
7
+ module Youdao
8
+
9
+ #Youdao API version
10
+
11
+ module_function
12
+
13
+ def translate(word)
14
+ client = HTTPClient.new
15
+ query = { keyfrom: APIKEYFROM, key: APIKEY, type: 'data', doctype: 'json',version: APIVERSION, q: word }
16
+ res = client.get(APIURL, query)
17
+ res = JSON.parse res.body
18
+ error_code = res['errorCode']
19
+ if error_code == 0
20
+ res['basic']['explains']
21
+ else
22
+ []
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ module GeekDict
2
+ module Youdao
3
+
4
+ APIKEY = "1127870837"
5
+
6
+ APIKEYFROM = "wbinglee"
7
+
8
+ APIVERSION = "1.1"
9
+
10
+ APIURL = "http://fanyi.youdao.com/openapi.do"
11
+
12
+ end
13
+ end
data/lib/geekdict.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'geekdict/cli'
2
+ require 'geekdict/youdao/api'
3
+
4
+ module GeekDict
5
+
6
+ end
data/spec/.keep ADDED
File without changes
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'geekdict'
2
+
3
+ describe GeekDict::CLI do
4
+
5
+ describe 'translate good' do
6
+
7
+ it 'should output translate result as string' do
8
+ cli = GeekDict::CLI.new
9
+ result = cli.t 'good'
10
+ expect(result).to include("好")
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ require 'geekdict'
2
+
3
+ describe GeekDict::Youdao do
4
+
5
+ describe 'translate good' do
6
+
7
+ it 'should output translate result as json' do
8
+ result = GeekDict::Youdao.translate 'good'
9
+ expect(result.length).to be > 0
10
+ end
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geekdict
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bruce Li
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.13.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.13.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.19.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.19.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: httpclient
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.4.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.4.0
69
+ description: A command line tool for translation.
70
+ email:
71
+ - wbinglee@gmail.com
72
+ executables:
73
+ - geekdict
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".ruby-version"
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - bin/geekdict
83
+ - geekdict.gemspec
84
+ - lib/geekdict.rb
85
+ - lib/geekdict/cli.rb
86
+ - lib/geekdict/google/.keep
87
+ - lib/geekdict/version.rb
88
+ - lib/geekdict/youdao/api.rb
89
+ - lib/geekdict/youdao/config.rb
90
+ - spec/.keep
91
+ - spec/cli_spec.rb
92
+ - spec/youdao/api_spec.rb
93
+ homepage: ''
94
+ licenses: []
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project: geekdict
112
+ rubygems_version: 2.2.2
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: A command line tool for translation.
116
+ test_files:
117
+ - spec/cli_spec.rb
118
+ - spec/youdao/api_spec.rb