rack-twitter-auth 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/README.rdoc +54 -0
  2. data/Rakefile +67 -0
  3. data/VERSION +1 -0
  4. data/examples/rails-example/README +243 -0
  5. data/examples/rails-example/Rakefile +10 -0
  6. data/examples/rails-example/app/controllers/application_controller.rb +18 -0
  7. data/examples/rails-example/app/controllers/welcome_controller.rb +23 -0
  8. data/examples/rails-example/app/helpers/application_helper.rb +3 -0
  9. data/examples/rails-example/app/helpers/welcome_helper.rb +2 -0
  10. data/examples/rails-example/app/views/welcome/index.html.erb +2 -0
  11. data/examples/rails-example/config/boot.rb +110 -0
  12. data/examples/rails-example/config/database.yml +22 -0
  13. data/examples/rails-example/config/environment.rb +16 -0
  14. data/examples/rails-example/config/environments/development.rb +17 -0
  15. data/examples/rails-example/config/environments/production.rb +28 -0
  16. data/examples/rails-example/config/environments/test.rb +33 -0
  17. data/examples/rails-example/config/initializers/backtrace_silencers.rb +7 -0
  18. data/examples/rails-example/config/initializers/inflections.rb +10 -0
  19. data/examples/rails-example/config/initializers/mime_types.rb +5 -0
  20. data/examples/rails-example/config/initializers/new_rails_defaults.rb +21 -0
  21. data/examples/rails-example/config/initializers/session_store.rb +15 -0
  22. data/examples/rails-example/config/locales/en.yml +5 -0
  23. data/examples/rails-example/config/routes.rb +6 -0
  24. data/examples/rails-example/db/development.sqlite3 +1 -0
  25. data/examples/rails-example/db/seeds.rb +7 -0
  26. data/examples/rails-example/db/test.sqlite3 +1 -0
  27. data/examples/rails-example/doc/README_FOR_APP +2 -0
  28. data/examples/rails-example/lib/tasks/rspec.rake +182 -0
  29. data/examples/rails-example/log/development.log +241 -0
  30. data/examples/rails-example/log/production.log +0 -0
  31. data/examples/rails-example/log/server.log +0 -0
  32. data/examples/rails-example/log/test.log +1750 -0
  33. data/examples/rails-example/public/404.html +30 -0
  34. data/examples/rails-example/public/422.html +30 -0
  35. data/examples/rails-example/public/500.html +30 -0
  36. data/examples/rails-example/public/favicon.ico +0 -0
  37. data/examples/rails-example/public/images/rails.png +0 -0
  38. data/examples/rails-example/public/javascripts/application.js +2 -0
  39. data/examples/rails-example/public/javascripts/controls.js +963 -0
  40. data/examples/rails-example/public/javascripts/dragdrop.js +973 -0
  41. data/examples/rails-example/public/javascripts/effects.js +1128 -0
  42. data/examples/rails-example/public/javascripts/prototype.js +4320 -0
  43. data/examples/rails-example/public/robots.txt +5 -0
  44. data/examples/rails-example/script/about +4 -0
  45. data/examples/rails-example/script/autospec +6 -0
  46. data/examples/rails-example/script/console +3 -0
  47. data/examples/rails-example/script/dbconsole +3 -0
  48. data/examples/rails-example/script/destroy +3 -0
  49. data/examples/rails-example/script/generate +3 -0
  50. data/examples/rails-example/script/performance/benchmarker +3 -0
  51. data/examples/rails-example/script/performance/profiler +3 -0
  52. data/examples/rails-example/script/plugin +3 -0
  53. data/examples/rails-example/script/runner +3 -0
  54. data/examples/rails-example/script/server +3 -0
  55. data/examples/rails-example/script/spec +10 -0
  56. data/examples/rails-example/script/spec_server +9 -0
  57. data/examples/rails-example/spec/integration/login_spec.rb +17 -0
  58. data/examples/rails-example/spec/rcov.opts +2 -0
  59. data/examples/rails-example/spec/spec.opts +4 -0
  60. data/examples/rails-example/spec/spec_helper.rb +16 -0
  61. data/examples/rails-example/tmp/webrat-1257205170.html +202 -0
  62. data/examples/rails-example/tmp/webrat-1257205276.html +31 -0
  63. data/examples/rails-example/tmp/webrat-1257205315.html +211 -0
  64. data/examples/rails-example/tmp/webrat-1257205333.html +31 -0
  65. data/examples/rails-example/tmp/webrat-1257205380.html +211 -0
  66. data/examples/rails-example/tmp/webrat-1257205757.html +211 -0
  67. data/examples/rails-example/tmp/webrat-1257210107.html +32 -0
  68. data/examples/rails-example/tmp/webrat-1257210160.html +32 -0
  69. data/examples/rails-example/tmp/webrat-1257210488.html +32 -0
  70. data/examples/rails-example/tmp/webrat-1257210501.html +32 -0
  71. data/examples/rails-example/tmp/webrat-1257210545.html +32 -0
  72. data/examples/rails-example/tmp/webrat-1257210564.html +32 -0
  73. data/examples/rails-example/tmp/webrat-1257210581.html +32 -0
  74. data/examples/rails-example/tmp/webrat-1257210600.html +32 -0
  75. data/examples/rails-example/tmp/webrat-1257210608.html +32 -0
  76. data/examples/rails-example/tmp/webrat-1257219890.html +211 -0
  77. data/examples/rails-example/tmp/webrat-1257219947.html +213 -0
  78. data/examples/rails-example/tmp/webrat-1257219957.html +213 -0
  79. data/examples/sinatra-twitter.rb +30 -0
  80. data/examples/sinatra-twitter.ru +2 -0
  81. data/lib/rack-oauth.rb +289 -0
  82. data/lib/rack/oauth.rb +1 -0
  83. data/spec/data/unauthorized_request_token.yml +56 -0
  84. data/spec/rack_oauth_middleware_spec.rb +156 -0
  85. data/spec/sample_sinatra_app_spec.rb +91 -0
  86. data/spec/spec_helper.rb +24 -0
  87. metadata +183 -0
