riaction 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/Gemfile.lock +59 -0
- data/README +110 -0
- data/Rakefile +1 -0
- data/lib/riaction.rb +3 -0
- data/lib/riaction/iactionable/api.rb +209 -0
- data/lib/riaction/iactionable/connection.rb +114 -0
- data/lib/riaction/iactionable/error.rb +17 -0
- data/lib/riaction/iactionable/objects.rb +6 -0
- data/lib/riaction/iactionable/objects/achievement.rb +19 -0
- data/lib/riaction/iactionable/objects/awardable.rb +44 -0
- data/lib/riaction/iactionable/objects/challenge.rb +18 -0
- data/lib/riaction/iactionable/objects/goal.rb +19 -0
- data/lib/riaction/iactionable/objects/i_actionable_object.rb +40 -0
- data/lib/riaction/iactionable/objects/identifier.rb +11 -0
- data/lib/riaction/iactionable/objects/leaderboard.rb +10 -0
- data/lib/riaction/iactionable/objects/leaderboard_report.rb +23 -0
- data/lib/riaction/iactionable/objects/level.rb +18 -0
- data/lib/riaction/iactionable/objects/level_type.rb +10 -0
- data/lib/riaction/iactionable/objects/point_type.rb +10 -0
- data/lib/riaction/iactionable/objects/profile_level.rb +16 -0
- data/lib/riaction/iactionable/objects/profile_points.rb +21 -0
- data/lib/riaction/iactionable/objects/profile_summary.rb +24 -0
- data/lib/riaction/iactionable/objects/progress.rb +37 -0
- data/lib/riaction/iactionable/settings.rb +30 -0
- data/lib/riaction/riaction.rb +368 -0
- data/lib/riaction/version.rb +3 -0
- data/lib/tasks/riaction.rake +101 -0
- data/riaction.gemspec +32 -0
- data/spec/api_spec.rb +288 -0
- data/spec/connection_spec.rb +111 -0
- data/spec/riaction_spec.rb +253 -0
- data/spec/settings_spec.rb +52 -0
- data/spec/spec_helper.rb +1 -0
- metadata +153 -0
@@ -0,0 +1,253 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Riaction do
|
4
|
+
class RiactionTestBase
|
5
|
+
include ActiveSupport::Callbacks
|
6
|
+
include Riaction
|
7
|
+
define_callbacks :after_create, :after_update, :after_destroy
|
8
|
+
|
9
|
+
def self.base_class
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
run_callbacks(:after_create)
|
15
|
+
end
|
16
|
+
|
17
|
+
def update
|
18
|
+
run_callbacks(:after_update)
|
19
|
+
end
|
20
|
+
|
21
|
+
def destroy
|
22
|
+
run_callbacks(:after_destroy)
|
23
|
+
end
|
24
|
+
|
25
|
+
def id
|
26
|
+
42
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
before do
|
31
|
+
@api = mock("mocked IActionable API")
|
32
|
+
IActionable::Api.stub!(:new).and_return(@api)
|
33
|
+
Resque.stub!(:enqueue)
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "logging events" do
|
37
|
+
class MyClass < RiactionTestBase
|
38
|
+
riaction :profile, :type => :user, :custom => :id
|
39
|
+
riaction :event, :name => :create_profile, :trigger => :create, :profile => :self, :params => {:foo => "bar"}
|
40
|
+
end
|
41
|
+
|
42
|
+
class BadClass < RiactionTestBase
|
43
|
+
end
|
44
|
+
|
45
|
+
before do
|
46
|
+
@instance = MyClass.new
|
47
|
+
MyClass.stub!(:find_by_id!).and_return(@instance)
|
48
|
+
@bad_instance = BadClass.new
|
49
|
+
BadClass.stub!(:find_by_id!).and_return(@bad_instance)
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "when the profile generating the event exists" do
|
53
|
+
before do
|
54
|
+
@api.stub!(:get_profile_summary).and_return(true)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should send the event with parameters based on the details provided in the class" do
|
58
|
+
@api.should_receive(:log_event).once.with("user", "custom", @instance.id.to_s, :create_profile, {:foo => "bar"})
|
59
|
+
Riaction::EventPerformer.perform(:create_profile, "MyClass", @instance.id)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "when the profile generating the event does not exist" do
|
64
|
+
before do
|
65
|
+
@api.stub!(:get_profile_summary).and_raise(IActionable::Error::BadRequest.new(nil))
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should create the profile and then send the event with parameters based on the details provided in the class" do
|
69
|
+
@api.should_receive(:create_profile).once.ordered.with("user", "custom", @instance.id.to_s)
|
70
|
+
@api.should_receive(:log_event).once.ordered.with("user", "custom", @instance.id.to_s, :create_profile, {:foo => "bar"})
|
71
|
+
Riaction::EventPerformer.perform(:create_profile, "MyClass", @instance.id)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "when the class does not define the named event" do
|
76
|
+
it "should not attempt to log the event, and raise an error" do
|
77
|
+
@api.should_not_receive(:log_event)
|
78
|
+
lambda { Riaction::EventPerformer.perform(:bad_event_name, "MyClass", @instance.id) }.should raise_error(Riaction::NoEventDefined)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "when the class does not define the named event or any other riaction property" do
|
83
|
+
it "should not attempt to log the event, and raise an error" do
|
84
|
+
@api.should_not_receive(:log_event)
|
85
|
+
lambda { Riaction::EventPerformer.perform(:create_profile, "BadClass", @bad_instance.id) }.should raise_error(Riaction::NoEventDefined)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "profile generation" do
|
91
|
+
class MyClass < RiactionTestBase
|
92
|
+
riaction :profile, :type => :user, :custom => :id
|
93
|
+
end
|
94
|
+
|
95
|
+
class BadClass < RiactionTestBase
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "with a class that defines itself as an iactionable profile" do
|
99
|
+
before do
|
100
|
+
@instance = MyClass.new
|
101
|
+
MyClass.stub!(:find_by_id!).and_return(@instance)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should create the profile with parameters based on the details provided in the class" do
|
105
|
+
@api.should_receive(:create_profile).once.ordered.with("user", "custom", @instance.id.to_s)
|
106
|
+
Riaction::ProfileCreator.perform("MyClass", @instance.id)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "with a class that does not define itself as an iactionable profile" do
|
111
|
+
before do
|
112
|
+
@instance = BadClass.new
|
113
|
+
BadClass.stub!(:find_by_id!).and_return(@instance)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should not attempt to create the profile, and raise an error" do
|
117
|
+
@api.should_not_receive(:create_profile)
|
118
|
+
lambda { Riaction::ProfileCreator.perform("BadClass", @instance.id) }.should raise_error(Riaction::NoProfileDefined)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "event triggering" do
|
124
|
+
class EventDrivingClass < RiactionTestBase
|
125
|
+
def initialize
|
126
|
+
super
|
127
|
+
end
|
128
|
+
|
129
|
+
riaction :event, :name => :creation_event, :trigger => :create, :profile => :self
|
130
|
+
riaction :event, :name => :updating_event, :trigger => :update, :profile => :self
|
131
|
+
riaction :event, :name => :destruction_event, :trigger => :destroy, :profile => :self
|
132
|
+
riaction :event, :name => :custom_event, :trigger => :custom, :profile => :self
|
133
|
+
|
134
|
+
def id
|
135
|
+
42
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
before do
|
140
|
+
@event_driver_instance = EventDrivingClass.new
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "from an after-create callback" do
|
144
|
+
it "should log the event using the profile and paramters specified in the class" do
|
145
|
+
Resque.should_receive(:enqueue).once.with(Riaction::EventPerformer, :creation_event, "EventDrivingClass", @event_driver_instance.id)
|
146
|
+
EventDrivingClass.new
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "from an after-update callback" do
|
151
|
+
it "should log the event using the profile and paramters specified in the class" do
|
152
|
+
Resque.should_receive(:enqueue).once.with(Riaction::EventPerformer, :updating_event, "EventDrivingClass", @event_driver_instance.id)
|
153
|
+
@event_driver_instance.update
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "from an after-destroy callback" do
|
158
|
+
it "should log the event using the profile and paramters specified in the class" do
|
159
|
+
Resque.should_receive(:enqueue).once.with(Riaction::EventPerformer, :destruction_event, "EventDrivingClass", @event_driver_instance.id)
|
160
|
+
@event_driver_instance.destroy
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "from a custom trigger" do
|
165
|
+
it "should log the event using the profile and paramters specified in the class" do
|
166
|
+
Resque.should_receive(:enqueue).once.with(Riaction::EventPerformer, :custom_event, "EventDrivingClass", @event_driver_instance.id)
|
167
|
+
@event_driver_instance.trigger_custom!
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe "profile" do
|
173
|
+
class ProfileClass < RiactionTestBase
|
174
|
+
def initialize
|
175
|
+
super
|
176
|
+
end
|
177
|
+
|
178
|
+
riaction :profile, :type => :user, :custom => :id, :username => :name
|
179
|
+
|
180
|
+
def id
|
181
|
+
42
|
182
|
+
end
|
183
|
+
|
184
|
+
def name
|
185
|
+
"zortnac"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe "creation triggering" do
|
190
|
+
it "should create the profile based on the parameters given in the class, when an instance of that class is created" do
|
191
|
+
Resque.should_receive(:enqueue).once.with(Riaction::ProfileCreator, "ProfileClass", 42)
|
192
|
+
ProfileClass.new
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe "instance methods" do
|
197
|
+
before do
|
198
|
+
@instance = ProfileClass.new
|
199
|
+
@mock_response = mock("mock response")
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "for loading a profile summary" do
|
203
|
+
it "should make the correct call to the API with the parameters given in the class, and the values provided by the instance" do
|
204
|
+
@api.should_receive(:get_profile_summary).once.with("user", "custom", @instance.id.to_s, 10).and_return(@mock_response)
|
205
|
+
@instance.riaction_profile_summary(10).should == @mock_response
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "for creating a profile" do
|
210
|
+
it "should make the correct call to the API with the parameters given in the class, and the values provided by the instance" do
|
211
|
+
@api.stub!(:get_profile_summary).and_return(nil)
|
212
|
+
@api.should_receive(:create_profile).once.with("user", "custom", @instance.id.to_s).and_return(@mock_response)
|
213
|
+
@instance.riaction_create_profile.should == @mock_response
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe "for adding new identifiers to a profile" do
|
218
|
+
it "should make the correct call to the API with the parameters given in the class, and the values provided by the instance" do
|
219
|
+
@api.should_receive(:add_profile_identifier).once.with("user", "custom", @instance.id.to_s, "username", @instance.name).and_return(@mock_response)
|
220
|
+
@instance.riaction_update_profile(:username).should == @mock_response
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe "for loading profile achievments" do
|
225
|
+
it "should make the correct call to the API with the parameters given in the class, and the values provided by the instance" do
|
226
|
+
@api.should_receive(:get_profile_achievements).once.with("user", "custom", @instance.id.to_s, nil).and_return(@mock_response)
|
227
|
+
@instance.riaction_profile_achievements.should == @mock_response
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
describe "for loading profile challenges" do
|
232
|
+
it "should make the correct call to the API with the parameters given in the class, and the values provided by the instance" do
|
233
|
+
@api.should_receive(:get_profile_challenges).once.with("user", "custom", @instance.id.to_s, nil).and_return(@mock_response)
|
234
|
+
@instance.riaction_profile_challenges.should == @mock_response
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
describe "for loading profile goals" do
|
239
|
+
it "should make the correct call to the API with the parameters given in the class, and the values provided by the instance" do
|
240
|
+
@api.should_receive(:get_profile_goals).once.with("user", "custom", @instance.id.to_s, nil).and_return(@mock_response)
|
241
|
+
@instance.riaction_profile_goals.should == @mock_response
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
describe "for loading profile notifications" do
|
246
|
+
it "should make the correct call to the API with the parameters given in the class, and the values provided by the instance" do
|
247
|
+
@api.should_receive(:get_profile_notifications).once.with("user", "custom", @instance.id.to_s).and_return(@mock_response)
|
248
|
+
@instance.riaction_profile_notifications.should == @mock_response
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe IActionable::Settings do
|
4
|
+
before do
|
5
|
+
@settings_hash = {
|
6
|
+
:app_key => "12345",
|
7
|
+
:api_key => "abcde",
|
8
|
+
:version => "3"
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "with a valid input hash" do
|
13
|
+
it "should initialize" do
|
14
|
+
lambda { IActionable::Settings.new(@settings_hash) }.should_not raise_error
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "with an invalid input hash" do
|
19
|
+
it "should not initialize from missing app key" do
|
20
|
+
@settings_hash.delete(:app_key)
|
21
|
+
lambda { IActionable::Settings.new(@settings_hash) }.should raise_error(IActionable::ConfigError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should not initialize from missing api key" do
|
25
|
+
@settings_hash.delete(:api_key)
|
26
|
+
lambda { IActionable::Settings.new(@settings_hash) }.should raise_error(IActionable::ConfigError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not initialize from missing version" do
|
30
|
+
@settings_hash.delete(:version)
|
31
|
+
lambda { IActionable::Settings.new(@settings_hash) }.should raise_error(IActionable::ConfigError)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "once initialized" do
|
36
|
+
before do
|
37
|
+
@settings = IActionable::Settings.new(@settings_hash)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return the app key" do
|
41
|
+
@settings.app_key.should == @settings_hash[:app_key]
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return the api key" do
|
45
|
+
@settings.api_key.should == @settings_hash[:api_key]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return the version" do
|
49
|
+
@settings.version.should == @settings_hash[:version]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'riaction'
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: riaction
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Eberz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-02 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &2156171600 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.6'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2156171600
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: faraday
|
27
|
+
requirement: &2156170920 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2156170920
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: faraday-stack
|
38
|
+
requirement: &2156162140 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2156162140
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: activesupport
|
49
|
+
requirement: &2156160880 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2156160880
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: activerecord
|
60
|
+
requirement: &2156159100 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2156159100
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: resque
|
71
|
+
requirement: &2156158240 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2156158240
|
80
|
+
description: Wrapper for IActionable's restful API and an "acts-as" style interface
|
81
|
+
for models to behave as profiles and drive game events.
|
82
|
+
email:
|
83
|
+
- ceberz@elctech.com
|
84
|
+
executables: []
|
85
|
+
extensions: []
|
86
|
+
extra_rdoc_files: []
|
87
|
+
files:
|
88
|
+
- Gemfile
|
89
|
+
- Gemfile.lock
|
90
|
+
- README
|
91
|
+
- Rakefile
|
92
|
+
- lib/riaction.rb
|
93
|
+
- lib/riaction/iactionable/api.rb
|
94
|
+
- lib/riaction/iactionable/connection.rb
|
95
|
+
- lib/riaction/iactionable/error.rb
|
96
|
+
- lib/riaction/iactionable/objects.rb
|
97
|
+
- lib/riaction/iactionable/objects/achievement.rb
|
98
|
+
- lib/riaction/iactionable/objects/awardable.rb
|
99
|
+
- lib/riaction/iactionable/objects/challenge.rb
|
100
|
+
- lib/riaction/iactionable/objects/goal.rb
|
101
|
+
- lib/riaction/iactionable/objects/i_actionable_object.rb
|
102
|
+
- lib/riaction/iactionable/objects/identifier.rb
|
103
|
+
- lib/riaction/iactionable/objects/leaderboard.rb
|
104
|
+
- lib/riaction/iactionable/objects/leaderboard_report.rb
|
105
|
+
- lib/riaction/iactionable/objects/level.rb
|
106
|
+
- lib/riaction/iactionable/objects/level_type.rb
|
107
|
+
- lib/riaction/iactionable/objects/point_type.rb
|
108
|
+
- lib/riaction/iactionable/objects/profile_level.rb
|
109
|
+
- lib/riaction/iactionable/objects/profile_points.rb
|
110
|
+
- lib/riaction/iactionable/objects/profile_summary.rb
|
111
|
+
- lib/riaction/iactionable/objects/progress.rb
|
112
|
+
- lib/riaction/iactionable/settings.rb
|
113
|
+
- lib/riaction/riaction.rb
|
114
|
+
- lib/riaction/version.rb
|
115
|
+
- lib/tasks/riaction.rake
|
116
|
+
- riaction.gemspec
|
117
|
+
- spec/api_spec.rb
|
118
|
+
- spec/connection_spec.rb
|
119
|
+
- spec/riaction_spec.rb
|
120
|
+
- spec/settings_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
homepage: ''
|
123
|
+
licenses: []
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
- spec
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
137
|
+
requirements:
|
138
|
+
- - ! '>='
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project: riaction
|
143
|
+
rubygems_version: 1.8.10
|
144
|
+
signing_key:
|
145
|
+
specification_version: 3
|
146
|
+
summary: Wrapper for IActionable's restful API and an "acts-as" style interface for
|
147
|
+
models to behave as profiles and drive game events.
|
148
|
+
test_files:
|
149
|
+
- spec/api_spec.rb
|
150
|
+
- spec/connection_spec.rb
|
151
|
+
- spec/riaction_spec.rb
|
152
|
+
- spec/settings_spec.rb
|
153
|
+
- spec/spec_helper.rb
|