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
data/spec/api_spec.rb
ADDED
@@ -0,0 +1,399 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe IActionable::Api do
|
4
|
+
before do
|
5
|
+
@mock_settings = mock("mock settings")
|
6
|
+
@mock_connection = mock("connection")
|
7
|
+
@mock_response = mock("mock response")
|
8
|
+
@mock_response_item = mock("mock response item")
|
9
|
+
@mock_object = mock("mock object")
|
10
|
+
|
11
|
+
IActionable::Connection.stub!(:new).and_return(@mock_connection)
|
12
|
+
IActionable::Settings.stub!(:new).and_return(@mock_settings)
|
13
|
+
|
14
|
+
@mock_response.stub!(:map).and_yield(@mock_response_item).and_return(@mock_response)
|
15
|
+
@mock_response.stub!(:[]).and_return(@mock_response)
|
16
|
+
|
17
|
+
IActionable::Api.init_settings(nil)
|
18
|
+
|
19
|
+
@api = IActionable::Api.new
|
20
|
+
@profile_type = "user"
|
21
|
+
@id_type = "custom"
|
22
|
+
@id = 42
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "initialization" do
|
26
|
+
it "should initialize the connection with the previously initialized settings" do
|
27
|
+
IActionable::Settings.should_receive(:new).once.with({:foo => "bar"})
|
28
|
+
IActionable::Connection.should_receive(:new).once.with(@mock_settings)
|
29
|
+
IActionable::Api.init_settings({:foo => "bar"})
|
30
|
+
IActionable::Api.new
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "without having been pre-initialized with settings" do
|
34
|
+
before do
|
35
|
+
IActionable::Api.class_variable_set(:@@settings, nil)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should raise a config error" do
|
39
|
+
lambda { IActionable::Api.new }.should raise_error(IActionable::ConfigError)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "event creation" do
|
45
|
+
before do
|
46
|
+
@event_key = "some_event"
|
47
|
+
@mock_event_attrs = mock("mock event attrs")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should make the correct IActionable API all" do
|
51
|
+
@mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
|
52
|
+
@mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
|
53
|
+
@mock_connection.should_receive(:with_api_key).and_return(@mock_connection)
|
54
|
+
@mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}/events/#{@event_key}").and_return(@mock_connection)
|
55
|
+
@mock_connection.should_receive(:with_params).with(@mock_event_attrs).and_return(@mock_connection)
|
56
|
+
@mock_connection.should_receive(:post).and_return(@mock_response)
|
57
|
+
@api.log_event(@profile_type, @id_type, @id, @event_key, @mock_event_attrs).should == @mock_response
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "profile" do
|
62
|
+
before do
|
63
|
+
@mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
|
64
|
+
@mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "fetching" do
|
68
|
+
before do
|
69
|
+
@mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}").and_return(@mock_connection)
|
70
|
+
@mock_connection.should_receive(:get).and_return(@mock_response)
|
71
|
+
IActionable::Objects::ProfileSummary.stub!(:new)
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "with achivement count" do
|
75
|
+
before do
|
76
|
+
@achievement_count = 10
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should be the correct IActionable API call" do
|
80
|
+
@mock_connection.should_receive(:with_params).with({:achievementCount => @achievement_count}).and_return(@mock_connection)
|
81
|
+
@api.get_profile_summary(@profile_type, @id_type, @id, @achievement_count)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "without achievement count" do
|
86
|
+
it "should be the correct IActionable API call" do
|
87
|
+
@mock_connection.should_not_receive(:with_params)
|
88
|
+
@api.get_profile_summary(@profile_type, @id_type, @id, nil)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should return the response as a ProfileSummary object" do
|
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
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "creation" do
|
110
|
+
before do
|
111
|
+
@mock_connection.should_receive(:with_api_key).and_return(@mock_connection)
|
112
|
+
@mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}").and_return(@mock_connection)
|
113
|
+
@mock_connection.should_receive(:post).and_return(@mock_response)
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "with optional display name" do
|
117
|
+
before do
|
118
|
+
@display_name = "zortnac"
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should be the correct IActionable API call" do
|
122
|
+
@mock_connection.should_receive(:with_params).with({:displayName => @display_name}).and_return(@mock_connection)
|
123
|
+
@api.create_profile(@profile_type, @id_type, @id, @display_name).should == @mock_response
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "without optional display name" do
|
128
|
+
it "should be the correct IActionable API call" do
|
129
|
+
@mock_connection.should_not_receive(:with_params)
|
130
|
+
@api.create_profile(@profile_type, @id_type, @id, nil).should == @mock_response
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "updating" do
|
136
|
+
it "should make the correct IActionable API all" do
|
137
|
+
new_type = "email"
|
138
|
+
new_id = 2
|
139
|
+
@mock_connection.should_receive(:with_api_key).and_return(@mock_connection)
|
140
|
+
@mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}/identifiers/#{new_type}/#{new_id}").and_return(@mock_connection)
|
141
|
+
@mock_connection.should_receive(:post).and_return(@mock_response)
|
142
|
+
@api.add_profile_identifier(@profile_type, @id_type, @id, new_type, new_id).should == @mock_response
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "profile points" do
|
148
|
+
before do
|
149
|
+
@mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
|
150
|
+
@mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
|
151
|
+
@point_type = "experience_points"
|
152
|
+
IActionable::Objects::ProfilePoints.stub!(:new).and_return(@mock_response)
|
153
|
+
end
|
154
|
+
|
155
|
+
describe "fetching" do
|
156
|
+
it "should make the correct IActionable API all" do
|
157
|
+
@mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}/points/#{@point_type}").and_return(@mock_connection)
|
158
|
+
@mock_connection.should_receive(:get).and_return(@mock_response)
|
159
|
+
@api.get_profile_points(@profile_type, @id_type, @id, @point_type)
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should return the response as a ProfileSummary object" do
|
163
|
+
@mock_connection.stub!(:to).and_return(@mock_connection)
|
164
|
+
@mock_connection.stub!(:get).and_return(@mock_response)
|
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
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "updating" do
|
184
|
+
before do
|
185
|
+
@amount = 100
|
186
|
+
@mock_connection.should_receive(:with_api_key).and_return(@mock_connection)
|
187
|
+
@mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}/points/#{@point_type}").and_return(@mock_connection)
|
188
|
+
@mock_connection.should_receive(:with_params).with(hash_including(:value => @amount)).and_return(@mock_connection)
|
189
|
+
@mock_connection.should_receive(:post).and_return(@mock_response)
|
190
|
+
end
|
191
|
+
|
192
|
+
describe "with optional reason" do
|
193
|
+
it "should make the correct IActionable API all" do
|
194
|
+
reason = "some reason"
|
195
|
+
@mock_connection.should_receive(:with_params).with(hash_including(:description => reason)).and_return(@mock_connection)
|
196
|
+
@api.update_profile_points(@profile_type, @id_type, @id, @point_type, @amount, reason)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe "without optional reason" do
|
201
|
+
it "should make the correct IActionable API all" do
|
202
|
+
reason = "some reason"
|
203
|
+
@mock_connection.should_not_receive(:with_params).with(hash_including(:description => reason))
|
204
|
+
@api.update_profile_points(@profile_type, @id_type, @id, @point_type, @amount, nil)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should return the response as a ProfileSummary object" do
|
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
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
[ [:achievements, IActionable::Objects::ProfileAchievements, IActionable::Objects::Achievement],
|
227
|
+
[:challenges, IActionable::Objects::ProfileChallenges, IActionable::Objects::Challenge],
|
228
|
+
[:goals, IActionable::Objects::ProfileGoals, IActionable::Objects::Goal]].each do |type|
|
229
|
+
describe "loading all #{type} for a profile" do
|
230
|
+
before do
|
231
|
+
type[1].stub!(:new).and_return(@mock_object)
|
232
|
+
@mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
|
233
|
+
@mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
|
234
|
+
@mock_connection.should_receive(:get).and_return(@mock_response)
|
235
|
+
end
|
236
|
+
|
237
|
+
describe "filtered by available" do
|
238
|
+
it "should make the correct IActionable API all" do
|
239
|
+
@mock_connection.should_receive(:to).once.with("/#{@profile_type}/#{@id_type}/#{@id}/#{type[0]}/Available").and_return(@mock_connection)
|
240
|
+
@api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, :available)
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should return as the proper object type" do
|
244
|
+
@mock_connection.stub!(:to).and_return(@mock_connection)
|
245
|
+
type[1].should_receive(:new).once.with(@mock_response).and_return(@mock_object)
|
246
|
+
@api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, :available).should == @mock_object
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
describe "filtered by complete" do
|
251
|
+
it "should make the correct IActionable API all" do
|
252
|
+
@mock_connection.should_receive(:to).once.with("/#{@profile_type}/#{@id_type}/#{@id}/#{type[0]}/Completed").and_return(@mock_connection)
|
253
|
+
@api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, :completed)
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should return as the proper object type" do
|
257
|
+
@mock_connection.stub!(:to).and_return(@mock_connection)
|
258
|
+
type[1].should_receive(:new).once.with(@mock_response).and_return(@mock_object)
|
259
|
+
@api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, :completed).should == @mock_object
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
describe "unfiltered" do
|
264
|
+
it "should make the correct IActionable API all" do
|
265
|
+
@mock_connection.should_receive(:to).once.with("/#{@profile_type}/#{@id_type}/#{@id}/#{type[0]}").and_return(@mock_connection)
|
266
|
+
@api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, nil)
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should return as the proper object type" do
|
270
|
+
@mock_connection.stub!(:to).and_return(@mock_connection)
|
271
|
+
type[1].should_receive(:new).once.with(@mock_response).and_return(@mock_object)
|
272
|
+
@api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, nil).should == @mock_object
|
273
|
+
end
|
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
|
287
|
+
end
|
288
|
+
|
289
|
+
describe "loading all #{type[0]} outside of a profile context" do
|
290
|
+
before do
|
291
|
+
type[2].stub!(:new).and_return(@mock_object)
|
292
|
+
@mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
|
293
|
+
@mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
|
294
|
+
@mock_connection.should_receive(:get).and_return(@mock_response)
|
295
|
+
end
|
296
|
+
|
297
|
+
it "should make the correct IActionable API all" do
|
298
|
+
@mock_connection.should_receive(:to).once.with("/#{type[0]}").and_return(@mock_connection)
|
299
|
+
@api.send("get_#{type[0]}")
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should return as the proper object type" do
|
303
|
+
@mock_connection.stub!(:to).and_return(@mock_connection)
|
304
|
+
type[2].should_receive(:new).once.with(@mock_response_item).and_return(@mock_object)
|
305
|
+
@api.send("get_#{type[0]}").should == @mock_response
|
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
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
describe "leaderboards" do
|
320
|
+
before do
|
321
|
+
@point_type = "experience_points"
|
322
|
+
@leaderboard = "top_players"
|
323
|
+
@page_number = 3
|
324
|
+
@page_count = 9
|
325
|
+
@mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
|
326
|
+
@mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
|
327
|
+
IActionable::Objects::LeaderboardReport.stub!(:new).and_return(@mock_response)
|
328
|
+
end
|
329
|
+
|
330
|
+
describe "fetching" do
|
331
|
+
it "should make the correct IActionable API all" do
|
332
|
+
@mock_connection.should_receive(:to).with("/#{@profile_type}/leaderboards/points/#{@point_type}/#{@leaderboard}").and_return(@mock_connection)
|
333
|
+
@mock_connection.should_receive(:with_params).with(hash_including(:pageNumber => @page_number)).and_return(@mock_connection)
|
334
|
+
@mock_connection.should_receive(:with_params).with(hash_including(:pageCount => @page_count)).and_return(@mock_connection)
|
335
|
+
@mock_connection.should_receive(:with_params).with(hash_including(:id => @id)).and_return(@mock_connection)
|
336
|
+
@mock_connection.should_receive(:with_params).with(hash_including(:idType => @id_type)).and_return(@mock_connection)
|
337
|
+
@mock_connection.should_receive(:get).and_return(@mock_response)
|
338
|
+
@api.get_leaderboard(@profile_type, @point_type, @leaderboard, @page_number, @page_count, @id, @id_type)
|
339
|
+
end
|
340
|
+
|
341
|
+
it "should return the response as a LeaderboardReport object" do
|
342
|
+
@mock_connection.stub!(:to).and_return(@mock_connection)
|
343
|
+
@mock_connection.stub!(:with_params).and_return(@mock_connection)
|
344
|
+
@mock_connection.stub!(:get).and_return(@mock_response)
|
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
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
describe "notifications" do
|
366
|
+
it "should make the correct IActionable API all" do
|
367
|
+
IActionable::Objects::ProfileNotifications.stub!(:new)
|
368
|
+
@mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
|
369
|
+
@mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
|
370
|
+
@mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}/notifications").and_return(@mock_connection)
|
371
|
+
@mock_connection.should_receive(:get).and_return(@mock_response)
|
372
|
+
@api.get_profile_notifications(@profile_type, @id_type, @id)
|
373
|
+
end
|
374
|
+
|
375
|
+
it "should return with the corect object" do
|
376
|
+
@mock_connection.stub!(:request).and_return(@mock_connection)
|
377
|
+
@mock_connection.stub!(:with_app_key).and_return(@mock_connection)
|
378
|
+
@mock_connection.stub!(:to).and_return(@mock_connection)
|
379
|
+
@mock_connection.stub!(:get).and_return(@mock_response)
|
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
|
397
|
+
end
|
398
|
+
end
|
399
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe IActionable::Connection do
|
4
|
+
before do
|
5
|
+
@settings_hash = {
|
6
|
+
:app_key => "12345",
|
7
|
+
:api_key => "abcde",
|
8
|
+
:version => "3"
|
9
|
+
}
|
10
|
+
@settings = IActionable::Settings.new(@settings_hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "initialization" do
|
14
|
+
it "should initialize a new Faraday connection object" do
|
15
|
+
mock_faraday_bulder = mock("faraday builder")
|
16
|
+
|
17
|
+
Faraday.should_receive(:new).once.with("http://api.iactionable.com/v#{@settings.version}/").and_yield(mock_faraday_bulder)
|
18
|
+
mock_faraday_bulder.should_receive(:use).once.with(FaradayMiddleware::ParseJson, {:content_type => 'application/json'})
|
19
|
+
mock_faraday_bulder.should_receive(:use).once.with(Faraday::Response::RaiseError)
|
20
|
+
mock_faraday_bulder.should_receive(:use).once.with(Faraday::Adapter::NetHttp)
|
21
|
+
|
22
|
+
IActionable::Connection.new(@settings)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "requests" do
|
27
|
+
before do
|
28
|
+
@mock_faraday_connection = mock("mock faraday connection")
|
29
|
+
@mock_faraday_response = mock("mock faraday response")
|
30
|
+
@mock_faraday_request_builder = mock("mock faraday request builder")
|
31
|
+
@mock_response_body = mock("mock response body")
|
32
|
+
@mock_faraday_request_headers = mock("mock faraday request headers")
|
33
|
+
@mock_faraday_response.stub!(:body).and_return(@mock_response_body)
|
34
|
+
@mock_faraday_request_builder.stub!(:headers).and_return(@mock_faraday_request_headers)
|
35
|
+
@mock_faraday_request_headers.stub!(:merge!).and_return(true)
|
36
|
+
Faraday.stub!(:new).and_return(@mock_faraday_connection)
|
37
|
+
@connection = IActionable::Connection.new(@settings)
|
38
|
+
@path = "/test/path"
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "using get method" do
|
42
|
+
describe "requiring an app key" do
|
43
|
+
describe "with optional params" do
|
44
|
+
it "should request correctly through faraday and return the body" do
|
45
|
+
@mock_faraday_connection.should_receive(:get).and_yield(@mock_faraday_request_builder).and_return(@mock_faraday_response)
|
46
|
+
@mock_faraday_request_builder.should_receive(:url).once.with(@path, hash_including(:appKey => @settings.app_key, :foo => :bar))
|
47
|
+
@mock_faraday_request_builder.should_receive(:headers).any_number_of_times
|
48
|
+
@connection.request.to(@path).with_app_key.with_params(:foo => :bar).get.should == @mock_response_body
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "without optional params" do
|
53
|
+
it "should request correctly through faraday and return the body" do
|
54
|
+
@mock_faraday_connection.should_receive(:get).and_yield(@mock_faraday_request_builder).and_return(@mock_faraday_response)
|
55
|
+
@mock_faraday_request_builder.should_receive(:url).once.with(@path, hash_including(:appKey => @settings.app_key))
|
56
|
+
@mock_faraday_request_builder.should_receive(:headers).any_number_of_times
|
57
|
+
@connection.request.to(@path).with_app_key.get.should == @mock_response_body
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "using post method" do
|
64
|
+
describe "requiring an app key" do
|
65
|
+
describe "requiring an api key" do
|
66
|
+
describe "with optional params" do
|
67
|
+
it "should request correctly through faraday and return the body" do
|
68
|
+
@mock_faraday_connection.should_receive(:post).and_yield(@mock_faraday_request_builder).and_return(@mock_faraday_response)
|
69
|
+
@mock_faraday_request_builder.should_receive(:url).once.with(@path, hash_including(:appKey => @settings.app_key, :foo => :bar))
|
70
|
+
@mock_faraday_request_builder.should_receive(:headers).once.and_return(@mock_faraday_request_headers)
|
71
|
+
@mock_faraday_request_headers.should_receive(:merge!).once.with(:Authorization => @settings.api_key)
|
72
|
+
@connection.request.to(@path).with_app_key.with_api_key.with_params(:foo => :bar).post.should == @mock_response_body
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "without optional params" do
|
77
|
+
it "should request correctly through faraday and return the body" do
|
78
|
+
@mock_faraday_connection.should_receive(:post).and_yield(@mock_faraday_request_builder).and_return(@mock_faraday_response)
|
79
|
+
@mock_faraday_request_builder.should_receive(:url).once.with(@path, hash_including(:appKey => @settings.app_key))
|
80
|
+
@mock_faraday_request_builder.should_receive(:headers).once.and_return(@mock_faraday_request_headers)
|
81
|
+
@mock_faraday_request_headers.should_receive(:merge!).once.with(:Authorization => @settings.api_key)
|
82
|
+
@connection.request.to(@path).with_app_key.with_api_key.post.should == @mock_response_body
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "with an optional body" do
|
87
|
+
it "should request correctly through faraday and return the body" do
|
88
|
+
@mock_faraday_connection.should_receive(:post).and_yield(@mock_faraday_request_builder).and_return(@mock_faraday_response)
|
89
|
+
@mock_faraday_request_builder.should_receive(:url).once.with(@path, hash_including(:appKey => @settings.app_key))
|
90
|
+
@mock_faraday_request_builder.should_receive(:headers).once.and_return(@mock_faraday_request_headers)
|
91
|
+
@mock_faraday_request_headers.should_receive(:merge!).once.with(:Authorization => @settings.api_key)
|
92
|
+
@mock_faraday_request_builder.should_receive(:body=).once.with(:foo => :bar)
|
93
|
+
@connection.request.to(@path).with_app_key.with_api_key.with_body(:foo => :bar).post.should == @mock_response_body
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "without an optional body" do
|
98
|
+
it "should request correctly through faraday and return the body" do
|
99
|
+
@mock_faraday_connection.should_receive(:post).and_yield(@mock_faraday_request_builder).and_return(@mock_faraday_response)
|
100
|
+
@mock_faraday_request_builder.should_receive(:url).once.with(@path, hash_including(:appKey => @settings.app_key))
|
101
|
+
@mock_faraday_request_builder.should_receive(:headers).once.and_return(@mock_faraday_request_headers)
|
102
|
+
@mock_faraday_request_headers.should_receive(:merge!).once.with(:Authorization => @settings.api_key)
|
103
|
+
@mock_faraday_request_builder.should_not_receive(:body=)
|
104
|
+
@connection.request.to(@path).with_app_key.with_api_key.post.should == @mock_response_body
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|