Class: Ankoder::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/ankoder/auth.rb

Overview

Authenticate to the ankoder service

user = Auth.create("login", "password")
user.

If you want to recover a session:

user = Auth.recover(session_id)
user.

The initialize and create methods can take blocks.

Auth.create("login", "password") do |user|
  video = user.videos.find(:first)
  profile = user.profiles.find(:first, :conditions => {:name => "iPod 4:3"})
  user.jobs.create :original_file_id => video.id, :profile_id => profile.id
end

All the resources (pluralized) are available within the Auth class:

jobs, videos, profiles, downloads, account

Constant Summary collapse

@@sessions =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Auth

Authenticate to the _ankoderapi_session service

options can be:

  • :login _ankoderapi_session username

  • :password _ankoderapi_session password

  • :session A previous session, using this option, you will not be reconnected, you will just recover your session

Yields:

  • (_self)

Yield Parameters:

  • _self (Ankoder::Auth)

    the object that the method was called on



35
36
37
38
39
40
41
42
43
# File 'lib/ankoder/auth.rb', line 35

def initialize(options={}, &block)
    if options[:session]
      @session = options[:session]
    else
      @session = Browser::(options[:login], options[:password])
      @@sessions.merge!(@session => true)
    end
    yield self if block_given?
end

Instance Attribute Details

#sessionObject (readonly)

Returns the value of attribute session.



25
26
27
# File 'lib/ankoder/auth.rb', line 25

def session
  @session
end

Class Method Details

.create(login = Configuration::auth_user, password = Configuration::auth_password, &block) ⇒ Object

Same as initialize

Auth::create ‘login’, ‘password’



48
49
50
# File 'lib/ankoder/auth.rb', line 48

def self.create(= Configuration::auth_user, password =Configuration::auth_password, &block)
  new(:login => , :password => password, &block)
end

.recover(session, &block) ⇒ Object

Recover a session

Auth.recover(session_id)


55
56
57
58
# File 'lib/ankoder/auth.rb', line 55

def self.recover(session, &block)
  #raise SessionNotFound if @@sessions[session].nil?
  new(:session => session, &block)
end

Instance Method Details

#accountObject

Show account info



78
79
80
81
# File 'lib/ankoder/auth.rb', line 78

def 
  Account.session = @session
  Account.find(:first)
end

#destroyObject

Delete the current session



72
73
74
75
# File 'lib/ankoder/auth.rb', line 72

def destroy
  @@sessions.delete(@session)
  @session = nil
end