Sha256: 30432a715433dc6d0d0e4d8813dc21a64f3f104ffe226c2fe494ce1ad0eaee3d

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

require 'yaml'

module GitHub
  class Base
    @base_uri = ''

    def initialize(attributes={})
      attributes.each do |key, value|
        raise "No attr_accessor for #{key} on #{self.class}" unless respond_to?("#{key}=")
        self.send("#{key}=", value)
      end
    end

    def self.base_uri uri
      @base_uri = uri
    end

    class << self
      def request verb, uri, params = {}
        res = api.request verb, @base_uri+uri, params
        YAML::load(res.body) if res.respond_to?(:body) # res.kind_of?(Net::HTTPSuccess)
        #p "in show: #{res}: #{res.code}: #{res.http_version}: #{res.message}", res.body
      end

      def get uri, params ={}
        request :get, uri, params
      end

      def post uri, params = {}
        request :post, uri, params
      end

      def api
        @@api ||= GitHub::Api.instance
      end
    end

    def get uri, params ={}
      self.class.get uri, params
    end

    def post uri, params ={}
      self.class.post uri, params
    end

    def api
      self.class.api
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
git_hub-0.1.0 lib/git_hub/base.rb
zemax-0.1.0 lib/git_hub/base.rb
git_hub-0.0.1 lib/git_hub/base.rb