login_radius 0.0.1

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.
Files changed (71) hide show
  1. data/.DS_Store +0 -0
  2. data/.gitignore +18 -0
  3. data/Gemfile +25 -0
  4. data/LICENSE +22 -0
  5. data/LoginRadiusTestApp/.gitignore +15 -0
  6. data/LoginRadiusTestApp/Gemfile +42 -0
  7. data/LoginRadiusTestApp/Gemfile.lock +136 -0
  8. data/LoginRadiusTestApp/README.rdoc +261 -0
  9. data/LoginRadiusTestApp/Rakefile +7 -0
  10. data/LoginRadiusTestApp/app/assets/images/rails.png +0 -0
  11. data/LoginRadiusTestApp/app/assets/javascripts/application.js +15 -0
  12. data/LoginRadiusTestApp/app/assets/stylesheets/application.css +13 -0
  13. data/LoginRadiusTestApp/app/controllers/application_controller.rb +17 -0
  14. data/LoginRadiusTestApp/app/helpers/application_helper.rb +2 -0
  15. data/LoginRadiusTestApp/app/mailers/.gitkeep +0 -0
  16. data/LoginRadiusTestApp/app/models/.gitkeep +0 -0
  17. data/LoginRadiusTestApp/app/views/application/callback.html.erb +1 -0
  18. data/LoginRadiusTestApp/app/views/application/index.html.erb +7 -0
  19. data/LoginRadiusTestApp/app/views/layouts/application.html.erb +14 -0
  20. data/LoginRadiusTestApp/config/application.rb +62 -0
  21. data/LoginRadiusTestApp/config/boot.rb +6 -0
  22. data/LoginRadiusTestApp/config/database.yml +25 -0
  23. data/LoginRadiusTestApp/config/environment.rb +5 -0
  24. data/LoginRadiusTestApp/config/environments/development.rb +37 -0
  25. data/LoginRadiusTestApp/config/environments/production.rb +67 -0
  26. data/LoginRadiusTestApp/config/environments/test.rb +37 -0
  27. data/LoginRadiusTestApp/config/initializers/backtrace_silencers.rb +7 -0
  28. data/LoginRadiusTestApp/config/initializers/inflections.rb +15 -0
  29. data/LoginRadiusTestApp/config/initializers/mime_types.rb +5 -0
  30. data/LoginRadiusTestApp/config/initializers/secret_token.rb +7 -0
  31. data/LoginRadiusTestApp/config/initializers/session_store.rb +8 -0
  32. data/LoginRadiusTestApp/config/initializers/wrap_parameters.rb +14 -0
  33. data/LoginRadiusTestApp/config/locales/en.yml +5 -0
  34. data/LoginRadiusTestApp/config/routes.rb +61 -0
  35. data/LoginRadiusTestApp/config.ru +4 -0
  36. data/LoginRadiusTestApp/db/seeds.rb +7 -0
  37. data/LoginRadiusTestApp/lib/assets/.gitkeep +0 -0
  38. data/LoginRadiusTestApp/lib/tasks/.gitkeep +0 -0
  39. data/LoginRadiusTestApp/log/.gitkeep +0 -0
  40. data/LoginRadiusTestApp/public/404.html +26 -0
  41. data/LoginRadiusTestApp/public/422.html +26 -0
  42. data/LoginRadiusTestApp/public/500.html +25 -0
  43. data/LoginRadiusTestApp/public/favicon.ico +0 -0
  44. data/LoginRadiusTestApp/public/robots.txt +5 -0
  45. data/LoginRadiusTestApp/script/rails +6 -0
  46. data/LoginRadiusTestApp/test/fixtures/.gitkeep +0 -0
  47. data/LoginRadiusTestApp/test/functional/.gitkeep +0 -0
  48. data/LoginRadiusTestApp/test/integration/.gitkeep +0 -0
  49. data/LoginRadiusTestApp/test/performance/browsing_test.rb +12 -0
  50. data/LoginRadiusTestApp/test/test_helper.rb +13 -0
  51. data/LoginRadiusTestApp/test/unit/.gitkeep +0 -0
  52. data/LoginRadiusTestApp/vendor/assets/javascripts/.gitkeep +0 -0
  53. data/LoginRadiusTestApp/vendor/assets/stylesheets/.gitkeep +0 -0
  54. data/LoginRadiusTestApp/vendor/plugins/.gitkeep +0 -0
  55. data/README.md +417 -0
  56. data/Rakefile +2 -0
  57. data/lib/hash.rb +13 -0
  58. data/lib/login_radius/exception.rb +4 -0
  59. data/lib/login_radius/messages.rb +102 -0
  60. data/lib/login_radius/user_profile.rb +102 -0
  61. data/lib/login_radius/user_profile_getters.rb +106 -0
  62. data/lib/login_radius/version.rb +3 -0
  63. data/lib/login_radius.rb +11 -0
  64. data/lib/string.rb +9 -0
  65. data/login_radius.gemspec +20 -0
  66. data/test/.DS_Store +0 -0
  67. data/test/basic_async_test.rb +29 -0
  68. data/test/unit/.DS_Store +0 -0
  69. data/test/unit/base_test.rb +11 -0
  70. data/test/unit/user_profile_test.rb +68 -0
  71. metadata +152 -0
