Class: GitHub::User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- GitHub::User
- Defined in:
- lib/github-api-client/user.rb
Overview
Basic model, stores retrieved user and his associations
Class Method Summary collapse
-
.get(login) ⇒ GitHub::User
Static function, that gets information about GitHub::User by login.
-
.get_followers(login) ⇒ Array<GitHub::User>
deprecated
Deprecated.
It should not support such way, there should be objects!
-
.search(login) ⇒ Array<GitHub::User>
Searches for users in GitHub database.
Instance Method Summary collapse
-
#auth_info ⇒ Hash
Collects information from authenticated user.
-
#fetch(*things) ⇒ GitHub::User
End-user way to fetch information.
-
#get ⇒ GitHub::User
Fetches info about current_user from GitHub GitHub::User.new.build(:login => ‘asd’, :token => ‘token’).get #=> GitHub::User.
-
#post(login, options = {}) ⇒ String
Experimental, sets information about GitHub::User or returns authenticated :self.
-
#set(route = [], options = {}) ⇒ Object
Experimental function, requests POST transmission to custom path of GitHub API.
Class Method Details
.get(login) ⇒ GitHub::User
27 28 29 30 31 32 33 |
# File 'lib/github-api-client/user.rb', line 27 def self.get(login) if u = GitHub::User.find_by_login(login) u.get else u = GitHub::User.new(:login => login).fetch(:self) end end |
.get_followers(login) ⇒ Array<GitHub::User>
It should not support such way, there should be objects!
Returns an array with logins of GitHub::User followers
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/github-api-client/user.rb', line 152 def self.get_followers(login) users = YAML::load(GitHub::Browser.get "/user/show/#{login}/followers")['users'] # Loading each user (not effective with 688 followers like schacon has) objects = [] i = 1 users.each do |user| puts "#{users.length.to_s} / #{i.to_s} - Fetching followers" i = i + 1 u = GitHub::User.find_or_create_by_login(user) objects << u end return objects end |
.search(login) ⇒ Array<GitHub::User>
Searches for users in GitHub database
38 39 40 41 42 43 44 |
# File 'lib/github-api-client/user.rb', line 38 def self.search(login) users = [] YAML::load(GitHub::Browser.get("/user/search/#{login}"))['users'].each do |user| users << GitHub::User.find_or_create_by_login(GitHub::Base.parse_attributes(:user_search, user)) end users end |
Instance Method Details
#auth_info ⇒ Hash
Collects information from authenticated user. Used by post requests to authenticate
170 171 172 |
# File 'lib/github-api-client/user.rb', line 170 def auth_info {:login => self.login, :token => self.token} end |
#fetch(*things) ⇒ GitHub::User
End-user way to fetch information
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/github-api-client/user.rb', line 62 def fetch(*things) things.each do |thing| case thing when :self then get when :followers then get_followers when :followings then get_followings when :organizations then get_organizations when :repos then get_repos end end self end |
#get ⇒ GitHub::User
Fetches info about current_user from GitHub GitHub::User.new.build(:login => ‘asd’, :token => ‘token’).get #=> GitHub::User
14 15 16 17 18 19 20 |
# File 'lib/github-api-client/user.rb', line 14 def get self.update_attributes( GitHub::Base.parse_attributes(:user_get, YAML::load( GitHub::Browser.get("/user/show/#{self.login}"))['user'])) self end |
#post(login, options = {}) ⇒ String
Experimental, sets information about GitHub::User or returns authenticated :self
179 180 181 182 183 184 |
# File 'lib/github-api-client/user.rb', line 179 def post(login, = {}) if [:self, :me].include? login login = self.login end return GitHub::Browser.post "/user/show/#{login}", .merge(self.auth_info) end |