login_radius 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/lib/hash.rb +12 -12
  3. data/lib/login_radius.rb +12 -11
  4. data/lib/login_radius/exception.rb +4 -4
  5. data/lib/login_radius/messages.rb +41 -102
  6. data/lib/login_radius/related.rb +34 -0
  7. data/lib/login_radius/user_profile.rb +101 -102
  8. data/lib/login_radius/user_profile_getters.rb +151 -105
  9. data/lib/login_radius/version.rb +3 -3
  10. data/lib/string.rb +7 -8
  11. metadata +20 -91
  12. data/.DS_Store +0 -0
  13. data/.gitignore +0 -18
  14. data/Gemfile +0 -25
  15. data/LICENSE +0 -22
  16. data/LoginRadiusTestApp/.gitignore +0 -15
  17. data/LoginRadiusTestApp/Gemfile +0 -42
  18. data/LoginRadiusTestApp/Gemfile.lock +0 -136
  19. data/LoginRadiusTestApp/README.rdoc +0 -261
  20. data/LoginRadiusTestApp/Rakefile +0 -7
  21. data/LoginRadiusTestApp/app/assets/images/rails.png +0 -0
  22. data/LoginRadiusTestApp/app/assets/javascripts/application.js +0 -15
  23. data/LoginRadiusTestApp/app/assets/stylesheets/application.css +0 -13
  24. data/LoginRadiusTestApp/app/controllers/application_controller.rb +0 -17
  25. data/LoginRadiusTestApp/app/helpers/application_helper.rb +0 -2
  26. data/LoginRadiusTestApp/app/mailers/.gitkeep +0 -0
  27. data/LoginRadiusTestApp/app/models/.gitkeep +0 -0
  28. data/LoginRadiusTestApp/app/views/application/callback.html.erb +0 -1
  29. data/LoginRadiusTestApp/app/views/application/index.html.erb +0 -7
  30. data/LoginRadiusTestApp/app/views/layouts/application.html.erb +0 -14
  31. data/LoginRadiusTestApp/config.ru +0 -4
  32. data/LoginRadiusTestApp/config/application.rb +0 -62
  33. data/LoginRadiusTestApp/config/boot.rb +0 -6
  34. data/LoginRadiusTestApp/config/database.yml +0 -25
  35. data/LoginRadiusTestApp/config/environment.rb +0 -5
  36. data/LoginRadiusTestApp/config/environments/development.rb +0 -37
  37. data/LoginRadiusTestApp/config/environments/production.rb +0 -67
  38. data/LoginRadiusTestApp/config/environments/test.rb +0 -37
  39. data/LoginRadiusTestApp/config/initializers/backtrace_silencers.rb +0 -7
  40. data/LoginRadiusTestApp/config/initializers/inflections.rb +0 -15
  41. data/LoginRadiusTestApp/config/initializers/mime_types.rb +0 -5
  42. data/LoginRadiusTestApp/config/initializers/secret_token.rb +0 -7
  43. data/LoginRadiusTestApp/config/initializers/session_store.rb +0 -8
  44. data/LoginRadiusTestApp/config/initializers/wrap_parameters.rb +0 -14
  45. data/LoginRadiusTestApp/config/locales/en.yml +0 -5
  46. data/LoginRadiusTestApp/config/routes.rb +0 -61
  47. data/LoginRadiusTestApp/db/seeds.rb +0 -7
  48. data/LoginRadiusTestApp/lib/assets/.gitkeep +0 -0
  49. data/LoginRadiusTestApp/lib/tasks/.gitkeep +0 -0
  50. data/LoginRadiusTestApp/log/.gitkeep +0 -0
  51. data/LoginRadiusTestApp/public/404.html +0 -26
  52. data/LoginRadiusTestApp/public/422.html +0 -26
  53. data/LoginRadiusTestApp/public/500.html +0 -25
  54. data/LoginRadiusTestApp/public/favicon.ico +0 -0
  55. data/LoginRadiusTestApp/public/robots.txt +0 -5
  56. data/LoginRadiusTestApp/script/rails +0 -6
  57. data/LoginRadiusTestApp/test/fixtures/.gitkeep +0 -0
  58. data/LoginRadiusTestApp/test/functional/.gitkeep +0 -0
  59. data/LoginRadiusTestApp/test/integration/.gitkeep +0 -0
  60. data/LoginRadiusTestApp/test/performance/browsing_test.rb +0 -12
  61. data/LoginRadiusTestApp/test/test_helper.rb +0 -13
  62. data/LoginRadiusTestApp/test/unit/.gitkeep +0 -0
  63. data/LoginRadiusTestApp/vendor/assets/javascripts/.gitkeep +0 -0
  64. data/LoginRadiusTestApp/vendor/assets/stylesheets/.gitkeep +0 -0
  65. data/LoginRadiusTestApp/vendor/plugins/.gitkeep +0 -0
  66. data/README.md +0 -417
  67. data/Rakefile +0 -2
  68. data/login_radius.gemspec +0 -20
  69. data/test/.DS_Store +0 -0
  70. data/test/basic_async_test.rb +0 -29
  71. data/test/unit/.DS_Store +0 -0
  72. data/test/unit/base_test.rb +0 -11
  73. data/test/unit/user_profile_test.rb +0 -68
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f10c5dff8edd14270ca75a8696f3b5d1f9d22c48
4
+ data.tar.gz: 1344ee04d0738519948ee7a20792e4fd0df2a595
5
+ SHA512:
6
+ metadata.gz: 7e7c1190b505d9ff9ae8efc57052650be817216bb4cf6e897c7e1a81fe5a85e347c2b354241aa6ab05037bc6f41ae602342b66b20002739bc6667c08a0869094
7
+ data.tar.gz: 23267885a78f2386e3fc87fa5ca988a27569c271b358b6ff4c7f9a0f3e3d5e80a149adffd1fb808aebec5fe7dd52d2ca6f29412663c98cb352b0aa5c8a4a13ba
data/lib/hash.rb CHANGED
@@ -1,13 +1,13 @@
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
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
13
  end
