Sha256: ae4decd0f879dff2c5447962d0a26485b8221c6bce697056938c0a775e4a402a

Contents?: true

Size: 1.26 KB

Versions: 23

Compression:

Stored size: 1.26 KB

Contents

module Videojuicer
  class User
    include Videojuicer::Resource
    include Videojuicer::Exceptions
    
    property :name, String
    property :login, String
    property :email, String
    property :password, String
    property :password_confirmation, String
    property :created_at, DateTime
    property :updated_at, DateTime
    property :roles, Array, :writer => :readonly
    
    # Authenticates the given login and password and returns
    # a user if the details are correct. Requires a Master token.
    def self.authenticate(login, password)
      proxy = Videojuicer::OAuth::RequestProxy.new
      begin
        jobj = JSON.parse(proxy.get("/users/authenticate.json", :login=>login, :password=>password).body)
        o = new(:id=>jobj["id"])
        o.reload
        return o
      rescue NoResource =>e
        return nil
      end
    end
    
    # Manage virtual attributes that are not sent back to the API
    attr_accessor :roles
    def has_role?(symbol)
      roles.include?(symbol.to_s)
    end
    
    def add_role(*symbols)
      symbols.each {|r| proxy_for(config).post(resource_path(:add_role), :role=>r) }
    end

    def remove_role(*symbols)
      symbols.each {|r| proxy_for(config).post(resource_path(:remove_role), :role=>r) }
    end
    
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
vj-sdk-0.8.0.1 lib/videojuicer/user.rb
vj-sdk-0.7.14 lib/videojuicer/user.rb
vj-sdk-0.7.13 lib/videojuicer/user.rb
vj-sdk-0.7.11 lib/videojuicer/user.rb
vj-sdk-0.7.10 lib/videojuicer/user.rb
vj-sdk-0.7.9 lib/videojuicer/user.rb
vj-sdk-0.7.8 lib/videojuicer/user.rb
vj-sdk-0.7.7 lib/videojuicer/user.rb
vj-sdk-0.7.6 lib/videojuicer/user.rb
vj-sdk-0.7.5 lib/videojuicer/user.rb
vj-sdk-0.7.4 lib/videojuicer/user.rb
vj-sdk-0.7.3 lib/videojuicer/user.rb
vj-sdk-0.7.2 lib/videojuicer/user.rb
vj-sdk-0.7.1 lib/videojuicer/user.rb
vj-sdk-0.7.0 lib/videojuicer/user.rb
vj-sdk-0.6.9 lib/videojuicer/user.rb
vj-sdk-0.6.8 lib/videojuicer/user.rb
vj-sdk-0.6.7 lib/videojuicer/user.rb
vj-sdk-0.6.5 lib/videojuicer/user.rb
vj-sdk-0.6.4 lib/videojuicer/user.rb