rgigya 1.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 (65) hide show
  1. data/.rvmrc +1 -0
  2. data/Gemfile +18 -0
  3. data/Gemfile.lock +54 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +135 -0
  6. data/Rakefile +36 -0
  7. data/VERSION +1 -0
  8. data/lib/rgigya.rb +196 -0
  9. data/rgigya.gemspec +118 -0
  10. data/spec/helpers.rb +8 -0
  11. data/spec/rgigya_spec.rb +310 -0
  12. data/spec/spec_helper.rb +12 -0
  13. data/test/dummy/Gemfile +40 -0
  14. data/test/dummy/Gemfile.lock +119 -0
  15. data/test/dummy/README.rdoc +261 -0
  16. data/test/dummy/Rakefile +7 -0
  17. data/test/dummy/app/assets/images/rails.png +0 -0
  18. data/test/dummy/app/assets/javascripts/application.js +15 -0
  19. data/test/dummy/app/assets/stylesheets/application.css +23 -0
  20. data/test/dummy/app/controllers/application_controller.rb +3 -0
  21. data/test/dummy/app/controllers/welcome_controller.rb +22 -0
  22. data/test/dummy/app/helpers/application_helper.rb +2 -0
  23. data/test/dummy/app/mailers/.gitkeep +0 -0
  24. data/test/dummy/app/models/.gitkeep +0 -0
  25. data/test/dummy/app/views/layouts/application.html.erb +44 -0
  26. data/test/dummy/app/views/welcome/index.html +0 -0
  27. data/test/dummy/app/views/welcome/index.html.erb +14 -0
  28. data/test/dummy/config/application.rb +62 -0
  29. data/test/dummy/config/boot.rb +6 -0
  30. data/test/dummy/config/database.yml +25 -0
  31. data/test/dummy/config/environment.rb +5 -0
  32. data/test/dummy/config/environments/development.rb +42 -0
  33. data/test/dummy/config/environments/production.rb +67 -0
  34. data/test/dummy/config/environments/test.rb +37 -0
  35. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  36. data/test/dummy/config/initializers/inflections.rb +15 -0
  37. data/test/dummy/config/initializers/mime_types.rb +5 -0
  38. data/test/dummy/config/initializers/secret_token.rb +7 -0
  39. data/test/dummy/config/initializers/session_store.rb +8 -0
  40. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  41. data/test/dummy/config/locales/en.yml +5 -0
  42. data/test/dummy/config/routes.rb +60 -0
  43. data/test/dummy/config.ru +4 -0
  44. data/test/dummy/db/development.sqlite3 +0 -0
  45. data/test/dummy/db/seeds.rb +7 -0
  46. data/test/dummy/lib/assets/.gitkeep +0 -0
  47. data/test/dummy/lib/tasks/.gitkeep +0 -0
  48. data/test/dummy/log/.gitkeep +0 -0
  49. data/test/dummy/log/development.log +1130 -0
  50. data/test/dummy/public/404.html +26 -0
  51. data/test/dummy/public/422.html +26 -0
  52. data/test/dummy/public/500.html +25 -0
  53. data/test/dummy/public/favicon.ico +0 -0
  54. data/test/dummy/public/robots.txt +5 -0
  55. data/test/dummy/script/rails +6 -0
  56. data/test/dummy/test/fixtures/.gitkeep +0 -0
  57. data/test/dummy/test/functional/.gitkeep +0 -0
  58. data/test/dummy/test/integration/.gitkeep +0 -0
  59. data/test/dummy/test/performance/browsing_test.rb +12 -0
  60. data/test/dummy/test/test_helper.rb +13 -0
  61. data/test/dummy/test/unit/.gitkeep +0 -0
  62. data/test/dummy/vendor/assets/javascripts/.gitkeep +0 -0
  63. data/test/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  64. data/test/dummy/vendor/plugins/.gitkeep +0 -0
  65. metadata +180 -0
