Class: Apimaster::Models::User
- Inherits:
-
Object
- Object
- Apimaster::Models::User
- Defined in:
- lib/apimaster/models/user.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#id ⇒ Object
Returns the value of attribute id.
-
#username ⇒ Object
Returns the value of attribute username.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash) ⇒ User
constructor
A new instance of User.
Constructor Details
#initialize(hash) ⇒ User
Returns a new instance of User.
15 16 17 18 19 20 |
# File 'lib/apimaster/models/user.rb', line 15 def initialize hash hash.each do |key, val| method_name = (key.to_s+'=').to_sym self.send(method_name, val) if respond_to?(method_name) end end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
11 12 13 |
# File 'lib/apimaster/models/user.rb', line 11 def email @email end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/apimaster/models/user.rb', line 10 def id @id end |
#username ⇒ Object
Returns the value of attribute username.
12 13 14 |
# File 'lib/apimaster/models/user.rb', line 12 def username @username end |
#uuid ⇒ Object
Returns the value of attribute uuid.
13 14 15 |
# File 'lib/apimaster/models/user.rb', line 13 def uuid @uuid end |
Class Method Details
.auth(access_token) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/apimaster/models/user.rb', line 22 def self.auth access_token oauth_domain = Apimaster::Setting.get('oauth.oauth_domain') json = Net::HTTP.get(oauth_domain, "/user?access_token=#{access_token}", 80) user_hash = JSON.parse(json) return nil unless user_hash.is_a?(Hash) raise Apimaster::OauthError.new(user_hash["message"]) if user_hash.key?("message") self.new user_hash end |