Class: UboostClient::Widgets
- Inherits:
-
Object
- Object
- UboostClient::Widgets
- Defined in:
- lib/uboost-client/uboost_client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#session ⇒ Object
Returns the value of attribute session.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #cache_uboost_cookie(response) ⇒ Object
- #cached_uboost_id_available? ⇒ Boolean
- #get(url, options) ⇒ Object
- #get_sso_token(account_id) ⇒ Object
-
#initialize(client, options) ⇒ Widgets
constructor
A new instance of Widgets.
- #leaderboard(options) ⇒ Object
- #list_of_leaderboards(options) ⇒ Object
- #my_badges(options) ⇒ Object
- #profile(options) ⇒ Object
- #session_cache_available? ⇒ Boolean
- #ubar(account_id, options = Hash.new) ⇒ Object
Constructor Details
#initialize(client, options) ⇒ Widgets
Returns a new instance of Widgets.
181 182 183 184 185 |
# File 'lib/uboost-client/uboost_client.rb', line 181 def initialize(client, ) @client = client @url = '/api/widgets' @session = [:session] || false end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
179 180 181 |
# File 'lib/uboost-client/uboost_client.rb', line 179 def client @client end |
#session ⇒ Object
Returns the value of attribute session.
179 180 181 |
# File 'lib/uboost-client/uboost_client.rb', line 179 def session @session end |
#url ⇒ Object
Returns the value of attribute url.
179 180 181 |
# File 'lib/uboost-client/uboost_client.rb', line 179 def url @url end |
Instance Method Details
#cache_uboost_cookie(response) ⇒ Object
199 200 201 202 |
# File 'lib/uboost-client/uboost_client.rb', line 199 def (response) = CGI::Cookie.parse(response.headers['set-cookie']) @session[:uboost_session_id] = "_uboost_session_id=" + ["_uboost_session_id"][0] end |
#cached_uboost_id_available? ⇒ Boolean
191 192 193 |
# File 'lib/uboost-client/uboost_client.rb', line 191 def cached_uboost_id_available? @session && @session[:uboost_session_id] end |
#get(url, options) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/uboost-client/uboost_client.rb', line 204 def get(url, ) response = nil if !session_cache_available? response = @client.connection.get url, :sso_token => get_sso_token([:account_id]) elsif !cached_uboost_id_available? response = @client.connection.get url, :sso_token => get_sso_token([:account_id]) (response) elsif cached_uboost_id_available? response = @client.connection_with_uboost_session(@session[:uboost_session_id]).get url (response) end response end |
#get_sso_token(account_id) ⇒ Object
195 196 197 |
# File 'lib/uboost-client/uboost_client.rb', line 195 def get_sso_token(account_id) client.account.token(account_id).student["sso_token"] end |
#leaderboard(options) ⇒ Object
235 236 237 238 239 |
# File 'lib/uboost-client/uboost_client.rb', line 235 def leaderboard() = {:account_id => nil, :leaderboard_id => nil}.merge() response = get(@url + '/leaderboards/' + [:leaderboard_id].to_s, ) OpenStruct.new(JSON.parse(response.body)) end |
#list_of_leaderboards(options) ⇒ Object
230 231 232 233 |
# File 'lib/uboost-client/uboost_client.rb', line 230 def list_of_leaderboards() response = get(@url + '/leaderboards/', ) OpenStruct.new(JSON.parse(response.body)) end |
#my_badges(options) ⇒ Object
224 225 226 227 228 |
# File 'lib/uboost-client/uboost_client.rb', line 224 def my_badges() = {:account_id => nil, :badge_category_id => 'all'}.merge() response = get(@url + '/badges/mine/' + [:badge_category_id], ) OpenStruct.new(JSON.parse(response.body)) end |
#profile(options) ⇒ Object
218 219 220 221 222 |
# File 'lib/uboost-client/uboost_client.rb', line 218 def profile() = {:account_id => nil}.merge() response = get(@url + '/profile', ) OpenStruct.new(JSON.parse(response.body)) end |
#session_cache_available? ⇒ Boolean
187 188 189 |
# File 'lib/uboost-client/uboost_client.rb', line 187 def session_cache_available? @session end |
#ubar(account_id, options = Hash.new) ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/uboost-client/uboost_client.rb', line 241 def (account_id, = Hash.new) = {:align => "", :bar_color => '', :div_id => 'ubar'}.merge() token = get_sso_token(account_id) subdomain_url = "http://" + client.subdomain + ".uboost.com" " <script type='text/javascript' src='#{subdomain_url}/javascripts/uBar.js'></script> <div class='uboost_ubar' id='#{[:div_id]}'> <object> <param value='#{subdomain_url}/uBar.swf' name='movie'> <param value='100%' name='width'> <param value='100%' name='height'> <param value='transparent' name='wmode'> <param value='always' name='allowScriptAccess'> <param value='url=#{subdomain_url}/ubar/&token=#{token}&align=#{[:align]}&barColor=#{[:bar_color]}&divId=#{[:div_id]}' name='flashvars'> <param value='false' name='cacheBusting'> <param value='true' name='allowFullScreen'> <embed width='1280' height='400' wmode='transparent' allowfullscreen='true' quality='high' cachebusting='false' flashvars='url=#{subdomain_url}/ubar/&token=#{token}&align=#{[:align]}&barColor=#{[:bar_color]}&divId=#{:div_id}' allowscriptaccess='always' src='#{subdomain_url}/uBar.swf'> </object> </div>" end |