Sha256: b0032b8f3144037ad71e900010d40fa576d2cf18eed875103ac97881c8deb45e

Contents?: true

Size: 775 Bytes

Versions: 8

Compression:

Stored size: 775 Bytes

Contents

# encoding: utf-8
#
# Copyright (C) 2011-2012  AdMaster, Inc.

require 'net/http'

module Apimaster::Models
  class User

    attr_accessor :id
    attr_accessor :email
    attr_accessor :username

    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

    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

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
apimaster-0.1.2 lib/apimaster/models/user.rb
apimaster-0.1.1 lib/apimaster/models/user.rb
apimaster-0.0.7 lib/apimaster/models/user.rb
apimaster-0.0.6 lib/apimaster/models/user.rb
apimaster-0.0.5 lib/apimaster/models/user.rb
apimaster-0.0.4 lib/apimaster/models/user.rb
apimaster-0.0.3 lib/apimaster/models/user.rb
apimaster-0.0.2 lib/apimaster/models/user.rb