riaction 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG.md +7 -0
  3. data/Gemfile.lock +47 -26
  4. data/README.md +101 -52
  5. data/db/riaction.db +0 -0
  6. data/lib/riaction.rb +1 -1
  7. data/lib/riaction/constants.rb +10 -0
  8. data/lib/riaction/crud_event_callback.rb +3 -3
  9. data/lib/riaction/event_performer.rb +11 -16
  10. data/lib/riaction/profile_creation_callback.rb +1 -1
  11. data/lib/riaction/profile_creator.rb +13 -6
  12. data/lib/riaction/railtie.rb +4 -0
  13. data/lib/riaction/riaction.rb +302 -282
  14. data/lib/riaction/version.rb +1 -1
  15. data/lib/tasks/riaction.rake +16 -14
  16. data/riaction.gemspec +3 -2
  17. data/spec/event_performer_spec.rb +233 -0
  18. data/spec/profile_creation_spec.rb +135 -0
  19. data/spec/riaction_spec.rb +820 -253
  20. data/spec/spec_helper.rb +8 -1
  21. metadata +38 -71
  22. data/lib/riaction/iactionable/api.rb +0 -170
  23. data/lib/riaction/iactionable/connection.rb +0 -114
  24. data/lib/riaction/iactionable/error.rb +0 -17
  25. data/lib/riaction/iactionable/objects.rb +0 -27
  26. data/lib/riaction/iactionable/objects/achievement.rb +0 -29
  27. data/lib/riaction/iactionable/objects/awardable.rb +0 -50
  28. data/lib/riaction/iactionable/objects/challenge.rb +0 -27
  29. data/lib/riaction/iactionable/objects/goal.rb +0 -30
  30. data/lib/riaction/iactionable/objects/i_actionable_object.rb +0 -36
  31. data/lib/riaction/iactionable/objects/identifier.rb +0 -17
  32. data/lib/riaction/iactionable/objects/leaderboard.rb +0 -15
  33. data/lib/riaction/iactionable/objects/leaderboard_report.rb +0 -30
  34. data/lib/riaction/iactionable/objects/level.rb +0 -24
  35. data/lib/riaction/iactionable/objects/level_type.rb +0 -15
  36. data/lib/riaction/iactionable/objects/point_type.rb +0 -15
  37. data/lib/riaction/iactionable/objects/profile_achievements.rb +0 -20
  38. data/lib/riaction/iactionable/objects/profile_challenges.rb +0 -20
  39. data/lib/riaction/iactionable/objects/profile_goals.rb +0 -20
  40. data/lib/riaction/iactionable/objects/profile_level.rb +0 -20
  41. data/lib/riaction/iactionable/objects/profile_notifications.rb +0 -29
  42. data/lib/riaction/iactionable/objects/profile_points.rb +0 -29
  43. data/lib/riaction/iactionable/objects/profile_summary.rb +0 -37
  44. data/lib/riaction/iactionable/objects/progress.rb +0 -46
  45. data/lib/riaction/iactionable/settings.rb +0 -30
  46. data/spec/api_spec.rb +0 -314
  47. data/spec/connection_spec.rb +0 -111
  48. data/spec/get_achievements_api_response_spec.rb +0 -46
  49. data/spec/get_challenges_api_response_spec.rb +0 -42
  50. data/spec/get_goals_api_response_spec.rb +0 -46
  51. data/spec/get_leaderboard_api_response_spec.rb +0 -76
  52. data/spec/get_profile_achievements_api_response_spec.rb +0 -99
  53. data/spec/get_profile_api_response_spec.rb +0 -103
  54. data/spec/get_profile_challenges_api_response_spec.rb +0 -85
  55. data/spec/get_profile_goals_api_response_spec.rb +0 -89
  56. data/spec/get_profile_notifications_api_response_spec.rb +0 -75
  57. data/spec/get_profile_points_api_response_spec.rb +0 -67
  58. data/spec/settings_spec.rb +0 -52
