Sha256: 06e948c5a1f9c5a7ee3e4d668f4c12a81ab6949769125b041024c18947fbc8c3

Contents?: true

Size: 788 Bytes

Versions: 1

Compression:

Stored size: 788 Bytes

Contents

module Cheatsheet
  class Client

    SOURCE = "https://raw.githubusercontent.com/rstacruz/cheatsheets/gh-pages/"

    def self.fetch(*args)
      key = args[0].first
      uri = URI(SOURCE + key + ".md")

      begin
        puts self.fetch_raw(uri)
      rescue CheatSheetClientException => e
        puts e.message
      end
    end

    def self.fetch_raw(uri)
      response = Net::HTTP.get_response(uri)

      case response
      when Net::HTTPSuccess then
        Net::HTTP.get(uri)
      when Net::HTTPNotFound then
        raise CheatSheetClientException.new "We don't have that cheatsheet yet. Feel free to contribute here: https://github.com/rstacruz/cheatsheets"
      else
        response.value
      end
    end

  end
end

class CheatSheetClientException < Exception
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cheatsheet-0.1.1 lib/cheatsheet/client.rb