Class: Skydrive::User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Skydrive::User
- Includes:
- ActiveModel::ForbiddenAttributesProtection
- Defined in:
- app/models/skydrive/user.rb
Instance Method Summary collapse
- #cleanup_api_keys ⇒ Object
- #ensure_token ⇒ Object
- #reset_token! ⇒ Object
- #session_api_key(params = {}) ⇒ Object
- #skydrive_client ⇒ Object
- #valid_skydrive_token? ⇒ Boolean
Instance Method Details
#cleanup_api_keys ⇒ Object
23 24 25 |
# File 'app/models/skydrive/user.rb', line 23 def cleanup_api_keys api_keys.inactive.each(&:destroy) end |
#ensure_token ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/skydrive/user.rb', line 31 def ensure_token if self.token begin self.token.refresh! if self.token.requires_refresh? rescue Skydrive::APIResponseErrorException, JSON::ParserError => error self.reset_token! end end self.token = self.create_token unless self.token end |
#reset_token! ⇒ Object
43 44 45 46 |
# File 'app/models/skydrive/user.rb', line 43 def reset_token! self.token.delete ensure_token end |
#session_api_key(params = {}) ⇒ Object
15 16 17 18 19 20 21 |
# File 'app/models/skydrive/user.rb', line 15 def session_api_key(params={}) ApiKey.create( user_id: self.id, scope: 'session', init_params: params.to_json ) end |
#skydrive_client ⇒ Object
48 49 50 51 52 53 |
# File 'app/models/skydrive/user.rb', line 48 def skydrive_client @skydrive_client ||= Client.new(SHAREPOINT.merge( user_token: self.token )) end |
#valid_skydrive_token? ⇒ Boolean
27 28 29 |
# File 'app/models/skydrive/user.rb', line 27 def valid_skydrive_token? !!self.token && self.token.is_valid? end |