Sha256: 80251e7e1342b3830708ad00566f3f6584cca7b282bd8f241976fb4e69b875ef

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

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

    def initialize(connection, attributes = {})
      @connection = connection
      @id         = attributes['id']
      @name       = attributes['name']
      @login      = attributes['login']
      @email      = attributes['email']
      @avatar_url = attributes['avatar_url']
      @node_id    = attributes['node_id']
      @external_profile_url = attributes['external_profile_url']
      @communication_token  = attributes['communication_token']
      @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

5 entries across 5 versions & 1 rubygems

Version Path
protolink-0.2.11 lib/protolink/user.rb
protolink-0.2.10 lib/protolink/user.rb
protolink-0.2.9 lib/protolink/user.rb
protolink-0.2.8 lib/protolink/user.rb
protolink-0.2.7 lib/protolink/user.rb