Sha256: 88c36832f2751b339a9ecfee86597f6a633652680347b9f50661395c95dc906f

Contents?: true

Size: 724 Bytes

Versions: 1

Compression:

Stored size: 724 Bytes

Contents

require 'excon'
require 'json'
require "colored"

module RubyChina
  module Helpers
    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

    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

    private

    def client
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubychina-0.0.1 ./lib/rubychina/helpers.rb