Module: OctocatHerder::Base
- Included in:
- PullRequest, PullRequest::Repo, Repository, User
- Defined in:
- lib/octocat_herder/base.rb
Overview
This provides most of the functionality to interact with the GitHub v3 API.
Instance Attribute Summary collapse
-
#connection ⇒ OctocatHerder::Connection
readonly
Our Connection, so we can make more requests based on the information we retrieved from the GitHub API.
-
#raw ⇒ Hash
readonly
The re-hydrated JSON retrieved from the GitHub API.
Instance Method Summary collapse
-
#available_attributes ⇒ Array<String>
This returns a list of the things that the API request returned to us.
- #initialize(raw_hash, conn = OctocatHerder::Connection.new) ⇒ Object private
-
#method_missing(id, *args) ⇒ Object
We use the
method_missing
magic to create accessors for the information we got back from the GitHub API.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id, *args) ⇒ Object
We use the method_missing
magic to create accessors for the information we got back from the GitHub API. You can get a list of all of the available things from #available_attributes.
48 49 50 51 52 53 54 |
# File 'lib/octocat_herder/base.rb', line 48 def method_missing(id, *args) unless @raw and @raw.keys.include?(id.id2name) raise NoMethodError.new("undefined method #{id.id2name} for #{self}:#{self.class}") end @raw[id.id2name] end |
Instance Attribute Details
#connection ⇒ OctocatHerder::Connection (readonly)
Our Connection, so we can make more requests based on the information we retrieved from the GitHub API.
28 29 30 |
# File 'lib/octocat_herder/base.rb', line 28 def connection @connection end |
#raw ⇒ Hash (readonly)
The re-hydrated JSON retrieved from the GitHub API.
21 22 23 |
# File 'lib/octocat_herder/base.rb', line 21 def raw @raw end |
Instance Method Details
#available_attributes ⇒ Array<String>
This returns a list of the things that the API request returned to us.
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/octocat_herder/base.rb', line 63 def available_attributes attrs = [] attrs += @raw.keys.reject do |k| [ 'id', 'type', ].include? k end if @raw (attrs + additional_attributes).uniq end |
#initialize(raw_hash, conn = OctocatHerder::Connection.new) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 41 |
# File 'lib/octocat_herder/base.rb', line 38 def initialize(raw_hash, conn = OctocatHerder::Connection.new) @connection = conn @raw = raw_hash end |