Class: GitHub::Base
- Inherits:
-
Object
- Object
- GitHub::Base
- Defined in:
- lib/git_hub/base.rb
Class Method Summary collapse
-
.aliases_for(attributes) ⇒ Object
Meta-defines alias(es) for multiple attribute-accessors.
- .base_uri ⇒ Object
- .get(uri, data = {}) ⇒ Object
- .post(uri, data = {}) ⇒ Object
- .request(verb, uri, data = {}) ⇒ Object
- .set_resource(base_uri, singular, plural) ⇒ Object
Instance Method Summary collapse
- #get(uri, data = {}) ⇒ Object
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
- #post(uri, data = {}) ⇒ Object
- #set_attributes(attributes) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
7 8 9 |
# File 'lib/git_hub/base.rb', line 7 def initialize(attributes={}) set_attributes attributes end |
Class Method Details
.aliases_for(attributes) ⇒ Object
Meta-defines alias(es) for multiple attribute-accessors
48 49 50 51 52 53 54 55 |
# File 'lib/git_hub/base.rb', line 48 def aliases_for attributes attributes.each do |attr, nicks| [nicks].flatten.each do |nick| self.class_eval("alias #{nick} #{attr} alias #{nick}= #{attr}=") end end end |
.base_uri ⇒ Object
43 44 45 |
# File 'lib/git_hub/base.rb', line 43 def base_uri @base_uri || '' end |
.get(uri, data = {}) ⇒ Object
29 30 31 |
# File 'lib/git_hub/base.rb', line 29 def get uri, data = {} request :get, uri, data end |
.post(uri, data = {}) ⇒ Object
33 34 35 |
# File 'lib/git_hub/base.rb', line 33 def post uri, data = {} request :post, uri, data end |
.request(verb, uri, data = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/git_hub/base.rb', line 19 def request verb, uri, data = {} full_uri = uri[0] == '/' ? base_uri+uri : uri res = API.request verb, full_uri, data if res.respond_to?(:content_type, :body) && res.content_type =~ /application\/x-yaml/ YAML::load(res.body) else res end end |
.set_resource(base_uri, singular, plural) ⇒ Object
37 38 39 40 41 |
# File 'lib/git_hub/base.rb', line 37 def set_resource base_uri, singular, plural @base_uri = base_uri @singular = singular.to_s @plural = plural.to_s end |
Instance Method Details
#get(uri, data = {}) ⇒ Object
110 111 112 |
# File 'lib/git_hub/base.rb', line 110 def get uri, data = {} self.class.get uri, data end |
#post(uri, data = {}) ⇒ Object
114 115 116 |
# File 'lib/git_hub/base.rb', line 114 def post uri, data = {} self.class.post uri, data end |
#set_attributes(attributes) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/git_hub/base.rb', line 11 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 |
#to_s ⇒ Object
118 119 120 |
# File 'lib/git_hub/base.rb', line 118 def to_s name end |