Class: OctocatHerder::User
- Inherits:
-
Object
- Object
- OctocatHerder::User
- Includes:
- Base
- Defined in:
- lib/octocat_herder/user.rb
Overview
Interface to the GitHub v3 API for interacting with users.
Currently, this only supports retrieval of information about the requested user.
Instance Attribute Summary
Attributes included from Base
Class Method Summary collapse
-
.fetch(user_name, conn = OctocatHerder::Connection.new) ⇒ OctocatHerder::User
Find a user by login name.
-
.following?(user, connection) ⇒ true, false
Check if the user authenticated by the provided Connection is following the specified user.
Instance Method Summary collapse
-
#followers ⇒ Array<OctocatHerder::User>
List of users following this user.
-
#following ⇒ Array<OctocatHerder::User>
List of users this user is following.
-
#repositories ⇒ Array<OctocatHerder::Repository>
All repositories owned by the user.
-
#user_id ⇒ Integer
The ID number of the user.
-
#user_type ⇒ String
The type of account.
Methods included from Base
#available_attributes, #initialize, #method_missing
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class OctocatHerder::Base
Class Method Details
.fetch(user_name, conn = OctocatHerder::Connection.new) ⇒ OctocatHerder::User
Find a user by login name
24 25 26 27 28 |
# File 'lib/octocat_herder/user.rb', line 24 def self.fetch(user_name, conn = OctocatHerder::Connection.new) user = conn.get("/users/#{CGI.escape(user_name)}") new(user, conn) end |
.following?(user, connection) ⇒ true, false
Check if the user authenticated by the provided Connection is following the specified user.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/octocat_herder/user.rb', line 109 def self.following?(user, connection) raise ArgumentError.new( "Provided user must be a String, or an OctocatHerder::User." ) unless user.is_a?(String) or user.is_a?(OctocatHerder::User) raise ArgumentError.new( "Provided connection must make authenticated requests." ) unless connection.authenticated_requests? user_name = user.is_a?(OctocatHerder::User) ? user.login : user result = connection.raw_get("/user/following/#{CGI.escape(user_name)}") # The GitHub API gives us back a "204 No Content" if we are # following the user. result.response.code == "204" end |
Instance Method Details
#followers ⇒ Array<OctocatHerder::User>
List of users following this user.
69 70 71 72 73 74 75 76 77 |
# File 'lib/octocat_herder/user.rb', line 69 def followers result = connection.get( "/users/#{CGI.escape(login)}/followers" ) result.map do |follower| self.class.new(follower, connection) end end |
#following ⇒ Array<OctocatHerder::User>
List of users this user is following.
83 84 85 86 87 88 89 90 91 |
# File 'lib/octocat_herder/user.rb', line 83 def following users = connection.get( "/users/#{CGI.escape(login)}/following" ) users.map do |stalkee| self.class.new(stalkee, connection) end end |
#repositories ⇒ Array<OctocatHerder::Repository>
This is cached locally to the OctocatHerder::User instance, but at least one API request will be made to populate it initially.
All repositories owned by the user.
38 39 40 |
# File 'lib/octocat_herder/user.rb', line 38 def repositories @repositories ||= OctocatHerder::Repository.list_all(login, user_type, connection) end |
#user_id ⇒ Integer
The ID number of the user.
46 47 48 49 50 51 |
# File 'lib/octocat_herder/user.rb', line 46 def user_id # The user id can't be handled by the method_missing magic from # OctocatHerder::Base, since the id method returns the object # id. @raw['id'] end |
#user_type ⇒ String
The type of account. Typically one of ‘User’, or ‘Organization’.
58 59 60 61 62 63 |
# File 'lib/octocat_herder/user.rb', line 58 def user_type # The user type can't be handled by the method_missing magic # from OctocatHerder::Base, since 'type' is the deprecated form # of the method 'class'. @raw['type'] end |