ruby-iactionable 0.0.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.
Files changed (49) hide show
  1. data/.gitignore +4 -0
  2. data/.rvmrc +3 -0
  3. data/CHANGELOG.md +5 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +43 -0
  6. data/README.md +49 -0
  7. data/Rakefile +1 -0
  8. data/lib/iactionable/api.rb +170 -0
  9. data/lib/iactionable/connection.rb +114 -0
  10. data/lib/iactionable/error.rb +17 -0
  11. data/lib/iactionable/objects/achievement.rb +29 -0
  12. data/lib/iactionable/objects/awardable.rb +50 -0
  13. data/lib/iactionable/objects/challenge.rb +27 -0
  14. data/lib/iactionable/objects/goal.rb +30 -0
  15. data/lib/iactionable/objects/i_actionable_object.rb +36 -0
  16. data/lib/iactionable/objects/identifier.rb +17 -0
  17. data/lib/iactionable/objects/leaderboard.rb +15 -0
  18. data/lib/iactionable/objects/leaderboard_report.rb +30 -0
  19. data/lib/iactionable/objects/level.rb +24 -0
  20. data/lib/iactionable/objects/level_type.rb +15 -0
  21. data/lib/iactionable/objects/point_type.rb +15 -0
  22. data/lib/iactionable/objects/profile_achievements.rb +20 -0
  23. data/lib/iactionable/objects/profile_challenges.rb +20 -0
  24. data/lib/iactionable/objects/profile_goals.rb +20 -0
  25. data/lib/iactionable/objects/profile_level.rb +20 -0
  26. data/lib/iactionable/objects/profile_notifications.rb +29 -0
  27. data/lib/iactionable/objects/profile_points.rb +29 -0
  28. data/lib/iactionable/objects/profile_summary.rb +32 -0
  29. data/lib/iactionable/objects/progress.rb +46 -0
  30. data/lib/iactionable/objects.rb +27 -0
  31. data/lib/iactionable/settings.rb +30 -0
  32. data/lib/iactionable/version.rb +3 -0
  33. data/lib/iactionable.rb +9 -0
  34. data/ruby_iactionable.gemspec +28 -0
  35. data/spec/api/get_achievements_api_response_spec.rb +46 -0
  36. data/spec/api/get_challenges_api_response_spec.rb +42 -0
  37. data/spec/api/get_goals_api_response_spec.rb +46 -0
  38. data/spec/api/get_leaderboard_api_response_spec.rb +76 -0
  39. data/spec/api/get_profile_achievements_api_response_spec.rb +99 -0
  40. data/spec/api/get_profile_api_response_spec.rb +103 -0
  41. data/spec/api/get_profile_challenges_api_response_spec.rb +85 -0
  42. data/spec/api/get_profile_goals_api_response_spec.rb +89 -0
  43. data/spec/api/get_profile_notifications_api_response_spec.rb +75 -0
  44. data/spec/api/get_profile_points_api_response_spec.rb +67 -0
  45. data/spec/api_spec.rb +314 -0
  46. data/spec/connection_spec.rb +111 -0
  47. data/spec/settings_spec.rb +52 -0
  48. data/spec/spec_helper.rb +1 -0
  49. metadata +163 -0
