gamifier 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gamifier/dsl/site.rb +1 -1
- data/lib/gamifier/engine.rb +1 -1
- data/lib/gamifier/model.rb +12 -3
- data/lib/gamifier/models/activity_definition.rb +10 -0
- data/lib/gamifier/models/player.rb +8 -8
- data/lib/gamifier/version.rb +1 -1
- data/lib/gamifier.rb +1 -1
- data/spec/unit/model_spec.rb +4 -4
- data/spec/unit/models/activity_definition_spec.rb +24 -0
- metadata +6 -4
data/lib/gamifier/dsl/site.rb
CHANGED
data/lib/gamifier/engine.rb
CHANGED
data/lib/gamifier/model.rb
CHANGED
@@ -13,8 +13,12 @@ module Gamifier
|
|
13
13
|
|
14
14
|
def attributes; @table.dup; end
|
15
15
|
|
16
|
-
def save
|
17
|
-
new?
|
16
|
+
def save(options = {})
|
17
|
+
if new?
|
18
|
+
options.has_key?(:async) ? async_create : create
|
19
|
+
else
|
20
|
+
update
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
24
|
# Allow to update only the specific attributes given in the +opts+ Hash.
|
@@ -148,7 +152,7 @@ module Gamifier
|
|
148
152
|
response
|
149
153
|
end
|
150
154
|
end
|
151
|
-
|
155
|
+
|
152
156
|
def map_to_models(response)
|
153
157
|
response['data'].map{|h| build(h)}
|
154
158
|
end
|
@@ -207,6 +211,11 @@ module Gamifier
|
|
207
211
|
replace_if_successful(res)
|
208
212
|
end
|
209
213
|
|
214
|
+
def async_create
|
215
|
+
res = engine.transmit :post, 'activities/async_create', :body => payload_for_submission
|
216
|
+
replace_if_successful(res)
|
217
|
+
end
|
218
|
+
|
210
219
|
def update(opts = {})
|
211
220
|
res = engine.transmit :put, path, :body => payload_for_submission(opts)
|
212
221
|
replace_if_successful(res)
|
@@ -2,5 +2,15 @@ require 'gamifier/model'
|
|
2
2
|
|
3
3
|
module Gamifier
|
4
4
|
class ActivityDefinition < Model
|
5
|
+
def limit_per_day(times_per_day)
|
6
|
+
self.enable_rate_limiting = true
|
7
|
+
self.bucket_max_capacity = times_per_day
|
8
|
+
self.bucket_drain_rate = times_per_day/24.0
|
9
|
+
end
|
10
|
+
|
11
|
+
def limit_once_per_day
|
12
|
+
limit_per_day 1
|
13
|
+
end
|
14
|
+
|
5
15
|
end
|
6
16
|
end
|
@@ -7,22 +7,22 @@ module Gamifier
|
|
7
7
|
mutable_attributes :first_name, :last_name, :nickname, :display_name, :picture_url, :admin
|
8
8
|
|
9
9
|
module FinderMethods
|
10
|
-
|
10
|
+
|
11
11
|
def find_by_site_and_email(site, email, params = {})
|
12
12
|
res = engine.transmit(:get, path, :query => params.merge({:site => site, :email => email}))
|
13
13
|
select_first_entry_if_any(res)
|
14
14
|
end
|
15
|
-
|
16
|
-
def find_by_player_id(player_id, params = {})
|
15
|
+
|
16
|
+
def find_by_player_id(player_id, params = {})
|
17
17
|
res = engine.transmit(:get, [path, player_id].join('/'))
|
18
18
|
select_first_entry_if_any(res)
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
end
|
22
22
|
|
23
|
-
def credit(verb, metadata = {})
|
24
|
-
engine.activities.build(metadata.merge({:player_id => _id, :verb => verb})).save
|
23
|
+
def credit(verb, metadata = {}, options = {})
|
24
|
+
engine.activities.build(metadata.merge({:player_id => _id, :verb => verb})).save(options)
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
end
|
28
|
-
end
|
28
|
+
end
|
data/lib/gamifier/version.rb
CHANGED
data/lib/gamifier.rb
CHANGED
data/spec/unit/model_spec.rb
CHANGED
@@ -102,7 +102,7 @@ describe Gamifier::Model do
|
|
102
102
|
expect{ @model.update_attributes(:key => "value") }.to raise_error(Gamifier::Error)
|
103
103
|
end
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
describe "#payload_for_submission" do
|
107
107
|
it "should reject any attribute not in the list of the mutable_attributes (if any)" do
|
108
108
|
@model.class.mutable_attributes :last_name
|
@@ -126,7 +126,7 @@ describe Gamifier::Model do
|
|
126
126
|
end
|
127
127
|
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
describe "FinderMethods" do
|
131
131
|
before do
|
132
132
|
@engine = mock(Gamifier::Engine)
|
@@ -177,6 +177,6 @@ describe Gamifier::Model do
|
|
177
177
|
entry.should be_nil
|
178
178
|
end
|
179
179
|
end
|
180
|
-
|
180
|
+
|
181
181
|
end
|
182
|
-
end
|
182
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gamifier::Player do
|
4
|
+
before do
|
5
|
+
@engine = mock(Gamifier::Engine)
|
6
|
+
end
|
7
|
+
describe "limit_per_day" do
|
8
|
+
it "should set rate limits" do
|
9
|
+
a = Gamifier::ActivityDefinition.new
|
10
|
+
|
11
|
+
a.limit_per_day(1)
|
12
|
+
a.attributes.should include({:enable_rate_limiting => true, :bucket_max_capacity => 1})
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "limit_once_per_day" do
|
18
|
+
it "should set rate limits" do
|
19
|
+
a = Gamifier::ActivityDefinition.new
|
20
|
+
a.should_receive(:limit_per_day).with(1)
|
21
|
+
a.limit_once_per_day
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gamifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 6
|
10
|
+
version: 1.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Cyril Rohr
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-09-
|
18
|
+
date: 2012-09-24 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: faraday
|
@@ -139,6 +139,7 @@ files:
|
|
139
139
|
- spec/unit/engine_spec.rb
|
140
140
|
- spec/unit/gamifier_spec.rb
|
141
141
|
- spec/unit/model_spec.rb
|
142
|
+
- spec/unit/models/activity_definition_spec.rb
|
142
143
|
- spec/unit/models/player_spec.rb
|
143
144
|
homepage: ""
|
144
145
|
licenses: []
|
@@ -187,4 +188,5 @@ test_files:
|
|
187
188
|
- spec/unit/engine_spec.rb
|
188
189
|
- spec/unit/gamifier_spec.rb
|
189
190
|
- spec/unit/model_spec.rb
|
191
|
+
- spec/unit/models/activity_definition_spec.rb
|
190
192
|
- spec/unit/models/player_spec.rb
|