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

Instance Method Summary collapse

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.

Since:

  • 0.0.1



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

#connectionOctocatHerder::Connection (readonly)

Our Connection, so we can make more requests based on the information we retrieved from the GitHub API.

Returns:

Since:

  • 0.0.1



28
29
30
# File 'lib/octocat_herder/base.rb', line 28

def connection
  @connection
end

#rawHash (readonly)

The re-hydrated JSON retrieved from the GitHub API.

Returns:

  • (Hash)

Since:

  • 0.0.1



21
22
23
# File 'lib/octocat_herder/base.rb', line 21

def raw
  @raw
end

Instance Method Details

#available_attributesArray<String>

This returns a list of the things that the API request returned to us.

Returns:

  • (Array<String>)

    Names of available methods providing additional detail about the object.

Since:

  • 0.0.1



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.

Parameters:

  • raw_hash (Hash)

    The re-hydrated JSON received from the GitHub API via Connection.

  • conn (OctocatHerder::Connection) (defaults to: OctocatHerder::Connection.new)

    If not provided requests will be unauthenticated.

Since:

  • 0.0.1



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