Class: Apimaster::Models::User

Inherits:
Object
  • Object
show all
Defined in:
lib/apimaster/models/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#emailObject

Returns the value of attribute email.



11
12
13
# File 'lib/apimaster/models/user.rb', line 11

def email
  @email
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/apimaster/models/user.rb', line 10

def id
  @id
end

#usernameObject

Returns the value of attribute username.



12
13
14
# File 'lib/apimaster/models/user.rb', line 12

def username
  @username
end

#uuidObject

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