dict 0.0.2 → 0.0.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.
Files changed (3) hide show
  1. data/bin/translate +9 -3
  2. data/lib/dict.rb +11 -3
  3. metadata +1 -1
data/bin/translate CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  require 'dict'
4
5
 
@@ -7,12 +8,17 @@ if ARGV.empty?
7
8
  exit
8
9
  end
9
10
 
10
- temp = ARGV[0].dup
11
-
12
- print temp << " translated: " << "\n"
13
11
  puts Dict::Translation.getResponse(ARGV[0])
14
12
 
15
13
  if ARGV[0] == "status"
16
14
  print "Status API: "
17
15
  print Dict::Translation.status
16
+ elsif ARGV[1] == "time"
17
+ if !ARGV[2].nil?
18
+ Dict::Translation.getResponse(ARGV[0], ARGV[2])
19
+ else
20
+ Dict::Translation.getResponse(ARGV[0])
21
+ end
22
+ else
23
+ Dict::Translation.getResponse(ARGV[0])
18
24
  end
data/lib/dict.rb CHANGED
@@ -1,5 +1,9 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
1
4
  require 'uri'
2
5
  require 'net/http'
6
+ require 'timeout'
3
7
 
4
8
  module Dict
5
9
  class Translation
@@ -13,10 +17,14 @@ module Dict
13
17
  puts res.message
14
18
  end
15
19
 
16
- def self.getResponse(word)
17
- uri = URI("http://dict-app-staging.shellyapp.com/#{word}")
18
- puts Net::HTTP.get(uri)
20
+ def self.getResponse(word, time = 3600)
21
+ uri = URI.parse(URI.escape("http://dict-app-staging.shellyapp.com/#{word}"))
22
+ Timeout::timeout(time.to_i) do
23
+ puts Net::HTTP.get(uri)
24
+ end
19
25
  end
26
+
27
+
20
28
  end
21
29
  end
22
30
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dict
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: