Class: Wxp::Command::Say
- Inherits:
-
Wxp::Command
- Object
- CLAide::Command
- Wxp::Command
- Wxp::Command::Say
- Defined in:
- lib/wxp/command/say.rb
Instance Method Summary collapse
-
#initialize(argv) ⇒ Say
constructor
A new instance of Say.
- #run ⇒ Object
- #say ⇒ Object
- #validate! ⇒ Object
Methods inherited from Wxp::Command
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
#run ⇒ Object
24 25 26 |
# File 'lib/wxp/command/say.rb', line 24 def run say end |
#say ⇒ Object
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.}' 没有熬好呀" puts end end |
#validate! ⇒ Object
20 21 22 |
# File 'lib/wxp/command/say.rb', line 20 def validate! super end |