Sha256: fc5d5814575240d9ae43815ce01ddf6f936f364869a3f59570ea9f4e99ec9ef3

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

module Protolink
  class User
    attr_reader :id, :name, :login, :email, :avatar_url, :external_profile_url

    def initialize(connection, attributes = {})
      @connection = connection
      @id         = attributes['id']
      @name       = attributes['name']
      @login      = attributes['login']
      @email      = attributes['email']
      @avatar_url = attributes['avatar_url']
      @external_profile_url = attributes['external_profile_url']
      @loaded     = false
    end

    # get token for autologin
    def auth_token
      connection.get("/api/v1/users/#{self.id}/auth_token.json")["token"]
    end
    
    def delete!
      connection.delete("/api/v1/users/#{self.id}")
    end

    protected

      def load
        reload! unless @loaded
      end

      # does not work yet
      def reload!
        attributes = connection.get("/api/v1/users/#{@id}.json")['user']

        @id         = attributes['id']
        @name       = attributes['name']
        @login      = attributes['login']
        @email      = attributes['email']
        @avatar_url = attributes['avatar_url']
        @loaded    = true
      end

      def connection
        @connection
      end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
protolink-0.2.6 lib/protolink/user.rb
protolink-0.2.5 lib/protolink/user.rb
protolink-0.2.4 lib/protolink/user.rb
protolink-0.2.3 lib/protolink/user.rb
protolink-0.2.2 lib/protolink/user.rb
protolink-0.2.1 lib/protolink/user.rb