data/spec/api_spec.rb ADDED
@@ -0,0 +1,314 @@
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)
94
+ @api.get_profile_summary(@profile_type, @id_type, @id, nil)
95
+ end
96
+ end
97
+
98
+ describe "creation" do
99
+ before do
100
+ @mock_connection.should_receive(:with_api_key).and_return(@mock_connection)
101
+ @mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}").and_return(@mock_connection)
102
+ @mock_connection.should_receive(:post).and_return(@mock_response)
103
+ end
104
+
105
+ describe "with optional display name" do
106
+ before do
107
+ @display_name = "zortnac"
108
+ end
109
+
110
+ it "should be the correct IActionable API call" do
111
+ @mock_connection.should_receive(:with_params).with({:displayName => @display_name}).and_return(@mock_connection)
112
+ @api.create_profile(@profile_type, @id_type, @id, @display_name).should == @mock_response
113
+ end
114
+ end
115
+
116
+ describe "without optional display name" do
117
+ it "should be the correct IActionable API call" do
118
+ @mock_connection.should_not_receive(:with_params)
119
+ @api.create_profile(@profile_type, @id_type, @id, nil).should == @mock_response
120
+ end
121
+ end
122
+ end
123
+
124
+ describe "updating" do
125
+ it "should make the correct IActionable API all" do
126
+ new_type = "email"
127
+ new_id = 2
128
+ @mock_connection.should_receive(:with_api_key).and_return(@mock_connection)
129
+ @mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}/identifiers/#{new_type}/#{new_id}").and_return(@mock_connection)
130
+ @mock_connection.should_receive(:post).and_return(@mock_response)
131
+ @api.add_profile_identifier(@profile_type, @id_type, @id, new_type, new_id).should == @mock_response
132
+ end
133
+ end
134
+ end
135
+
136
+ describe "profile points" do
137
+ before do
138
+ @mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
139
+ @mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
140
+ @point_type = "experience_points"
141
+ IActionable::Objects::ProfilePoints.stub!(:new).and_return(@mock_response)
142
+ end
143
+
144
+ describe "fetching" do
145
+ it "should make the correct IActionable API all" do
146
+ @mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}/points/#{@point_type}").and_return(@mock_connection)
147
+ @mock_connection.should_receive(:get).and_return(@mock_response)
148
+ @api.get_profile_points(@profile_type, @id_type, @id, @point_type)
149
+ end
150
+
151
+ it "should return the response as a ProfileSummary object" do
152
+ @mock_connection.stub!(:to).and_return(@mock_connection)
153
+ @mock_connection.stub!(:get).and_return(@mock_response)
154
+ IActionable::Objects::ProfilePoints.should_receive(:new).once.with(@mock_response).and_return(@mock_response)
155
+ @api.get_profile_points(@profile_type, @id_type, @id, @point_type).should == @mock_response
156
+ end
157
+ end
158
+
159
+ describe "updating" do
160
+ before do
161
+ @amount = 100
162
+ @mock_connection.should_receive(:with_api_key).and_return(@mock_connection)
163
+ @mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}/points/#{@point_type}").and_return(@mock_connection)
164
+ @mock_connection.should_receive(:with_params).with(hash_including(:value => @amount)).and_return(@mock_connection)
165
+ @mock_connection.should_receive(:post).and_return(@mock_response)
166
+ end
167
+
168
+ describe "with optional reason" do
169
+ it "should make the correct IActionable API all" do
170
+ reason = "some reason"
171
+ @mock_connection.should_receive(:with_params).with(hash_including(:description => reason)).and_return(@mock_connection)
172
+ @api.update_profile_points(@profile_type, @id_type, @id, @point_type, @amount, reason)
173
+ end
174
+ end
175
+
176
+ describe "without optional reason" do
177
+ it "should make the correct IActionable API all" do
178
+ reason = "some reason"
179
+ @mock_connection.should_not_receive(:with_params).with(hash_including(:description => reason))
180
+ @api.update_profile_points(@profile_type, @id_type, @id, @point_type, @amount, nil)
181
+ end
182
+ end
183
+
184
+ it "should return the response as a ProfileSummary object" do
185
+ IActionable::Objects::ProfilePoints.should_receive(:new).once.with(@mock_response).and_return(@mock_response)
186
+ @api.update_profile_points(@profile_type, @id_type, @id, @point_type, @amount, nil).should == @mock_response
187
+ end
188
+ end
189
+ end
190
+
191
+ [ [:achievements, IActionable::Objects::ProfileAchievements, IActionable::Objects::Achievement],
192
+ [:challenges, IActionable::Objects::ProfileChallenges, IActionable::Objects::Challenge],
193
+ [:goals, IActionable::Objects::ProfileGoals, IActionable::Objects::Goal]].each do |type|
194
+ describe "loading all #{type} for a profile" do
195
+ before do
196
+ type[1].stub!(:new).and_return(@mock_object)
197
+ @mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
198
+ @mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
199
+ @mock_connection.should_receive(:get).and_return(@mock_response)
200
+ end
201
+
202
+ describe "filtered by available" do
203
+ it "should make the correct IActionable API all" do
204
+ @mock_connection.should_receive(:to).once.with("/#{@profile_type}/#{@id_type}/#{@id}/#{type[0]}/Available").and_return(@mock_connection)
205
+ @api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, :available)
206
+ end
207
+
208
+ it "should return as the proper object type" do
209
+ @mock_connection.stub!(:to).and_return(@mock_connection)
210
+ type[1].should_receive(:new).once.with(@mock_response).and_return(@mock_object)
211
+ @api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, :available).should == @mock_object
212
+ end
213
+ end
214
+
215
+ describe "filtered by complete" do
216
+ it "should make the correct IActionable API all" do
217
+ @mock_connection.should_receive(:to).once.with("/#{@profile_type}/#{@id_type}/#{@id}/#{type[0]}/Completed").and_return(@mock_connection)
218
+ @api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, :completed)
219
+ end
220
+
221
+ it "should return as the proper object type" do
222
+ @mock_connection.stub!(:to).and_return(@mock_connection)
223
+ type[1].should_receive(:new).once.with(@mock_response).and_return(@mock_object)
224
+ @api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, :completed).should == @mock_object
225
+ end
226
+ end
227
+
228
+ describe "unfiltered" do
229
+ it "should make the correct IActionable API all" do
230
+ @mock_connection.should_receive(:to).once.with("/#{@profile_type}/#{@id_type}/#{@id}/#{type[0]}").and_return(@mock_connection)
231
+ @api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, nil)
232
+ end
233
+
234
+ it "should return as the proper object type" do
235
+ @mock_connection.stub!(:to).and_return(@mock_connection)
236
+ type[1].should_receive(:new).once.with(@mock_response).and_return(@mock_object)
237
+ @api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, nil).should == @mock_object
238
+ end
239
+ end
240
+ end
241
+
242
+ describe "loading all #{type[0]} outside of a profile context" do
243
+ before do
244
+ type[2].stub!(:new).and_return(@mock_object)
245
+ @mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
246
+ @mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
247
+ @mock_connection.should_receive(:get).and_return(@mock_response)
248
+ end
249
+
250
+ it "should make the correct IActionable API all" do
251
+ @mock_connection.should_receive(:to).once.with("/#{type[0]}").and_return(@mock_connection)
252
+ @api.send("get_#{type[0]}")
253
+ end
254
+
255
+ it "should return as the proper object type" do
256
+ @mock_connection.stub!(:to).and_return(@mock_connection)
257
+ type[2].should_receive(:new).once.with(@mock_response_item).and_return(@mock_object)
258
+ @api.send("get_#{type[0]}").should == @mock_response
259
+ end
260
+ end
261
+ end
262
+
263
+ describe "leaderboards" do
264
+ before do
265
+ @point_type = "experience_points"
266
+ @leaderboard = "top_players"
267
+ @page_number = 3
268
+ @page_count = 9
269
+ @mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
270
+ @mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
271
+ IActionable::Objects::LeaderboardReport.stub!(:new).and_return(@mock_response)
272
+ end
273
+
274
+ describe "fetching" do
275
+ it "should make the correct IActionable API all" do
276
+ @mock_connection.should_receive(:to).with("/#{@profile_type}/leaderboards/points/#{@point_type}/#{@leaderboard}").and_return(@mock_connection)
277
+ @mock_connection.should_receive(:with_params).with(hash_including(:pageNumber => @page_number)).and_return(@mock_connection)
278
+ @mock_connection.should_receive(:with_params).with(hash_including(:pageCount => @page_count)).and_return(@mock_connection)
279
+ @mock_connection.should_receive(:with_params).with(hash_including(:id => @id)).and_return(@mock_connection)
280
+ @mock_connection.should_receive(:with_params).with(hash_including(:idType => @id_type)).and_return(@mock_connection)
281
+ @mock_connection.should_receive(:get).and_return(@mock_response)
282
+ @api.get_leaderboard(@profile_type, @point_type, @leaderboard, @page_number, @page_count, @id, @id_type)
283
+ end
284
+
285
+ it "should return the response as a LeaderboardReport object" do
286
+ @mock_connection.stub!(:to).and_return(@mock_connection)
287
+ @mock_connection.stub!(:with_params).and_return(@mock_connection)
288
+ @mock_connection.stub!(:get).and_return(@mock_response)
289
+ IActionable::Objects::LeaderboardReport.should_receive(:new).once.with(@mock_response).and_return(@mock_response)
290
+ @api.get_leaderboard(@profile_type, @point_type, @leaderboard, nil, nil, nil, nil).should == @mock_response
291
+ end
292
+ end
293
+ end
294
+
295
+ describe "notifications" do
296
+ it "should make the correct IActionable API all" do
297
+ IActionable::Objects::ProfileNotifications.stub!(:new)
298
+ @mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
299
+ @mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
300
+ @mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}/notifications").and_return(@mock_connection)
301
+ @mock_connection.should_receive(:get).and_return(@mock_response)
302
+ @api.get_profile_notifications(@profile_type, @id_type, @id)
303
+ end
304
+
305
+ it "should return with the corect object" do
306
+ @mock_connection.stub!(:request).and_return(@mock_connection)
307
+ @mock_connection.stub!(:with_app_key).and_return(@mock_connection)
308
+ @mock_connection.stub!(:to).and_return(@mock_connection)
309
+ @mock_connection.stub!(:get).and_return(@mock_response)
310
+ IActionable::Objects::ProfileNotifications.should_receive(:new).once.with(@mock_response).and_return(@mock_response)
311
+ @api.get_profile_notifications(@profile_type, @id_type, @id).should == @mock_response
312
+ end
313
+ end
314
+ 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(FaradayStack::ResponseJSON, {: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
@@ -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
@@ -0,0 +1 @@
1
+ require 'iactionable'
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-iactionable
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: 2012-02-03 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &2164523480 !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: *2164523480
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &2164523060 !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: *2164523060
36
+ - !ruby/object:Gem::Dependency
37
+ name: faraday
38
+ requirement: &2164522600 !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: *2164522600
47
+ - !ruby/object:Gem::Dependency
48
+ name: faraday-stack
49
+ requirement: &2164522180 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *2164522180
58
+ - !ruby/object:Gem::Dependency
59
+ name: activesupport
60
+ requirement: &2164521680 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: 3.0.0
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *2164521680
69
+ description: Ruby wrapper for IActionable's restful API.
70
+ email:
71
+ - ceberz@elctech.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rvmrc
78
+ - CHANGELOG.md
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - README.md
82
+ - Rakefile
83
+ - lib/iactionable.rb
84
+ - lib/iactionable/api.rb
85
+ - lib/iactionable/connection.rb
86
+ - lib/iactionable/error.rb
87
+ - lib/iactionable/objects.rb
88
+ - lib/iactionable/objects/achievement.rb
89
+ - lib/iactionable/objects/awardable.rb
90
+ - lib/iactionable/objects/challenge.rb
91
+ - lib/iactionable/objects/goal.rb
92
+ - lib/iactionable/objects/i_actionable_object.rb
93
+ - lib/iactionable/objects/identifier.rb
94
+ - lib/iactionable/objects/leaderboard.rb
95
+ - lib/iactionable/objects/leaderboard_report.rb
96
+ - lib/iactionable/objects/level.rb
97
+ - lib/iactionable/objects/level_type.rb
98
+ - lib/iactionable/objects/point_type.rb
99
+ - lib/iactionable/objects/profile_achievements.rb
100
+ - lib/iactionable/objects/profile_challenges.rb
101
+ - lib/iactionable/objects/profile_goals.rb
102
+ - lib/iactionable/objects/profile_level.rb
103
+ - lib/iactionable/objects/profile_notifications.rb
104
+ - lib/iactionable/objects/profile_points.rb
105
+ - lib/iactionable/objects/profile_summary.rb
106
+ - lib/iactionable/objects/progress.rb
107
+ - lib/iactionable/settings.rb
108
+ - lib/iactionable/version.rb
109
+ - ruby_iactionable.gemspec
110
+ - spec/api/get_achievements_api_response_spec.rb
111
+ - spec/api/get_challenges_api_response_spec.rb
112
+ - spec/api/get_goals_api_response_spec.rb
113
+ - spec/api/get_leaderboard_api_response_spec.rb
114
+ - spec/api/get_profile_achievements_api_response_spec.rb
115
+ - spec/api/get_profile_api_response_spec.rb
116
+ - spec/api/get_profile_challenges_api_response_spec.rb
117
+ - spec/api/get_profile_goals_api_response_spec.rb
118
+ - spec/api/get_profile_notifications_api_response_spec.rb
119
+ - spec/api/get_profile_points_api_response_spec.rb
120
+ - spec/api_spec.rb
121
+ - spec/connection_spec.rb
122
+ - spec/settings_spec.rb
123
+ - spec/spec_helper.rb
124
+ homepage: ''
125
+ licenses: []
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ - spec
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project: ruby-iactionable
145
+ rubygems_version: 1.8.10
146
+ signing_key:
147
+ specification_version: 3
148
+ summary: Ruby wrapper for IActionable's restful API.
149
+ test_files:
150
+ - spec/api/get_achievements_api_response_spec.rb
151
+ - spec/api/get_challenges_api_response_spec.rb
152
+ - spec/api/get_goals_api_response_spec.rb
153
+ - spec/api/get_leaderboard_api_response_spec.rb
154
+ - spec/api/get_profile_achievements_api_response_spec.rb
155
+ - spec/api/get_profile_api_response_spec.rb
156
+ - spec/api/get_profile_challenges_api_response_spec.rb
157
+ - spec/api/get_profile_goals_api_response_spec.rb
158
+ - spec/api/get_profile_notifications_api_response_spec.rb
159
+ - spec/api/get_profile_points_api_response_spec.rb
160
+ - spec/api_spec.rb
161
+ - spec/connection_spec.rb
162
+ - spec/settings_spec.rb
163
+ - spec/spec_helper.rb