nm-gigya 0.0.19 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 158cb06fa4fad8493c7e615a86c819204a7aa86b
4
- data.tar.gz: 193676bfef6af691295381e9393d09907f02d68b
3
+ metadata.gz: '08dedb042027f017d213d93046184ee54df44a71'
4
+ data.tar.gz: cca56000dce031c95a65fbc7eea6fcc6682b4f1c
5
5
  SHA512:
6
- metadata.gz: 8562a605078f8787de737ca358ff6a335ba4ff6a0bf09007f91be06f9a20aefb2848d659cfc07a22cf43346e00e9c370d7037f32f6cc1fef70ab06c6a91f218b
7
- data.tar.gz: 82f6e2cd41de7d15d80ba594c180d118d7daf53a5b118dd7ba8aa64591b4774ef7b9ef0649c5d1a960aa35df825820059c28b7127ced0095358d60ea8faac5f0
6
+ metadata.gz: 647521daf579395dbb2a7061a04a566ae78b84c5ebff76a30102b284846f8f2825b0314c5f6ea2eaf120f5fd654ca4f0663ced06d8428669c2338dd34c647b04
7
+ data.tar.gz: 193a834dc918e0f9294604835116df78064fadfe77cc6b762d0f8c131a7d078e39bbf9619d66745f1ffa11c703968f5334bb85400bc33d632c7686291a4713e5
@@ -338,6 +338,10 @@ module Gigya
338
338
 
339
339
  return response
340
340
  end
341
+
342
+ def lookup_user(uid)
343
+ Gigya::User.find(uid, :connection => self)
344
+ end
341
345
 
342
346
  def method_missing(name, *args, &block)
343
347
  if args.size == 0
@@ -103,6 +103,7 @@ module Gigya
103
103
  # Keep refreshing with the same time period
104
104
  expiration = info["exp"] - info["iat"]
105
105
  end
106
+ expiration_time = Time.now + expiration
106
107
  result = Gigya::Connection.shared_connection.api_get("accounts", "getJWT", {:UID => gigya_user_identifier, :fields => fields.join(","), :expiration => expiration})
107
108
  token = result["id_token"]
108
109
 
@@ -110,7 +111,8 @@ module Gigya
110
111
 
111
112
  case @gigya_token_location
112
113
  when :header
113
- headers["X-Set-Authorization-Token"] = token
114
+ headers["X-Set-Authorization-Token"] = token
115
+ headers["X-Set-Authorization-Token-Expiration"] = expiration_time.to_i
114
116
  when :cookie
115
117
  cookies[GIGYA_COOKIE_PARAM] = token
116
118
  when :session
