Module: RubyChina::Helpers
- Defined in:
- lib/rubychina/helpers.rb
Instance Method Summary collapse
Instance Method Details
#describe(topic) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rubychina/helpers.rb', line 16 def describe(topic) puts %{\033[1m#{topic['id']}: 回复数量 [#{topic['replies_count']}] "#{topic['title']} "\033[0m}.green puts topic['body'].yellow puts "#" * 20 topic['replies'].each do |r| puts r['user']['login'].red puts "\t" * 2 + r['body'] puts "=" * 20 end puts end |
#get(path) {|response| ... } ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/rubychina/helpers.rb', line 7 def get(path) response = Excon.get("http://ruby-china.org/api" + path) say_error "Error #{response.status}" and abort unless response.status == 200 yield response if block_given? JSON.parse(response.body) end |