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.
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#session ⇒ Object
Returns the value of attribute session.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #badge_categories(options = Hash.new) ⇒ Object
- #badges_for_category(options = Hash.new) ⇒ Object
- #cache_uboost_cookie(response) ⇒ Object
- #cached_uboost_id_available? ⇒ Boolean
- #credentials_available? ⇒ Boolean
- #get(url, options) ⇒ Object
- #get_sso_token(account_id) ⇒ Object
-
#initialize(client, options) ⇒ Widgets
constructor
A new instance of Widgets.
- #leaderboard(options = Hash.new) ⇒ Object
- #list_of_leaderboards(options = Hash.new) ⇒ Object
- #my_badges(options = Hash.new) ⇒ Object
- #profile(options = Hash.new) ⇒ Object
- #session_cache_available? ⇒ Boolean
- #ubar(options = Hash.new) ⇒ Object
- #unearned_badges(options = Hash.new) ⇒ Object
Constructor Details
#initialize(client, options) ⇒ Widgets
Returns a new instance of Widgets.
186 187 188 189 190 191 |
# File 'lib/uboost-client/uboost_client.rb', line 186 def initialize(client, ) @client = client @url = '/api/widgets' @session = [:session] || false @credentials = [:credentials] || false end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
184 185 186 |
# File 'lib/uboost-client/uboost_client.rb', line 184 def client @client end |
#credentials ⇒ Object
Returns the value of attribute credentials.
184 185 186 |
# File 'lib/uboost-client/uboost_client.rb', line 184 def credentials @credentials end |
#session ⇒ Object
Returns the value of attribute session.
184 185 186 |
# File 'lib/uboost-client/uboost_client.rb', line 184 def session @session end |
#url ⇒ Object
Returns the value of attribute url.
184 185 186 |
# File 'lib/uboost-client/uboost_client.rb', line 184 def url @url end |
Instance Method Details
#badge_categories(options = Hash.new) ⇒ Object
236 237 238 239 |
# File 'lib/uboost-client/uboost_client.rb', line 236 def badge_categories( = Hash.new) response = get(@url + '/badge_categories', ) OpenStruct.new(JSON.parse(response.body)) end |
#badges_for_category(options = Hash.new) ⇒ Object
241 242 243 244 245 |
# File 'lib/uboost-client/uboost_client.rb', line 241 def badges_for_category( = Hash.new) = {:account_id => nil, :badge_category_id => nil}.merge() response = get(@url + '/badge_categories/' + [:badge_category_id].to_s + '/badges', ) OpenStruct.new(JSON.parse(response.body)) end |
#cache_uboost_cookie(response) ⇒ Object
209 210 211 212 |
# File 'lib/uboost-client/uboost_client.rb', line 209 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
201 202 203 |
# File 'lib/uboost-client/uboost_client.rb', line 201 def cached_uboost_id_available? @session && @session[:uboost_session_id] end |
#credentials_available? ⇒ Boolean
193 194 195 |
# File 'lib/uboost-client/uboost_client.rb', line 193 def credentials_available? @credentials end |
#get(url, options) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/uboost-client/uboost_client.rb', line 214 def get(url, ) response = nil if credentials_available? response = @client.connection(@credentials).get url elsif !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
205 206 207 |
# File 'lib/uboost-client/uboost_client.rb', line 205 def get_sso_token(account_id) client.account.token(account_id).student["sso_token"] end |
#leaderboard(options = Hash.new) ⇒ Object
264 265 266 267 268 |
# File 'lib/uboost-client/uboost_client.rb', line 264 def leaderboard( = Hash.new) = {: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 = Hash.new) ⇒ Object
259 260 261 262 |
# File 'lib/uboost-client/uboost_client.rb', line 259 def list_of_leaderboards( = Hash.new) response = get(@url + '/leaderboards/', ) OpenStruct.new(JSON.parse(response.body)) end |
#my_badges(options = Hash.new) ⇒ Object
247 248 249 250 251 |
# File 'lib/uboost-client/uboost_client.rb', line 247 def my_badges( = Hash.new) = {:account_id => nil, :badge_category_id => 'all'}.merge() response = get(@url + '/badges/mine/' + [:badge_category_id].to_s, ) OpenStruct.new(JSON.parse(response.body)) end |
#profile(options = Hash.new) ⇒ Object
230 231 232 233 234 |
# File 'lib/uboost-client/uboost_client.rb', line 230 def profile( = Hash.new) = {:account_id => nil}.merge() response = get(@url + '/profile', ) OpenStruct.new(JSON.parse(response.body)) end |
#session_cache_available? ⇒ Boolean
197 198 199 |
# File 'lib/uboost-client/uboost_client.rb', line 197 def session_cache_available? @session end |
#ubar(options = Hash.new) ⇒ Object
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/uboost-client/uboost_client.rb', line 270 def ( = Hash.new) = {:align => "top", :bar_color => '0x222222', :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 |
#unearned_badges(options = Hash.new) ⇒ Object
253 254 255 256 257 |
# File 'lib/uboost-client/uboost_client.rb', line 253 def unearned_badges( = Hash.new) = {:account_id => nil, :badge_category_id => nil}.merge() response = get(@url + '/badges/unearned/' + [:badge_category_id].to_s, ) OpenStruct.new(JSON.parse(response.body)) end |