nm-gigya 0.1.21 → 0.1.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16a25e8dd7145c0f168abd4cb48d5a0015e36acf5b5875ab14847cd409da1517
4
- data.tar.gz: 89575031565c30fece68f11d68cfb2c172c955861468890a1b4dd347cb5df555
3
+ metadata.gz: c8e15740efa701141cdd538da4839d5ce5286c02aaceff82e990022e3578bb10
4
+ data.tar.gz: 7495fa6f7cf0cd1f761e410652fb5bb1f69cb6dd48b22787042b7f855ee924e3
5
5
  SHA512:
6
- metadata.gz: a3afe07e75ba869edfd28d40560c1355e6fdfac5e724be115dd9a31a3c36c7626ad1c8be98251a95714f0b37bfd9f3d5f0a6cb0605525dbcdf53298ff2737236
7
- data.tar.gz: 3b41ed2716229a0a4c9c7b5b13a0f874977b42a5e4673d9df01e15184ceb707368e833bd0c2b9adef5080063a9823f8daa474b2d9512be85f49e560c89ab5377
6
+ metadata.gz: 128ac6258b41c8b5e8de224a6d98587ce7130e49b010f511e8ff47ec92ce67ebff03c300772db51d9c8b87f531924970b642bf448b4633265ce20cc5c86da681
7
+ data.tar.gz: 013ea387ae6850a00a1c255ee3d95f0b72e7d954f84a2a815eb8ba897dc18f7d5beedb35093950798c93e12c12b80269daf97b44586bd8aebf158d120ebe7665
@@ -292,6 +292,15 @@ module Gigya
292
292
  api_call("POST", area, function, params, opts)
293
293
  end
294
294
 
295
+ # This allows substituting how HTTP calls are made (could be useful for testing)
296
+ def http_driver
297
+ @http_driver || HTTParty
298
+ end
299
+
300
+ def http_driver=(val)
301
+ @http_driver = val
302
+ end
303
+
295
304
  def api_call(http_method, area, function, params = nil, opts = nil)
296
305
  params ||= {}
297
306
  opts ||= {}
@@ -302,7 +311,7 @@ module Gigya
302
311
  params[:apiKey] = opts[:api_key]
303
312
  unless opts[:authenticate_app] == false
304
313
  params[:secret] = opts[:user_secret]
305
- params[:userKey] = opts[:user_key]
314
+ params[:userKey] = opts[:user_key] unless opts[:user_key].blank?
306
315
  end
307
316
 
308
317
  if opts[:session] != nil
@@ -319,7 +328,7 @@ module Gigya
319
328
  end
320
329
  http_response = nil
321
330
  response = begin
322
- http_response = http_method == "GET" ? HTTParty.get(base_url, :query => params) : HTTParty.post(base_url, :body => params)
331
+ http_response = http_method == "GET" ? http_driver.get(base_url, :query => params) : http_driver.post(base_url, :body => params)
323
332
  JSON.parse(http_response.body)
324
333
  rescue
325
334
  {"errorCode" => 600, "errorMessage" => "Unknown error", "errorDetail" => "Unable to communicate with authentication server", :http => http_response.inspect}
data/lib/gigya/user.rb CHANGED
@@ -50,7 +50,7 @@ module Gigya
50
50
  end
51
51
 
52
52
  def reload
53
- conn = gigya_connection || Gigya::Connection.shared_connection
53
+ conn = my_gigya_connection
54
54
  set_attributes(conn.api_get("accounts", "getAccountInfo", {UID: uid, include:"profile,data,subscriptions,userInfo,preferences", extraProfileFields:@@extra_profile_fields.join(",")}))
55
55
  end
56
56
 
@@ -60,7 +60,7 @@ module Gigya
60
60
  info["data"] = gigya_details["data"].to_json if gigya_details["data"].present?
61
61
  # What about isActive, isVerified?, password/newPassword, preferences, add/removeLoginEmails, subscriptions, lang, rba
62
62
 
