ruby-iactionable 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/lib/iactionable/api.rb +68 -14
- data/lib/iactionable/version.rb +1 -1
- data/spec/api_spec.rb +95 -10
- metadata +12 -12
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# CHANGELOG #
|
2
2
|
|
3
|
+
## 0.1.0 ##
|
4
|
+
|
5
|
+
* New feature: api instance can be set to not wrap raw response within objects with: `@api.set\_object\_wrapping(false)`
|
6
|
+
|
3
7
|
## 0.0.5 ##
|
4
8
|
|
5
9
|
* Fixed: IActionable::Objects::Awardable#awarded_on was stripping out time information when converting IActionable timestamp to Ruby time object
|
data/lib/iactionable/api.rb
CHANGED
@@ -6,6 +6,8 @@ module IActionable
|
|
6
6
|
|
7
7
|
class Api
|
8
8
|
attr :connection
|
9
|
+
attr :wrap_in_object
|
10
|
+
|
9
11
|
@@settings = nil
|
10
12
|
|
11
13
|
def initialize
|
@@ -14,6 +16,7 @@ module IActionable
|
|
14
16
|
else
|
15
17
|
raise IActionable::ConfigError.new("IActionable::Api cannot be initialized without credentials being set in IActionable::Api.init_settings()")
|
16
18
|
end
|
19
|
+
@wrap_in_object = true
|
17
20
|
end
|
18
21
|
|
19
22
|
def self.init_settings(values)
|
@@ -26,6 +29,11 @@ module IActionable
|
|
26
29
|
@@settings
|
27
30
|
end
|
28
31
|
|
32
|
+
def set_object_wrapping(bool)
|
33
|
+
@wrap_in_object = !!bool
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
29
37
|
# =================
|
30
38
|
# = Event Logging =
|
31
39
|
# =================
|
@@ -41,8 +49,11 @@ module IActionable
|
|
41
49
|
def get_profile_summary(profile_type, id_type, id, achievement_count = nil)
|
42
50
|
request = @connection.request.with_app_key.to("/#{profile_type}/#{id_type}/#{id}")
|
43
51
|
request.with_params(:achievementCount => achievement_count) unless achievement_count.blank?
|
44
|
-
|
45
|
-
|
52
|
+
if @wrap_in_object
|
53
|
+
IActionable::Objects::ProfileSummary.new(request.get)
|
54
|
+
else
|
55
|
+
request.get
|
56
|
+
end
|
46
57
|
end
|
47
58
|
|
48
59
|
def create_profile(profile_type, id_type, id, display_name = nil)
|
@@ -62,14 +73,21 @@ module IActionable
|
|
62
73
|
|
63
74
|
def get_profile_points(profile_type, id_type, id, point_type)
|
64
75
|
response = @connection.request.with_app_key.to("/#{profile_type}/#{id_type}/#{id}/points/#{point_type}").get
|
65
|
-
|
76
|
+
if @wrap_in_object
|
77
|
+
IActionable::Objects::ProfilePoints.new(response)
|
78
|
+
else
|
79
|
+
response
|
80
|
+
end
|
66
81
|
end
|
67
82
|
|
68
83
|
def update_profile_points(profile_type, id_type, id, point_type, amount, reason = nil)
|
69
84
|
request = @connection.request.with_app_key.with_api_key.to("/#{profile_type}/#{id_type}/#{id}/points/#{point_type}").with_params(:value => amount)
|
70
85
|
request.with_params(:description => reason) unless reason.blank?
|
71
|
-
|
72
|
-
|
86
|
+
if @wrap_in_object
|
87
|
+
IActionable::Objects::ProfilePoints.new(request.post)
|
88
|
+
else
|
89
|
+
request.post
|
90
|
+
end
|
73
91
|
end
|
74
92
|
|
75
93
|
# =========================
|
@@ -86,12 +104,21 @@ module IActionable
|
|
86
104
|
else
|
87
105
|
request.to("/#{profile_type}/#{id_type}/#{id}/achievements")
|
88
106
|
end
|
89
|
-
|
107
|
+
|
108
|
+
if @wrap_in_object
|
109
|
+
IActionable::Objects::ProfileAchievements.new(request.get)
|
110
|
+
else
|
111
|
+
request.get
|
112
|
+
end
|
90
113
|
end
|
91
114
|
|
92
115
|
def get_achievements()
|
93
116
|
response = @connection.request.with_app_key.to("/achievements").get
|
94
|
-
|
117
|
+
if @wrap_in_object
|
118
|
+
response.map{|achievement_json| IActionable::Objects::Achievement.new(achievement_json)}
|
119
|
+
else
|
120
|
+
response
|
121
|
+
end
|
95
122
|
rescue NoMethodError => e
|
96
123
|
[]
|
97
124
|
end
|
@@ -110,12 +137,21 @@ module IActionable
|
|
110
137
|
else
|
111
138
|
request.to("/#{profile_type}/#{id_type}/#{id}/challenges")
|
112
139
|
end
|
113
|
-
|
140
|
+
|
141
|
+
if @wrap_in_object
|
142
|
+
IActionable::Objects::ProfileChallenges.new(request.get)
|
143
|
+
else
|
144
|
+
request.get
|
145
|
+
end
|
114
146
|
end
|
115
147
|
|
116
148
|
def get_challenges()
|
117
149
|
response = @connection.request.with_app_key.to("/challenges").get
|
118
|
-
|
150
|
+
if @wrap_in_object
|
151
|
+
response.map{|challenge_json| IActionable::Objects::Challenge.new(challenge_json)}
|
152
|
+
else
|
153
|
+
response
|
154
|
+
end
|
119
155
|
rescue NoMethodError => e
|
120
156
|
[]
|
121
157
|
end
|
@@ -134,12 +170,21 @@ module IActionable
|
|
134
170
|
else
|
135
171
|
request.to("/#{profile_type}/#{id_type}/#{id}/goals")
|
136
172
|
end
|
137
|
-
|
173
|
+
|
174
|
+
if @wrap_in_object
|
175
|
+
IActionable::Objects::ProfileGoals.new(request.get)
|
176
|
+
else
|
177
|
+
request.get
|
178
|
+
end
|
138
179
|
end
|
139
180
|
|
140
181
|
def get_goals()
|
141
182
|
response = @connection.request.with_app_key.to("/goals").get
|
142
|
-
|
183
|
+
if @wrap_in_object
|
184
|
+
response.map{|goal_json| IActionable::Objects::Goal.new(goal_json)}
|
185
|
+
else
|
186
|
+
response
|
187
|
+
end
|
143
188
|
rescue NoMethodError => e
|
144
189
|
[]
|
145
190
|
end
|
@@ -154,8 +199,12 @@ module IActionable
|
|
154
199
|
request.with_params(:pageCount => page_count) unless page_count.blank?
|
155
200
|
request.with_params(:id => id) unless id.blank? || id_type.blank?
|
156
201
|
request.with_params(:idType => id_type) unless id.blank? || id_type.blank?
|
157
|
-
|
158
|
-
|
202
|
+
|
203
|
+
if @wrap_in_object
|
204
|
+
IActionable::Objects::LeaderboardReport.new(request.get)
|
205
|
+
else
|
206
|
+
request.get
|
207
|
+
end
|
159
208
|
end
|
160
209
|
|
161
210
|
# ===================================
|
@@ -164,7 +213,12 @@ module IActionable
|
|
164
213
|
|
165
214
|
def get_profile_notifications(profile_type, id_type, id)
|
166
215
|
response = @connection.request.with_app_key.to("/#{profile_type}/#{id_type}/#{id}/notifications").get
|
167
|
-
|
216
|
+
|
217
|
+
if @wrap_in_object
|
218
|
+
IActionable::Objects::ProfileNotifications.new(response)
|
219
|
+
else
|
220
|
+
response
|
221
|
+
end
|
168
222
|
end
|
169
223
|
end
|
170
224
|
end
|
data/lib/iactionable/version.rb
CHANGED
data/spec/api_spec.rb
CHANGED
@@ -90,8 +90,19 @@ describe IActionable::Api do
|
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should return the response as a ProfileSummary object" do
|
93
|
-
IActionable::Objects::ProfileSummary.should_receive(:new).once.with(@mock_response)
|
94
|
-
@api.get_profile_summary(@profile_type, @id_type, @id, nil)
|
93
|
+
IActionable::Objects::ProfileSummary.should_receive(:new).once.with(@mock_response).and_return(@mock_object)
|
94
|
+
@api.get_profile_summary(@profile_type, @id_type, @id, nil).should == @mock_object
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "when told to be returned as raw json/key-values" do
|
98
|
+
before do
|
99
|
+
@api.set_object_wrapping(false)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should return the data from the response un-altered" do
|
103
|
+
IActionable::Objects::ProfileSummary.should_not_receive(:new)
|
104
|
+
@api.get_profile_summary(@profile_type, @id_type, @id, nil).should == @mock_response
|
105
|
+
end
|
95
106
|
end
|
96
107
|
end
|
97
108
|
|
@@ -151,8 +162,21 @@ describe IActionable::Api do
|
|
151
162
|
it "should return the response as a ProfileSummary object" do
|
152
163
|
@mock_connection.stub!(:to).and_return(@mock_connection)
|
153
164
|
@mock_connection.stub!(:get).and_return(@mock_response)
|
154
|
-
IActionable::Objects::ProfilePoints.should_receive(:new).once.with(@mock_response).and_return(@
|
155
|
-
@api.get_profile_points(@profile_type, @id_type, @id, @point_type).should == @
|
165
|
+
IActionable::Objects::ProfilePoints.should_receive(:new).once.with(@mock_response).and_return(@mock_object)
|
166
|
+
@api.get_profile_points(@profile_type, @id_type, @id, @point_type).should == @mock_object
|
167
|
+
end
|
168
|
+
|
169
|
+
describe "when told to be returned as raw json/key-values" do
|
170
|
+
before do
|
171
|
+
@api.set_object_wrapping(false)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should return the data from the response un-altered" do
|
175
|
+
@mock_connection.stub!(:to).and_return(@mock_connection)
|
176
|
+
@mock_connection.stub!(:get).and_return(@mock_response)
|
177
|
+
IActionable::Objects::ProfilePoints.should_not_receive(:new)
|
178
|
+
@api.get_profile_points(@profile_type, @id_type, @id, @point_type).should == @mock_response
|
179
|
+
end
|
156
180
|
end
|
157
181
|
end
|
158
182
|
|
@@ -182,8 +206,19 @@ describe IActionable::Api do
|
|
182
206
|
end
|
183
207
|
|
184
208
|
it "should return the response as a ProfileSummary object" do
|
185
|
-
IActionable::Objects::ProfilePoints.should_receive(:new).once.with(@mock_response).and_return(@
|
186
|
-
@api.update_profile_points(@profile_type, @id_type, @id, @point_type, @amount, nil).should == @
|
209
|
+
IActionable::Objects::ProfilePoints.should_receive(:new).once.with(@mock_response).and_return(@mock_object)
|
210
|
+
@api.update_profile_points(@profile_type, @id_type, @id, @point_type, @amount, nil).should == @mock_object
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "when told to be returned as raw json/key-values" do
|
214
|
+
before do
|
215
|
+
@api.set_object_wrapping(false)
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should return the data from the response un-altered" do
|
219
|
+
IActionable::Objects::ProfilePoints.should_not_receive(:new)
|
220
|
+
@api.update_profile_points(@profile_type, @id_type, @id, @point_type, @amount, nil).should == @mock_response
|
221
|
+
end
|
187
222
|
end
|
188
223
|
end
|
189
224
|
end
|
@@ -237,6 +272,18 @@ describe IActionable::Api do
|
|
237
272
|
@api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, nil).should == @mock_object
|
238
273
|
end
|
239
274
|
end
|
275
|
+
|
276
|
+
describe "when told to be returned as raw json/key-values" do
|
277
|
+
before do
|
278
|
+
@api.set_object_wrapping(false)
|
279
|
+
end
|
280
|
+
|
281
|
+
it "should return the data from the response un-altered" do
|
282
|
+
@mock_connection.stub!(:to).and_return(@mock_connection)
|
283
|
+
type[1].should_not_receive(:new)
|
284
|
+
@api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, nil).should == @mock_response
|
285
|
+
end
|
286
|
+
end
|
240
287
|
end
|
241
288
|
|
242
289
|
describe "loading all #{type[0]} outside of a profile context" do
|
@@ -257,6 +304,15 @@ describe IActionable::Api do
|
|
257
304
|
type[2].should_receive(:new).once.with(@mock_response_item).and_return(@mock_object)
|
258
305
|
@api.send("get_#{type[0]}").should == @mock_response
|
259
306
|
end
|
307
|
+
|
308
|
+
describe "when told to be returned as raw json/key-values" do
|
309
|
+
it "should return the data from the response un-altered" do
|
310
|
+
@mock_connection.stub!(:to).and_return(@mock_connection)
|
311
|
+
type[2].should_not_receive(:new)
|
312
|
+
@api.set_object_wrapping(false)
|
313
|
+
@api.send("get_#{type[0]}").should == @mock_response
|
314
|
+
end
|
315
|
+
end
|
260
316
|
end
|
261
317
|
end
|
262
318
|
|
@@ -286,8 +342,22 @@ describe IActionable::Api do
|
|
286
342
|
@mock_connection.stub!(:to).and_return(@mock_connection)
|
287
343
|
@mock_connection.stub!(:with_params).and_return(@mock_connection)
|
288
344
|
@mock_connection.stub!(:get).and_return(@mock_response)
|
289
|
-
IActionable::Objects::LeaderboardReport.should_receive(:new).once.with(@mock_response).and_return(@
|
290
|
-
@api.get_leaderboard(@profile_type, @point_type, @leaderboard, nil, nil, nil, nil).should == @
|
345
|
+
IActionable::Objects::LeaderboardReport.should_receive(:new).once.with(@mock_response).and_return(@mock_object)
|
346
|
+
@api.get_leaderboard(@profile_type, @point_type, @leaderboard, nil, nil, nil, nil).should == @mock_object
|
347
|
+
end
|
348
|
+
|
349
|
+
describe "when told to be returned as raw json/key-values" do
|
350
|
+
before do
|
351
|
+
@api.set_object_wrapping(false)
|
352
|
+
end
|
353
|
+
|
354
|
+
it "should return the data from the response un-altered" do
|
355
|
+
@mock_connection.stub!(:to).and_return(@mock_connection)
|
356
|
+
@mock_connection.stub!(:with_params).and_return(@mock_connection)
|
357
|
+
@mock_connection.stub!(:get).and_return(@mock_response)
|
358
|
+
IActionable::Objects::LeaderboardReport.should_not_receive(:new)
|
359
|
+
@api.get_leaderboard(@profile_type, @point_type, @leaderboard, nil, nil, nil, nil).should == @mock_response
|
360
|
+
end
|
291
361
|
end
|
292
362
|
end
|
293
363
|
end
|
@@ -307,8 +377,23 @@ describe IActionable::Api do
|
|
307
377
|
@mock_connection.stub!(:with_app_key).and_return(@mock_connection)
|
308
378
|
@mock_connection.stub!(:to).and_return(@mock_connection)
|
309
379
|
@mock_connection.stub!(:get).and_return(@mock_response)
|
310
|
-
IActionable::Objects::ProfileNotifications.should_receive(:new).once.with(@mock_response).and_return(@
|
311
|
-
@api.get_profile_notifications(@profile_type, @id_type, @id).should == @
|
380
|
+
IActionable::Objects::ProfileNotifications.should_receive(:new).once.with(@mock_response).and_return(@mock_object)
|
381
|
+
@api.get_profile_notifications(@profile_type, @id_type, @id).should == @mock_object
|
382
|
+
end
|
383
|
+
|
384
|
+
describe "when told to be returned as raw json/key-values" do
|
385
|
+
before do
|
386
|
+
@api.set_object_wrapping(false)
|
387
|
+
end
|
388
|
+
|
389
|
+
it "should return the data from the response un-altered" do
|
390
|
+
@mock_connection.stub!(:request).and_return(@mock_connection)
|
391
|
+
@mock_connection.stub!(:with_app_key).and_return(@mock_connection)
|
392
|
+
@mock_connection.stub!(:to).and_return(@mock_connection)
|
393
|
+
@mock_connection.stub!(:get).and_return(@mock_response)
|
394
|
+
IActionable::Objects::ProfileNotifications.should_not_receive(:new)
|
395
|
+
@api.get_profile_notifications(@profile_type, @id_type, @id).should == @mock_response
|
396
|
+
end
|
312
397
|
end
|
313
398
|
end
|
314
399
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-iactionable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-21 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2165266560 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.6'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2165266560
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &2165266140 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2165266140
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: faraday
|
38
|
-
requirement: &
|
38
|
+
requirement: &2165265680 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2165265680
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: faraday-stack
|
49
|
-
requirement: &
|
49
|
+
requirement: &2165265260 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2165265260
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: activesupport
|
60
|
-
requirement: &
|
60
|
+
requirement: &2165264760 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 3.0.0
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2165264760
|
69
69
|
description: Ruby wrapper for IActionable's restful API.
|
70
70
|
email:
|
71
71
|
- ceberz@elctech.com
|