Class: Ankoder::Auth
- Inherits:
-
Object
- Object
- Ankoder::Auth
- Defined in:
- lib/ankoder/auth.rb
Overview
Authenticate to the ankoder service
user = Auth.create("login", "password")
user.account
If you want to recover a session:
user = Auth.recover(session_id)
user.account
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
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Class Method Summary collapse
-
.create(login = Configuration::auth_user, password = Configuration::auth_password, &block) ⇒ Object
Same as initialize.
-
.recover(session, &block) ⇒ Object
Recover a session.
Instance Method Summary collapse
-
#account ⇒ Object
Show account info.
-
#destroy ⇒ Object
Delete the current session.
-
#initialize(options = {}) {|_self| ... } ⇒ Auth
constructor
Authenticate to the _ankoderapi_session service.
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
35 36 37 38 39 40 41 42 43 |
# File 'lib/ankoder/auth.rb', line 35 def initialize(={}, &block) if [:session] @session = [:session] else @session = Browser::login([:login], [:password]) @@sessions.merge!(@session => true) end yield self if block_given? end |
Instance Attribute Details
#session ⇒ Object (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(login= Configuration::auth_user, password =Configuration::auth_password, &block) new(:login => 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
#account ⇒ Object
Show account info
78 79 80 81 |
# File 'lib/ankoder/auth.rb', line 78 def account Account.session = @session Account.find(:first) end |
#destroy ⇒ Object
Delete the current session
72 73 74 75 |
# File 'lib/ankoder/auth.rb', line 72 def destroy @@sessions.delete(@session) @session = nil end |