@@ -0,0 +1,91 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ require 'fakeweb'
4
+ FakeWeb.allow_net_connect = false
5
+ FakeWeb.register_uri :get, 'http://twitter.com/account/verify_credentials.json', :body => %{{"friends_count":190,"utc_offset":-28800,"profile_sidebar_border_color":"829D5E","status":{"in_reply_to_screen_name":null,"text":"Come on people, don't you realize that smoking isn't cool anymore? Try a healthier stimulant. Maybe one that doesn't irritate my sinuses?","in_reply_to_user_id":null,"in_reply_to_status_id":null,"source":"web","truncated":false,"favorited":false,"id":5177704516,"created_at":"Mon Oct 26 17:15:10 +0000 2009"},"notifications":false,"statuses_count":1689,"time_zone":"Pacific Time (US & Canada)","verified":false,"profile_text_color":"3E4415","profile_image_url":"http://a3.twimg.com/profile_images/54765389/remi-rock-on_bak_normal.png","profile_background_image_url":"http://s.twimg.com/a/1256577591/images/themes/theme5/bg.gif","location":"Phoenix, AZ","following":false,"favourites_count":0,"profile_link_color":"D02B55","screen_name":"THE_REAL_SHAQ","geo_enabled":false,"profile_background_tile":false,"protected":false,"profile_background_color":"352726","name":"THE_REAL_SHAQ","followers_count":255,"url":"http://remi.org","id":11043342,"created_at":"Tue Dec 11 09:13:43 +0000 2007","profile_sidebar_fill_color":"99CC33","description":"Beer goes in, Code comes out"}}
6
+
7
+ require 'json'
8
+ require 'sinatra/base'
9
+ class SampleSinatraApp < Sinatra::Base
10
+
11
+ use Rack::Session::Cookie
12
+ use Rack::OAuth, :site => 'http://twitter.com',
13
+ :key => '4JjFmhjfZyQ6rdbiql5A',
14
+ :secret => 'rv4ZaCgvxVPVjxHIDbMxTGFbIMxUa4KkIdPqL7HmaQo'
15
+
16
+ enable :raise_errors
17
+
18
+ helpers do
19
+ include Rack::OAuth::Methods
20
+
21
+ def logged_in?
22
+ get_access_token.present?
23
+ end
24
+ end
25
+
26
+ get '/' do
27
+ if logged_in?
28
+ "Hello World"
29
+ else
30
+ redirect oauth_login_path
31
+ end
32
+ end
33
+
34
+ get '/get_many' do
35
+ get_access_token.inspect
36
+ end
37
+
38
+ get '/get_once' do
39
+ get_access_token!.inspect
40
+ end
41
+
42
+ get '/oauth_complete' do
43
+ info = JSON.parse get_access_token.get('/account/verify_credentials.json').body
44
+ name = info['screen_name']
45
+ end
46
+
47
+ get '/get_user_info' do
48
+ info = JSON.parse get_access_token.get('/account/verify_credentials.json').body
49
+ end
50
+ end
51
+
52
+ describe SampleSinatraApp do
53
+
54
+ def example_json
55
+ %[{"time_zone":"Pacific Time (US & Canada)","profile_image_url":"http://a3.twimg.com/profile_images/54765389/remi-rock-on_bak_normal.png","description":"Beer goes in, Code comes out","following":false,"profile_text_color":"3E4415","status":{"source":"web","in_reply_to_user_id":64218381,"in_reply_to_status_id":5352275994,"truncated":false,"created_at":"Mon Nov 02 02:00:26 +0000 2009","favorited":false,"in_reply_to_screen_name":"benatkin","id":5352407184,"text":"@benatkin For GoldBar, they would want to tell you when you buy something because lots of people are coming in and not buying anything :/"},"profile_background_image_url":"http://s.twimg.com/a/1256928834/images/themes/theme5/bg.gif","followers_count":257,"screen_name":"remitaylor","profile_link_color":"D02B55","profile_background_tile":false,"friends_count":190,"url":"http://remi.org","created_at":"Tue Dec 11 09:13:43 +0000 2007","profile_background_color":"352726","notifications":false,"favourites_count":0,"statuses_count":1700,"profile_sidebar_fill_color":"99CC33","protected":false,"geo_enabled":false,"location":"Phoenix, AZ","name":"remitaylor","profile_sidebar_border_color":"829D5E","id":11043342,"verified":false,"utc_offset":-28800}]
56
+ end
57
+
58
+ before :all do
59
+ @rackbox_app = RackBox.app
60
+ RackBox.app = SampleSinatraApp
61
+ Rack::OAuth.enable_test_mode
62
+ end
63
+
64
+ after :all do
65
+ RackBox.app = @rackbox_app
66
+ Rack::OAuth.disable_test_mode
67
+ end
68
+
69
+ it 'should be able to "authorize" a user' do
70
+ # we're not authorized, so logged_in? is false and we should redirect to /oauth_login
71
+ request('/').status.should == 302
72
+ request('/').headers['Location'].should include('/oauth_login')
73
+
74
+ # because we're in test mode, redirecting to /oauth_login should pretend to log
75
+ # us in and it should redirect to /oauth_complete
76
+ request('/oauth_login').status.should == 302
77
+ request('/oauth_login').headers['Location'].should include('/oauth_complete')
78
+
79
+ # now the user should be authorized
80
+ request('/').status.should == 200
81
+ request('/').body.should include('Hello World')
82
+
83
+ request('/get_many').body.should include('OAuth::AccessToken')
84
+ request('/get_many').body.should include('OAuth::AccessToken')
85
+
86
+ request('/get_once').body.should include('OAuth::AccessToken')
87
+ request('/get_once').body.should_not include('OAuth::AccessToken')
88
+ request('/get_once').body.should_not include('OAuth::AccessToken')
89
+ end
90
+
91
+ end
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'rackbox'
4
+ require File.dirname(__FILE__) + '/../lib/rack-oauth'
5
+
6
+ # returns the path to a data file, eg. data_path(:foo) => 'spec/data/foo.yml'
7
+ def data_path name
8
+ File.join File.dirname(__FILE__), 'data', "#{ name }.yml"
9
+ end
10
+
11
+ # returns the string body of a file using data_path to get the path to the file
12
+ def data name
13
+ File.read data_path(name)
14
+ end
15
+
16
+ def mock_request_token options = {}
17
+ YAML.load data(:unauthorized_request_token).sub('AUTH_PATH', options[:authorize_path] || '/oauth/authorize')
18
+ end
19
+
20
+ RackBox.app = lambda {}
21
+
22
+ Spec::Runner.configure do |config|
23
+ config.use_blackbox = true
24
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-twitter-auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - remi
8
+ - brianthecoder
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-02-22 00:00:00 -06:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: oauth
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: rack
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ version:
36
+ description: Rack Middleware for OAuth Authorization and Authentication via/twitter
37
+ email:
38
+ - remi@remitaylor.com
39
+ - brianthecoder@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - README.rdoc
46
+ files:
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION
50
+ - examples/rails-example/README
51
+ - examples/rails-example/Rakefile
52
+ - examples/rails-example/app/controllers/application_controller.rb
53
+ - examples/rails-example/app/controllers/welcome_controller.rb
54
+ - examples/rails-example/app/helpers/application_helper.rb
55
+ - examples/rails-example/app/helpers/welcome_helper.rb
56
+ - examples/rails-example/app/views/welcome/index.html.erb
57
+ - examples/rails-example/config/boot.rb
58
+ - examples/rails-example/config/database.yml
59
+ - examples/rails-example/config/environment.rb
60
+ - examples/rails-example/config/environments/development.rb
61
+ - examples/rails-example/config/environments/production.rb
62
+ - examples/rails-example/config/environments/test.rb
63
+ - examples/rails-example/config/initializers/backtrace_silencers.rb
64
+ - examples/rails-example/config/initializers/inflections.rb
65
+ - examples/rails-example/config/initializers/mime_types.rb
66
+ - examples/rails-example/config/initializers/new_rails_defaults.rb
67
+ - examples/rails-example/config/initializers/session_store.rb
68
+ - examples/rails-example/config/locales/en.yml
69
+ - examples/rails-example/config/routes.rb
70
+ - examples/rails-example/db/development.sqlite3
71
+ - examples/rails-example/db/seeds.rb
72
+ - examples/rails-example/db/test.sqlite3
73
+ - examples/rails-example/doc/README_FOR_APP
74
+ - examples/rails-example/lib/tasks/rspec.rake
75
+ - examples/rails-example/log/development.log
76
+ - examples/rails-example/log/production.log
77
+ - examples/rails-example/log/server.log
78
+ - examples/rails-example/log/test.log
79
+ - examples/rails-example/public/404.html
80
+ - examples/rails-example/public/422.html
81
+ - examples/rails-example/public/500.html
82
+ - examples/rails-example/public/favicon.ico
83
+ - examples/rails-example/public/images/rails.png
84
+ - examples/rails-example/public/javascripts/application.js
85
+ - examples/rails-example/public/javascripts/controls.js
86
+ - examples/rails-example/public/javascripts/dragdrop.js
87
+ - examples/rails-example/public/javascripts/effects.js
88
+ - examples/rails-example/public/javascripts/prototype.js
89
+ - examples/rails-example/public/robots.txt
90
+ - examples/rails-example/script/about
91
+ - examples/rails-example/script/autospec
92
+ - examples/rails-example/script/console
93
+ - examples/rails-example/script/dbconsole
94
+ - examples/rails-example/script/destroy
95
+ - examples/rails-example/script/generate
96
+ - examples/rails-example/script/performance/benchmarker
97
+ - examples/rails-example/script/performance/profiler
98
+ - examples/rails-example/script/plugin
99
+ - examples/rails-example/script/runner
100
+ - examples/rails-example/script/server
101
+ - examples/rails-example/script/spec
102
+ - examples/rails-example/script/spec_server
103
+ - examples/rails-example/spec/integration/login_spec.rb
104
+ - examples/rails-example/spec/rcov.opts
105
+ - examples/rails-example/spec/spec.opts
106
+ - examples/rails-example/spec/spec_helper.rb
107
+ - examples/rails-example/tmp/webrat-1257205170.html
108
+ - examples/rails-example/tmp/webrat-1257205276.html
109
+ - examples/rails-example/tmp/webrat-1257205315.html
110
+ - examples/rails-example/tmp/webrat-1257205333.html
111
+ - examples/rails-example/tmp/webrat-1257205380.html
112
+ - examples/rails-example/tmp/webrat-1257205757.html
113
+ - examples/rails-example/tmp/webrat-1257210107.html
114
+ - examples/rails-example/tmp/webrat-1257210160.html
115
+ - examples/rails-example/tmp/webrat-1257210488.html
116
+ - examples/rails-example/tmp/webrat-1257210501.html
117
+ - examples/rails-example/tmp/webrat-1257210545.html
118
+ - examples/rails-example/tmp/webrat-1257210564.html
119
+ - examples/rails-example/tmp/webrat-1257210581.html
120
+ - examples/rails-example/tmp/webrat-1257210600.html
121
+ - examples/rails-example/tmp/webrat-1257210608.html
122
+ - examples/rails-example/tmp/webrat-1257219890.html
123
+ - examples/rails-example/tmp/webrat-1257219947.html
124
+ - examples/rails-example/tmp/webrat-1257219957.html
125
+ - examples/sinatra-twitter.rb
126
+ - examples/sinatra-twitter.ru
127
+ - lib/rack-oauth.rb
128
+ - lib/rack/oauth.rb
129
+ - spec/data/unauthorized_request_token.yml
130
+ - spec/rack_oauth_middleware_spec.rb
131
+ - spec/sample_sinatra_app_spec.rb
132
+ - spec/spec_helper.rb
133
+ has_rdoc: true
134
+ homepage: http://github.com/remi/rack-twitter-auth
135
+ licenses: []
136
+
137
+ post_install_message:
138
+ rdoc_options:
139
+ - --charset=UTF-8
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: "0"
147
+ version:
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: "0"
153
+ version:
154
+ requirements: []
155
+
156
+ rubyforge_project:
157
+ rubygems_version: 1.3.5
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: Rack Middleware for OAuth Authorization
161
+ test_files:
162
+ - spec/rack_oauth_middleware_spec.rb
163
+ - spec/sample_sinatra_app_spec.rb
164
+ - spec/spec_helper.rb
165
+ - examples/rails-example/app/controllers/application_controller.rb
166
+ - examples/rails-example/app/controllers/welcome_controller.rb
167
+ - examples/rails-example/app/helpers/application_helper.rb
168
+ - examples/rails-example/app/helpers/welcome_helper.rb
169
+ - examples/rails-example/config/boot.rb
170
+ - examples/rails-example/config/environment.rb
171
+ - examples/rails-example/config/environments/development.rb
172
+ - examples/rails-example/config/environments/production.rb
173
+ - examples/rails-example/config/environments/test.rb
174
+ - examples/rails-example/config/initializers/backtrace_silencers.rb
175
+ - examples/rails-example/config/initializers/inflections.rb
176
+ - examples/rails-example/config/initializers/mime_types.rb
177
+ - examples/rails-example/config/initializers/new_rails_defaults.rb
178
+ - examples/rails-example/config/initializers/session_store.rb
179
+ - examples/rails-example/config/routes.rb
180
+ - examples/rails-example/db/seeds.rb
181
+ - examples/rails-example/spec/integration/login_spec.rb
182
+ - examples/rails-example/spec/spec_helper.rb
183
+ - examples/sinatra-twitter.rb