riaction 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/Gemfile +4 -0
  2. data/Gemfile.lock +59 -0
  3. data/README +110 -0
  4. data/Rakefile +1 -0
  5. data/lib/riaction.rb +3 -0
  6. data/lib/riaction/iactionable/api.rb +209 -0
  7. data/lib/riaction/iactionable/connection.rb +114 -0
  8. data/lib/riaction/iactionable/error.rb +17 -0
  9. data/lib/riaction/iactionable/objects.rb +6 -0
  10. data/lib/riaction/iactionable/objects/achievement.rb +19 -0
  11. data/lib/riaction/iactionable/objects/awardable.rb +44 -0
  12. data/lib/riaction/iactionable/objects/challenge.rb +18 -0
  13. data/lib/riaction/iactionable/objects/goal.rb +19 -0
  14. data/lib/riaction/iactionable/objects/i_actionable_object.rb +40 -0
  15. data/lib/riaction/iactionable/objects/identifier.rb +11 -0
  16. data/lib/riaction/iactionable/objects/leaderboard.rb +10 -0
  17. data/lib/riaction/iactionable/objects/leaderboard_report.rb +23 -0
  18. data/lib/riaction/iactionable/objects/level.rb +18 -0
  19. data/lib/riaction/iactionable/objects/level_type.rb +10 -0
  20. data/lib/riaction/iactionable/objects/point_type.rb +10 -0
  21. data/lib/riaction/iactionable/objects/profile_level.rb +16 -0
  22. data/lib/riaction/iactionable/objects/profile_points.rb +21 -0
  23. data/lib/riaction/iactionable/objects/profile_summary.rb +24 -0
  24. data/lib/riaction/iactionable/objects/progress.rb +37 -0
  25. data/lib/riaction/iactionable/settings.rb +30 -0
  26. data/lib/riaction/riaction.rb +368 -0
  27. data/lib/riaction/version.rb +3 -0
  28. data/lib/tasks/riaction.rake +101 -0
  29. data/riaction.gemspec +32 -0
  30. data/spec/api_spec.rb +288 -0
  31. data/spec/connection_spec.rb +111 -0
  32. data/spec/riaction_spec.rb +253 -0
  33. data/spec/settings_spec.rb +52 -0
  34. data/spec/spec_helper.rb +1 -0
  35. metadata +153 -0