@@ -0,0 +1,310 @@
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
@@ -0,0 +1,12 @@
1
+ require 'rgigya' # and any other gems you need
2
+ require 'helpers.rb'
3
+ RSpec.configure do |config|
4
+ # some (optional) config here
5
+ config.include Helpers
6
+
7
+
8
+ # these need to be filled out for tests to work
9
+ GIGYA_API_KEY = "<add api key here>"
10
+ GIGYA_API_SECRET = "<add api secret here>"
11
+
12
+ end
@@ -0,0 +1,40 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '3.2.13'
4
+
5
+ # Bundle edge Rails instead:
6
+ # gem 'rails', :git => 'git://github.com/rails/rails.git'
7
+
8
+ gem 'sqlite3'
9
+
10
+ gem 'rgigya'
11
+
12
+
13
+ # Gems used only for assets and not required
14
+ # in production environments by default.
15
+ group :assets do
16
+ gem 'sass-rails', '~> 3.2.3'
17
+ gem 'coffee-rails', '~> 3.2.1'
18
+
19
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
20
+ # gem 'therubyracer', :platforms => :ruby
21
+
22
+ gem 'uglifier', '>= 1.0.3'
23
+ end
24
+
25
+ gem 'jquery-rails'
26
+
27
+ # To use ActiveModel has_secure_password
28
+ # gem 'bcrypt-ruby', '~> 3.0.0'
29
+
30
+ # To use Jbuilder templates for JSON
31
+ # gem 'jbuilder'
32
+
33
+ # Use unicorn as the app server
34
+ # gem 'unicorn'
35
+
36
+ # Deploy with Capistrano
37
+ # gem 'capistrano'
38
+
39
+ # To use debugger
40
+ # gem 'debugger'
@@ -0,0 +1,119 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ actionmailer (3.2.13)
5
+ actionpack (= 3.2.13)
6
+ mail (~> 2.5.3)
7
+ actionpack (3.2.13)
8
+ activemodel (= 3.2.13)
9
+ activesupport (= 3.2.13)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.4)
13
+ rack (~> 1.4.5)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.2.1)
17
+ activemodel (3.2.13)
18
+ activesupport (= 3.2.13)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.13)
21
+ activemodel (= 3.2.13)
22
+ activesupport (= 3.2.13)
23
+ arel (~> 3.0.2)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.13)
26
+ activemodel (= 3.2.13)
27
+ activesupport (= 3.2.13)
28
+ activesupport (3.2.13)
29
+ i18n (= 0.6.1)
30
+ multi_json (~> 1.0)
31
+ arel (3.0.2)
32
+ builder (3.0.4)
33
+ coffee-rails (3.2.2)
34
+ coffee-script (>= 2.2.0)
35
+ railties (~> 3.2.0)
36
+ coffee-script (2.2.0)
37
+ coffee-script-source
38
+ execjs
39
+ coffee-script-source (1.6.2)
40
+ erubis (2.7.0)
41
+ execjs (1.4.0)
42
+ multi_json (~> 1.0)
43
+ hike (1.2.2)
44
+ httparty (0.11.0)
45
+ multi_json (~> 1.0)
46
+ multi_xml (>= 0.5.2)
47
+ i18n (0.6.1)
48
+ journey (1.0.4)
49
+ jquery-rails (2.2.1)
50
+ railties (>= 3.0, < 5.0)
51
+ thor (>= 0.14, < 2.0)
52
+ json (1.7.7)
53
+ mail (2.5.3)
54
+ i18n (>= 0.4.0)
55
+ mime-types (~> 1.16)
56
+ treetop (~> 1.4.8)
57
+ mime-types (1.22)
58
+ multi_json (1.7.2)
59
+ multi_xml (0.5.3)
60
+ polyglot (0.3.3)
61
+ rack (1.4.5)
62
+ rack-cache (1.2)
63
+ rack (>= 0.4)
64
+ rack-ssl (1.3.3)
65
+ rack
66
+ rack-test (0.6.2)
67
+ rack (>= 1.0)
68
+ rails (3.2.13)
69
+ actionmailer (= 3.2.13)
70
+ actionpack (= 3.2.13)
71
+ activerecord (= 3.2.13)
72
+ activeresource (= 3.2.13)
73
+ activesupport (= 3.2.13)
74
+ bundler (~> 1.0)
75
+ railties (= 3.2.13)
76
+ railties (3.2.13)
77
+ actionpack (= 3.2.13)
78
+ activesupport (= 3.2.13)
79
+ rack-ssl (~> 1.3.2)
80
+ rake (>= 0.8.7)
81
+ rdoc (~> 3.4)
82
+ thor (>= 0.14.6, < 2.0)
83
+ rake (10.0.4)
84
+ rdoc (3.12.2)
85
+ json (~> 1.4)
86
+ rgigya (0.1.0)
87
+ httparty (~> 0.11.0)
88
+ sass (3.2.7)
89
+ sass-rails (3.2.6)
90
+ railties (~> 3.2.0)
91
+ sass (>= 3.1.10)
92
+ tilt (~> 1.3)
93
+ sprockets (2.2.2)
94
+ hike (~> 1.2)
95
+ multi_json (~> 1.0)
96
+ rack (~> 1.0)
97
+ tilt (~> 1.1, != 1.3.0)
98
+ sqlite3 (1.3.7)
99
+ thor (0.18.1)
100
+ tilt (1.3.7)
101
+ treetop (1.4.12)
102
+ polyglot
103
+ polyglot (>= 0.3.1)
104
+ tzinfo (0.3.37)
105
+ uglifier (2.0.1)
106
+ execjs (>= 0.3.0)
107
+ multi_json (~> 1.0, >= 1.0.2)
108
+
109
+ PLATFORMS
110
+ ruby
111
+
112
+ DEPENDENCIES
113
+ coffee-rails (~> 3.2.1)
114
+ jquery-rails
115
+ rails (= 3.2.13)
116
+ rgigya
117
+ sass-rails (~> 3.2.3)
118
+ sqlite3
119
+ uglifier (>= 1.0.3)