login_radius 1.0.1 → 11.0.0.pre.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE.txt +21 -0
  3. data/README.md +58 -0
  4. data/lib/login_radius.rb +27 -9
  5. data/lib/login_radius/api/account/account_api.rb +581 -0
  6. data/lib/login_radius/api/account/role_api.rb +330 -0
  7. data/lib/login_radius/api/account/sott_api.rb +47 -0
  8. data/lib/login_radius/api/advanced/configuration_api.rb +57 -0
  9. data/lib/login_radius/api/advanced/consent_management_api.rb +161 -0
  10. data/lib/login_radius/api/advanced/custom_object_api.rb +316 -0
  11. data/lib/login_radius/api/advanced/custom_registration_data_api.rb +195 -0
  12. data/lib/login_radius/api/advanced/multi_factor_authentication_api.rb +606 -0
  13. data/lib/login_radius/api/advanced/re_authentication_api.rb +243 -0
  14. data/lib/login_radius/api/advanced/web_hook_api.rb +101 -0
  15. data/lib/login_radius/api/authentication/authentication_api.rb +989 -0
  16. data/lib/login_radius/api/authentication/one_touch_login_api.rb +160 -0
  17. data/lib/login_radius/api/authentication/password_less_login_api.rb +158 -0
  18. data/lib/login_radius/api/authentication/phone_authentication_api.rb +329 -0
  19. data/lib/login_radius/api/authentication/pin_authentication_api.rb +316 -0
  20. data/lib/login_radius/api/authentication/risk_based_authentication_api.rb +286 -0
  21. data/lib/login_radius/api/authentication/smart_login_api.rb +146 -0
  22. data/lib/login_radius/api/social/native_social_api.rb +255 -0
  23. data/lib/login_radius/api/social/social_api.rb +806 -0
  24. data/lib/login_radius/error.rb +7 -0
  25. data/lib/login_radius/request_client.rb +295 -0
  26. data/lib/login_radius/response.rb +12 -0
  27. data/lib/login_radius/version.rb +2 -2
  28. data/login_radius.gemspec +28 -0
  29. metadata +47 -30
  30. data/lib/hash.rb +0 -13
  31. data/lib/login_radius/exception.rb +0 -4
  32. data/lib/login_radius/messages.rb +0 -41
  33. data/lib/login_radius/related.rb +0 -34
  34. data/lib/login_radius/user_profile.rb +0 -101
  35. data/lib/login_radius/user_profile_getters.rb +0 -152
  36. data/lib/string.rb +0 -8
