naudo-ruby-iactionable 0.1.1
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/.gitignore +4 -0
- data/CHANGELOG.md +29 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +39 -0
- data/README.md +49 -0
- data/Rakefile +1 -0
- data/lib/iactionable/api.rb +224 -0
- data/lib/iactionable/connection.rb +118 -0
- data/lib/iactionable/error.rb +17 -0
- data/lib/iactionable/objects.rb +27 -0
- data/lib/iactionable/objects/achievement.rb +29 -0
- data/lib/iactionable/objects/awardable.rb +50 -0
- data/lib/iactionable/objects/challenge.rb +27 -0
- data/lib/iactionable/objects/goal.rb +30 -0
- data/lib/iactionable/objects/i_actionable_object.rb +40 -0
- data/lib/iactionable/objects/identifier.rb +17 -0
- data/lib/iactionable/objects/leaderboard.rb +15 -0
- data/lib/iactionable/objects/leaderboard_report.rb +30 -0
- data/lib/iactionable/objects/level.rb +24 -0
- data/lib/iactionable/objects/level_type.rb +15 -0
- data/lib/iactionable/objects/point_type.rb +15 -0
- data/lib/iactionable/objects/profile_achievements.rb +20 -0
- data/lib/iactionable/objects/profile_challenges.rb +20 -0
- data/lib/iactionable/objects/profile_goals.rb +20 -0
- data/lib/iactionable/objects/profile_level.rb +20 -0
- data/lib/iactionable/objects/profile_notifications.rb +29 -0
- data/lib/iactionable/objects/profile_points.rb +29 -0
- data/lib/iactionable/objects/profile_summary.rb +32 -0
- data/lib/iactionable/objects/progress.rb +46 -0
- data/lib/iactionable/settings.rb +30 -0
- data/lib/iactionable/version.rb +3 -0
- data/lib/ruby-iactionable.rb +9 -0
- data/ruby_iactionable.gemspec +28 -0
- data/spec/api/get_achievements_api_response_spec.rb +46 -0
- data/spec/api/get_challenges_api_response_spec.rb +42 -0
- data/spec/api/get_goals_api_response_spec.rb +46 -0
- data/spec/api/get_leaderboard_api_response_spec.rb +76 -0
- data/spec/api/get_profile_achievements_api_response_spec.rb +113 -0
- data/spec/api/get_profile_api_response_spec.rb +103 -0
- data/spec/api/get_profile_challenges_api_response_spec.rb +99 -0
- data/spec/api/get_profile_goals_api_response_spec.rb +103 -0
- data/spec/api/get_profile_notifications_api_response_spec.rb +75 -0
- data/spec/api/get_profile_points_api_response_spec.rb +67 -0
- data/spec/api_spec.rb +399 -0
- data/spec/connection_spec.rb +111 -0
- data/spec/settings_spec.rb +52 -0
- data/spec/spec_helper.rb +1 -0
- metadata +165 -0
@@ -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
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module IActionable
|
2
|
+
module Objects
|
3
|
+
class ProfilePoints < IActionableObject
|
4
|
+
attr_accessor :level # not always present
|
5
|
+
attr_accessor :point_type
|
6
|
+
attr_accessor :points
|
7
|
+
attr_accessor :reason # not always present
|
8
|
+
|
9
|
+
def initialize(key_values={})
|
10
|
+
levels = key_values.delete("Level")
|
11
|
+
@level = IActionable::Objects::ProfileLevel.new(levels) unless levels.nil?
|
12
|
+
@point_type = IActionable::Objects::PointType.new(key_values.delete("PointType"))
|
13
|
+
super(key_values)
|
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
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module IActionable
|
2
|
+
module Objects
|
3
|
+
class ProfileSummary < IActionableObject
|
4
|
+
attr_accessor :display_name
|
5
|
+
attr_accessor :identifiers
|
6
|
+
attr_accessor :points
|
7
|
+
attr_accessor :recent_achievements # not always present
|
8
|
+
attr_accessor :rank # not always present
|
9
|
+
|
10
|
+
def initialize(key_values={})
|
11
|
+
@identifiers = extract_many_as(key_values, "Identifiers", IActionable::Objects::Identifier)
|
12
|
+
@points = extract_many_as(key_values, "Points", IActionable::Objects::ProfilePoints)
|
13
|
+
@recent_achievements = extract_many_as(key_values, "RecentAchievements", IActionable::Objects::Achievement)
|
14
|
+
|
15
|
+
super(key_values)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_hash
|
19
|
+
hash = {
|
20
|
+
"DisplayName" => @display_name,
|
21
|
+
"Identifiers" => @identifiers.map{|identifier| identifier.to_hash}
|
22
|
+
}
|
23
|
+
unless @points.nil?
|
24
|
+
hash["Points"] = @points.kind_of?(Array) ? @points.map{|point| point.to_hash} : @points
|
25
|
+
end
|
26
|
+
hash["RecentAchievements"] = @recent_achievements.map{|recent_achievement| recent_achievement.to_hash} unless @recent_achievements.empty?
|
27
|
+
hash["Rank"] = @rank unless @rank.nil?
|
28
|
+
hash
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module IActionable
|
2
|
+
module Objects
|
3
|
+
class Progress < IActionableObject
|
4
|
+
attr_accessor :description
|
5
|
+
attr_accessor :condition_met_date
|
6
|
+
attr_accessor :original_condition_met_date
|
7
|
+
attr_accessor :current_value
|
8
|
+
attr_accessor :required_value
|
9
|
+
attr :complete
|
10
|
+
|
11
|
+
def initialize(key_values={})
|
12
|
+
super(key_values)
|
13
|
+
# convert the miliseconds within the date string to seconds (per ruby)
|
14
|
+
# "/Date(1275706032317-0600)/" => "1275706032-0600"
|
15
|
+
@original_condition_met_date = @condition_met_date
|
16
|
+
@condition_met_date = IActionableObject.timestamp_to_seconds(@condition_met_date) unless @condition_met_date.blank?
|
17
|
+
end
|
18
|
+
|
19
|
+
def complete?
|
20
|
+
Integer(@current_value) >= Integer(@required_value)
|
21
|
+
rescue TypeError => e
|
22
|
+
false
|
23
|
+
end
|
24
|
+
|
25
|
+
def percent_complete
|
26
|
+
Integer(Float(@current_value) / Integer(@required_value) * 100)
|
27
|
+
rescue TypeError => e
|
28
|
+
0
|
29
|
+
end
|
30
|
+
|
31
|
+
def condition_met_date
|
32
|
+
# bug in ruby 1.9.2 where Time.strptime does not support seconds-since-epoch format, but DateTime.strptime does, so we'll use that for now
|
33
|
+
DateTime.strptime(@condition_met_date, "%s%z").to_time unless @condition_met_date.blank?
|
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
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module IActionable
|
2
|
+
class ConfigError < StandardError
|
3
|
+
end
|
4
|
+
|
5
|
+
class Settings
|
6
|
+
attr :settings
|
7
|
+
|
8
|
+
def initialize(values)
|
9
|
+
@settings = {
|
10
|
+
:app_key => values.fetch(:app_key),
|
11
|
+
:api_key => values.fetch(:api_key),
|
12
|
+
:version => values.fetch(:version)
|
13
|
+
}
|
14
|
+
rescue NoMethodError, KeyError => e
|
15
|
+
raise ConfigError.new("IAction::Settings being initialized with invalid arguments")
|
16
|
+
end
|
17
|
+
|
18
|
+
def app_key
|
19
|
+
@settings.fetch(:app_key)
|
20
|
+
end
|
21
|
+
|
22
|
+
def api_key
|
23
|
+
@settings.fetch(:api_key)
|
24
|
+
end
|
25
|
+
|
26
|
+
def version
|
27
|
+
@settings.fetch(:version)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
require 'active_support/core_ext/object/blank'
|
3
|
+
require 'active_support/core_ext/date/conversions'
|
4
|
+
require 'active_support/core_ext/time/calculations'
|
5
|
+
require 'iactionable/version'
|
6
|
+
require 'iactionable/api.rb'
|
7
|
+
|
8
|
+
module IActionable
|
9
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "iactionable/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "naudo-ruby-iactionable"
|
7
|
+
s.version = IActionable::VERSION
|
8
|
+
s.authors = ["Chris Eberz"]
|
9
|
+
s.email = ["ceberz@elctech.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Ruby wrapper for IActionable's restful API.}
|
12
|
+
s.description = %q{Ruby wrapper for IActionable's restful API.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "ruby-iactionable"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib", "spec"]
|
20
|
+
|
21
|
+
|
22
|
+
s.add_development_dependency "rspec", ">= 2.6"
|
23
|
+
s.add_development_dependency "yard"
|
24
|
+
|
25
|
+
s.add_runtime_dependency "faraday"
|
26
|
+
s.add_runtime_dependency "faraday_middleware", '~> 0.8.7'
|
27
|
+
s.add_runtime_dependency "activesupport", ">= 3.0.0"
|
28
|
+
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
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe "API response to get_challenges" do
|
4
|
+
before do
|
5
|
+
@sample_response = [
|
6
|
+
{
|
7
|
+
"Key" => "easy_challenge",
|
8
|
+
"Description" => "Do something easy 5 times and earn 100 points",
|
9
|
+
"Name" => "Easy Challenge"
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"Key" => "hard_challenge",
|
13
|
+
"Description" => "Do something hard 10 times and earn 200 points",
|
14
|
+
"Name" => "Hard Challenge"
|
15
|
+
}
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not raise error on wrapping in an object" do
|
20
|
+
lambda { @sample_response.map{|data| IActionable::Objects::Challenge.new(data) } }.should_not raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "when wrapped in an object" do
|
24
|
+
before do
|
25
|
+
@wrapped = @sample_response.map{|data| IActionable::Objects::Challenge.new(data) }
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should contain ar array of available challenges" do
|
29
|
+
@wrapped.should be_instance_of Array
|
30
|
+
@wrapped.first.key.should == @sample_response[0]["Key"]
|
31
|
+
@wrapped.first.description.should == @sample_response[0]["Description"]
|
32
|
+
@wrapped.first.name.should == @sample_response[0]["Name"]
|
33
|
+
@wrapped.last.key.should == @sample_response[1]["Key"]
|
34
|
+
@wrapped.last.description.should == @sample_response[1]["Description"]
|
35
|
+
@wrapped.last.name.should == @sample_response[1]["Name"]
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should convert to a hash equal to the original" do
|
39
|
+
hash_including(:array => @sample_response).should == {:array => @wrapped.map{|challenge| challenge.to_hash}}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe "API response to get_goals" do
|
4
|
+
before do
|
5
|
+
@sample_response = [
|
6
|
+
{
|
7
|
+
"Key" => "easy_goal",
|
8
|
+
"Description" => "Do something easy 5 times today and earn 100 points",
|
9
|
+
"Name" => "Easy Goal",
|
10
|
+
"Interval" => "Daily"
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"Key" => "hard_goal",
|
14
|
+
"Description" => "Do something hard 10 times this week and earn 200 points",
|
15
|
+
"Name" => "Hard Goal",
|
16
|
+
"Interval" => "Daily"
|
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::Goal.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::Goal.new(data) }
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should contain ar array of available goals" 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.name.should == @sample_response[0]["Name"]
|
35
|
+
@wrapped.first.interval.should == @sample_response[0]["Interval"]
|
36
|
+
@wrapped.last.key.should == @sample_response[1]["Key"]
|
37
|
+
@wrapped.last.description.should == @sample_response[1]["Description"]
|
38
|
+
@wrapped.last.name.should == @sample_response[1]["Name"]
|
39
|
+
@wrapped.last.interval.should == @sample_response[1]["Interval"]
|
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{|goal| goal.to_hash}}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe "API response to get_leaderboard" do
|
4
|
+
before do
|
5
|
+
@sample_response = {
|
6
|
+
"Leaderboard" => {
|
7
|
+
"Key" => "weekly_leaderboard",
|
8
|
+
"Name" => "Weekly Experience Points Leaderboard"
|
9
|
+
},
|
10
|
+
"PageCount" => 10,
|
11
|
+
"PageNumber" => 1,
|
12
|
+
"PointType" => {
|
13
|
+
"Key" => "experience_points",
|
14
|
+
"Name" => "Experience Points"
|
15
|
+
},
|
16
|
+
"Profiles" => [
|
17
|
+
{
|
18
|
+
"DisplayName" => "Jimmy Dean",
|
19
|
+
"Identifiers" => [
|
20
|
+
{
|
21
|
+
"ID" => "100005",
|
22
|
+
"IDHash" => "d63c48a193f960380f0ac353eddc25d4",
|
23
|
+
"IDType" => "Facebook"
|
24
|
+
}
|
25
|
+
],
|
26
|
+
"Rank" => 1,
|
27
|
+
"Points" => 246
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"DisplayName" => "Jason Barnes",
|
31
|
+
"Identifiers" => [
|
32
|
+
{
|
33
|
+
"ID" => "100010",
|
34
|
+
"IDHash" => "d3d33fb3e33963b58f681ed2e98d835c",
|
35
|
+
"IDType" => "Facebook"
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"ID" => "email@dot.com",
|
39
|
+
"IDHash" => "66a1bd06edcc1a2d208953d441e1374e",
|
40
|
+
"IDType" => "Email"
|
41
|
+
}
|
42
|
+
],
|
43
|
+
"Rank" => 2,
|
44
|
+
"Points" => 216
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"DisplayName" => "Ben Burt",
|
48
|
+
"Identifiers" => [
|
49
|
+
{
|
50
|
+
"ID" => "600004",
|
51
|
+
"IDHash" => "e567689d28abc93867955ff85324bd08",
|
52
|
+
"IDType" => "Facebook"
|
53
|
+
}
|
54
|
+
],
|
55
|
+
"Rank" => 3,
|
56
|
+
"Points" => 50
|
57
|
+
}
|
58
|
+
],
|
59
|
+
"TotalCount" => 50
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not raise error on wrapping in an object" do
|
64
|
+
lambda { IActionable::Objects::LeaderboardReport.new(@sample_response) }.should_not raise_error
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "when wrapped in an object" do
|
68
|
+
before do
|
69
|
+
@wrapped = IActionable::Objects::LeaderboardReport.new(Marshal.load(Marshal.dump(@sample_response)))
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should convert to a hash equal to the original" do
|
73
|
+
hash_including(@sample_response).should == @wrapped.to_hash
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe "API response to get_profile_achievements" do
|
4
|
+
before do
|
5
|
+
@sample_response = {
|
6
|
+
"Available" => [
|
7
|
+
{
|
8
|
+
"Key" => "super_user",
|
9
|
+
"Description" => "Post 35 Photos and make 50 Comments",
|
10
|
+
"ImageURL" => "http://iactionable.blob.core.windows.net/achievementimages/99999",
|
11
|
+
"Name" => "Super User",
|
12
|
+
"Progress" => [
|
13
|
+
{
|
14
|
+
"ConditionMetDate" => nil,
|
15
|
+
"CurrentValue" => 12,
|
16
|
+
"Description" => "Post 35 Photos",
|
17
|
+
"RequiredValue" => "35"
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"ConditionMetDate" => nil,
|
21
|
+
"CurrentValue" => 6,
|
22
|
+
"Description" => "Make 50 Comments",
|
23
|
+
"RequiredValue" => "50"
|
24
|
+
}
|
25
|
+
]
|
26
|
+
}
|
27
|
+
],
|
28
|
+
"Completed" => [
|
29
|
+
{
|
30
|
+
"Key" => "you_can_talk",
|
31
|
+
"Description" => "Post a Comment on any blog post.",
|
32
|
+
"ImageURL" => "http://iactionable.blob.core.windows.net/achievementimages/99998",
|
33
|
+
"Name" => "You can talk!",
|
34
|
+
"Progress" => [
|
35
|
+
{
|
36
|
+
"ConditionMetDate" => "/Date(1275706032317-0600)/",
|
37
|
+
"CurrentValue" => 1,
|
38
|
+
"Description" => "Make 1 Comment",
|
39
|
+
"RequiredValue" => "1"
|
40
|
+
}
|
41
|
+
],
|
42
|
+
"AwardDate" => "/Date(1275706032317-0600)/"
|
43
|
+
}
|
44
|
+
]
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should not raise error on wrapping in an object" do
|
49
|
+
lambda { IActionable::Objects::ProfileAchievements.new(@sample_response) }.should_not raise_error
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "with a malformed AwardDate string" do
|
53
|
+
before do
|
54
|
+
@sample_response["Completed"].first["AwardDate"] = 'bogus'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should not raise error on wrapping in an object" do
|
58
|
+
lambda { IActionable::Objects::ProfileAchievements.new(@sample_response) }.should_not raise_error
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should set the value of AwardDate to nil" do
|
62
|
+
IActionable::Objects::ProfileAchievements.new(@sample_response).completed.first.award_date.should be_nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "when wrapped in an object" do
|
67
|
+
before do
|
68
|
+
@wrapped = IActionable::Objects::ProfileAchievements.new(Marshal.load(Marshal.dump(@sample_response)))
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should contain ar array of available achievements" do
|
72
|
+
@wrapped.available.should be_instance_of Array
|
73
|
+
@wrapped.available.first.key.should == @sample_response["Available"][0]["Key"]
|
74
|
+
@wrapped.available.first.description.should == @sample_response["Available"][0]["Description"]
|
75
|
+
@wrapped.available.first.image_url.should == @sample_response["Available"][0]["ImageURL"]
|
76
|
+
@wrapped.available.first.name.should == @sample_response["Available"][0]["Name"]
|
77
|
+
@wrapped.available.first.award_date.should be_nil
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should contain an array of progresses within each available achievement" do
|
81
|
+
@wrapped.available.first.progress.should be_instance_of Array
|
82
|
+
@wrapped.available.first.progress.first.condition_met_date.should be_nil
|
83
|
+
@wrapped.available.first.progress.first.current_value.should == @sample_response["Available"][0]["Progress"][0]["CurrentValue"]
|
84
|
+
@wrapped.available.first.progress.first.description.should == @sample_response["Available"][0]["Progress"][0]["Description"]
|
85
|
+
@wrapped.available.first.progress.first.required_value.should == @sample_response["Available"][0]["Progress"][0]["RequiredValue"]
|
86
|
+
@wrapped.available.first.progress.last.condition_met_date.should be_nil
|
87
|
+
@wrapped.available.first.progress.last.current_value.should == @sample_response["Available"][0]["Progress"][1]["CurrentValue"]
|
88
|
+
@wrapped.available.first.progress.last.description.should == @sample_response["Available"][0]["Progress"][1]["Description"]
|
89
|
+
@wrapped.available.first.progress.last.required_value.should == @sample_response["Available"][0]["Progress"][1]["RequiredValue"]
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should contain ar array of completed achievements" do
|
93
|
+
@wrapped.completed.should be_instance_of Array
|
94
|
+
@wrapped.completed.first.key.should == @sample_response["Completed"][0]["Key"]
|
95
|
+
@wrapped.completed.first.description.should == @sample_response["Completed"][0]["Description"]
|
96
|
+
@wrapped.completed.first.image_url.should == @sample_response["Completed"][0]["ImageURL"]
|
97
|
+
@wrapped.completed.first.name.should == @sample_response["Completed"][0]["Name"]
|
98
|
+
@wrapped.completed.first.award_date.should_not be_nil
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should contain an array of progresses within each completed achievement" do
|
102
|
+
@wrapped.completed.first.progress.should be_instance_of Array
|
103
|
+
@wrapped.completed.first.progress.first.condition_met_date.should_not be_nil
|
104
|
+
@wrapped.completed.first.progress.first.current_value.should == @sample_response["Completed"][0]["Progress"][0]["CurrentValue"]
|
105
|
+
@wrapped.completed.first.progress.first.description.should == @sample_response["Completed"][0]["Progress"][0]["Description"]
|
106
|
+
@wrapped.completed.first.progress.first.required_value.should == @sample_response["Completed"][0]["Progress"][0]["RequiredValue"]
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should convert to a hash equal to the original" do
|
110
|
+
hash_including(@sample_response).should == @wrapped.to_hash
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|