@@ -0,0 +1,3 @@
1
+ module Riaction
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,101 @@
1
+ namespace 'iactionable' do
2
+ namespace 'list' do
3
+ desc "List all registered events"
4
+ task :events => :environment do
5
+ Dir.glob(File.join(RAILS_ROOT,"app","models","*.rb")).each do |rbfile|
6
+ require rbfile
7
+ end
8
+
9
+ Riaction::EVENT_LOGGING_CLASSES.each do |klass|
10
+ puts "#{klass} defines the following events:"
11
+ klass.riaction_events.each_pair do |name, deets|
12
+ puts " :#{name}:"
13
+ if Riaction.crud_actions.include? deets[:trigger]
14
+ puts " Trigger: Fired on ActiveRecord after_#{deets[:trigger]} callback"
15
+ else
16
+ puts " Trigger: By calling :trigger_#{deets[:trigger]}!"
17
+ end
18
+ case deets[:profile]
19
+ when Symbol
20
+ if deets[:profile] == :self
21
+ puts " Profile: (self)"
22
+ else
23
+ puts " Profile: Value returned by :#{deets[:profile]}"
24
+ end
25
+ when Proc
26
+ puts " Profile: Returned via Proc"
27
+ end
28
+ case deets[:params]
29
+ when NilClass
30
+ puts " Event Params: None"
31
+ when Symbol
32
+ puts " Event Params: Hash returned by :#{deets[:params]}"
33
+ when Proc
34
+ puts " Event Params: Hash returned via Proc"
35
+ when Hash
36
+ puts " Event Params: #{deets[:params]}"
37
+ end
38
+ case deets[:guard]
39
+ when NilClass
40
+ puts " Guard: None"
41
+ when Proc
42
+ puts " Guard: Boolean returned via Proc"
43
+ when Hash
44
+ puts " Guard: Boolean returned by :#{deets[:guard]}"
45
+ end
46
+ puts ""
47
+ end
48
+ puts "-------------------------------------------------------"
49
+ end
50
+ end
51
+
52
+ desc "List all registered profiles"
53
+ task :profiles => :environment do
54
+ Dir.glob(File.join(RAILS_ROOT,"app","models","*.rb")).each do |rbfile|
55
+ require rbfile
56
+ end
57
+
58
+ Riaction::PROFILE_CLASSES.each do |klass|
59
+ puts "#{klass} defines the following profile types:"
60
+ klass.riaction_profiles.each_pair do |type, ids|
61
+ puts " :#{type}:"
62
+ puts " With the following ID types, and field used for the value:"
63
+ ids.each_pair do |id_type, id|
64
+ puts " :#{id_type} => :#{id}"
65
+ end
66
+ puts ""
67
+ end
68
+ puts "-------------------------------------------------------"
69
+ end
70
+ end
71
+ end
72
+
73
+ namespace 'process' do
74
+ desc "Run through all classes acting as profiles and make sure each record/instance exists on IActionable"
75
+ task :profiles => :environment do
76
+ Dir.glob(File.join(RAILS_ROOT,"app","models","*.rb")).each do |rbfile|
77
+ require rbfile
78
+ end
79
+
80
+ Riaction::PROFILE_CLASSES.each do |klass|
81
+ begin
82
+ klass.all.each do |obj|
83
+ puts "Addressing #{klass} record #{obj.id}..."
84
+ klass.riaction_profiles.each_pair do |type, ids|
85
+ puts "...creating profile under type '#{type}'"
86
+ obj.riaction_create_profile(type)
87
+ default_keys = obj.riaction_profile_keys(type)
88
+ ids.each_pair do |id_type, id|
89
+ value = obj.send(id)
90
+ puts "...updating profile with id type #{id_type} and value #{value}"
91
+ obj.riaction_update_profile(type, default_keys[:profile_type], id_type)
92
+ end
93
+ end
94
+ end
95
+ rescue IAction::Error::NoProfileDefined => e
96
+ puts "ERROR: #{klass} does not properly define a profile; skipping"
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
data/riaction.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "riaction/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "riaction"
7
+ s.version = Riaction::VERSION
8
+ s.authors = ["Chris Eberz"]
9
+ s.email = ["ceberz@elctech.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Wrapper for IActionable's restful API and an "acts-as" style interface for models to behave as profiles and drive game events.}
12
+ s.description = %q{Wrapper for IActionable's restful API and an "acts-as" style interface for models to behave as profiles and drive game events.}
13
+
14
+ s.rubyforge_project = "riaction"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib", "spec"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+
25
+ s.add_development_dependency "rspec", "~> 2.6"
26
+
27
+ s.add_runtime_dependency "faraday"
28
+ s.add_runtime_dependency "faraday-stack"
29
+ s.add_runtime_dependency "activesupport", "~> 2.0"
30
+ s.add_runtime_dependency "activerecord"
31
+ s.add_runtime_dependency "resque"
32
+ end
data/spec/api_spec.rb ADDED
@@ -0,0 +1,288 @@
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
+
10
+ IActionable::Connection.stub!(:new).and_return(@mock_connection)
11
+ IActionable::Settings.stub!(:new).and_return(@mock_settings)
12
+
13
+ @mock_response.stub!(:map).and_yield(@mock_response_item).and_return(@mock_response)
14
+ @mock_response.stub!(:[]).and_return(@mock_response)
15
+
16
+ IActionable::Api.init_settings(nil)
17
+
18
+ @api = IActionable::Api.new
19
+ @profile_type = "user"
20
+ @id_type = "custom"
21
+ @id = 42
22
+ end
23
+
24
+ describe "initialization" do
25
+ it "should initialize the connection with the previously initialized settings" do
26
+ IActionable::Settings.should_receive(:new).once.with({:foo => "bar"})
27
+ IActionable::Connection.should_receive(:new).once.with(@mock_settings)
28
+ IActionable::Api.init_settings({:foo => "bar"})
29
+ IActionable::Api.new
30
+ end
31
+
32
+ describe "without having been pre-initialized with settings" do
33
+ before do
34
+ IActionable::Api.class_variable_set(:@@settings, nil)
35
+ end
36
+
37
+ it "should raise a config error" do
38
+ lambda { IActionable::Api.new }.should raise_error(IActionable::ConfigError)
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "event creation" do
44
+ before do
45
+ @event_key = "some_event"
46
+ @mock_event_attrs = mock("mock event attrs")
47
+ end
48
+
49
+ it "should make the correct IActionable API all" do
50
+ @mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
51
+ @mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
52
+ @mock_connection.should_receive(:with_api_key).and_return(@mock_connection)
53
+ @mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}/events/#{@event_key}").and_return(@mock_connection)
54
+ @mock_connection.should_receive(:with_params).with(@mock_event_attrs).and_return(@mock_connection)
55
+ @mock_connection.should_receive(:post).and_return(@mock_response)
56
+ @api.log_event(@profile_type, @id_type, @id, @event_key, @mock_event_attrs).should == @mock_response
57
+ end
58
+ end
59
+
60
+ describe "profile" do
61
+ before do
62
+ @mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
63
+ @mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
64
+ end
65
+
66
+ describe "fetching" do
67
+ before do
68
+ @mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}").and_return(@mock_connection)
69
+ @mock_connection.should_receive(:get).and_return(@mock_response)
70
+ IActionable::Objects::ProfileSummary.stub!(:new)
71
+ end
72
+
73
+ describe "with achivement count" do
74
+ before do
75
+ @achievement_count = 10
76
+ end
77
+
78
+ it "should be the correct IActionable API call" do
79
+ @mock_connection.should_receive(:with_params).with({:achievement_count => @achievement_count}).and_return(@mock_connection)
80
+ @api.get_profile_summary(@profile_type, @id_type, @id, @achievement_count)
81
+ end
82
+ end
83
+
84
+ describe "without achievement count" do
85
+ it "should be the correct IActionable API call" do
86
+ @mock_connection.should_not_receive(:with_params)
87
+ @api.get_profile_summary(@profile_type, @id_type, @id, nil)
88
+ end
89
+ end
90
+
91
+ it "should return the response as a ProfileSummary object" do
92
+ IActionable::Objects::ProfileSummary.should_receive(:new).once.with(@mock_response)
93
+ @api.get_profile_summary(@profile_type, @id_type, @id, nil)
94
+ end
95
+ end
96
+
97
+ describe "creation" do
98
+ before do
99
+ @mock_connection.should_receive(:with_api_key).and_return(@mock_connection)
100
+ @mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}").and_return(@mock_connection)
101
+ @mock_connection.should_receive(:post).and_return(@mock_response)
102
+ end
103
+
104
+ describe "with optional display name" do
105
+ before do
106
+ @display_name = "zortnac"
107
+ end
108
+
109
+ it "should be the correct IActionable API call" do
110
+ @mock_connection.should_receive(:with_params).with({:display_name => @display_name}).and_return(@mock_connection)
111
+ @api.create_profile(@profile_type, @id_type, @id, @display_name).should == @mock_response
112
+ end
113
+ end
114
+
115
+ describe "without optional display name" do
116
+ it "should be the correct IActionable API call" do
117
+ @mock_connection.should_not_receive(:with_params)
118
+ @api.create_profile(@profile_type, @id_type, @id, nil).should == @mock_response
119
+ end
120
+ end
121
+ end
122
+
123
+ describe "updating" do
124
+ it "should make the correct IActionable API all" do
125
+ new_type = "email"
126
+ new_id = 2
127
+ @mock_connection.should_receive(:with_api_key).and_return(@mock_connection)
128
+ @mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}/identifiers/#{new_type}/#{new_id}").and_return(@mock_connection)
129
+ @mock_connection.should_receive(:post).and_return(@mock_response)
130
+ @api.add_profile_identifier(@profile_type, @id_type, @id, new_type, new_id).should == @mock_response
131
+ end
132
+ end
133
+ end
134
+
135
+ describe "profile points" do
136
+ before do
137
+ @mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
138
+ @mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
139
+ @point_type = "experience_points"
140
+ IActionable::Objects::ProfilePoints.stub!(:new).and_return(@mock_response)
141
+ end
142
+
143
+ describe "fetching" do
144
+ it "should make the correct IActionable API all" do
145
+ @mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}/points/#{@point_type}").and_return(@mock_connection)
146
+ @mock_connection.should_receive(:get).and_return(@mock_response)
147
+ @api.get_profile_points(@profile_type, @id_type, @id, @point_type)
148
+ end
149
+
150
+ it "should return the response as a ProfileSummary object" do
151
+ @mock_connection.stub!(:to).and_return(@mock_connection)
152
+ @mock_connection.stub!(:get).and_return(@mock_response)
153
+ IActionable::Objects::ProfilePoints.should_receive(:new).once.with(@mock_response).and_return(@mock_response)
154
+ @api.get_profile_points(@profile_type, @id_type, @id, @point_type).should == @mock_response
155
+ end
156
+ end
157
+
158
+ describe "updating" do
159
+ before do
160
+ @amount = 100
161
+ @mock_connection.should_receive(:with_api_key).and_return(@mock_connection)
162
+ @mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}/points/#{@point_type}").and_return(@mock_connection)
163
+ @mock_connection.should_receive(:with_params).with(hash_including(:value => @amount)).and_return(@mock_connection)
164
+ @mock_connection.should_receive(:post).and_return(@mock_response)
165
+ end
166
+
167
+ describe "with optional reason" do
168
+ it "should make the correct IActionable API all" do
169
+ reason = "some reason"
170
+ @mock_connection.should_receive(:with_params).with(hash_including(:description => reason)).and_return(@mock_connection)
171
+ @api.update_profile_points(@profile_type, @id_type, @id, @point_type, @amount, reason)
172
+ end
173
+ end
174
+
175
+ describe "without optional reason" do
176
+ it "should make the correct IActionable API all" do
177
+ reason = "some reason"
178
+ @mock_connection.should_not_receive(:with_params).with(hash_including(:description => reason))
179
+ @api.update_profile_points(@profile_type, @id_type, @id, @point_type, @amount, nil)
180
+ end
181
+ end
182
+
183
+ it "should return the response as a ProfileSummary object" do
184
+ IActionable::Objects::ProfilePoints.should_receive(:new).once.with(@mock_response).and_return(@mock_response)
185
+ @api.update_profile_points(@profile_type, @id_type, @id, @point_type, @amount, nil).should == @mock_response
186
+ end
187
+ end
188
+ end
189
+
190
+ [ [:achievements, IActionable::Objects::Achievement],
191
+ [:challenges, IActionable::Objects::Challenge],
192
+ [:goals, IActionable::Objects::Goal]].each do |type|
193
+ describe "loading all #{type} for a profile" do
194
+ before do
195
+ type[1].stub!(:new)
196
+ @mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
197
+ @mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
198
+ @mock_connection.should_receive(:get).and_return(@mock_response)
199
+ end
200
+
201
+ describe "filtered by available" do
202
+ it "should make the correct IActionable API all" do
203
+ @mock_connection.should_receive(:to).once.with("/#{@profile_type}/#{@id_type}/#{@id}/#{type[0]}/Available").and_return(@mock_connection)
204
+ @api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, :available)
205
+ end
206
+
207
+ it "should return as the proper object type" do
208
+ @mock_connection.stub!(:to).and_return(@mock_connection)
209
+ type[1].should_receive(:new).once.with(@mock_response_item)
210
+ @api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, :available).should == @mock_response
211
+ end
212
+ end
213
+
214
+ describe "filtered by complete" do
215
+ it "should make the correct IActionable API all" do
216
+ @mock_connection.should_receive(:to).once.with("/#{@profile_type}/#{@id_type}/#{@id}/#{type[0]}/Completed").and_return(@mock_connection)
217
+ @api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, :completed)
218
+ end
219
+
220
+ it "should return as the proper object type" do
221
+ @mock_connection.stub!(:to).and_return(@mock_connection)
222
+ type[1].should_receive(:new).once.with(@mock_response_item)
223
+ @api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, :completed).should == @mock_response
224
+ end
225
+ end
226
+
227
+ describe "unfiltered" do
228
+ it "should make the correct IActionable API all" do
229
+ @mock_connection.should_receive(:to).once.with("/#{@profile_type}/#{@id_type}/#{@id}/#{type[0]}").and_return(@mock_connection)
230
+ @api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, nil)
231
+ end
232
+
233
+ it "should return as the proper object type, in a hash with both filter types" do
234
+ @mock_connection.stub!(:to).and_return(@mock_connection)
235
+ type[1].should_receive(:new).twice.with(@mock_response_item)
236
+ @api.send("get_profile_#{type[0]}", @profile_type, @id_type, @id, nil).should == {:available => @mock_response, :completed => @mock_response}
237
+ end
238
+ end
239
+ end
240
+ end
241
+
242
+ describe "leaderboards" do
243
+ before do
244
+ @point_type = "experience_points"
245
+ @leaderboard = "top_players"
246
+ @page_number = 3
247
+ @page_count = 9
248
+ @mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
249
+ @mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
250
+ IActionable::Objects::LeaderboardReport.stub!(:new).and_return(@mock_response)
251
+ end
252
+
253
+ describe "fetching" do
254
+ it "should make the correct IActionable API all" do
255
+ @mock_connection.should_receive(:to).with("/#{@profile_type}/leaderboards/points/#{@point_type}/#{@leaderboard}").and_return(@mock_connection)
256
+ @mock_connection.should_receive(:with_params).with(hash_including(:pageNumber => @page_number)).and_return(@mock_connection)
257
+ @mock_connection.should_receive(:with_params).with(hash_including(:pageCount => @page_count)).and_return(@mock_connection)
258
+ @mock_connection.should_receive(:with_params).with(hash_including(:id => @id)).and_return(@mock_connection)
259
+ @mock_connection.should_receive(:with_params).with(hash_including(:idType => @id_type)).and_return(@mock_connection)
260
+ @mock_connection.should_receive(:get).and_return(@mock_response)
261
+ @api.get_leaderboard(@profile_type, @point_type, @leaderboard, @page_number, @page_count, @id, @id_type)
262
+ end
263
+
264
+ it "should return the response as a LeaderboardReport object" do
265
+ @mock_connection.stub!(:to).and_return(@mock_connection)
266
+ @mock_connection.stub!(:with_params).and_return(@mock_connection)
267
+ @mock_connection.stub!(:get).and_return(@mock_response)
268
+ IActionable::Objects::LeaderboardReport.should_receive(:new).once.with(@mock_response).and_return(@mock_response)
269
+ @api.get_leaderboard(@profile_type, @point_type, @leaderboard, nil, nil, nil, nil).should == @mock_response
270
+ end
271
+ end
272
+ end
273
+
274
+ describe "notifications" do
275
+ it "should make the correct IActionable API all" do
276
+ IActionable::Objects::Achievement.stub!(:new)
277
+ IActionable::Objects::Challenge.stub!(:new)
278
+ IActionable::Objects::Goal.stub!(:new)
279
+ IActionable::Objects::Level.stub!(:new)
280
+ IActionable::Objects::ProfilePoints.stub!(:new)
281
+ @mock_connection.should_receive(:request).once.ordered.and_return(@mock_connection)
282
+ @mock_connection.should_receive(:with_app_key).and_return(@mock_connection)
283
+ @mock_connection.should_receive(:to).with("/#{@profile_type}/#{@id_type}/#{@id}/notifications").and_return(@mock_connection)
284
+ @mock_connection.should_receive(:get).and_return(@mock_response)
285
+ @api.get_profile_notifications(@profile_type, @id_type, @id)
286
+ end
287
+ end
288
+ 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