@@ -1,13 +0,0 @@
1
- class Hash
2
- def self.lr_convert_hash_keys(value) #lr_ appended so no method naming conflicts with other gems
3
- case value
4
- when Array
5
- value.map { |v| lr_convert_hash_keys(v) }
6
- # or `value.map(&method(:convert_hash_keys))`
7
- when Hash
8
- Hash[value.map { |k, v| [k.to_s.lr_underscore, lr_convert_hash_keys(v)] }]
9
- else
10
- value
11
- end
12
- end
13
- end
@@ -1,4 +0,0 @@
1
- module LoginRadius
2
- class Exception < Exception
3
- end
4
- end
@@ -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
@@ -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
@@ -1,152 +0,0 @@
1
- #Include this module in UserProfile, and UserProfile will magically have all the methods
2
- #I dynamically generate below!
3
- module LoginRadius
4
- module UserProfileGetters
5
- # Below is metaprogramming. This is what Ruby is magic for.
6
- # Since most API calls are similar, I define an interface for them.
7
- # You add a hash with these keys below, and it makes a method for them on loadup.
8
- # It creates both a ! version of the method, which throws errors if you don't have access
9
- # To an API endpoint, and a safe one without a ! symbol(login! vs login) that just returns false.
10
- #
11
- # @param method [Symbol] Method's name
12
- # @param route [String] Route, ex. is "/users/:token/:secret" (:something is interpolated to be self.something)
13
- # @param params [Hash] Hash of params you wish to send to the route. If you use symbols for values, are interpolated.
14
- # @param key_success_check [Symbol] Key to check for in the response to see if it was successful. Ex, :id for login, if not set, whole response hash is returned instead of true/false
15
- # @return [Boolean] Whether or not it was successful.
16
- [
17
- {
18
- :method => :access_token,
19
- :route => "api/v2/access_token",
20
- :params => {:token=>:token, :secret=>:secret},
21
- :key_success_check => :access_token
22
- },
23
- {
24
- :method => :userprofile,
25
- :route => "api/v2/userprofile",
26
- :params => {:access_token => :access_token},
27
- :key_success_check => :id
28
- },
29
- {
30
- :method => :event,
31
- :route => "api/v2/event",
32
- :params => {:access_token => :access_token}
33
- },
34
- {
35
- :method => :contact,
36
- :route => "api/v2/contact",
37
- :params => {:access_token => :access_token}
38
- },
39
- {
40
- :method => :mention,
41
- :route => "api/v2/mention",
42
- :params => {:access_token => :access_token}
43
- },
44
- {
45
- :method => :company,
46
- :route => "api/v2/company",
47
- :params => {:access_token => :access_token}
48
- },
49
- {
50
- :method => :group,
51
- :route => "api/v2/group",
52
- :params => {:access_token => :access_token}
53
- },
54
- {
55
- :method => :post,
56
- :route => "api/v2/post",
57
- :params => {:access_token => :access_token}
58
- },
59
- {
60
- :method => :status,
61
- :route => "api/v2/status",
62
- :params => {:access_token => :access_token}
63
- },
64
- {
65
- :method => :following,
66
- :route => "api/v2/following",
67
- :params => {:access_token => :access_token}
68
- },
69
- {
70
- :method => :album,
71
- :route => "api/v2/album",
72
- :params => {:access_token => :access_token}
73
- },
74
- {
75
- :method => :checkin,
76
- :route => "api/v2/checkin",
77
- :params => {:access_token => :access_token}
78
- },
79
- {
80
- :method => :like,
81
- :route => "api/v2/like",
82
- :params => {:access_token => :access_token}
83
- },
84
- {
85
- :method => :photo,
86
- :route => "api/v2/photo",
87
- :params => {:access_token => :access_token, :id => :id}
88
- },
89
- {
90
- :method => :audio,
91
- :route => "api/v2/audio",
92
- :params => {:access_token => :access_token}
93
- },
94
- {
95
- :method => :video,
96
- :route => "api/v2/video",
97
- :params => {:access_token => :access_token}
98
- },
99
- {
100
- :method => :page,
101
- :route => "api/v2/page",
102
- :params => {:access_token => :access_token, :pagename => :PageNameOrId}
103
- }
104
- ].each do |method_info|
105
- define_method(method_info[:method].to_s + "!") do
106
-
107
- #when params have symbols as values, means we actually want fields on the object,
108
- #so we dynamically generate real params.
109
- real_params = method_info[:params].inject(Hash.new) do |hash, entry|
110
- hash[entry.first] = self.send(entry.last)
111
- hash
112
- end
113
-
114
- #allows interpolation of routes - so /blah/:token becomes /blah/2323-233d3e etc.
115
- real_route = method_info[:route].gsub(/\/:(\w+)/) do |match|
116
- key = match.split(":").last
117
- "/"+self.send(key).to_s
118
- end
119
- response = call_api(real_route, real_params)
120
-
121
- if response.is_a?(Hash)
122
- #Special feature: If we get a hash back instead of an array,
123
- #we create methods on the user profile object for each key.
124
- #If we're just getting an array back, there is no need for this,
125
- #The method itself that it's called from is all that is needed to access
126
- #the data.
127
-
128
- #define methods for each key in the hash, so they are accessible:
129
- #(I dont like using method missing returns because then respond_to? doesn't work)
130
- response.each do |key, value|
131
- define_singleton_method(key) do
132
- return value
133
- end
134
- end
135
- end
136
-
137
- #raise an error if there is one, otherwise, return.
138
- raise LoginRadius::Exception.new(response[:errormessage]) if (response.is_a?(Hash) and response[:errorcode])
139
- return response
140
- end
141
-
142
- #safe version of the method that doesn't throw an exception
143
- define_method(method_info[:method]) do
144
- begin
145
- self.send(method_info[:method].to_s+"!")
146
- rescue LoginRadius::Exception
147
- return false
148
- end
149
- end
150
- end
151
- end
152
- end
@@ -1,8 +0,0 @@
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
- end