@@ -0,0 +1,106 @@
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 => :login,
19
+ :route => "userprofile.ashx",
20
+ :params => {:token => :token, :apisecrete => :secret},
21
+ :key_success_check => :id
22
+ },
23
+ {
24
+ :method => :twitter_mentions,
25
+ :route => "status/mentions/:secret/:token",
26
+ :params => {}
27
+ },
28
+ {
29
+ :method => :twitter_timeline,
30
+ :route => "status/timeline/:secret/:token",
31
+ :params => {}
32
+ },
33
+ {
34
+ :method => :linked_in_companies,
35
+ :route => "GetCompany/:secret/:token",
36
+ :params => {}
37
+ },
38
+ {
39
+ :method => :contacts,
40
+ :route => "contacts/:secret/:token",
41
+ :params => {}
42
+ },
43
+ {
44
+ :method => :facebook_groups,
45
+ :route => "GetGroups/:secret/:token",
46
+ :params => {}
47
+ },
48
+ {
49
+ :method => :facebook_posts,
50
+ :route => "GetPosts/:secret/:token",
51
+ :params => {}
52
+ },
53
+ {
54
+ :method => :facebook_events,
55
+ :route => "GetEvents/:secret/:token",
56
+ :params => {}
57
+ }
58
+ ].each do |method_info|
59
+ define_method(method_info[:method].to_s + "!") do
60
+
61
+ #when params have symbols as values, means we actually want fields on the object,
62
+ #so we dynamically generate real params.
63
+ real_params = method_info[:params].inject(Hash.new) do |hash, entry|
64
+ hash[entry.first] = self.send(entry.last)
65
+ hash
66
+ end
67
+
68
+ #allows interpolation of routes - so /blah/:token becomes /blah/2323-233d3e etc.
69
+ real_route = method_info[:route].gsub(/\/:(\w+)/) do |match|
70
+ key = match.split(":").last
71
+ "/"+self.send(key).to_s
72
+ end
73
+ response = call_api(real_route, real_params)
74
+
75
+ if response.is_a?(Hash)
76
+ #Special feature: If we get a hash back instead of an array,
77
+ #we create methods on the user profile object for each key.
78
+ #If we're just getting an array back, there is no need for this,
79
+ #The method itself that it's called from is all that is needed to access
80
+ #the data.
81
+
82
+ #define methods for each key in the hash, so they are accessible:
83
+ #(I dont like using method missing returns because then respond_to? doesn't work)
84
+ response.each do |key, value|
85
+ define_singleton_method(key) do
86
+ return value
87
+ end
88
+ end
89
+ end
90
+
91
+ #raise an error if there is one, otherwise, return.
92
+ raise LoginRadius::Exception.new(response[:errormessage]) if (response.is_a?(Hash) and response[:errorcode])
93
+ return response
94
+ end
95
+
96
+ #safe version of the method that doesn't throw an exception
97
+ define_method(method_info[:method]) do
98
+ begin
99
+ self.send(method_info[:method].to_s+"!")
100
+ rescue LoginRadius::Exception
101
+ return false
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,3 @@
1
+ module LoginRadius
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,11 @@
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
data/lib/string.rb ADDED
@@ -0,0 +1,9 @@
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
+ tr("-", "_").
7
+ downcase
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/login_radius/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["LoginRadius"]
6
+ gem.email = ["developers@loginradius.com"]
7
+ gem.description = %q{Ruby wrapper for LoginRadius API}
8
+ gem.summary = %q{Is a ruby wrapper for LoginRadius API}
9
+ gem.homepage = "http://www.loginradius.com"
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
+ gem.name = "login_radius"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = LoginRadius::VERSION
16
+
17
+ gem.add_dependency 'em-http-request'
18
+ gem.add_dependency 'em-synchrony'
19
+
20
+ end
data/test/.DS_Store ADDED
Binary file
@@ -0,0 +1,29 @@
1
+ #Just a basic ruby script for testing EM-Synchrony.
2
+ #Run it in the command line: bundle exec ruby test/basic_async_test.rb
3
+ #Just does a few GETs to make sure it works in the EM environment.
4
+ require "rubygems"
5
+ require "bundler"
6
+ Bundler.require(:default, :test)
7
+ require 'em-synchrony'
8
+ require "em-synchrony/em-http"
9
+
10
+ require 'yaml'
11
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), "../"))
12
+ require base_dir + "/lib/login_radius.rb"
13
+
14
+ EM.synchrony do
15
+ TOKEN = "2543d3b0-d3f3-480e-a320-48f297446458"
16
+ SECRET = "1337670d-f7fd-4066-a2e3-e440aec071ee"
17
+
18
+ time = Time.now
19
+ @user_profile = LoginRadius::UserProfile.new({
20
+ :token => TOKEN,
21
+ :secret => SECRET,
22
+ :async => true
23
+ })
24
+
25
+ @user_profile.login
26
+ puts @user_profile.contacts!.first
27
+ p "Total time async was #{Time.now - time}"
28
+
29
+ end
Binary file
@@ -0,0 +1,11 @@
1
+ require "rubygems"
2
+ require "bundler"
3
+ Bundler.require(:default, :test)
4
+ require 'yaml'
5
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), "../.."))
6
+ require base_dir + "/lib/login_radius.rb"
7
+
8
+ class BaseTest < ActiveSupport::TestCase
9
+ def setup
10
+ end
11
+ end
@@ -0,0 +1,68 @@
1
+ require_relative 'base_test.rb'
2
+ class UserProfileTest < BaseTest
3
+ TOKEN = "yourtoken"
4
+ SECRET = "yoursecret"
5
+
6
+ def setup
7
+ @user_profile = LoginRadius::UserProfile.new({
8
+ :token => TOKEN,
9
+ :secret => SECRET,
10
+ :async => false
11
+ })
12
+ @user_profile.login
13
+ end
14
+
15
+ test "basic user profile login sync" do
16
+ assert_not_nil(@user_profile.id)
17
+ assert_not_nil(@user_profile.provider)
18
+ assert(@user_profile.authenticated?)
19
+ end
20
+
21
+ test "mentions" do
22
+ assert(@user_profile.twitter_mentions.is_a?(Array))
23
+ end
24
+
25
+ test "timeline" do
26
+ assert(@user_profile.twitter_timeline.is_a?(Array))
27
+ end
28
+
29
+ test "companies" do
30
+ assert(@user_profile.linked_in_companies.is_a?(Array))
31
+ end
32
+
33
+ test "contacts" do
34
+ assert(@user_profile.contacts.is_a?(Array))
35
+ end
36
+
37
+ test "groups" do
38
+ assert(@user_profile.facebook_groups.is_a?(Array))
39
+ end
40
+
41
+ test "posts" do
42
+ assert(@user_profile.facebook_posts.is_a?(Array))
43
+ end
44
+
45
+ test "events" do
46
+ assert(@user_profile.facebook_events.is_a?(Array))
47
+ end
48
+
49
+ test "fb post" do
50
+ params = {
51
+ :title => "Testing",
52
+ :url => "www.loginradius.com",
53
+ :status => "Wizzup",
54
+ :caption => "Testly",
55
+ :description => "Testing"
56
+ }
57
+ assert(@user_profile.make_facebook_post(params))
58
+ end
59
+
60
+ test "twitter message" do
61
+ assert(@user_profile.send_twitter_message(@user_profile.contacts.first[:id], "Testing", "This is a test."))
62
+ end
63
+
64
+ test "linked in message" do
65
+ assert(@user_profile.send_linked_in_message(@user_profile.contacts.first[:id], "Testing", "This is a test."))
66
+ end
67
+
68
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: login_radius
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - LoginRadius
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: em-http-request
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: em-synchrony
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Ruby wrapper for LoginRadius API
47
+ email:
48
+ - developers@loginradius.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .DS_Store
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - LoginRadiusTestApp/.gitignore
58
+ - LoginRadiusTestApp/Gemfile
59
+ - LoginRadiusTestApp/Gemfile.lock
60
+ - LoginRadiusTestApp/README.rdoc
61
+ - LoginRadiusTestApp/Rakefile
62
+ - LoginRadiusTestApp/app/assets/images/rails.png
63
+ - LoginRadiusTestApp/app/assets/javascripts/application.js
64
+ - LoginRadiusTestApp/app/assets/stylesheets/application.css
65
+ - LoginRadiusTestApp/app/controllers/application_controller.rb
66
+ - LoginRadiusTestApp/app/helpers/application_helper.rb
67
+ - LoginRadiusTestApp/app/mailers/.gitkeep
68
+ - LoginRadiusTestApp/app/models/.gitkeep
69
+ - LoginRadiusTestApp/app/views/application/callback.html.erb
70
+ - LoginRadiusTestApp/app/views/application/index.html.erb
71
+ - LoginRadiusTestApp/app/views/layouts/application.html.erb
72
+ - LoginRadiusTestApp/config.ru
73
+ - LoginRadiusTestApp/config/application.rb
74
+ - LoginRadiusTestApp/config/boot.rb
75
+ - LoginRadiusTestApp/config/database.yml
76
+ - LoginRadiusTestApp/config/environment.rb
77
+ - LoginRadiusTestApp/config/environments/development.rb
78
+ - LoginRadiusTestApp/config/environments/production.rb
79
+ - LoginRadiusTestApp/config/environments/test.rb
80
+ - LoginRadiusTestApp/config/initializers/backtrace_silencers.rb
81
+ - LoginRadiusTestApp/config/initializers/inflections.rb
82
+ - LoginRadiusTestApp/config/initializers/mime_types.rb
83
+ - LoginRadiusTestApp/config/initializers/secret_token.rb
84
+ - LoginRadiusTestApp/config/initializers/session_store.rb
85
+ - LoginRadiusTestApp/config/initializers/wrap_parameters.rb
86
+ - LoginRadiusTestApp/config/locales/en.yml
87
+ - LoginRadiusTestApp/config/routes.rb
88
+ - LoginRadiusTestApp/db/seeds.rb
89
+ - LoginRadiusTestApp/lib/assets/.gitkeep
90
+ - LoginRadiusTestApp/lib/tasks/.gitkeep
91
+ - LoginRadiusTestApp/log/.gitkeep
92
+ - LoginRadiusTestApp/public/404.html
93
+ - LoginRadiusTestApp/public/422.html
94
+ - LoginRadiusTestApp/public/500.html
95
+ - LoginRadiusTestApp/public/favicon.ico
96
+ - LoginRadiusTestApp/public/robots.txt
97
+ - LoginRadiusTestApp/script/rails
98
+ - LoginRadiusTestApp/test/fixtures/.gitkeep
99
+ - LoginRadiusTestApp/test/functional/.gitkeep
100
+ - LoginRadiusTestApp/test/integration/.gitkeep
101
+ - LoginRadiusTestApp/test/performance/browsing_test.rb
102
+ - LoginRadiusTestApp/test/test_helper.rb
103
+ - LoginRadiusTestApp/test/unit/.gitkeep
104
+ - LoginRadiusTestApp/vendor/assets/javascripts/.gitkeep
105
+ - LoginRadiusTestApp/vendor/assets/stylesheets/.gitkeep
106
+ - LoginRadiusTestApp/vendor/plugins/.gitkeep
107
+ - README.md
108
+ - Rakefile
109
+ - lib/hash.rb
110
+ - lib/login_radius.rb
111
+ - lib/login_radius/exception.rb
112
+ - lib/login_radius/messages.rb
113
+ - lib/login_radius/user_profile.rb
114
+ - lib/login_radius/user_profile_getters.rb
115
+ - lib/login_radius/version.rb
116
+ - lib/string.rb
117
+ - login_radius.gemspec
118
+ - test/.DS_Store
119
+ - test/basic_async_test.rb
120
+ - test/unit/.DS_Store
121
+ - test/unit/base_test.rb
122
+ - test/unit/user_profile_test.rb
123
+ homepage: http://www.loginradius.com
124
+ licenses: []
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 1.8.25
144
+ signing_key:
145
+ specification_version: 3
146
+ summary: Is a ruby wrapper for LoginRadius API
147
+ test_files:
148
+ - test/.DS_Store
149
+ - test/basic_async_test.rb
150
+ - test/unit/.DS_Store
151
+ - test/unit/base_test.rb
152
+ - test/unit/user_profile_test.rb