Class: Github::User
Instance Attribute Summary
Attributes included from Base
Class Method Summary collapse
-
.fetch(user = nil, conn = Github::Connection.new) ⇒ Object
Generate JSON hash and create new Github::User object through Github::Base.
Instance Method Summary collapse
-
#followers ⇒ Object
Return a Github::User object for each follower.
-
#id ⇒ Object
Define ID because its reserved by ruby.
- #notifications(params = {}) ⇒ Object
- #repos(params = {}) ⇒ Object
-
#type ⇒ Object
Define type because its reserved by ruby.
- #watchers(type) ⇒ Object
Methods included from Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Github::Base
Class Method Details
.fetch(user = nil, conn = Github::Connection.new) ⇒ Object
Generate JSON hash and create new Github::User object through Github::Base
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/hubdate/user.rb', line 6 def self.fetch(user = nil, conn = Github::Connection.new) conn = user if user.class == Github::Connection user = nil if user.class == Github::Connection if user.nil? raise ArgumentError.new("Authenticated request required when making calls on logged in user.") unless conn.authenticated? responseHash = conn.get("/user") else responseHash = conn.get("/users/#{user}") end new(responseHash, conn) end |
Instance Method Details
#followers ⇒ Object
Return a Github::User object for each follower
30 31 32 33 34 35 36 |
# File 'lib/hubdate/user.rb', line 30 def followers result = connection.get("/users/#{login}/followers") result.map do |follower| self.class.new(follower, connection) end end |
#id ⇒ Object
Define ID because its reserved by ruby
20 21 22 |
# File 'lib/hubdate/user.rb', line 20 def id @response['id'] end |
#notifications(params = {}) ⇒ Object
38 39 40 |
# File 'lib/hubdate/user.rb', line 38 def notifications(params = {}) Github::Notification.list(params, connection) end |
#repos(params = {}) ⇒ Object
42 43 44 |
# File 'lib/hubdate/user.rb', line 42 def repos(params = {}) Github::Repository.list(login, type, params, connection) end |
#type ⇒ Object
Define type because its reserved by ruby
25 26 27 |
# File 'lib/hubdate/user.rb', line 25 def type @response['type'] end |
#watchers(type) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/hubdate/user.rb', line 46 def watchers(type) case type when :stargazer type = "stargazers" when :watcher type = "subscribers" else raise StandardError.new("Watcher type must be either :stargazer or :watcher!") end stargazers_hash = {} repos = self.repos.map {|repo| repo.name} repos.each do |repo| stargazers = connection.get("/repos/#{login}/#{repo}/#{type}") stargazers_array = stargazers.map {|gazer| gazer["login"]} stargazers_hash[repo.to_s] = stargazers_array end return stargazers_hash end |