Class GitHub::Base
In: lib/git_hub/base.rb
Parent: Object

Methods

api   api   base_uri   get   get   new   post   post   request   set_attributes   set_resource   to_s  

Public Class methods

[Source]

# File lib/git_hub/base.rb, line 34
      def api
        @@api ||= Api.instance
      end

[Source]

# File lib/git_hub/base.rb, line 44
      def base_uri
        @base_uri || ''
      end

[Source]

# File lib/git_hub/base.rb, line 26
      def get uri, params ={}
        request :get, uri, params
      end

[Source]

# File lib/git_hub/base.rb, line 6
    def initialize(attributes={})
      set_attributes attributes
    end

[Source]

# File lib/git_hub/base.rb, line 30
      def post uri, params = {}
        request :post, uri, params
      end

[Source]

# File lib/git_hub/base.rb, line 18
      def request verb, uri, params = {}
        full_uri = uri[0] == '/' ? base_uri+uri : uri
        #p "request: #{verb} #{full_uri} #{params}"
        res = api.request verb, full_uri, params
        YAML::load(res.body) if res.respond_to?(:body)
        #p "response: #{res}: #{res.code}: #{res.http_version}: #{res.message}", res.body
      end

[Source]

# File lib/git_hub/base.rb, line 38
      def set_resource base_uri, singulars, plurals
        @base_uri = base_uri
        @singulars = [singulars].flatten
        @plurals = [plurals].flatten
      end

Public Instance methods

[Source]

# File lib/git_hub/base.rb, line 97
    def api
      self.class.api
    end

[Source]

# File lib/git_hub/base.rb, line 89
    def get uri, params ={}
      self.class.get uri, params
    end

[Source]

# File lib/git_hub/base.rb, line 93
    def post uri, params ={}
      self.class.post uri, params
    end

[Source]

# File lib/git_hub/base.rb, line 10
    def set_attributes attributes
      attributes.each do |key, value|
        raise "No attr_accessor for #{key} on #{self.class}" unless respond_to?("#{key}=")
        self.send("#{key.to_s}=", value)
      end
    end

[Source]

# File lib/git_hub/base.rb, line 101
    def to_s
      name
    end

[Validate]