riaction 0.5.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +5 -0
- data/lib/riaction/iactionable/api.rb +4 -43
- data/lib/riaction/iactionable/objects/achievement.rb +12 -0
- data/lib/riaction/iactionable/objects/awardable.rb +9 -1
- data/lib/riaction/iactionable/objects/challenge.rb +11 -0
- data/lib/riaction/iactionable/objects/goal.rb +13 -0
- data/lib/riaction/iactionable/objects/identifier.rb +8 -0
- data/lib/riaction/iactionable/objects/leaderboard.rb +7 -0
- data/lib/riaction/iactionable/objects/leaderboard_report.rb +11 -0
- data/lib/riaction/iactionable/objects/level.rb +9 -0
- data/lib/riaction/iactionable/objects/level_type.rb +7 -0
- data/lib/riaction/iactionable/objects/point_type.rb +7 -0
- data/lib/riaction/iactionable/objects/profile_achievements.rb +20 -0
- data/lib/riaction/iactionable/objects/profile_challenges.rb +20 -0
- data/lib/riaction/iactionable/objects/profile_goals.rb +20 -0
- data/lib/riaction/iactionable/objects/profile_level.rb +7 -0
- data/lib/riaction/iactionable/objects/profile_notifications.rb +29 -0
- data/lib/riaction/iactionable/objects/profile_points.rb +12 -0
- data/lib/riaction/iactionable/objects/profile_summary.rb +16 -3
- data/lib/riaction/iactionable/objects/progress.rb +11 -0
- data/lib/riaction/iactionable/objects.rb +4 -0
- data/lib/riaction/version.rb +1 -1
- data/spec/api_spec.rb +42 -16
- data/spec/get_achievements_api_response_spec.rb +46 -0
- data/spec/get_challenges_api_response_spec.rb +42 -0
- data/spec/get_goals_api_response_spec.rb +46 -0
- data/spec/get_leaderboard_api_response_spec.rb +76 -0
- data/spec/get_profile_achievements_api_response_spec.rb +99 -0
- data/spec/get_profile_api_response_spec.rb +103 -0
- data/spec/get_profile_challenges_api_response_spec.rb +85 -0
- data/spec/get_profile_goals_api_response_spec.rb +89 -0
- data/spec/get_profile_notifications_api_response_spec.rb +75 -0
- data/spec/get_profile_points_api_response_spec.rb +67 -0
- metadata +40 -16
data/CHANGELOG.md
CHANGED
|
@@ -81,20 +81,12 @@ module IActionable
|
|
|
81
81
|
case filter_type
|
|
82
82
|
when :completed
|
|
83
83
|
request.to("/#{profile_type}/#{id_type}/#{id}/achievements/Completed")
|
|
84
|
-
response = request.get
|
|
85
|
-
response.map{|achievement_json| IActionable::Objects::Achievement.new(achievement_json)}
|
|
86
84
|
when :available
|
|
87
85
|
request.to("/#{profile_type}/#{id_type}/#{id}/achievements/Available")
|
|
88
|
-
response = request.get
|
|
89
|
-
response.map{|achievement_json| IActionable::Objects::Achievement.new(achievement_json)}
|
|
90
86
|
else
|
|
91
87
|
request.to("/#{profile_type}/#{id_type}/#{id}/achievements")
|
|
92
|
-
response = request.get
|
|
93
|
-
{
|
|
94
|
-
:available => response["Available"].map{|achievement_json| IActionable::Objects::Achievement.new(achievement_json)},
|
|
95
|
-
:completed => response["Completed"].map{|achievement_json| IActionable::Objects::Achievement.new(achievement_json)}
|
|
96
|
-
}
|
|
97
88
|
end
|
|
89
|
+
IActionable::Objects::ProfileAchievements.new(request.get)
|
|
98
90
|
end
|
|
99
91
|
|
|
100
92
|
def get_achievements()
|
|
@@ -113,20 +105,12 @@ module IActionable
|
|
|
113
105
|
case filter_type
|
|
114
106
|
when :completed
|
|
115
107
|
request.to("/#{profile_type}/#{id_type}/#{id}/challenges/Completed")
|
|
116
|
-
response = request.get
|
|
117
|
-
response.map{|challenge_json| IActionable::Objects::Challenge.new(challenge_json)}
|
|
118
108
|
when :available
|
|
119
109
|
request.to("/#{profile_type}/#{id_type}/#{id}/challenges/Available")
|
|
120
|
-
response = request.get
|
|
121
|
-
response.map{|challenge_json| IActionable::Objects::Challenge.new(challenge_json)}
|
|
122
110
|
else
|
|
123
111
|
request.to("/#{profile_type}/#{id_type}/#{id}/challenges")
|
|
124
|
-
response = request.get
|
|
125
|
-
{
|
|
126
|
-
:available => response["Available"].map{|challenge_json| IActionable::Objects::Challenge.new(challenge_json)},
|
|
127
|
-
:completed => response["Completed"].map{|challenge_json| IActionable::Objects::Challenge.new(challenge_json)}
|
|
128
|
-
}
|
|
129
112
|
end
|
|
113
|
+
IActionable::Objects::ProfileChallenges.new(request.get)
|
|
130
114
|
end
|
|
131
115
|
|
|
132
116
|
def get_challenges()
|
|
@@ -145,20 +129,12 @@ module IActionable
|
|
|
145
129
|
case filter_type
|
|
146
130
|
when :completed
|
|
147
131
|
request.to("/#{profile_type}/#{id_type}/#{id}/goals/Completed")
|
|
148
|
-
response = request.get
|
|
149
|
-
response.map{|goal_json| IActionable::Objects::Goal.new(goal_json)}
|
|
150
132
|
when :available
|
|
151
133
|
request.to("/#{profile_type}/#{id_type}/#{id}/goals/Available")
|
|
152
|
-
response = request.get
|
|
153
|
-
response.map{|goal_json| IActionable::Objects::Goal.new(goal_json)}
|
|
154
134
|
else
|
|
155
135
|
request.to("/#{profile_type}/#{id_type}/#{id}/goals")
|
|
156
|
-
response = request.get
|
|
157
|
-
{
|
|
158
|
-
:available => response["Available"].map{|goal_json| IActionable::Objects::Goal.new(goal_json)},
|
|
159
|
-
:completed => response["Completed"].map{|goal_json| IActionable::Objects::Goal.new(goal_json)}
|
|
160
|
-
}
|
|
161
136
|
end
|
|
137
|
+
IActionable::Objects::ProfileGoals.new(request.get)
|
|
162
138
|
end
|
|
163
139
|
|
|
164
140
|
def get_goals()
|
|
@@ -188,22 +164,7 @@ module IActionable
|
|
|
188
164
|
|
|
189
165
|
def get_profile_notifications(profile_type, id_type, id)
|
|
190
166
|
response = @connection.request.with_app_key.to("/#{profile_type}/#{id_type}/#{id}/notifications").get
|
|
191
|
-
|
|
192
|
-
:achievements => {
|
|
193
|
-
:available => response["Achievements"]["Available"].map{|a| IActionable::Objects::Achievement.new(a)},
|
|
194
|
-
:completed => response["Achievements"]["Completed"].map{|a| IActionable::Objects::Achievement.new(a)}
|
|
195
|
-
},
|
|
196
|
-
:challenges => {
|
|
197
|
-
:available => response["Challenges"]["Available"].map{|c| IActionable::Objects::Challenge.new(c)},
|
|
198
|
-
:completed => response["Challenges"]["Completed"].map{|c| IActionable::Objects::Challenge.new(c)}
|
|
199
|
-
},
|
|
200
|
-
:goals => {
|
|
201
|
-
:available => response["Goals"]["Available"].map{|g| IActionable::Objects::Goal.new(g)},
|
|
202
|
-
:completed => response["Goals"]["Completed"].map{|g| IActionable::Objects::Goal.new(g)}
|
|
203
|
-
},
|
|
204
|
-
:levels => response["Levels"].map{|l| IActionable::Objects::Level.new(l)},
|
|
205
|
-
:points => response["Points"].map{|p| IActionable::Objects::ProfilePoints.new(p)}
|
|
206
|
-
}
|
|
167
|
+
IActionable::Objects::ProfileNotifications.new(response)
|
|
207
168
|
end
|
|
208
169
|
end
|
|
209
170
|
end
|
|
@@ -12,6 +12,18 @@ module IActionable
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
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
|
|
15
27
|
end
|
|
16
28
|
end
|
|
17
29
|
end
|
|
@@ -8,6 +8,7 @@ module IActionable
|
|
|
8
8
|
module ClassMethods
|
|
9
9
|
def awardable
|
|
10
10
|
attr_accessor :award_date
|
|
11
|
+
attr_accessor :original_award_date
|
|
11
12
|
attr_accessor :progress
|
|
12
13
|
include IActionable::Objects::Awardable::InstanceMethods
|
|
13
14
|
end
|
|
@@ -18,7 +19,7 @@ module IActionable
|
|
|
18
19
|
@progress = extract_many_as(key_values, "Progress", IActionable::Objects::Progress)
|
|
19
20
|
# convert the miliseconds within the date string to seconds (per ruby)
|
|
20
21
|
# "/Date(1275706032317-0600)/" => "1275706032-0600"
|
|
21
|
-
@award_date = key_values.delete("AwardDate")
|
|
22
|
+
@original_award_date = @award_date = key_values.delete("AwardDate")
|
|
22
23
|
@award_date = IActionableObject.timestamp_to_seconds(@award_date) unless @award_date.blank?
|
|
23
24
|
end
|
|
24
25
|
|
|
@@ -36,6 +37,13 @@ module IActionable
|
|
|
36
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
|
|
37
38
|
Date.strptime(@award_date, "%s%z").to_time unless @award_date.blank?
|
|
38
39
|
end
|
|
40
|
+
|
|
41
|
+
def awardable_hash
|
|
42
|
+
{
|
|
43
|
+
"AwardDate" => @original_award_date,
|
|
44
|
+
"Progress" => @progress.map{|prog| prog.to_hash}
|
|
45
|
+
}
|
|
46
|
+
end
|
|
39
47
|
end
|
|
40
48
|
end
|
|
41
49
|
end
|
|
@@ -11,6 +11,17 @@ module IActionable
|
|
|
11
11
|
initialize_awardable(key_values)
|
|
12
12
|
super(key_values)
|
|
13
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
|
|
14
25
|
end
|
|
15
26
|
end
|
|
16
27
|
end
|
|
@@ -12,6 +12,19 @@ module IActionable
|
|
|
12
12
|
initialize_awardable(key_values)
|
|
13
13
|
super(key_values)
|
|
14
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
|
|
15
28
|
end
|
|
16
29
|
end
|
|
17
30
|
end
|
|
@@ -14,6 +14,17 @@ module IActionable
|
|
|
14
14
|
@profiles = extract_many_as(key_values, "Profiles", IActionable::Objects::ProfileSummary)
|
|
15
15
|
super(key_values)
|
|
16
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
|
|
17
28
|
end
|
|
18
29
|
end
|
|
19
30
|
end
|
|
@@ -10,6 +10,15 @@ module IActionable
|
|
|
10
10
|
@level_type = IActionable::Objects::LevelType.new(key_values.delete("LevelType"))
|
|
11
11
|
super(key_values)
|
|
12
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
|
|
13
22
|
end
|
|
14
23
|
end
|
|
15
24
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
|
@@ -8,6 +8,13 @@ module IActionable
|
|
|
8
8
|
@current = IActionable::Objects::Level.new(key_values.delete("Current")) unless key_values["Current"].blank?
|
|
9
9
|
@next = IActionable::Objects::Level.new(key_values.delete("Next")) unless key_values["Next"].blank?
|
|
10
10
|
end
|
|
11
|
+
|
|
12
|
+
def to_hash
|
|
13
|
+
{
|
|
14
|
+
"Current" => @current.to_hash,
|
|
15
|
+
"Next" => @next.to_hash
|
|
16
|
+
}
|
|
17
|
+
end
|
|
11
18
|
end
|
|
12
19
|
end
|
|
13
20
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
|
@@ -12,6 +12,18 @@ module IActionable
|
|
|
12
12
|
@point_type = IActionable::Objects::PointType.new(key_values.delete("PointType"))
|
|
13
13
|
super(key_values)
|
|
14
14
|
end
|
|
15
|
+
|
|
16
|
+
def to_hash
|
|
17
|
+
hash = {
|
|
18
|
+
"Level" => @level.nil? ? nil : @level.to_hash,
|
|
19
|
+
"PointType" => @point_type.to_hash,
|
|
20
|
+
"Points" => @points,
|
|
21
|
+
"Reason" => @reason
|
|
22
|
+
}
|
|
23
|
+
hash.delete "Level" if @level.nil?
|
|
24
|
+
hash.delete "Reason" if @reason.nil?
|
|
25
|
+
hash
|
|
26
|
+
end
|
|
15
27
|
end
|
|
16
28
|
end
|
|
17
29
|
end
|
|
@@ -8,9 +8,9 @@ module IActionable
|
|
|
8
8
|
class ProfileSummary < IActionableObject
|
|
9
9
|
attr_accessor :display_name
|
|
10
10
|
attr_accessor :identifiers
|
|
11
|
-
attr_accessor :points
|
|
12
|
-
attr_accessor :recent_achievements
|
|
13
|
-
attr_accessor :rank
|
|
11
|
+
attr_accessor :points
|
|
12
|
+
attr_accessor :recent_achievements # not always present
|
|
13
|
+
attr_accessor :rank # not always present
|
|
14
14
|
|
|
15
15
|
def initialize(key_values={})
|
|
16
16
|
@identifiers = extract_many_as(key_values, "Identifiers", IActionable::Objects::Identifier)
|
|
@@ -19,6 +19,19 @@ module IActionable
|
|
|
19
19
|
|
|
20
20
|
super(key_values)
|
|
21
21
|
end
|
|
22
|
+
|
|
23
|
+
def to_hash
|
|
24
|
+
hash = {
|
|
25
|
+
"DisplayName" => @display_name,
|
|
26
|
+
"Identifiers" => @identifiers.map{|identifier| identifier.to_hash}
|
|
27
|
+
}
|
|
28
|
+
unless @points.nil?
|
|
29
|
+
hash["Points"] = @points.kind_of?(Array) ? @points.map{|point| point.to_hash} : @points
|
|
30
|
+
end
|
|
31
|
+
hash["RecentAchievements"] = @recent_achievements.map{|recent_achievement| recent_achievement.to_hash} unless @recent_achievements.empty?
|
|
32
|
+
hash["Rank"] = @rank unless @rank.nil?
|
|
33
|
+
hash
|
|
34
|
+
end
|
|
22
35
|
end
|
|
23
36
|
end
|
|
24
37
|
end
|
|
@@ -3,6 +3,7 @@ module IActionable
|
|
|
3
3
|
class Progress < IActionableObject
|
|
4
4
|
attr_accessor :description
|
|
5
5
|
attr_accessor :condition_met_date
|
|
6
|
+
attr_accessor :original_condition_met_date
|
|
6
7
|
attr_accessor :current_value
|
|
7
8
|
attr_accessor :required_value
|
|
8
9
|
attr :complete
|
|
@@ -11,6 +12,7 @@ module IActionable
|
|
|
11
12
|
super(key_values)
|
|
12
13
|
# convert the miliseconds within the date string to seconds (per ruby)
|
|
13
14
|
# "/Date(1275706032317-0600)/" => "1275706032-0600"
|
|
15
|
+
@original_condition_met_date = @condition_met_date
|
|
14
16
|
@condition_met_date = IActionableObject.timestamp_to_seconds(@condition_met_date) unless @condition_met_date.blank?
|
|
15
17
|
end
|
|
16
18
|
|
|
@@ -30,6 +32,15 @@ module IActionable
|
|
|
30
32
|
# 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
|
|
31
33
|
Date.strptime(@condition_met_date, "%s%z").to_time unless @condition_met_date.blank?
|
|
32
34
|
end
|
|
35
|
+
|
|
36
|
+
def to_hash
|
|
37
|
+
{
|
|
38
|
+
"Description" => @description,
|
|
39
|
+
"CurrentValue" => @current_value,
|
|
40
|
+
"RequiredValue" => @required_value,
|
|
41
|
+
"ConditionMetDate" => @original_condition_met_date
|
|
42
|
+
}
|
|
43
|
+
end
|
|
33
44
|
end
|
|
34
45
|
end
|
|
35
46
|
end
|
|
@@ -21,3 +21,7 @@ require 'riaction/iactionable/objects/point_type.rb'
|
|
|
21
21
|
require 'riaction/iactionable/objects/profile_level.rb'
|
|
22
22
|
require 'riaction/iactionable/objects/profile_points.rb'
|
|
23
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'
|
data/lib/riaction/version.rb
CHANGED
data/spec/api_spec.rb
CHANGED
|
@@ -6,6 +6,7 @@ describe IActionable::Api do
|
|
|
6
6
|
@mock_connection = mock("connection")
|
|
7
7
|
@mock_response = mock("mock response")
|
|
8
8
|
@mock_response_item = mock("mock response item")
|
|
9
|
+
@mock_object = mock("mock object")
|
|
9
10
|
|
|
10
11
|
IActionable::Connection.stub!(:new).and_return(@mock_connection)
|
|
11
12
|
IActionable::Settings.stub!(:new).and_return(@mock_settings)
|
|
@@ -187,12 +188,12 @@ describe IActionable::Api do
|
|
|
187
188
|
end
|
|
188
189
|
end
|
|
189
190
|
|
|
190
|
-
[ [:achievements, IActionable::Objects::Achievement],
|
|
191
|
-
[:challenges, IActionable::Objects::Challenge],
|
|
192
|
-
[:goals, IActionable::Objects::Goal]].each do |type|
|
|
191
|
+
[ [:achievements, IActionable::Objects::ProfileAchievements, IActionable::Objects::Achievement],
|
|
192
|
+
[:challenges, IActionable::Objects::ProfileChallenges, IActionable::Objects::Challenge],
|
|
193
|
+
[:goals, IActionable::Objects::ProfileGoals, IActionable::Objects::Goal]].each do |type|
|
|
193
194
|
describe "loading all #{type} for a profile" do
|
|
194
195
|
before do
|
|
195
|
-
type[1].stub!(:new)
|
|
196
|
+
type[1].stub!(:new).and_return(@mock_object)
|
|
196
197
|
@mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
|
|
197
198
|
@mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
|
|
198
199
|
@mock_connection.should_receive(:get).and_return(@mock_response)
|
|
@@ -206,8 +207,8 @@ describe IActionable::Api do
|
|
|
206
207
|
|
|
207
208
|
it "should return as the proper object type" do
|
|
208
209
|
@mock_connection.stub!(:to).and_return(@mock_connection)
|
|
209
|
-
type[1].should_receive(:new).once.with(@
|
|
210
|
-
@api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, :available).should == @
|
|
210
|
+
type[1].should_receive(:new).once.with(@mock_response).and_return(@mock_object)
|
|
211
|
+
@api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, :available).should == @mock_object
|
|
211
212
|
end
|
|
212
213
|
end
|
|
213
214
|
|
|
@@ -219,8 +220,8 @@ describe IActionable::Api do
|
|
|
219
220
|
|
|
220
221
|
it "should return as the proper object type" do
|
|
221
222
|
@mock_connection.stub!(:to).and_return(@mock_connection)
|
|
222
|
-
type[1].should_receive(:new).once.with(@
|
|
223
|
-
@api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, :completed).should == @
|
|
223
|
+
type[1].should_receive(:new).once.with(@mock_response).and_return(@mock_object)
|
|
224
|
+
@api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, :completed).should == @mock_object
|
|
224
225
|
end
|
|
225
226
|
end
|
|
226
227
|
|
|
@@ -230,13 +231,33 @@ describe IActionable::Api do
|
|
|
230
231
|
@api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, nil)
|
|
231
232
|
end
|
|
232
233
|
|
|
233
|
-
it "should return as the proper object type
|
|
234
|
+
it "should return as the proper object type" do
|
|
234
235
|
@mock_connection.stub!(:to).and_return(@mock_connection)
|
|
235
|
-
type[1].should_receive(:new).
|
|
236
|
-
@api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, nil).should ==
|
|
236
|
+
type[1].should_receive(:new).once.with(@mock_response).and_return(@mock_object)
|
|
237
|
+
@api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, nil).should == @mock_object
|
|
237
238
|
end
|
|
238
239
|
end
|
|
239
240
|
end
|
|
241
|
+
|
|
242
|
+
describe "loading all #{type[0]} outside of a profile context" do
|
|
243
|
+
before do
|
|
244
|
+
type[2].stub!(:new).and_return(@mock_object)
|
|
245
|
+
@mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
|
|
246
|
+
@mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
|
|
247
|
+
@mock_connection.should_receive(:get).and_return(@mock_response)
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
it "should make the correct IActionable API all" do
|
|
251
|
+
@mock_connection.should_receive(:to).once.with("/#{type[0]}").and_return(@mock_connection)
|
|
252
|
+
@api.send("get_#{type[0]}")
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
it "should return as the proper object type" do
|
|
256
|
+
@mock_connection.stub!(:to).and_return(@mock_connection)
|
|
257
|
+
type[2].should_receive(:new).once.with(@mock_response_item).and_return(@mock_object)
|
|
258
|
+
@api.send("get_#{type[0]}").should == @mock_response
|
|
259
|
+
end
|
|
260
|
+
end
|
|
240
261
|
end
|
|
241
262
|
|
|
242
263
|
describe "leaderboards" do
|
|
@@ -273,16 +294,21 @@ describe IActionable::Api do
|
|
|
273
294
|
|
|
274
295
|
describe "notifications" do
|
|
275
296
|
it "should make the correct IActionable API all" do
|
|
276
|
-
IActionable::Objects::
|
|
277
|
-
IActionable::Objects::Challenge.stub!(:new)
|
|
278
|
-
IActionable::Objects::Goal.stub!(:new)
|
|
279
|
-
IActionable::Objects::Level.stub!(:new)
|
|
280
|
-
IActionable::Objects::ProfilePoints.stub!(:new)
|
|
297
|
+
IActionable::Objects::ProfileNotifications.stub!(:new)
|
|
281
298
|
@mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
|
|
282
299
|
@mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
|
|
283
300
|
@mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}/notifications").and_return(@mock_connection)
|
|
284
301
|
@mock_connection.should_receive(:get).and_return(@mock_response)
|
|
285
302
|
@api.get_profile_notifications(@profile_type, @id_type, @id)
|
|
286
303
|
end
|
|
304
|
+
|
|
305
|
+
it "should return with the corect object" do
|
|
306
|
+
@mock_connection.stub!(:request).and_return(@mock_connection)
|
|
307
|
+
@mock_connection.stub!(:with_app_key).and_return(@mock_connection)
|
|
308
|
+
@mock_connection.stub!(:to).and_return(@mock_connection)
|
|
309
|
+
@mock_connection.stub!(:get).and_return(@mock_response)
|
|
310
|
+
IActionable::Objects::ProfileNotifications.should_receive(:new).once.with(@mock_response).and_return(@mock_response)
|
|
311
|
+
@api.get_profile_notifications(@profile_type, @id_type, @id).should == @mock_response
|
|
312
|
+
end
|
|
287
313
|
end
|
|
288
314
|
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'spec_helper.rb'
|
|
2
|
+
|
|
3
|
+
describe "API response to get_achievements" do
|
|
4
|
+
before do
|
|
5
|
+
@sample_response = [
|
|
6
|
+
{
|
|
7
|
+
"Key" => "opinionated_gold",
|
|
8
|
+
"Description" => "Leave 25 comments.",
|
|
9
|
+
"ImageURL" => "http://iactionable.blob.core.windows.net/achievementimages/33333",
|
|
10
|
+
"Name" => "Opinionated - Gold"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"Key" => "opinionated_silver",
|
|
14
|
+
"Description" => "Make 10 comments.",
|
|
15
|
+
"ImageURL" => "http://iactionable.blob.core.windows.net/achievementimages/44444",
|
|
16
|
+
"Name" => "Opinionated - Silver"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should not raise error on wrapping in an object" do
|
|
22
|
+
lambda { @sample_response.map{|data| IActionable::Objects::Achievement.new(data) } }.should_not raise_error
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "when wrapped in an object" do
|
|
26
|
+
before do
|
|
27
|
+
@wrapped = @sample_response.map{|data| IActionable::Objects::Achievement.new(data) }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should contain ar array of available achievements" do
|
|
31
|
+
@wrapped.should be_instance_of Array
|
|
32
|
+
@wrapped.first.key.should == @sample_response[0]["Key"]
|
|
33
|
+
@wrapped.first.description.should == @sample_response[0]["Description"]
|
|
34
|
+
@wrapped.first.image_url.should == @sample_response[0]["ImageURL"]
|
|
35
|
+
@wrapped.first.name.should == @sample_response[0]["Name"]
|
|
36
|
+
@wrapped.last.key.should == @sample_response[1]["Key"]
|
|
37
|
+
@wrapped.last.description.should == @sample_response[1]["Description"]
|
|
38
|
+
@wrapped.last.image_url.should == @sample_response[1]["ImageURL"]
|
|
39
|
+
@wrapped.last.name.should == @sample_response[1]["Name"]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "should convert to a hash equal to the original" do
|
|
43
|
+
hash_including(:array => @sample_response).should == {:array => @wrapped.map{|achievement| achievement.to_hash}}
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|