data/lib/login_radius.rb CHANGED
@@ -1,11 +1,12 @@
1
- require "login_radius/version"
2
- require "login_radius/user_profile_getters"
3
- require "login_radius/messages"
4
- require "login_radius/user_profile"
5
- require "login_radius/exception"
6
- require "string"
7
- require "hash"
8
-
9
- module LoginRadius
10
-
11
- end
1
+ require "login_radius/version"
2
+ require "login_radius/user_profile_getters"
3
+ require "login_radius/messages"
4
+ require "login_radius/related"
5
+ require "login_radius/user_profile"
6
+ require "login_radius/exception"
7
+ require "string"
8
+ require "hash"
9
+
10
+ module LoginRadius
11
+
12
+ end
@@ -1,4 +1,4 @@
1
- module LoginRadius
2
- class Exception < Exception
3
- end
4
- end
1
+ module LoginRadius
2
+ class Exception < Exception
3
+ end
4
+ end
@@ -1,102 +1,41 @@
1
- module LoginRadius
2
- module Messages
3
-
4
- # Sends a message to a person using twitter
5
- #
6
- # @param sendto [String] Social ID of person you're contacting from contact list
7
- # @param subject [String]
8
- # @param message [String]
9
- # @return [Boolean] Whether or not message succeeded
10
- def send_twitter_message(sendto, subject, message)
11
- send_message({:sendto => sendto, :subject => subject, :message => message})
12
- end
13
-
14
- # Sends a message to a person using twitter
15
- #
16
- # @param sendto [String] Social ID of person you're contacting from contact list
17
- # @param subject [String]
18
- # @param message [String]
19
- # @return [Boolean] Whether or not message succeeded
20
- def send_twitter_message!(sendto, subject, message)
21
- send_message({:sendto => sendto, :subject => subject, :message => message})
22
- end
23
-
24
- # Sends a message to a person using linkedin
25
- #
26
- # @param sendto [String] Social ID of person you're contacting from contact list
27
- # @param subject [String]
28
- # @param message [String]
29
- # @return [Boolean] Whether or not message succeeded
30
- def send_linked_in_message(sendto, subject, message)
31
- send_message({:sendto => sendto, :subject => subject, :message => message})
32
- end
33
-
34
- # Sends a message to a person using linkedin
35
- #
36
- # @param sendto [String] Social ID of person you're contacting from contact list
37
- # @param subject [String]
38
- # @param message [String]
39
- # @return [Boolean] Whether or not message succeeded
40
- def send_linked_in_message!(sendto, subject, message)
41
- send_message!({:sendto => sendto, :subject => subject, :message => message})
42
- end
43
-
44
- # Sends a message to a person using facebook. Params hash takes following keys:
45
- # to(optional) :- Person's wall it's going to, if blank, is your own
46
- # title :- [optional parameter] status message title
47
- # url:- [optional parameter] any url that you want post in status message
48
- # imageurl :- [optional parameter] any image url that you want post in status message
49
- # status :- your status message
50
- # caption : [optional parameter] caption that you want post in status message
51
- # description :- [optional parameter] description that you want post in status message
52
- #
53
- # @param params [Hash]
54
- # @return [Boolean] Whether or not message succeeded
55
- def make_facebook_post!(params = {})
56
- call_api("status/update/#{secret}/#{token}", params)
57
- end
58
-
59
- # Sends a message to a person using facebook. Params hash takes following keys:
60
- # to(optional) :- Person's wall it's going to, if blank, is your own
61
- # title :- [optional parameter] status message title
62
- # url:- [optional parameter] any url that you want post in status message
63
- # imageurl :- [optional parameter] any image url that you want post in status message
64
- # status :- your status message
65
- # caption : [optional parameter] caption that you want post in status message
66
- # description :- [optional parameter] description that you want post in status message
67
- #
68
- # @param params [Hash]
69
- # @return [Boolean] Whether or not message succeeded
70
- def make_facebook_post(params = {})
71
- make_facebook_post!(params)
72
- rescue LoginRadius::Exception => e
73
- false
74
- end
75
-
76
- private
77
-
78
- # Sends a message to a person. Will use either twitter, facebook or linked in, depending
79
- # on where the person you're sending it to came from, and the keys present in the hash.
80
- # Other methods in this module describe the keys they use, they all call this method
81
- # with the proper keys for their service type.
82
- #
83
- # @param params [Hash] Params hash describing what you'd like to send.
84
- # @return [Boolean] Whether or not message succeeded
85
- def send_message!(params = {})
86
- call_api("directmessage/#{secret}/#{token}",params)
87
- end
88
-
89
- # Sends a message to a person. Will use either twitter, facebook or linked in, depending
90
- # on where the person you're sending it to came from, and the keys present in the hash.
91
- # Other methods in this module describe the keys they use, they all call this method
92
- # with the proper keys for their service type.
93
- #
94
- # @param params [Hash] Params hash describing what you'd like to send.
95
- # @return [Boolean] Whether or not message succeeded
96
- def send_message(params = {})
97
- send_message!(params)
98
- rescue LoginRadius::Exception => e
99
- false
100
- end
101
- end
102
- end
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
@@ -0,0 +1,34 @@
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,102 +1,101 @@
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://hub.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?(:id)
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
- unconverted_response = JSON.parse(response)
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
-
96
- return converted_response
97
- rescue JSON::ParserError => e
98
- 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}")
99
- end
100
- end
101
- end
102
- end
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
+ unconverted_response = JSON.parse(response)
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