Class: RTokBox::TokBoxUser
Overview
This class creates API calls for different user functions. You get an instance using TokBox.register_user, TokBox.get_user or directly:
tokbuser = RTokBox::TokBoxUser.new(EMAIL, PASSWORD, API_KEY, API_SECRET)
Returns nil on failure to log in.
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#error_code ⇒ Object
Returns the value of attribute error_code.
-
#password ⇒ Object
Returns the value of attribute password.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
-
#widget_id ⇒ Object
Returns the value of attribute widget_id.
Instance Method Summary collapse
-
#get_UserID ⇒ Object
Retrieves the user’s id.
-
#get_WidgetID ⇒ Object
Retrieves the user’s widget id.
-
#initialize(email, password, api_key, api_secret, api_url = 'http://api.tokbox.com/api.php') ⇒ TokBoxUser
constructor
Initializes the class and retrieves the needed information.
-
#make_widget ⇒ Object
Creates the Widget HTML code for this user.
Methods inherited from TokBox
#get_user, #register_user, #request
Constructor Details
#initialize(email, password, api_key, api_secret, api_url = 'http://api.tokbox.com/api.php') ⇒ TokBoxUser
Initializes the class and retrieves the needed information. Practically validates a login and returns nil if it fails.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rtokbox/tokbox_user.rb', line 17 def initialize(email, password, api_key, api_secret, api_url = 'http://api.tokbox.com/api.php') @api_key = api_key @api_secret = api_secret @api_url = api_url self.email = email self.password = Digest::MD5.hexdigest(password) self.user_id = get_UserID self. = get_WidgetID unless self.user_id or self. # raise "Could not log in. (error: #{self.error_code})" return nil end end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
13 14 15 |
# File 'lib/rtokbox/tokbox_user.rb', line 13 def email @email end |
#error_code ⇒ Object
Returns the value of attribute error_code.
13 14 15 |
# File 'lib/rtokbox/tokbox_user.rb', line 13 def error_code @error_code end |
#password ⇒ Object
Returns the value of attribute password.
13 14 15 |
# File 'lib/rtokbox/tokbox_user.rb', line 13 def password @password end |
#user_id ⇒ Object
Returns the value of attribute user_id.
13 14 15 |
# File 'lib/rtokbox/tokbox_user.rb', line 13 def user_id @user_id end |
#widget_id ⇒ Object
Returns the value of attribute widget_id.
13 14 15 |
# File 'lib/rtokbox/tokbox_user.rb', line 13 def end |
Instance Method Details
#get_UserID ⇒ Object
Retrieves the user’s id.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rtokbox/tokbox_user.rb', line 35 def get_UserID call = 'getUserID' call_id = Time.now.to_i.to_s msg = @api_key + call + call_id + self.email + FORMAT + self.password + VER sig = Digest::MD5.hexdigest(msg + @api_secret) params = {} params[:email] = self.email params[:password] = self.password result = request(call, call_id, params, sig, @api_key, @api_url) if result['success'] return result['userid'] else self.error_code = result['errorCode'] return nil end end |
#get_WidgetID ⇒ Object
Retrieves the user’s widget id.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rtokbox/tokbox_user.rb', line 56 def get_WidgetID call = 'getWidgetID' call_id = Time.now.to_i.to_s msg = @api_key + call + call_id + self.email + FORMAT + self.password + VER sig = Digest::MD5.hexdigest(msg + @api_secret) params = {} params[:email] = self.email params[:password] = self.password result = request(call, call_id, params, sig, @api_key, @api_url) if result['success'] return result['widgetid'] else self.error_code = result['errorCode'] return nil end end |
#make_widget ⇒ Object
Creates the Widget HTML code for this user.
77 78 79 80 81 82 83 |
# File 'lib/rtokbox/tokbox_user.rb', line 77 def result = '<object type="application/x-shockwave-flash" data="http://www.tokbox.com/f/' + self. + '" width="540" height="260"> <param name="movie" value="http://www.tokbox.com/f/' + self. + '"></param> <param name=FlashVars value="user=' + self.user_id + '&pass=' + self.password + '"></param> </object>' result end |