rgigya 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -5
- data/VERSION +1 -1
- data/lib/rgigya/base.rb +340 -0
- data/lib/rgigya/hash.rb +19 -0
- data/lib/rgigya/sig_utils.rb +98 -0
- data/lib/rgigya.rb +3 -193
- data/rgigya.gemspec +8 -3
- data/spec/helpers.rb +26 -0
- data/spec/rgigya_secure_spec.rb +18 -0
- data/spec/rgigya_shared_examples.rb +315 -0
- data/spec/rgigya_signature_spec.rb +62 -0
- data/spec/spec_helper.rb +4 -5
- data/test/dummy/Gemfile +0 -1
- data/test/dummy/Gemfile.lock +8 -9
- data/test/dummy/config/environments/development.rb +6 -2
- data/test/dummy/log/development.log +300 -0
- metadata +21 -16
- data/spec/rgigya_spec.rb +0 -310
data/spec/rgigya_spec.rb
DELETED
@@ -1,310 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe RGigya do
|
4
|
-
|
5
|
-
it "should use the socialize url when making a socialize api call" do
|
6
|
-
RGigya.stub(:required_parameters) {
|
7
|
-
''
|
8
|
-
}
|
9
|
-
# we pass in the "_" replaced with "." already
|
10
|
-
url = RGigya.build_url("socialize.getUserInfo",{})
|
11
|
-
url.should match(/https:\/\/socialize-api.gigya.com/)
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
it "should use the gm url when making a game mechanic api call" do
|
17
|
-
RGigya.stub(:required_parameters) {
|
18
|
-
''
|
19
|
-
}
|
20
|
-
# we pass in the "_" replaced with "." already
|
21
|
-
url = RGigya.build_url("gm.notifyAction",{})
|
22
|
-
url.should match(/https:\/\/gm.gigya.com/)
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
it "should use the comments url when making a comment api call" do
|
27
|
-
RGigya.stub(:required_parameters) {
|
28
|
-
''
|
29
|
-
}
|
30
|
-
# we pass in the "_" replaced with "." already
|
31
|
-
url = RGigya.build_url("comments.getTopStreams",{})
|
32
|
-
url.should match(/https:\/\/comments.gigya.com/)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should use the accounts url when making an accounts api call" do
|
36
|
-
RGigya.stub(:required_parameters) {
|
37
|
-
''
|
38
|
-
}
|
39
|
-
# we pass in the "_" replaced with "." already
|
40
|
-
url = RGigya.build_url("accounts.getPolicies",{})
|
41
|
-
url.should match(/https:\/\/accounts.gigya.com/)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should use the reports url when making a reports api call" do
|
45
|
-
RGigya.stub(:required_parameters) {
|
46
|
-
''
|
47
|
-
}
|
48
|
-
# we pass in the "_" replaced with "." already
|
49
|
-
url = RGigya.build_url("reports.getChatStats",{})
|
50
|
-
url.should match(/https:\/\/reports.gigya.com/)
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
it "should use the chats url when making a chats api call" do
|
55
|
-
RGigya.stub(:required_parameters) {
|
56
|
-
''
|
57
|
-
}
|
58
|
-
# we pass in the "_" replaced with "." already
|
59
|
-
url = RGigya.build_url("chat.getMessages",{})
|
60
|
-
url.should match(/https:\/\/chat.gigya.com/)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should use the ds url when making a data store api call" do
|
64
|
-
RGigya.stub(:required_parameters) {
|
65
|
-
''
|
66
|
-
}
|
67
|
-
# we pass in the "_" replaced with "." already
|
68
|
-
url = RGigya.build_url("ds.get",{})
|
69
|
-
url.should match(/https:\/\/ds.gigya.com/)
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
it "should raise a bad param error if UID is nil" do
|
75
|
-
expect {
|
76
|
-
RGigya.build_url('socialize.getUserInfo', {:uid => nil})
|
77
|
-
}.to raise_error(RGigya::UIDParamIsNil)
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should raise a bad param error if siteUID is nil" do
|
81
|
-
expect {
|
82
|
-
RGigya.build_url('socialize.getUserInfo', {:siteUID => nil})
|
83
|
-
}.to raise_error(RGigya::SiteUIDParamIsNil)
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should fill in the required parameters on request" do
|
87
|
-
# we pass in the "_" replaced with "." already
|
88
|
-
params = RGigya.required_parameters
|
89
|
-
params.should match(/apiKey=#{CGI.escape(GIGYA_API_KEY)}/)
|
90
|
-
params.should match(/secret=#{CGI.escape(GIGYA_API_SECRET)}/)
|
91
|
-
params.should match(/format=json/)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should succeed with a result code of 0 from gigya" do
|
95
|
-
params = RGigya.check_for_errors({'errorCode' => 0})
|
96
|
-
params.should have_key('errorCode')
|
97
|
-
end
|
98
|
-
|
99
|
-
|
100
|
-
it "should return nil and not raise an error with a limit reached error" do
|
101
|
-
results = RGigya.check_for_errors({'errorCode' => 400124})
|
102
|
-
results.should be_nil
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should raise an error when we pass in a bad parameter" do
|
106
|
-
expect {
|
107
|
-
RGigya.check_for_errors({
|
108
|
-
'errorCode' => 400002
|
109
|
-
})
|
110
|
-
}.to raise_error(RGigya::BadParamsOrMethodName)
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should raise an error when an errorcode other than 0,400002, or 400124 is returned" do
|
114
|
-
# Buffering the log
|
115
|
-
buffer = StringIO.new
|
116
|
-
$stdout = buffer
|
117
|
-
expect {
|
118
|
-
RGigya.check_for_errors({
|
119
|
-
'errorCode' => 4034934
|
120
|
-
})
|
121
|
-
}.to raise_error(RGigya::ErrorCodeReturned)
|
122
|
-
$stdout = STDOUT
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should report method missing if method does not start with socialize" do
|
126
|
-
expect {
|
127
|
-
RGigya.method_missing(:abc,{})
|
128
|
-
}.to raise_error(NameError)
|
129
|
-
expect {
|
130
|
-
RGigya.method_missing(:socialize_getUserInfo)
|
131
|
-
}.to raise_error(RGigya::BadParamsOrMethodName)
|
132
|
-
end
|
133
|
-
|
134
|
-
|
135
|
-
it "should report method missing if method does not start with gm" do
|
136
|
-
expect {
|
137
|
-
RGigya.method_missing(:abc,{})
|
138
|
-
}.to raise_error(NameError)
|
139
|
-
expect {
|
140
|
-
RGigya.method_missing(:gm_notifyAction)
|
141
|
-
}.to raise_error(RGigya::BadParamsOrMethodName)
|
142
|
-
end
|
143
|
-
|
144
|
-
|
145
|
-
it "should report method missing if method does not start with socialize,gm, accounts,reports, chat,ds or comments" do
|
146
|
-
expect {
|
147
|
-
RGigya.method_missing(:abc,{})
|
148
|
-
}.to raise_error(NameError)
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should not respond to method starting without socialize,gm, accounts,reports, chat,ds or comments" do
|
152
|
-
RGigya.respond_to?(:abc,false).should be_false
|
153
|
-
end
|
154
|
-
|
155
|
-
it "should respond to method starting with socialize" do
|
156
|
-
RGigya.respond_to?(:socialize_getUserInfo,false).should be_true
|
157
|
-
end
|
158
|
-
|
159
|
-
|
160
|
-
it "should respond to method starting with gm" do
|
161
|
-
RGigya.respond_to?(:gm_notifyAction,false).should be_true
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should respond_to method starting with comments" do
|
165
|
-
RGigya.respond_to?(:comments_getComments,false).should be_true
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should respond_to method starting with accounts" do
|
169
|
-
RGigya.respond_to?(:accounts_getPolicies,false).should be_true
|
170
|
-
end
|
171
|
-
|
172
|
-
it "should respond_to method starting with reports" do
|
173
|
-
RGigya.respond_to?(:reports_getChatStats,false).should be_true
|
174
|
-
end
|
175
|
-
|
176
|
-
it "should respond_to method starting with chat" do
|
177
|
-
RGigya.respond_to?(:chat_getMessages,false).should be_true
|
178
|
-
end
|
179
|
-
|
180
|
-
it "should respond_to method starting with ds" do
|
181
|
-
RGigya.respond_to?(:ds_get,false).should be_true
|
182
|
-
end
|
183
|
-
|
184
|
-
|
185
|
-
it "should print log to standard out" do
|
186
|
-
str = "This should print to the screen"
|
187
|
-
buffer = StringIO.new
|
188
|
-
$stdout = buffer
|
189
|
-
RGigya.log(str)
|
190
|
-
$stdout = STDOUT
|
191
|
-
buffer.rewind
|
192
|
-
buffer.read.should == str + "\n"
|
193
|
-
end
|
194
|
-
|
195
|
-
|
196
|
-
it "should print log to standard out" do
|
197
|
-
# buffer the input and check
|
198
|
-
str = "This should print to the screen"
|
199
|
-
buffer = StringIO.new
|
200
|
-
$stdout = buffer
|
201
|
-
RGigya.log(str)
|
202
|
-
$stdout = STDOUT
|
203
|
-
buffer.rewind
|
204
|
-
buffer.read.should == str + "\n"
|
205
|
-
end
|
206
|
-
|
207
|
-
|
208
|
-
it "should log to the Rails log if rails exists" do
|
209
|
-
# Mock and Stub Rails.logger.info
|
210
|
-
Rails = mock("Rails")
|
211
|
-
Rails.stub(:logger) {
|
212
|
-
logger = mock("Logger");
|
213
|
-
logger.stub(:info) do |str|
|
214
|
-
puts "mocked_data=#{str}"
|
215
|
-
end
|
216
|
-
logger
|
217
|
-
}
|
218
|
-
|
219
|
-
# buffer the input and check
|
220
|
-
str = "This should print to the screen"
|
221
|
-
buffer = StringIO.new
|
222
|
-
$stdout = buffer
|
223
|
-
RGigya.log(str)
|
224
|
-
$stdout = STDOUT
|
225
|
-
buffer.rewind
|
226
|
-
buffer.read.should == "mocked_data=" + str + "\n"
|
227
|
-
# Remove the rails object so it doesn't interfere with tests below
|
228
|
-
Object.send(:remove_const, :Rails)
|
229
|
-
end
|
230
|
-
|
231
|
-
it "should return a result of false if we pass a bad method" do
|
232
|
-
HTTParty.stub(:get) do |url,options|
|
233
|
-
nil
|
234
|
-
end
|
235
|
-
RGigya.parse_results("socialize_notAMethod",{}).should be_false
|
236
|
-
end
|
237
|
-
|
238
|
-
it "should raise json error if gigya returns bad json" do
|
239
|
-
HTTParty.stub(:get) do |url,options|
|
240
|
-
Response = mock("Response")
|
241
|
-
Response.stub(:body) {
|
242
|
-
'{'
|
243
|
-
}
|
244
|
-
Response
|
245
|
-
end
|
246
|
-
|
247
|
-
expect {
|
248
|
-
RGigya.parse_results("socialize_notAMethod",{}).should be_false
|
249
|
-
}.to raise_error(RGigya::JSONParseError)
|
250
|
-
end
|
251
|
-
|
252
|
-
|
253
|
-
it "should raise a response error if the gigya call fails" do
|
254
|
-
HTTParty.stub(:get) do |url,options|
|
255
|
-
raise SocketError
|
256
|
-
end
|
257
|
-
|
258
|
-
expect {
|
259
|
-
RGigya.parse_results("socialize_notAMethod",{}).should be_false
|
260
|
-
}.to raise_error(RGigya::ResponseError)
|
261
|
-
end
|
262
|
-
|
263
|
-
it "should raise a response error if the gigya call times out" do
|
264
|
-
HTTParty.stub(:get) do |url,options|
|
265
|
-
raise Timeout::Error
|
266
|
-
end
|
267
|
-
|
268
|
-
expect {
|
269
|
-
RGigya.parse_results("socialize_notAMethod",{}).should be_false
|
270
|
-
}.to raise_error(RGigya::ResponseError)
|
271
|
-
|
272
|
-
end
|
273
|
-
|
274
|
-
|
275
|
-
# Actual tests that modify the gigya account below
|
276
|
-
|
277
|
-
it "should login a user" do
|
278
|
-
|
279
|
-
userInfo = {
|
280
|
-
'nickname' => 'Gigems',
|
281
|
-
'email' => 'ralph@cloudspace.com',
|
282
|
-
'firstName' => 'Ralph',
|
283
|
-
'lastName' => 'Masterson'
|
284
|
-
}
|
285
|
-
|
286
|
-
response = RGigya.socialize_notifyLogin({
|
287
|
-
:siteUID => '1',
|
288
|
-
:userInfo => userInfo.to_json
|
289
|
-
})
|
290
|
-
end
|
291
|
-
|
292
|
-
it "should register a user" do
|
293
|
-
uid = get_uid
|
294
|
-
RGigya.socialize_notifyRegistration({
|
295
|
-
:UID => uid,
|
296
|
-
:siteUID => '1',
|
297
|
-
})
|
298
|
-
|
299
|
-
end
|
300
|
-
|
301
|
-
it "should get the users info" do
|
302
|
-
uid = get_uid
|
303
|
-
response = RGigya.socialize_getUserInfo({
|
304
|
-
:UID => uid,
|
305
|
-
})
|
306
|
-
response['nickname'].should match 'Gigems'
|
307
|
-
end
|
308
|
-
|
309
|
-
|
310
|
-
end
|