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 +4 -4
- data/lib/gigya/connection.rb +4 -0
- data/lib/gigya/controller_utils.rb +3 -1
- data/lib/gigya/user.rb +138 -0
- data/lib/gigya.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '08dedb042027f017d213d93046184ee54df44a71'
|
|
4
|
+
data.tar.gz: cca56000dce031c95a65fbc7eea6fcc6682b4f1c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 647521daf579395dbb2a7061a04a566ae78b84c5ebff76a30102b284846f8f2825b0314c5f6ea2eaf120f5fd654ca4f0663ced06d8428669c2338dd34c647b04
|
|
7
|
+
data.tar.gz: 193a834dc918e0f9294604835116df78064fadfe77cc6b762d0f8c131a7d078e39bbf9619d66745f1ffa11c703968f5334bb85400bc33d632c7686291a4713e5
|
data/lib/gigya/connection.rb
CHANGED
|
@@ -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
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.
|
|
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-
|
|
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
|