login_radius 0.0.1 → 1.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.
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
@@ -1,106 +1,152 @@
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
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
106
152
  end
@@ -1,3 +1,3 @@
1
- module LoginRadius
2
- VERSION = "0.0.1"
3
- end
1
+ module LoginRadius
2
+ VERSION = "1.0.0"
3
+ end
data/lib/string.rb CHANGED
@@ -1,9 +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
- tr("-", "_").
7
- downcase
8
- 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
9
8
  end
metadata CHANGED
@@ -1,152 +1,81 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: login_radius
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - LoginRadius
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-02-20 00:00:00.000000000 Z
11
+ date: 2014-05-09 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: em-http-request
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: em-synchrony
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
- description: Ruby wrapper for LoginRadius API
41
+ description: Ruby wrapper for LoginRadius API v2
47
42
  email:
48
- - developers@loginradius.com
43
+ - hello@loginradius.com
49
44
  executables: []
50
45
  extensions: []
51
46
  extra_rdoc_files: []
52
47
  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
48
  - lib/hash.rb
110
49
  - lib/login_radius.rb
50
+ - lib/string.rb
111
51
  - lib/login_radius/exception.rb
112
52
  - lib/login_radius/messages.rb
53
+ - lib/login_radius/related.rb
113
54
  - lib/login_radius/user_profile.rb
114
55
  - lib/login_radius/user_profile_getters.rb
115
56
  - 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: []
57
+ homepage: https://www.loginradius.com
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
125
61
  post_install_message:
126
62
  rdoc_options: []
127
63
  require_paths:
128
64
  - lib
129
65
  required_ruby_version: !ruby/object:Gem::Requirement
130
- none: false
131
66
  requirements:
132
- - - ! '>='
67
+ - - '>='
133
68
  - !ruby/object:Gem::Version
134
69
  version: '0'
135
70
  required_rubygems_version: !ruby/object:Gem::Requirement
136
- none: false
137
71
  requirements:
138
- - - ! '>='
72
+ - - '>='
139
73
  - !ruby/object:Gem::Version
140
74
  version: '0'
141
75
  requirements: []
142
76
  rubyforge_project:
143
- rubygems_version: 1.8.25
77
+ rubygems_version: 2.0.14
144
78
  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
79
+ specification_version: 4
80
+ summary: Is a ruby wrapper for LoginRadius API v2
81
+ test_files: []