Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Defined in:
- lib/travis/model/user.rb
Class Method Summary collapse
- .find_or_create_for_oauth(payload) ⇒ Object
-
.user_data_from_oauth(payload) ⇒ Object
TODO move this to a OauthPayload.
Instance Method Summary collapse
Class Method Details
.find_or_create_for_oauth(payload) ⇒ Object
16 17 18 19 20 |
# File 'lib/travis/model/user.rb', line 16 def find_or_create_for_oauth(payload) data = user_data_from_oauth(payload) user = User.find_by_github_id(data['github_id']) user ? user.update_attributes(data) && user : create!(data) end |
.user_data_from_oauth(payload) ⇒ Object
TODO move this to a OauthPayload
22 23 24 25 26 27 28 29 30 |
# File 'lib/travis/model/user.rb', line 22 def user_data_from_oauth(payload) # TODO move this to a OauthPayload { 'name' => payload['user_info']['name'], 'email' => payload['user_info']['email'], 'login' => payload['user_info']['nickname'], 'github_id' => payload['uid'], 'github_oauth_token' => payload['credentials']['token'] } end |
Instance Method Details
#github_repositories ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/travis/model/user.rb', line 45 def github_repositories Travis::GithubApi.repositories_for_user(login).each_with_index do |repository, ix| repository.uid = [login, ix].join(':') repository.active = active_repositories[repository.name] || false repository.owner = repository['owner'].login end end |
#profile_image_hash ⇒ Object
41 42 43 |
# File 'lib/travis/model/user.rb', line 41 def profile_image_hash self.email? ? Digest::MD5.hexdigest(self.email) : '00000000000000000000000000000000' end |
#recently_signed_up? ⇒ Boolean
37 38 39 |
# File 'lib/travis/model/user.rb', line 37 def recently_signed_up? !!@recently_signed_up end |