data/lib/gigya/user.rb ADDED
@@ -0,0 +1,138 @@
1
+ module Gigya
2
+ class User # A model to represent Gigya Account records provided by the API (as JSON hash)
3
+ attr_accessor :gigya_details
4
+ attr_accessor :gigya_connection
5
+
6
+ @@cache_options = {}
7
+ def self.cache_options
8
+ @@cache_options
9
+ end
10
+
11
+ def self.cache_options=(val)
12
+ @@cache_options = val
13
+ end
14
+
15
+ # A user can be initialized with a JSON hash of a Gigya account record
16
+ def initialize(json = {}, needs_caching = true)
17
+ # needs_caching is used for internal methods which load the record from cache and therefore don't need to save to cache
18
+ set_attributes(json)
19
+ save_to_cache if needs_caching
20
+
21
+ return nil
22
+ end
23
+
24
+ def set_attributes(json = {})
25
+ self.gigya_details = json
26
+ end
27
+
28
+ def reload
29
+ conn = gigya_connection || Gigya::Connection.shared_connection
30
+ set_attributes(conn.api_get("accounts", "getAccountInfo", {UID: uid}))
31
+ end
32
+
33
+ def save
34
+ info = {UID: uid}
35
+ info["profile"] = gigya_details["profile"].to_json if gigya_details["profile"].present?
36
+ info["data"] = gigya_details["data"].to_json if gigya_details["data"].present?
37
+ # What about isActive, isVerified?, password/newPassword, preferences, add/removeLoginEmails, subscriptions, lang, rba
38
+
39
+ conn = gigya_connection || Gigya::Connection.shared_connection
40
+ conn.api_post("accounts", "setAccountInfo", info)
41
+ save_to_cache
42
+
43
+ return true
44
+ end
45
+
46
+ def save_to_cache
47
+ if defined?(Rails)
48
+ u = uid
49
+ return if u.blank? # Don't save a blank object
50
+ Rails.cache.write("gigya-user-#{u}", gigya_details)
51
+ else
52
+ # Nothing to do
53
+ end
54
+ end
55
+
56
+ def self.load_from_cache(uid)
57
+ if defined?(Rails)
58
+ return Rails.cache.read("gigya-user-#{uid}")
59
+ else
60
+ return nil
61
+ end
62
+ end
63
+
64
+ def self.find_by_email(email, opts = {})
65
+ email = email.gsub('"', '') # get rid of quotes
66
+ opts = {} if opts.nil?
67
+ conn = opts[:connection] || Gigya::Connection.shared_connection
68
+ resp = conn.api_get("accounts", "search", {:query => "SELECT uid FROM accounts WHERE profile.email = \"#{email}\""})
69
+ uid = resp["results"][0]["UID"] rescue nil
70
+ return nil if uid.blank?
71
+ return self.find(uid, opts)
72
+ end
73
+
74
+ def self.find(uid, opts = {}) # Find a Gigya account record by its UID attribute
75
+ opts = {} if opts.nil?
76
+
77
+ cache_info = load_from_cache(uid)
78
+ if cache_info.present?
79
+ return self.new(cache_info, false)
80
+ else
81
+ connection = opts[:connection] || Gigya::Connection.shared_connection
82
+ response = connection.api_get("accounts", "getAccountInfo", {UID: uid})
83
+ obj = self.new(response)
84
+ obj.gigya_connection = connection
85
+ return obj
86
+ end
87
+ end
88
+
89
+ ### Gigya accessors
90
+ def uid
91
+ gigya_details["UID"] rescue nil
92
+ end
93
+
94
+ def created_at
95
+ DateTime.strptime(gigya_details["createdTimestamp"].to_s, "%Q") rescue nil
96
+ end
97
+
98
+ def full_name
99
+ [first_name, last_name].join(" ")
100
+ end
101
+
102
+ def first_name
103
+ gigya_details["profile"]["firstName"].to_s.capitalize rescue nil
104
+ end
105
+
106
+ def last_name
107
+ gigya_details["profile"]["lastName"].to_s.capitalize rescue nil
108
+ end
109
+
110
+ def email
111
+ gigya_details["profile"]["email"].to_s.downcase rescue nil
112
+ end
113
+
114
+ def birthday
115
+ profile = gigya_details["profile"]
116
+ Date.new(profile["birthYear"], profile["birthMonth"], profile["birthDay"]) rescue nil
117
+ end
118
+
119
+ def gender
120
+ gigya_details["profile"]["gender"] rescue nil
121
+ end
122
+
123
+ def gender_string
124
+ begin
125
+ case gigya_details["profile"]["gender"]
126
+ when "f"
127
+ "Female"
128
+ when "m"
129
+ "Male"
130
+ else
131
+ nil
132
+ end
133
+ rescue
134
+ nil
135
+ end
136
+ end
137
+ end
138
+ end
data/lib/gigya.rb CHANGED
@@ -3,3 +3,4 @@ require 'httparty'
3
3
  require "gigya/connection"
4
4
  require "gigya/controller_utils" if defined?(Rails)
5
5
  require "gigya/session"
6
+ require "gigya/user"
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.0.19
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Bartlett
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-06-22 00:00:00.000000000 Z
12
+ date: 2018-08-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -49,6 +49,7 @@ files:
49
49
  - lib/gigya/connection.rb
50
50
  - lib/gigya/controller_utils.rb
51
51
  - lib/gigya/session.rb
52
+ - lib/gigya/user.rb
52
53
  homepage: http://www.newmedio.com/
53
54
  licenses:
54
55
  - MIT