Module: Riaction::ProfileInstanceMethods

Defined in:
lib/riaction/riaction.rb

Instance Method Summary collapse

Instance Method Details

#riaction_create_profileObject



308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/riaction/riaction.rb', line 308

def riaction_create_profile
  keys = riaction_profile_keys
  unless keys.empty?
    existing = riaction_profile_summary
    unless existing
      @iactionable_api ||= IActionable::Api.new
      @iactionable_api.create_profile(keys[:profile_type], keys[:id_type], keys[:id])
    else
      existing
    end
  else
    raise NoProfileDefined.new("Class #{self.class} does not adequately define itself as an IActionable profile")
  end
end

#riaction_profile_achievements(filter_type = nil) ⇒ Object



334
335
336
337
338
339
340
341
342
343
344
# File 'lib/riaction/riaction.rb', line 334

def riaction_profile_achievements(filter_type=nil)
  keys = riaction_profile_keys
  unless keys.empty?
    @iactionable_api ||= IActionable::Api.new
    @iactionable_api.get_profile_achievements(keys[:profile_type], keys[:id_type], keys[:id], filter_type)
  else
    raise NoProfileDefined.new("Class #{self.class} does not adequately define itself as an IActionable profile")
  end
rescue IActionable::Error::BadRequest => e
  nil
end

#riaction_profile_challenges(filter_type = nil) ⇒ Object



346
347
348
349
350
351
352
353
354
355
356
# File 'lib/riaction/riaction.rb', line 346

def riaction_profile_challenges(filter_type=nil)
  keys = riaction_profile_keys
  unless keys.empty?
    @iactionable_api ||= IActionable::Api.new
    @iactionable_api.get_profile_challenges(keys[:profile_type], keys[:id_type], keys[:id], filter_type)
  else
    raise NoProfileDefined.new("Class #{self.class} does not adequately define itself as an IActionable profile")
  end
rescue IActionable::Error::BadRequest => e
  nil
end

#riaction_profile_goals(filter_type = nil) ⇒ Object



358
359
360
361
362
363
364
365
366
367
368
# File 'lib/riaction/riaction.rb', line 358

def riaction_profile_goals(filter_type=nil)
  keys = riaction_profile_keys
  unless keys.empty?
    @iactionable_api ||= IActionable::Api.new
    @iactionable_api.get_profile_goals(keys[:profile_type], keys[:id_type], keys[:id], filter_type)
  else
    raise NoProfileDefined.new("Class #{self.class} does not adequately define itself as an IActionable profile")
  end
rescue IActionable::Error::BadRequest => e
  nil
end

#riaction_profile_keys(profile_type = nil, id_type = nil) ⇒ Object



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/riaction/riaction.rb', line 269

def riaction_profile_keys(profile_type=nil, id_type=nil)
  profiles = self.class.class_variable_defined?(:@@riaction_profiles) ? self.class.class_variable_get(:@@riaction_profiles) : {}
  
  if profiles.size > 0
    if profile_type && profiles.has_key?(profile_type)
      ids = profiles.fetch(profile_type)
    else
      profile_type = profiles.first[0]
      ids = profiles.first[1]
    end
  
    if id_type && ids.has_key?(id_type)
      {:profile_type => profile_type.to_s, :id_type => id_type.to_s, :id => self.send(ids.fetch(id_type)).to_s}
    else
      {:profile_type => profile_type.to_s, :id_type => ids.first[0].to_s, :id => self.send(ids.first[1]).to_s}
    end
  else
    {}
  end
rescue KeyError, NoMethodError => e
  {}
end

#riaction_profile_notificationsObject



370
371
372
373
374
375
376
377
378
379
380
# File 'lib/riaction/riaction.rb', line 370

def riaction_profile_notifications
  keys = riaction_profile_keys
  unless keys.empty?
    @iactionable_api ||= IActionable::Api.new
    @iactionable_api.get_profile_notifications(keys[:profile_type], keys[:id_type], keys[:id])
  else
    raise NoProfileDefined.new("Class #{self.class} does not adequately define itself as an IActionable profile")
  end
rescue IActionable::Error::BadRequest => e
  nil
end

#riaction_profile_summary(achievement_count = nil) ⇒ Object

API wrappers #



296
297
298
299
300
301
302
303
304
305
306
# File 'lib/riaction/riaction.rb', line 296

def riaction_profile_summary(achievement_count=nil)
  keys = riaction_profile_keys
  unless keys.empty?
    @iactionable_api ||= IActionable::Api.new
    @iactionable_api.get_profile_summary(keys[:profile_type], keys[:id_type], keys[:id], achievement_count)
  else
    raise NoProfileDefined.new("Class #{self.class} does not adequately define itself as an IActionable profile")
  end
rescue IActionable::Error::BadRequest => e
  nil
end

#riaction_update_profile(new_id_type) ⇒ Object



323
324
325
326
327
328
329
330
331
332
# File 'lib/riaction/riaction.rb', line 323

def riaction_update_profile(new_id_type)
  old_keys = riaction_profile_keys
  new_keys = riaction_profile_keys(old_keys[:profile_type], new_id_type)
  unless old_keys.empty? || new_keys.empty?
    @iactionable_api ||= IActionable::Api.new
    @iactionable_api.add_profile_identifier(old_keys[:profile_type], old_keys[:id_type], old_keys[:id], new_keys[:id_type], new_keys[:id])
  else
    raise NoProfileDefined.new("Class #{self.class} does not adequately define itself as an IActionable profile")
  end
end