@@ -1,17 +0,0 @@
1
- module IActionable
2
- module Error
3
- class Error < StandardError
4
- attr_accessor :response
5
-
6
- def initialize(response)
7
- @response = response
8
- super
9
- end
10
- end
11
-
12
- # http://iactionable.com/api/response-codes/
13
- class BadRequest < Error; end
14
- class Unauthorized < Error; end
15
- class Internal < Error; end
16
- end
17
- end
@@ -1,27 +0,0 @@
1
- module IActionable
2
- module Objects
3
- end
4
- end
5
-
6
- require 'riaction/iactionable/objects/i_actionable_object.rb'
7
- require 'riaction/iactionable/objects/progress.rb'
8
- require 'riaction/iactionable/objects/awardable.rb'
9
-
10
- IActionable::Objects::IActionableObject.send(:include, IActionable::Objects::Awardable)
11
-
12
- require 'riaction/iactionable/objects/achievement.rb'
13
- require 'riaction/iactionable/objects/challenge.rb'
14
- require 'riaction/iactionable/objects/goal.rb'
15
- require 'riaction/iactionable/objects/identifier.rb'
16
- require 'riaction/iactionable/objects/leaderboard.rb'
17
- require 'riaction/iactionable/objects/leaderboard_report.rb'
18
- require 'riaction/iactionable/objects/level_type.rb'
19
- require 'riaction/iactionable/objects/level.rb'
20
- require 'riaction/iactionable/objects/point_type.rb'
21
- require 'riaction/iactionable/objects/profile_level.rb'
22
- require 'riaction/iactionable/objects/profile_points.rb'
23
- require 'riaction/iactionable/objects/profile_summary.rb'
24
- require 'riaction/iactionable/objects/profile_achievements.rb'
25
- require 'riaction/iactionable/objects/profile_challenges.rb'
26
- require 'riaction/iactionable/objects/profile_goals.rb'
27
- require 'riaction/iactionable/objects/profile_notifications.rb'
@@ -1,29 +0,0 @@
1
- module IActionable
2
- module Objects
3
- class Achievement < IActionableObject
4
- attr_accessor :key
5
- attr_accessor :description
6
- attr_accessor :image_url
7
- attr_accessor :name
8
-
9
- def initialize(key_values={})
10
- initialize_awardable(key_values)
11
- super(key_values)
12
- end
13
-
14
- awardable
15
-
16
- def to_hash
17
- hash = {
18
- "Key" => @key,
19
- "Description" => @description,
20
- "ImageURL" => @image_url,
21
- "Name" => @name
22
- }
23
- hash.merge!(awardable_hash) unless @progress.empty?
24
- hash.delete("AwardDate") if @award_date.nil?
25
- hash
26
- end
27
- end
28
- end
29
- end
@@ -1,50 +0,0 @@
1
- module IActionable
2
- module Objects
3
- module Awardable
4
- def self.included(base)
5
- base.extend(ClassMethods)
6
- end
7
-
8
- module ClassMethods
9
- def awardable
10
- attr_accessor :award_date
11
- attr_accessor :original_award_date
12
- attr_accessor :progress
13
- include IActionable::Objects::Awardable::InstanceMethods
14
- end
15
- end
16
-
17
- module InstanceMethods
18
- def initialize_awardable(key_values={})
19
- @progress = extract_many_as(key_values, "Progress", IActionable::Objects::Progress)
20
- # convert the miliseconds within the date string to seconds (per ruby)
21
- # "/Date(1275706032317-0600)/" => "1275706032-0600"
22
- @original_award_date = @award_date = key_values.delete("AwardDate")
23
- @award_date = IActionableObject.timestamp_to_seconds(@award_date) unless @award_date.blank?
24
- end
25
-
26
- def complete?
27
- @progress.any? && @progress.all?
28
- end
29
-
30
- def percent_complete
31
- Integer(Float(@progress.select{|p| p.complete?}.size) / @progress.size * 100)
32
- rescue TypeError => e
33
- 0
34
- end
35
-
36
- def awarded_on
37
- # bug in ruby 1.9.2 where Time.strptime does not support seconds-since-epoch format, but Date.strptime does, so we'll use that for now
38
- Date.strptime(@award_date, "%s%z").to_time unless @award_date.blank?
39
- end
40
-
41
- def awardable_hash
42
- {
43
- "AwardDate" => @original_award_date,
44
- "Progress" => @progress.map{|prog| prog.to_hash}
45
- }
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,27 +0,0 @@
1
- module IActionable
2
- module Objects
3
- class Challenge < IActionableObject
4
- awardable
5
-
6
- attr_accessor :key
7
- attr_accessor :description
8
- attr_accessor :name
9
-
10
- def initialize(key_values={})
11
- initialize_awardable(key_values)
12
- super(key_values)
13
- end
14
-
15
- def to_hash
16
- hash = {
17
- "Key" => @key,
18
- "Description" => @description,
19
- "Name" => @name
20
- }
21
- hash.merge!(awardable_hash) unless @progress.empty?
22
- hash.delete("AwardDate") if @award_date.nil?
23
- hash
24
- end
25
- end
26
- end
27
- end
@@ -1,30 +0,0 @@
1
- module IActionable
2
- module Objects
3
- class Goal < IActionableObject
4
- awardable
5
-
6
- attr_accessor :key
7
- attr_accessor :description
8
- attr_accessor :name
9
- attr_accessor :interval
10
-
11
- def initialize(key_values={})
12
- initialize_awardable(key_values)
13
- super(key_values)
14
- end
15
-
16
- def to_hash
17
- hash = {
18
- "Key" => @key,
19
- "Description" => @description,
20
- "Name" => @name,
21
- "Interval" => @interval
22
- }
23
- hash.merge!(awardable_hash) unless @progress.empty?
24
- hash.delete("AwardDate") if @award_date.nil?
25
- hash.delete("Interval") if @interval.nil?
26
- hash
27
- end
28
- end
29
- end
30
- end
@@ -1,36 +0,0 @@
1
- module IActionable
2
- module Objects
3
- class IActionableObject
4
- def initialize(key_values={})
5
- key_values.each_pair do |key, value|
6
- instance_variable_set "@#{key.camelize.underscore}".to_sym, value
7
- end
8
- end
9
-
10
- def self.timestamp_regexp
11
- /\/Date\((\d+)((\-|\+)\d{4})\)\//
12
- end
13
-
14
- def self.timestamp_to_seconds(timestamp)
15
- milliseconds = timestamp[timestamp_regexp, 1]
16
- tz = timestamp[timestamp_regexp, 2]
17
- "#{Integer(milliseconds)/1000}#{tz}"
18
- end
19
-
20
- private
21
-
22
- def extract_many_as(key_values, field, klass)
23
- if key_values.fetch(field, nil).respond_to?(:inject)
24
- loaded = []
25
- content = key_values.delete(field)
26
- content.each do |c|
27
- loaded << klass.new(c)
28
- end
29
- loaded
30
- else
31
- []
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,17 +0,0 @@
1
- module IActionable
2
- module Objects
3
- class Identifier < IActionableObject
4
- attr_accessor :id
5
- attr_accessor :id_hash
6
- attr_accessor :id_type
7
-
8
- def to_hash
9
- {
10
- "ID" => @id,
11
- "IDHash" => @id_hash,
12
- "IDType" => @id_type
13
- }
14
- end
15
- end
16
- end
17
- end
@@ -1,15 +0,0 @@
1
- module IActionable
2
- module Objects
3
- class Leaderboard < IActionableObject
4
- attr_accessor :key
5
- attr_accessor :name
6
-
7
- def to_hash
8
- {
9
- "Key" => @key,
10
- "Name" => @name
11
- }
12
- end
13
- end
14
- end
15
- end
@@ -1,30 +0,0 @@
1
- module IActionable
2
- module Objects
3
- class LeaderboardReport < IActionableObject
4
- attr_accessor :page_count
5
- attr_accessor :page_number
6
- attr_accessor :total_count
7
- attr_accessor :leaderboard
8
- attr_accessor :point_type
9
- attr_accessor :profiles
10
-
11
- def initialize(key_values={})
12
- @leaderboard = IActionable::Objects::PointType.new(key_values.delete("Leaderboard"))
13
- @point_type = IActionable::Objects::PointType.new(key_values.delete("PointType"))
14
- @profiles = extract_many_as(key_values, "Profiles", IActionable::Objects::ProfileSummary)
15
- super(key_values)
16
- end
17
-
18
- def to_hash
19
- {
20
- "PageCount" => @page_count,
21
- "PageNumber" => @page_number,
22
- "TotalCount" => @total_count,
23
- "Leaderboard" => @leaderboard.to_hash,
24
- "PointType" => @point_type.to_hash,
25
- "Profiles" => @profiles.map{|profile| profile.to_hash}
26
- }
27
- end
28
- end
29
- end
30
- end
@@ -1,24 +0,0 @@
1
- module IActionable
2
- module Objects
3
- class Level < IActionableObject
4
- attr_accessor :name
5
- attr_accessor :number
6
- attr_accessor :required_points
7
- attr_accessor :level_type
8
-
9
- def initialize(key_values={})
10
- @level_type = IActionable::Objects::LevelType.new(key_values.delete("LevelType"))
11
- super(key_values)
12
- end
13
-
14
- def to_hash
15
- {
16
- "Name" => @name,
17
- "Number" => @number,
18
- "RequiredPoints" => @required_points,
19
- "LevelType" => @level_type.to_hash
20
- }
21
- end
22
- end
23
- end
24
- end
@@ -1,15 +0,0 @@
1
- module IActionable
2
- module Objects
3
- class LevelType < IActionableObject
4
- attr_accessor :key
5
- attr_accessor :name
6
-
7
- def to_hash
8
- {
9
- "Key" => @key,
10
- "Name" => @name
11
- }
12
- end
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- module IActionable
2
- module Objects
3
- class PointType < IActionableObject
4
- attr_accessor :key
5
- attr_accessor :name
6
-
7
- def to_hash
8
- {
9
- "Key" => @key,
10
- "Name" => @name
11
- }
12
- end
13
- end
14
- end
15
- end
@@ -1,20 +0,0 @@
1
- module IActionable
2
- module Objects
3
- class ProfileAchievements < IActionableObject
4
- attr_accessor :available
5
- attr_accessor :completed
6
-
7
- def initialize(key_values={})
8
- @available = extract_many_as(key_values, "Available", IActionable::Objects::Achievement)
9
- @completed = extract_many_as(key_values, "Completed", IActionable::Objects::Achievement)
10
- end
11
-
12
- def to_hash
13
- {
14
- "Available" => @available.map{|achievement| achievement.to_hash},
15
- "Completed" => @completed.map{|achievement| achievement.to_hash}
16
- }
17
- end
18
- end
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- module IActionable
2
- module Objects
3
- class ProfileChallenges < IActionableObject
4
- attr_accessor :available
5
- attr_accessor :completed
6
-
7
- def initialize(key_values={})
8
- @available = extract_many_as(key_values, "Available", IActionable::Objects::Challenge)
9
- @completed = extract_many_as(key_values, "Completed", IActionable::Objects::Challenge)
10
- end
11
-
12
- def to_hash
13
- {
14
- "Available" => @available.map{|challenge| challenge.to_hash},
15
- "Completed" => @completed.map{|challenge| challenge.to_hash}
16
- }
17
- end
18
- end
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- module IActionable
2
- module Objects
3
- class ProfileGoals < IActionableObject
4
- attr_accessor :available
5
- attr_accessor :completed
6
-
7
- def initialize(key_values={})
8
- @available = extract_many_as(key_values, "Available", IActionable::Objects::Goal)
9
- @completed = extract_many_as(key_values, "Completed", IActionable::Objects::Goal)
10
- end
11
-
12
- def to_hash
13
- {
14
- "Available" => @available.map{|goal| goal.to_hash},
15
- "Completed" => @completed.map{|goal| goal.to_hash}
16
- }
17
- end
18
- end
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- module IActionable
2
- module Objects
3
- class ProfileLevel < IActionableObject
4
- attr_accessor :current
5
- attr_accessor :next
6
-
7
- def initialize(key_values={})
8
- @current = IActionable::Objects::Level.new(key_values.delete("Current")) unless key_values["Current"].blank?
9
- @next = IActionable::Objects::Level.new(key_values.delete("Next")) unless key_values["Next"].blank?
10
- end
11
-
12
- def to_hash
13
- {
14
- "Current" => @current.to_hash,
15
- "Next" => @next.to_hash
16
- }
17
- end
18
- end
19
- end
20
- end
@@ -1,29 +0,0 @@
1
- module IActionable
2
- module Objects
3
- class ProfileNotifications < IActionableObject
4
- attr_accessor :achievements
5
- attr_accessor :challenges
6
- attr_accessor :goals
7
- attr_accessor :levels
8
- attr_accessor :points
9
-
10
- def initialize(key_values={})
11
- @achievements = IActionable::Objects::ProfileAchievements.new(key_values.delete("Achievements"))
12
- @challenges = IActionable::Objects::ProfileChallenges.new(key_values.delete("Challenges"))
13
- @goals = IActionable::Objects::ProfileGoals.new(key_values.delete("Goals"))
14
- @levels = extract_many_as(key_values, "Levels", IActionable::Objects::Level)
15
- @points = extract_many_as(key_values, "Points", IActionable::Objects::ProfilePoints)
16
- end
17
-
18
- def to_hash
19
- {
20
- "Achievements" => @achievements.to_hash,
21
- "Challenges" => @challenges.to_hash,
22
- "Goals" => @goals.to_hash,
23
- "Levels" => @levels.map{|level| level.to_hash},
24
- "Points" => @points.map{|point| point.to_hash}
25
- }
26
- end
27
- end
28
- end
29
- end