Class: Wxp::Command::Say

Inherits:
Wxp::Command show all
Defined in:
lib/wxp/command/say.rb

Instance Method Summary collapse

Methods inherited from Wxp::Command

options, run

Constructor Details

#initialize(argv) ⇒ Say

Returns a new instance of Say.



16
17
18
# File 'lib/wxp/command/say.rb', line 16

def initialize(argv)
  super
end

Instance Method Details

#runObject



24
25
26
# File 'lib/wxp/command/say.rb', line 24

def run
  say
end

#sayObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/wxp/command/say.rb', line 28

def say

  base_path = "https://v1.hitokoto.cn"
  uri = URI.parse("#{base_path}/?c=e")

  res = Net::HTTP.start(uri.host, uri.port,
    :use_ssl => uri.scheme == 'https') do |http|
    request = Net::HTTP::Get.new uri
    http.request request
  end

  if res.code == "200"
    resbody = JSON.parse(res.body)
    puts
    puts resbody['hitokoto']
    puts
  else  
    puts                              
    puts "鸡汤因为 '#{res.message}' 没有熬好呀" 
    puts
  end
end

#validate!Object



20
21
22
# File 'lib/wxp/command/say.rb', line 20

def validate!
  super
end