Class: LoginRadius::SocialApi

Inherits:
Object
  • Object
show all
Includes:
RequestClient
Defined in:
lib/login_radius/api/social/social_api.rb

Overview

SocialApi module

Constant Summary

Constants included from RequestClient

RequestClient::API_V2_BASE_URL, RequestClient::API_V2_BASE_URL_CONFIG, RequestClient::INIT_VECTOR, RequestClient::KEY_SIZE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RequestClient

#build_new_uri_obj, #create_hash_secret, #delete_request, #getValidationMessage, #get_request, #get_sott, #isNullOrWhiteSpace, #local_generate_sott, #post_request, #put_request

Constructor Details

#initializeSocialApi

Initializes a LoginRadius Account object with an apikey and secret Takes in a hash containing site_name(required), api_key(required), api_secret(required)

Raises:



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/login_radius/api/social/social_api.rb', line 16

def initialize
  @site_name = ENV['SITE_NAME']
  @api_key = ENV['API_KEY']
  @api_secret = ENV['API_SECRET']
  raise LoginRadius::Error.new, "'site_name' is a required option for Account class initialization." \
    unless @site_name != '' && @site_name != nil
  raise LoginRadius::Error.new, "'api_key' is a required option for Account class initialization." \
    unless @api_key != '' && @api_key != nil
  raise LoginRadius::Error.new, "'api_secret is a required option for Account class initialization." \
    unless @api_secret != '' && @api_secret != nil
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



12
13
14
# File 'lib/login_radius/api/social/social_api.rb', line 12

def api_key
  @api_key
end

#api_secretObject

Returns the value of attribute api_secret.



12
13
14
# File 'lib/login_radius/api/social/social_api.rb', line 12

def api_secret
  @api_secret
end

#site_nameObject

Returns the value of attribute site_name.



12
13
14
# File 'lib/login_radius/api/social/social_api.rb', line 12

def site_name
  @site_name
end

Instance Method Details

#exchange_access_token(token) ⇒ Object

This API Is used to translate the Request Token returned during authentication into an Access Token that can be used with other API calls.

20.1

Parameters:

  • token
    • Token generated from a successful oauth from social platform

Returns:

  • Response containing Definition of Complete Token data



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/login_radius/api/social/social_api.rb', line 34

def exchange_access_token(token)
  if isNullOrWhiteSpace(token)
    raise LoginRadius::Error.new, getValidationMessage('token')
  end

  query_parameters = {}
  query_parameters['secret'] = @api_secret
  query_parameters['token'] = token

  resource_path = 'api/v2/access_token'
  get_request(resource_path, query_parameters, {})
end

#get_active_session(token) ⇒ Object

This api is use to get all active session by Access Token.

20.11.1

Parameters:

  • token
    • Token generated from a successful oauth from social platform

Returns:

  • Response containing Definition for Complete active sessions



120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/login_radius/api/social/social_api.rb', line 120

def get_active_session(token)
  if isNullOrWhiteSpace(token)
    raise LoginRadius::Error.new, getValidationMessage('token')
  end

  query_parameters = {}
  query_parameters['key'] = @api_key
  query_parameters['secret'] = @api_secret
  query_parameters['token'] = token

  resource_path = 'api/v2/access_token/activesession'
  get_request(resource_path, query_parameters, {})
end

#get_active_session_by_account_id(account_id) ⇒ Object

This api is used to get all active sessions by AccountID(UID).

20.11.2

Parameters:

  • account_id
    • UID, the unified identifier for each user account

Returns:

  • Response containing Definition for Complete active sessions



140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/login_radius/api/social/social_api.rb', line 140

def ()
  if isNullOrWhiteSpace()
    raise LoginRadius::Error.new, getValidationMessage('account_id')
  end

  query_parameters = {}
  query_parameters['accountId'] = 
  query_parameters['key'] = @api_key
  query_parameters['secret'] = @api_secret

  resource_path = 'api/v2/access_token/activesession'
  get_request(resource_path, query_parameters, {})
end

#get_active_session_by_profile_id(profile_id) ⇒ Object

This api is used to get all active sessions by ProfileId.

20.11.3

Parameters:

  • profile_id
    • Social Provider Id

Returns:

  • Response containing Definition for Complete active sessions



160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/login_radius/api/social/social_api.rb', line 160

def get_active_session_by_profile_id(profile_id)
  if isNullOrWhiteSpace(profile_id)
    raise LoginRadius::Error.new, getValidationMessage('profile_id')
  end

  query_parameters = {}
  query_parameters['key'] = @api_key
  query_parameters['profileId'] = profile_id
  query_parameters['secret'] = @api_secret

  resource_path = 'api/v2/access_token/activesession'
  get_request(resource_path, query_parameters, {})
end

#in_validate_access_token(access_token) ⇒ Object

This api invalidates the active access token or expires an access token validity.

20.10

Parameters:

  • access_token
    • Uniquely generated identifier key by LoginRadius that is activated after successful authentication.

Returns:

  • Response containing Definition for Complete Validation data



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/login_radius/api/social/social_api.rb', line 100

def in_validate_access_token(access_token)
  if isNullOrWhiteSpace(access_token)
    raise LoginRadius::Error.new, getValidationMessage('access_token')
  end

  query_parameters = {}
  query_parameters['access_token'] = access_token
  query_parameters['key'] = @api_key
  query_parameters['secret'] = @api_secret

  resource_path = 'api/v2/access_token/invalidate'
  get_request(resource_path, query_parameters, {})
end

#refresh_access_token(access_token, expires_in, is_web = false) ⇒ Object

The Refresh Access Token API is used to refresh the provider access token after authentication. It will be valid for up to 60 days on LoginRadius depending on the provider. In order to use the access token in other APIs, always refresh the token using this API.
Supported Providers : Facebook,Yahoo,Google,Twitter, Linkedin.
Contact LoginRadius support team to enable this API.

20.2

Parameters:

  • access_token
    • Uniquely generated identifier key by LoginRadius that is activated after successful authentication.

  • expires_in
    • Allows you to specify a desired expiration time in minutes for the newly issued access token.

  • is_web (defaults to: false)
    • Is web or not.

Returns:

  • Response containing Definition of Complete Token data



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/login_radius/api/social/social_api.rb', line 55

def refresh_access_token(access_token, expires_in, is_web = false)
  if isNullOrWhiteSpace(access_token)
    raise LoginRadius::Error.new, getValidationMessage('access_token')
  end

  query_parameters = {}
  query_parameters['access_token'] = access_token
  query_parameters['secret'] = @api_secret
  unless expires_in == false
    query_parameters['expiresIn'] = expires_in
  end
  unless is_web == false
    query_parameters['isWeb'] = is_web
  end

  resource_path = 'api/v2/access_token/refresh'
  get_request(resource_path, query_parameters, {})
end

#validate_access_token(access_token) ⇒ Object

This API validates access token, if valid then returns a response with its expiry otherwise error.

20.9

Parameters:

  • access_token
    • Uniquely generated identifier key by LoginRadius that is activated after successful authentication.

Returns:

  • Response containing Definition of Complete Token data



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/login_radius/api/social/social_api.rb', line 80

def validate_access_token(access_token)
  if isNullOrWhiteSpace(access_token)
    raise LoginRadius::Error.new, getValidationMessage('access_token')
  end

  query_parameters = {}
  query_parameters['access_token'] = access_token
  query_parameters['key'] = @api_key
  query_parameters['secret'] = @api_secret

  resource_path = 'api/v2/access_token/validate'
  get_request(resource_path, query_parameters, {})
end