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,17 @@
|
|
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
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module IActionable
|
2
|
+
module Objects
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'iactionable/objects/i_actionable_object.rb'
|
7
|
+
require 'iactionable/objects/progress.rb'
|
8
|
+
require 'iactionable/objects/awardable.rb'
|
9
|
+
|
10
|
+
IActionable::Objects::IActionableObject.send(:include, IActionable::Objects::Awardable)
|
11
|
+
|
12
|
+
require 'iactionable/objects/achievement.rb'
|
13
|
+
require 'iactionable/objects/challenge.rb'
|
14
|
+
require 'iactionable/objects/goal.rb'
|
15
|
+
require 'iactionable/objects/identifier.rb'
|
16
|
+
require 'iactionable/objects/leaderboard.rb'
|
17
|
+
require 'iactionable/objects/leaderboard_report.rb'
|
18
|
+
require 'iactionable/objects/level_type.rb'
|
19
|
+
require 'iactionable/objects/level.rb'
|
20
|
+
require 'iactionable/objects/point_type.rb'
|
21
|
+
require 'iactionable/objects/profile_level.rb'
|
22
|
+
require 'iactionable/objects/profile_points.rb'
|
23
|
+
require 'iactionable/objects/profile_summary.rb'
|
24
|
+
require 'iactionable/objects/profile_achievements.rb'
|
25
|
+
require 'iactionable/objects/profile_challenges.rb'
|
26
|
+
require 'iactionable/objects/profile_goals.rb'
|
27
|
+
require 'iactionable/objects/profile_notifications.rb'
|
@@ -0,0 +1,29 @@
|
|
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
|
@@ -0,0 +1,50 @@
|
|
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 DateTime.strptime does, so we'll use that for now
|
38
|
+
DateTime.strptime(@award_date, "%s%z") 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
|
@@ -0,0 +1,27 @@
|
|
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
|
@@ -0,0 +1,30 @@
|
|
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
|
@@ -0,0 +1,40 @@
|
|
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
|
+
unless milliseconds.nil? || tz.nil?
|
18
|
+
"#{Integer(milliseconds)/1000}#{tz}"
|
19
|
+
else
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def extract_many_as(key_values, field, klass)
|
27
|
+
if key_values.fetch(field, nil).respond_to?(:inject)
|
28
|
+
loaded = []
|
29
|
+
content = key_values.delete(field)
|
30
|
+
content.each do |c|
|
31
|
+
loaded << klass.new(c)
|
32
|
+
end
|
33
|
+
loaded
|
34
|
+
else
|
35
|
+
[]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,17 @@
|
|
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
|
@@ -0,0 +1,30 @@
|
|
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
|
@@ -0,0 +1,24 @@
|
|
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
|
@@ -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
|
@@ -0,0 +1,20 @@
|
|
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
|