63
- conn = gigya_connection || Gigya::Connection.shared_connection
63
+ conn = my_gigya_connection
64
64
  conn.api_post("accounts", "setAccountInfo", info)
65
65
  save_to_cache
66
66
 
@@ -97,7 +97,7 @@ module Gigya
97
97
 
98
98
  def self.find(uid, opts = {}) # Find a Gigya account record by its UID attribute
99
99
  opts = {} if opts.nil?
100
- opts[:cache] = true if opts[:cache].nil?
100
+ opts[:cache] = true if opts[:cache].nil?
101
101
 
102
102
  cache_info = load_from_cache(uid)
103
103
  if cache_info.present? && opts[:cache]
@@ -163,5 +163,135 @@ module Gigya
163
163
  nil
164
164
  end
165
165
  end
166
+
167
+
168
+ # Intended way of calling this:
169
+ # Gigya::User.create_gigya_user_through_notify_login("abc@example.com", :password => "Abc123!!", :account => { "preferences" => {"foo" => "bar" } }, :verified => true)
170
+ #
171
+ # Options:
172
+ # :password => Set a password,
173
+ # :source => the registration source
174
+ # :account => hash of any account defaults you want to set. Profile defaults should be under the "profile" key.
175
+ # :send_verification => Will send verification email
176
+ # :verified => Will auto-set "verified"
177
+ # :force => Will do things that Gigya doesn't naturally want to do (often used in combination with :verified)
178
+ # :debug => will print out call information
179
+
180
+ # Creates a gigya user through the `notify_login` pathway
181
+ def self.create_gigya_user_through_notify_login(email, opts = {})
182
+ conn = opts[:gigya_connection] || Gigya::Connection.shared_connection
183
+
184
+ # Create UUID
185
+ new_uid = opts[:UID] || "#{SecureRandom.uuid.gsub("-", "")}#{SecureRandom.uuid.gsub("-", "")}"
186
+
187
+ # Is the address available?
188
+ email_is_available = conn.api_get("accounts", "isAvailableLoginID", { "loginID" => email }, :debug_connection => opts[:debug])["isAvailable"] rescue false
189
+ raise "Username is unavailable" unless email_is_available
190
+
191
+ # Register UUID
192
+ response = conn.api_get("accounts", "notifyLogin", {"siteUID" => new_uid}, :debug_connection => opts[:debug])
193
+ raise "Could not register UID" unless response["errorCode"] == 0 || response["errorCode"] == 206001
194
+
195
+ # Start the registration process
196
+ regtoken = conn.api_get("accounts", "initRegistration", {}, :debug_connection => opts[:debug])["regToken"] rescue nil
197
+ raise "Could not initiate registration" if regtoken.blank?
198
+
199
+ # Create the data record
200
+ account_info = opts[:account] || {} # This allows the caller to send us defaults
201
+ account_info["UID"] = new_uid # Primary key
202
+ account_info["regToken"] = regtoken # Ties it to the initial registration
203
+ account_info["securityOverride"] = true # Allows us to set passwords if we want
204
+ account_info["profile"] ||= {}
205
+ account_info["profile"]["email"] = email # Actual login username
206
+ account_info["profile"] = account_info["profile"].to_json
207
+ account_info["preferences"] = account_info["preferences"].to_json
208
+ account_info["regSource"] = opts[:source] || "nm-gigya"
209
+
210
+ # Optional data record pieces
211
+ account_info["isVerified"] = true if opts[:verified]
212
+ account_info["newPassword"] = opts[:password] unless opts[:password].blank?
213
+
214
+ # Create the registration with the data record
215
+ results = conn.api_post("accounts", "setAccountInfo", account_info, :debug_connection => opts[:debug])
216
+
217
+ # If not everything got set correctly (NOTE - doesn't work if :password is not also sent)
218
+ if opts[:force]
219
+ response = conn.api_get("accounts", "login", {"loginID" => email, "password" => opts[:password]}, :debug_connection => opts[:debug])
220
+ if response["errorCode"] != 0
221
+ verify_reg_token = response["regToken"]
222
+ response = conn.api_get("accounts", "finalizeRegistration", {"regToken" => verify_reg_token, "include" => "emails, profile"}, :debug_connection => opts[:debug])
223
+ unless response["errorCode"] == 0 || response["errorCode"] == 206002 || response["errorCode"] == 206001
224
+ raise "Unable to finalize registration"
225
+ end
226
+ end
227
+ end
228
+
229
+ if opts[:send_verification]
230
+ conn.api_get("accounts", "resendVerificationCode", {"UID" => new_uid, "email" => email})
231
+ end
232
+
233
+ if opts[:send_password_change]
234
+ conn.api_get("accounts", "resetPassword", {"UID" => new_uid, "loginID" => email, "email" => email})
235
+ end
236
+
237
+ return new_uid
238
+ end
239
+
240
+ # Creates a gigya user through the `register` pathway
241
+
242
+ # Options:
243
+ # :password => Set a password,
244
+ # :source => the registration source
245
+ # :account => hash of any account defaults you want to set. Profile defaults should be under the "profile" key.
246
+ # :debug => will print out call information
247
+
248
+ def self.create_gigya_user_through_register(email, opts = {})
249
+ conn = opts[:gigya_connection] || Gigya::Connection.shared_connection
250
+
251
+ new_password = opts[:password] || SecureRandom.urlsafe_base64(8)
252
+
253
+ # Create UUID
254
+ new_uid = opts[:UID] || "#{SecureRandom.uuid.gsub("-", "")}#{SecureRandom.uuid.gsub("-", "")}"
255
+
256
+ # Is the address available?
257
+ email_is_available = conn.api_get("accounts", "isAvailableLoginID", { "loginID" => email }, :debug_connection => opts[:debug])["isAvailable"] rescue false
258
+ raise "Username is unavailable" unless email_is_available
259
+
260
+ # Start the registration process
261
+ regtoken = conn.api_get("accounts", "initRegistration", {}, :debug_connection => opts[:debug])["regToken"] rescue nil
262
+ raise "Could not initiate registration" if regtoken.blank?
263
+
264
+ # Create the data record
265
+ account_info = opts[:account] || {} # This allows the caller to send us defaults
266
+ account_info["siteUID"] = new_uid # Primary key
267
+ account_info["regToken"] = regtoken # Ties it to the initial registration
268
+ account_info["profile"] ||= {}
269
+ account_info["email"] = email
270
+ account_info["profile"]["email"] = email # Actual login username
271
+ account_info["profile"] = account_info["profile"].to_json
272
+ account_info["preferences"] = account_info["preferences"].to_json unless account_info["preferences"].nil?
273
+ account_info["regSource"] = opts[:source] unless opts[:source].blank?
274
+ account_info["password"] = new_password
275
+ account_info["data"] = account_info["data"].to_json unless account_info["data"].nil?
276
+
277
+ # Complete the registration process
278
+ conn.api_post("accounts", "register", account_info, :debug_connection => opts[:debug])
279
+
280
+ if opts[:send_verification]
281
+ conn.api_get("accounts", "resendVerificationCode", {"UID" => new_uid, "email" => email})
282
+ end
283
+
284
+ if opts[:send_password_change]
285
+ conn.api_get("accounts", "resetPassword", {"UID" => new_uid, "loginID" => email, "email" => email})
286
+ end
287
+
288
+ return new_uid
289
+ end
290
+
291
+ private
292
+
293
+ def my_gigya_connection
294
+ gigya_connection || Gigya::Connection.shared_connection
295
+ end
166
296
  end
167
297
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nm-gigya
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Bartlett
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-02-07 00:00:00.000000000 Z
13
+ date: 2020-04-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -41,7 +41,7 @@ dependencies:
41
41
  - !ruby/object:Gem::Version
42
42
  version: '2.1'
43
43
  description:
44
- email: jonathan@newmedio.com
44
+ email: jonathan.bartlett@specialized.com
45
45
  executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  requirements: []
74
- rubygems_version: 3.0.2
74
+ rubygems_version: 3.1.2
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: Gigya API Utility Package