login_radius 1.0.1 → 2.0.0
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/LICENSE +22 -0
- data/README.md +52 -0
- data/lib/hash.rb +11 -12
- data/lib/login_radius/account_api.rb +130 -0
- data/lib/login_radius/basic_api.rb +389 -0
- data/lib/login_radius/custom_object_api.rb +347 -0
- data/lib/login_radius/exception.rb +4 -4
- data/lib/login_radius/raas_api.rb +102 -0
- data/lib/login_radius/user_api.rb +283 -0
- data/lib/login_radius/version.rb +3 -3
- data/lib/login_radius.rb +13 -12
- data/lib/string.rb +7 -7
- metadata +17 -41
- data/lib/login_radius/messages.rb +0 -41
- data/lib/login_radius/related.rb +0 -34
- data/lib/login_radius/user_profile.rb +0 -101
- data/lib/login_radius/user_profile_getters.rb +0 -152
@@ -0,0 +1,283 @@
|
|
1
|
+
module LoginRadiusRaas
|
2
|
+
module UserApi
|
3
|
+
#
|
4
|
+
# This API is used to create a new user on your site. This API bypasses the normal email verification process and manually creates the user for your system.
|
5
|
+
#
|
6
|
+
# params = {:emailid => "example@example.com",
|
7
|
+
# :password => "FakePass",
|
8
|
+
# :firstname => "Joe",
|
9
|
+
# :lastname => "Smith",
|
10
|
+
# :gender => "M",
|
11
|
+
# :birthdate => "11-08-1987",
|
12
|
+
# :Country => "USA",
|
13
|
+
# :city => "Chicago",
|
14
|
+
# :state => "Illinois ",
|
15
|
+
# :phonenumber => "1232333232",
|
16
|
+
# :address1 => "23/43, II Street",
|
17
|
+
# :address2 => "Near Paris garden",
|
18
|
+
# :company => "Orange Inc.",
|
19
|
+
# :postalcode => "43435",
|
20
|
+
# :emailsubscription => "true",
|
21
|
+
# :customfields => {
|
22
|
+
# :example_field1 => "some data 1",
|
23
|
+
# :example_field2 => "some data 2",
|
24
|
+
# :example_field3 => "some data 3"
|
25
|
+
# }
|
26
|
+
# }
|
27
|
+
#
|
28
|
+
# return all user profile
|
29
|
+
#
|
30
|
+
def user_create_profile!(params)
|
31
|
+
api_client("raas/v1/user", {}, params, 'json');
|
32
|
+
end
|
33
|
+
|
34
|
+
def user_create_profile(params={})
|
35
|
+
user_create_profile!(params)
|
36
|
+
rescue LoginRadiusRaas::Exception => e
|
37
|
+
false
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# This API used to register user from server side, verification email will be send to provided email address
|
42
|
+
#
|
43
|
+
# params = {"emailid => "example@example.com",
|
44
|
+
# :password => "FakePass",
|
45
|
+
# :firstname => "Joe",
|
46
|
+
# :lastname => "Smith",
|
47
|
+
# :gender => "M",
|
48
|
+
# :birthdate => "11-08-1987",
|
49
|
+
# :Country => "USA",
|
50
|
+
# :city => "Chicago",
|
51
|
+
# :state => "Illinois ",
|
52
|
+
# :phonenumber => "1232333232",
|
53
|
+
# :address1 => "23/43, II Street",
|
54
|
+
# :address2 => "Near Paris garden",
|
55
|
+
# :company => "Orange Inc.",
|
56
|
+
# :postalcode => "43435",
|
57
|
+
# :emailsubscription => "true",
|
58
|
+
# :customfields => {
|
59
|
+
# :example_field1 => "some data 1",
|
60
|
+
# :example_field2 => "some data 2",
|
61
|
+
# :example_field3 => "some data 3"
|
62
|
+
# },
|
63
|
+
# :EmailVerificationUrl => "http://yoursite.com/verifyemail"
|
64
|
+
# }
|
65
|
+
#
|
66
|
+
# return "isPosted": "true"
|
67
|
+
#
|
68
|
+
def user_registration!(params)
|
69
|
+
api_client("raas/v1/user/register", {}, params, 'json');
|
70
|
+
end
|
71
|
+
|
72
|
+
def user_registration(params)
|
73
|
+
user_registration!(params)
|
74
|
+
rescue LoginRadiusRaas::Exception => e
|
75
|
+
false
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# This API is used to Modify/Update details of an existing user.
|
80
|
+
#
|
81
|
+
# params = {
|
82
|
+
# :firstname => 'first name',
|
83
|
+
# :lastname => 'last name',
|
84
|
+
# :gender => 'm',
|
85
|
+
# :birthdate => 'MM-DD-YYYY',
|
86
|
+
# ....................
|
87
|
+
# ....................
|
88
|
+
# }
|
89
|
+
#
|
90
|
+
# return {“isPosted”: “true”}
|
91
|
+
#
|
92
|
+
def user_edit_profile!(userId, params)
|
93
|
+
api_client("raas/v1/user", {:userid => userId}, params, 'json');
|
94
|
+
end
|
95
|
+
|
96
|
+
def user_edit_profile(userId, params={})
|
97
|
+
user_edit_profile!(userId, params)
|
98
|
+
rescue LoginRadiusRaas::Exception => e
|
99
|
+
false
|
100
|
+
end
|
101
|
+
|
102
|
+
#
|
103
|
+
# This API is used to check email of an existing user.
|
104
|
+
#
|
105
|
+
# email = example@provider.com
|
106
|
+
#
|
107
|
+
# return {“isExist”: “true”}
|
108
|
+
#
|
109
|
+
|
110
|
+
def check_email!(email)
|
111
|
+
api_client("raas/client/auth/checkEmail", {:email => email});
|
112
|
+
end
|
113
|
+
|
114
|
+
def check_email(email)
|
115
|
+
check_email!(email)
|
116
|
+
rescue LoginRadiusRaas::Exception => e
|
117
|
+
false
|
118
|
+
end
|
119
|
+
|
120
|
+
#
|
121
|
+
# This API is used to get token for forgot password of an existing user.
|
122
|
+
#
|
123
|
+
# email = example@provider.com
|
124
|
+
#
|
125
|
+
# return object of token and provider list
|
126
|
+
#
|
127
|
+
|
128
|
+
def user_forgot_password_token!(email)
|
129
|
+
api_client("raas/v1/user", {:email => email});
|
130
|
+
end
|
131
|
+
|
132
|
+
def user_forgot_password_token(email)
|
133
|
+
user_forgot_password_token!(email)
|
134
|
+
rescue LoginRadiusRaas::Exception => e
|
135
|
+
false
|
136
|
+
end
|
137
|
+
|
138
|
+
#
|
139
|
+
# This API deletes the RaaS account of the user and allowing them to begin the registration process
|
140
|
+
#
|
141
|
+
# return [{"isPosted": "true"}]
|
142
|
+
#
|
143
|
+
def user_delete!(uid)
|
144
|
+
api_client("raas/v1/user/delete", {:UID => uid});
|
145
|
+
end
|
146
|
+
|
147
|
+
def user_delete(uid)
|
148
|
+
user_delete!(uid)
|
149
|
+
rescue LoginRadiusRaas::Exception => e
|
150
|
+
false
|
151
|
+
end
|
152
|
+
|
153
|
+
#
|
154
|
+
# This API is used to create a user using the currently logged in social provider.
|
155
|
+
#
|
156
|
+
# params = {
|
157
|
+
# :accountid => uid,
|
158
|
+
# :password => 'xxxxxxxxxx',
|
159
|
+
# :emailid => 'example@doamin.com'
|
160
|
+
# }
|
161
|
+
#
|
162
|
+
# return {“isPosted”: “true”}
|
163
|
+
#
|
164
|
+
def user_set_password!(params)
|
165
|
+
api_client("raas/v1/account/profile", {}, params, 'json');
|
166
|
+
end
|
167
|
+
|
168
|
+
def user_set_password(params={})
|
169
|
+
user_set_password!(params)
|
170
|
+
rescue LoginRadiusRaas::Exception => e
|
171
|
+
false
|
172
|
+
end
|
173
|
+
|
174
|
+
#
|
175
|
+
# This API is used to Update/Change the user’s password.
|
176
|
+
#
|
177
|
+
# userId => 'xxxxxxxxxx';
|
178
|
+
# oldpassword => 'xxxxxxxxxx';
|
179
|
+
# newpassword => 'xxxxxxxxxx';
|
180
|
+
#
|
181
|
+
# return {“isPosted”: “true”}
|
182
|
+
#
|
183
|
+
def user_change_password!(uid, oldPassword, newPassword)
|
184
|
+
data = {:oldpassword => oldPassword, :newpassword => newPassword}
|
185
|
+
api_client("raas/v1/account/password", {:accountid => uid}, data)
|
186
|
+
end
|
187
|
+
|
188
|
+
def user_change_password(uid, oldPassword, newPassword)
|
189
|
+
user_change_password!(uid, oldPassword, newPassword)
|
190
|
+
rescue LoginRadiusRaas::Exception => e
|
191
|
+
false
|
192
|
+
end
|
193
|
+
|
194
|
+
#
|
195
|
+
# This API is used to set the password of user, used in admin section.
|
196
|
+
#
|
197
|
+
# userId = 'xxxxxx'; // RaaS account ID only not Social Account ID
|
198
|
+
# password = 'xxxxxxxxxx';
|
199
|
+
# return {“isPosted”: “true”}
|
200
|
+
#
|
201
|
+
def user_set_password_by_admin!(userId, password)
|
202
|
+
parameter = {:userid => userId, :action => 'set'}
|
203
|
+
api_client('raas/v1/user/password', parameter, {:password => password});
|
204
|
+
end
|
205
|
+
|
206
|
+
def user_set_password_by_admin(userId, password)
|
207
|
+
user_set_password_by_admin!(userId, password)
|
208
|
+
rescue LoginRadiusRaas::Exception => e
|
209
|
+
false
|
210
|
+
end
|
211
|
+
|
212
|
+
#
|
213
|
+
# This API is used to authenticate users and returns the profile data associated with the authenticated user.
|
214
|
+
#
|
215
|
+
# username = 'username';//email id
|
216
|
+
# password = 'xxxxxxxxxx';
|
217
|
+
#
|
218
|
+
# return all user profile
|
219
|
+
#
|
220
|
+
def user_authentication!(username, password)
|
221
|
+
api_client('raas/v1/user', {:username => username, :password => password});
|
222
|
+
end
|
223
|
+
|
224
|
+
def user_authentication(username, password)
|
225
|
+
user_authentication!(username, password)
|
226
|
+
rescue LoginRadiusRaas::Exception => e
|
227
|
+
false
|
228
|
+
end
|
229
|
+
|
230
|
+
#
|
231
|
+
# This API retrieves the profile data associated with the specific user using the users unique UserID
|
232
|
+
#
|
233
|
+
# userId = 'xxxxxxxxxx';
|
234
|
+
#
|
235
|
+
# return all user profile
|
236
|
+
#
|
237
|
+
def user_get_profile_by_id!(userId)
|
238
|
+
api_client('raas/v1/user', {:userid => userId});
|
239
|
+
end
|
240
|
+
|
241
|
+
def user_get_profile_by_id(userId)
|
242
|
+
user_get_profile_by_id!(userId)
|
243
|
+
rescue LoginRadiusRaas::Exception => e
|
244
|
+
false
|
245
|
+
end
|
246
|
+
|
247
|
+
#
|
248
|
+
# This API retrieves the profile data associated with the specific user using the users unique Email Address
|
249
|
+
#
|
250
|
+
# email = 'xxxxxxxxxx@xxxxxxxx.xxx';
|
251
|
+
#
|
252
|
+
# return all user profile
|
253
|
+
#
|
254
|
+
def user_get_profile_by_email!(email)
|
255
|
+
api_client('raas/v1/user', {:emailid => email});
|
256
|
+
end
|
257
|
+
|
258
|
+
def user_get_profile_by_email(email)
|
259
|
+
user_get_profile_by_email!(email)
|
260
|
+
rescue LoginRadiusRaas::Exception => e
|
261
|
+
false
|
262
|
+
end
|
263
|
+
|
264
|
+
#
|
265
|
+
# This API is used to block or un-block a user using the users unique UserID (UID).
|
266
|
+
#
|
267
|
+
# uid = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
|
268
|
+
# action = true/false(boolean)
|
269
|
+
#
|
270
|
+
# return all user profile
|
271
|
+
#/
|
272
|
+
def user_set_status!(uid, action)
|
273
|
+
api_client('raas/v1/user/status', {:accountid => uid}, {:isblock => action});
|
274
|
+
end
|
275
|
+
|
276
|
+
def user_set_status(uid, action = true)
|
277
|
+
user_set_status!(uid, action)
|
278
|
+
rescue LoginRadiusRaas::Exception => e
|
279
|
+
false
|
280
|
+
end
|
281
|
+
|
282
|
+
end
|
283
|
+
end
|
data/lib/login_radius/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "
|
3
|
-
end
|
1
|
+
module LoginRadiusRaas
|
2
|
+
VERSION = "2.0.0"
|
3
|
+
end
|
data/lib/login_radius.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
require "login_radius/version"
|
2
|
-
require "login_radius/
|
3
|
-
require "login_radius/
|
4
|
-
require "login_radius/
|
5
|
-
require "login_radius/
|
6
|
-
require "login_radius/exception"
|
7
|
-
require "
|
8
|
-
require "
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
require "login_radius/version"
|
2
|
+
require "login_radius/user_api"
|
3
|
+
require "login_radius/account_api"
|
4
|
+
require "login_radius/basic_api"
|
5
|
+
require "login_radius/custom_object_api"
|
6
|
+
require "login_radius/exception"
|
7
|
+
require "login_radius/raas_api"
|
8
|
+
require "string"
|
9
|
+
require "hash"
|
10
|
+
|
11
|
+
module LoginRadiusRaas
|
12
|
+
|
13
|
+
end
|
data/lib/string.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
class String
|
2
|
-
def lr_underscore #lr_ appended so no method naming conflicts with other gems
|
3
|
-
self.gsub(/::/, '/').
|
4
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1 \2').
|
5
|
-
gsub(/([a-z\d])([A-Z])/,'\1 \2').
|
6
|
-
downcase
|
7
|
-
end
|
1
|
+
class String
|
2
|
+
def lr_underscore #lr_ appended so no method naming conflicts with other gems
|
3
|
+
self.gsub(/::/, '/').
|
4
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1 \2').
|
5
|
+
gsub(/([a-z\d])([A-Z])/,'\1 \2').
|
6
|
+
downcase
|
7
|
+
end
|
8
8
|
end
|
metadata
CHANGED
@@ -1,59 +1,34 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: login_radius
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LoginRadius
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
name: em-http-request
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '>='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: em-synchrony
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
description: Ruby wrapper for LoginRadius API v2
|
11
|
+
date: 2016-04-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby wrapper for User Registration API
|
42
14
|
email:
|
43
15
|
- hello@loginradius.com
|
44
16
|
executables: []
|
45
17
|
extensions: []
|
46
18
|
extra_rdoc_files: []
|
47
19
|
files:
|
20
|
+
- LICENSE
|
21
|
+
- README.md
|
48
22
|
- lib/hash.rb
|
49
23
|
- lib/login_radius.rb
|
50
|
-
- lib/
|
24
|
+
- lib/login_radius/account_api.rb
|
25
|
+
- lib/login_radius/basic_api.rb
|
26
|
+
- lib/login_radius/custom_object_api.rb
|
51
27
|
- lib/login_radius/exception.rb
|
52
|
-
- lib/login_radius/
|
53
|
-
- lib/login_radius/
|
54
|
-
- lib/login_radius/user_profile.rb
|
55
|
-
- lib/login_radius/user_profile_getters.rb
|
28
|
+
- lib/login_radius/raas_api.rb
|
29
|
+
- lib/login_radius/user_api.rb
|
56
30
|
- lib/login_radius/version.rb
|
31
|
+
- lib/string.rb
|
57
32
|
homepage: https://www.loginradius.com
|
58
33
|
licenses:
|
59
34
|
- MIT
|
@@ -64,18 +39,19 @@ require_paths:
|
|
64
39
|
- lib
|
65
40
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
41
|
requirements:
|
67
|
-
- -
|
42
|
+
- - ">="
|
68
43
|
- !ruby/object:Gem::Version
|
69
44
|
version: '0'
|
70
45
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
46
|
requirements:
|
72
|
-
- -
|
47
|
+
- - ">="
|
73
48
|
- !ruby/object:Gem::Version
|
74
49
|
version: '0'
|
75
50
|
requirements: []
|
76
51
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.
|
52
|
+
rubygems_version: 2.2.2
|
78
53
|
signing_key:
|
79
54
|
specification_version: 4
|
80
|
-
summary: Is a ruby wrapper for
|
55
|
+
summary: Is a ruby wrapper for User Registration API
|
81
56
|
test_files: []
|
57
|
+
has_rdoc:
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module LoginRadius
|
2
|
-
module Messages
|
3
|
-
|
4
|
-
# Sends a Status message to on facebook. Params hash takes following keys:
|
5
|
-
# access_token :- [Required parameter] access token
|
6
|
-
# title :- [optional parameter] status message title
|
7
|
-
# url:- [optional parameter] any url that you want post in status message
|
8
|
-
# imageurl :- [optional parameter] any image url that you want post in status message
|
9
|
-
# status :- your status message
|
10
|
-
# caption : [optional parameter] caption that you want post in status message
|
11
|
-
# description :- [optional parameter] description that you want post in status message
|
12
|
-
#
|
13
|
-
# @param params [Hash]
|
14
|
-
# @return [Boolean] Whether or not message succeeded
|
15
|
-
def post_status!(params = {})
|
16
|
-
call_api("api/v2/status/js", params)
|
17
|
-
end
|
18
|
-
def post_status(params = {})
|
19
|
-
post_status!(params)
|
20
|
-
rescue LoginRadius::Exception => e
|
21
|
-
false
|
22
|
-
end
|
23
|
-
|
24
|
-
# Sends a Direct message to on facebook. Params hash takes following keys:
|
25
|
-
# access_token :- [Required parameter] access token
|
26
|
-
# to :- [Required parameter] with whom you want post you direct message
|
27
|
-
# subject :- [optional parameter] any subject that you want post in direct message
|
28
|
-
# message :- [optional parameter] any message that you want post in direct message
|
29
|
-
#
|
30
|
-
# @param params [Hash]
|
31
|
-
# @return [Boolean] Whether or not message succeeded
|
32
|
-
def direct_message!(params = {})
|
33
|
-
call_api("api/v2/message/js", params)
|
34
|
-
end
|
35
|
-
def direct_message(params = {})
|
36
|
-
direct_message!(params)
|
37
|
-
rescue LoginRadius::Exception => e
|
38
|
-
false
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/lib/login_radius/related.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
module LoginRadius
|
2
|
-
module Related
|
3
|
-
# fetch images with respact album id. Params hash takes following keys:
|
4
|
-
# access_token :- [Required parameter] access token
|
5
|
-
# albumid :- [Required parameter] albumid for fetch images from album
|
6
|
-
#
|
7
|
-
# @param params [Hash]
|
8
|
-
# @return [Boolean] Whether or not message succeeded
|
9
|
-
|
10
|
-
def photo!(params = {})
|
11
|
-
call_api("api/v2/photo", params)
|
12
|
-
end
|
13
|
-
def photo(params = {})
|
14
|
-
photo!(params)
|
15
|
-
rescue LoginRadius::Exception => e
|
16
|
-
false
|
17
|
-
end
|
18
|
-
|
19
|
-
# fetch page with respact PageNameOrId. Params hash takes following keys:
|
20
|
-
# access_token :- [Required parameter] access token
|
21
|
-
# pagename :- [Required parameter] pagename for fetch page details from provider
|
22
|
-
#
|
23
|
-
# @param params [Hash]
|
24
|
-
# @return [Boolean] Whether or not message succeeded
|
25
|
-
def page!(params = {})
|
26
|
-
call_api("api/v2/page", params)
|
27
|
-
end
|
28
|
-
def page(params = {})
|
29
|
-
page!(params)
|
30
|
-
rescue LoginRadius::Exception => e
|
31
|
-
false
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
module LoginRadius
|
3
|
-
class UserProfile
|
4
|
-
include UserProfileGetters
|
5
|
-
include Messages
|
6
|
-
|
7
|
-
attr_accessor :secret, :token, :async
|
8
|
-
|
9
|
-
API_ROOT = "https://api.loginradius.com/"
|
10
|
-
|
11
|
-
# Takes a hash of account secret, token, and connection type(net_http or em_http)
|
12
|
-
# and uses it to auth against the LoginRadius API. Then it returns the Account object. The
|
13
|
-
# async key is optional, if set to true, will use Em::HTTP instead of Net::HTTP.
|
14
|
-
#
|
15
|
-
# @param opts [Hash] Must have keys :token, :secret, and :async(optional)
|
16
|
-
# @return [LoginRadius::Account]
|
17
|
-
def initialize(opts = {})
|
18
|
-
self.token = opts[:token]
|
19
|
-
self.secret = opts[:secret]
|
20
|
-
self.async = opts[:async]
|
21
|
-
raise LoginRadius::Exception.new("Invalid Request") unless token
|
22
|
-
raise LoginRadius::Exception.new("Invalid Token") unless guid_valid?(token)
|
23
|
-
raise LoginRadius::Exception.new("Invalid Secret") unless guid_valid?(secret)
|
24
|
-
end
|
25
|
-
|
26
|
-
# Takes a guid and returns whether or not it is valid.
|
27
|
-
#
|
28
|
-
# @param guid [String]
|
29
|
-
# @return [Boolean]
|
30
|
-
def guid_valid?(guid)
|
31
|
-
guid.match(/^\{?[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12}\}?$/i)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Returns whether or not this object is authed.
|
35
|
-
#
|
36
|
-
# @return [Boolean]
|
37
|
-
def authenticated?
|
38
|
-
respond_to?(:access_token)
|
39
|
-
end
|
40
|
-
|
41
|
-
# Generic GET call function that other submodules can use to hit the API.
|
42
|
-
#
|
43
|
-
# @param url [String] Target URL to fetch data from.
|
44
|
-
# @param params [Hash] Parameters to send
|
45
|
-
# @return data [Hash] Parsed JSON data from the call
|
46
|
-
def call_api(url, params = {})
|
47
|
-
url = API_ROOT+url unless url.match(/^#{API_ROOT}/) #in case api root is included,
|
48
|
-
#as would happen in a recursive redirect call.
|
49
|
-
|
50
|
-
if async
|
51
|
-
#UNTESTED
|
52
|
-
#if async is true, we expect you to be using EM::Synchrony submodule and to be in an eventloop,
|
53
|
-
#like with a thin server using the Cramp framework. Otherwise, this method blows up.
|
54
|
-
response = EM::Synchrony.sync EventMachine::HttpRequest.new(url).aget :redirects => 2, :query => params
|
55
|
-
response = response.response
|
56
|
-
else
|
57
|
-
#synchronous version of the call.
|
58
|
-
url_obj = URI.parse(url)
|
59
|
-
url_obj.query = URI.encode_www_form(params)
|
60
|
-
|
61
|
-
http = Net::HTTP.new(url_obj.host, url_obj.port)
|
62
|
-
http.use_ssl = true
|
63
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
64
|
-
response = http.get(url_obj.request_uri)
|
65
|
-
|
66
|
-
if response.is_a?(Net::HTTPTemporaryRedirect)
|
67
|
-
#for some reason, we always get redirected when calling server first time.
|
68
|
-
#so if we do, we scan body for the redirect url, and the scan returns
|
69
|
-
#an array of arrays. So we grab the array we know has what we need,
|
70
|
-
#and grab the first element.
|
71
|
-
redirect_url_array = response.body.scan(/<a href=\"([^>]+)\">/i)[1]
|
72
|
-
redirect_url = redirect_url_array.first
|
73
|
-
return call_api(redirect_url, params)
|
74
|
-
end
|
75
|
-
|
76
|
-
response = response.body
|
77
|
-
end
|
78
|
-
|
79
|
-
# For some reason, this API returns true/false instead of JSON responses for certain calls.
|
80
|
-
# We catch this here.
|
81
|
-
return true if response.match(/^true/i)
|
82
|
-
return false if response.match(/^false/i)
|
83
|
-
|
84
|
-
#We rescue this because sometimes the API returns HTML pages(which can't be JSON parsed)
|
85
|
-
#This mostly happens when people use expired tokens. So we go ahead and raise an exception
|
86
|
-
#About it if it gets caught.
|
87
|
-
begin
|
88
|
-
converted_response = JSON.parse(response, :symbolize_names => true)
|
89
|
-
#it's all String keys in CamelCase above, so...
|
90
|
-
# IF we got a hash back, convert it directly, if its an array, convert each item which is a hash
|
91
|
-
# into snake case
|
92
|
-
#converted_response = unconverted_response.is_a?(Hash) ?
|
93
|
-
# Hash.lr_convert_hash_keys(unconverted_response).symbolize_keys! :
|
94
|
-
# unconverted_response.map { |item| Hash.lr_convert_hash_keys(item).symbolize_keys!
|
95
|
-
return converted_response
|
96
|
-
rescue JSON::ParserError => e
|
97
|
-
raise LoginRadius::Exception.new("A JSON parsing error occured because the API returned an HTML page instead of JSON. This happens mostly when you're using an expired Token. Specifics: #{e.message}")
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|