rest-more 1.0.2 → 2.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 (72) hide show
  1. data/.gitignore +0 -5
  2. data/.travis.yml +4 -6
  3. data/CHANGES.md +16 -0
  4. data/Gemfile +6 -3
  5. data/README.md +43 -129
  6. data/Rakefile +2 -3
  7. data/example/multi.rb +12 -23
  8. data/example/rails3/Gemfile +2 -1
  9. data/example/rails3/app/controllers/application_controller.rb +9 -4
  10. data/example/rails3/test/functional/application_controller_test.rb +1 -1
  11. data/example/rainbows.rb +48 -7
  12. data/example/simple.rb +3 -3
  13. data/example/sinatra/config.ru +1 -1
  14. data/lib/rest-core/client/dropbox.rb +19 -27
  15. data/lib/rest-core/client/facebook.rb +28 -51
  16. data/lib/rest-core/client/facebook/rails_util.rb +13 -11
  17. data/lib/rest-core/client/github.rb +13 -21
  18. data/lib/rest-core/client/linkedin.rb +19 -27
  19. data/lib/rest-core/client/twitter.rb +13 -21
  20. data/lib/rest-more.rb +0 -2
  21. data/lib/rest-more/test.rb +11 -0
  22. data/lib/rest-more/version.rb +1 -1
  23. data/rest-more.gemspec +7 -41
  24. data/task/.gitignore +1 -0
  25. data/task/gemgem.rb +267 -0
  26. data/test/dropbox/test_api.rb +1 -1
  27. data/test/facebook/config/rest-core.yaml +1 -1
  28. data/test/facebook/test_api.rb +10 -14
  29. data/test/facebook/test_error.rb +2 -2
  30. data/test/facebook/test_handler.rb +6 -6
  31. data/test/facebook/test_load_config.rb +4 -4
  32. data/test/facebook/test_misc.rb +3 -3
  33. data/test/facebook/test_old.rb +2 -37
  34. data/test/facebook/test_page.rb +26 -24
  35. data/test/facebook/test_parse.rb +1 -1
  36. data/test/facebook/test_serialize.rb +3 -19
  37. data/test/facebook/test_timeout.rb +6 -2
  38. data/test/twitter/test_api.rb +1 -1
  39. metadata +6 -40
  40. data/doc/ToC.md +0 -9
  41. data/doc/dependency.md +0 -4
  42. data/doc/design.md +0 -4
  43. data/doc/rest-graph.md +0 -4
  44. data/example/async.rb +0 -89
  45. data/example/facebook.rb +0 -13
  46. data/example/rails2/Gemfile +0 -22
  47. data/example/rails2/README +0 -4
  48. data/example/rails2/Rakefile +0 -11
  49. data/example/rails2/app/controllers/application_controller.rb +0 -138
  50. data/example/rails2/app/views/application/helper.html.erb +0 -1
  51. data/example/rails2/config/boot.rb +0 -130
  52. data/example/rails2/config/environment.rb +0 -25
  53. data/example/rails2/config/environments/development.rb +0 -17
  54. data/example/rails2/config/environments/production.rb +0 -28
  55. data/example/rails2/config/environments/test.rb +0 -30
  56. data/example/rails2/config/initializers/cookie_verification_secret.rb +0 -7
  57. data/example/rails2/config/initializers/new_rails_defaults.rb +0 -21
  58. data/example/rails2/config/initializers/session_store.rb +0 -15
  59. data/example/rails2/config/preinitializer.rb +0 -23
  60. data/example/rails2/config/rest-core.yaml +0 -12
  61. data/example/rails2/config/routes.rb +0 -43
  62. data/example/rails2/log +0 -0
  63. data/example/rails2/test/functional/application_controller_test.rb +0 -259
  64. data/example/rails2/test/test_helper.rb +0 -18
  65. data/example/rails2/test/unit/rails_util_test.rb +0 -49
  66. data/lib/rest-core/client/bing.rb +0 -102
  67. data/lib/rest-core/client/bing/rails_util.rb +0 -13
  68. data/lib/rest-core/client/mixi.rb +0 -60
  69. data/lib/rest-core/client/mixi/rails_util.rb +0 -13
  70. data/test/bing/test_api.rb +0 -34
  71. data/test/facebook/test_cache.rb +0 -58
  72. data/test/mixi/test_api.rb +0 -20
@@ -1,25 +0,0 @@
1
- # Be sure to restart your server when you modify this file
2
-
3
- # Specifies gem version of Rails to use when vendor/rails is not present
4
- RAILS_GEM_VERSION = '2.3.14' unless defined? RAILS_GEM_VERSION
5
-
6
- # monkey patch from https://github.com/rails/rails/pull/3473
7
- class MissingSourceFile < LoadError #:nodoc:
8
- REGEXPS = [
9
- [/^no such file to load -- (.+)$/i, 1],
10
- [/^Missing \w+ (file\s*)?([^\s]+.rb)$/i, 2],
11
- [/^Missing API definition file in (.+)$/i, 1],
12
- [/^cannot load such file -- (.+)$/i, 1]
13
- ]
14
- end
15
-
16
- # Bootstrap the Rails environment, frameworks, and default configuration
17
- require File.join(File.dirname(__FILE__), 'boot')
18
-
19
- Rails::Initializer.run do |config|
20
- # we use bundler now, so don't do this at this example
21
- # config.gem 'rest-graph'
22
-
23
- config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
24
- config.time_zone = 'UTC'
25
- end
@@ -1,17 +0,0 @@
1
- # Settings specified here will take precedence over those in config/environment.rb
2
-
3
- # In the development environment your application's code is reloaded on
4
- # every request. This slows down response time but is perfect for development
5
- # since you don't have to restart the webserver when you make code changes.
6
- config.cache_classes = false
7
-
8
- # Log error messages when you accidentally call methods on nil.
9
- config.whiny_nils = true
10
-
11
- # Show full error reports and disable caching
12
- config.action_controller.consider_all_requests_local = true
13
- config.action_view.debug_rjs = true
14
- config.action_controller.perform_caching = false
15
-
16
- # Don't care if the mailer can't send
17
- config.action_mailer.raise_delivery_errors = false
@@ -1,28 +0,0 @@
1
- # Settings specified here will take precedence over those in config/environment.rb
2
-
3
- # The production environment is meant for finished, "live" apps.
4
- # Code is not reloaded between requests
5
- config.cache_classes = true
6
-
7
- # Full error reports are disabled and caching is turned on
8
- config.action_controller.consider_all_requests_local = false
9
- config.action_controller.perform_caching = true
10
- config.action_view.cache_template_loading = true
11
-
12
- # See everything in the log (default is :info)
13
- # config.log_level = :debug
14
-
15
- # Use a different logger for distributed setups
16
- # config.logger = SyslogLogger.new
17
-
18
- # Use a different cache store in production
19
- # config.cache_store = :mem_cache_store
20
-
21
- # Enable serving of images, stylesheets, and javascripts from an asset server
22
- # config.action_controller.asset_host = "http://assets.example.com"
23
-
24
- # Disable delivery errors, bad email addresses will be ignored
25
- # config.action_mailer.raise_delivery_errors = false
26
-
27
- # Enable threaded mode
28
- # config.threadsafe!
@@ -1,30 +0,0 @@
1
- # Settings specified here will take precedence over those in config/environment.rb
2
-
3
- # The test environment is used exclusively to run your application's
4
- # test suite. You never need to work with it otherwise. Remember that
5
- # your test database is "scratch space" for the test suite and is wiped
6
- # and recreated between test runs. Don't rely on the data there!
7
- config.cache_classes = true
8
-
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
11
-
12
- # Show full error reports and disable caching
13
- config.action_controller.consider_all_requests_local = true
14
- config.action_controller.perform_caching = false
15
- config.action_view.cache_template_loading = true
16
-
17
- # Disable request forgery protection in test environment
18
- config.action_controller.allow_forgery_protection = false
19
-
20
- # Tell Action Mailer not to deliver emails to the real world.
21
- # The :test delivery method accumulates sent emails in the
22
- # ActionMailer::Base.deliveries array.
23
- config.action_mailer.delivery_method = :test
24
-
25
- # Use SQL instead of Active Record's schema dumper when creating the test database.
26
- # This is necessary if your schema can't be completely dumped by the schema dumper,
27
- # like if you have constraints or database-specific column types
28
- # config.active_record.schema_format = :sql
29
-
30
- config.logger = Logger.new($stdout, :debug)
@@ -1,7 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Your secret key for verifying the integrity of signed cookies.
4
- # If you change this key, all old signed cookies will become invalid!
5
- # Make sure the secret is at least 30 characters and all random,
6
- # no regular words or you'll be exposed to dictionary attacks.
7
- ActionController::Base.cookie_verifier_secret = '095e8e5c0b6b901901efb23fab50005b68d9d6a9d41f4ec780946cff34b26603762bc0ea1baf204613b252e5ae499d38b232d5b75edac513a723e450e76548a3';
@@ -1,21 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # These settings change the behavior of Rails 2 apps and will be defaults
4
- # for Rails 3. You can remove this initializer when Rails 3 is released.
5
-
6
- if defined?(ActiveRecord)
7
- # Include Active Record class name as root for JSON serialized output.
8
- ActiveRecord::Base.include_root_in_json = true
9
-
10
- # Store the full class name (including module namespace) in STI type column.
11
- ActiveRecord::Base.store_full_sti_class = true
12
- end
13
-
14
- ActionController::Routing.generate_best_match = false
15
-
16
- # Use ISO 8601 format for JSON serialized times and dates.
17
- ActiveSupport.use_standard_json_time_format = true
18
-
19
- # Don't escape HTML entities in JSON, leave that for the #json_escape helper.
20
- # if you're including raw json in an HTML page.
21
- ActiveSupport.escape_html_entities_in_json = false
@@ -1,15 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Your secret key for verifying cookie session data integrity.
4
- # If you change this key, all old sessions will become invalid!
5
- # Make sure the secret is at least 30 characters and all random,
6
- # no regular words or you'll be exposed to dictionary attacks.
7
- ActionController::Base.session = {
8
- :key => '_rails2_session',
9
- :secret => 'c99a19ce0dc4ed1809e32b6b43bd9229c3a504c456230119dd445fdcb63c0ce06b436f1bf1eace27ebbe0da6041ff2b65cbb4ae4beadc3077e3e6ae07ea75118'
10
- }
11
-
12
- # Use the database for sessions instead of the cookie-based default,
13
- # which shouldn't be used to store highly confidential information
14
- # (create the session table with "rake db:sessions:create")
15
- # ActionController::Base.session_store = :active_record_store
@@ -1,23 +0,0 @@
1
-
2
- # copied from http://gembundler.com/rails23.html
3
-
4
- begin
5
- require "rubygems"
6
- require "bundler"
7
- rescue LoadError
8
- raise "Could not load the bundler gem. Install it with `gem install bundler`."
9
- end
10
-
11
- if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
12
- raise RuntimeError, "Your bundler version is too old for Rails 2.3." +
13
- "Run `gem install bundler` to upgrade."
14
- end
15
-
16
- begin
17
- # Set up load paths for all bundled gems
18
- ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
19
- Bundler.setup
20
- rescue Bundler::GemNotFound
21
- raise RuntimeError, "Bundler couldn't find some gems." +
22
- "Did you run `bundle install`?"
23
- end
@@ -1,12 +0,0 @@
1
-
2
- development: &default
3
- facebook:
4
- app_id: '123'
5
- secret: '456'
6
- canvas: 'can'
7
-
8
- production:
9
- *default
10
-
11
- test:
12
- *default
@@ -1,43 +0,0 @@
1
- ActionController::Routing::Routes.draw do |map|
2
- # The priority is based upon order of creation: first created -> highest priority.
3
-
4
- # Sample of regular route:
5
- # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
6
- # Keep in mind you can assign values other than :controller and :action
7
-
8
- # Sample of named route:
9
- # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
10
- # This route can be invoked with purchase_url(:id => product.id)
11
-
12
- # Sample resource route (maps HTTP verbs to controller actions automatically):
13
- # map.resources :products
14
-
15
- # Sample resource route with options:
16
- # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
17
-
18
- # Sample resource route with sub-resources:
19
- # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
20
-
21
- # Sample resource route with more complex sub-resources
22
- # map.resources :products do |products|
23
- # products.resources :comments
24
- # products.resources :sales, :collection => { :recent => :get }
25
- # end
26
-
27
- # Sample resource route within a namespace:
28
- # map.namespace :admin do |admin|
29
- # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
30
- # admin.resources :products
31
- # end
32
-
33
- # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
34
- map.connect ':action', :controller => 'application'
35
-
36
- # See how all your routes lay out with "rake routes"
37
-
38
- # Install the default routes as the lowest priority.
39
- # Note: These default routes make all actions in every controller accessible via GET requests. You should
40
- # consider removing or commenting them out if you're using named routes and resources.
41
- # map.connect ':controller/:action/:id'
42
- # map.connect ':controller/:action/:id.:format'
43
- end
data/example/rails2/log DELETED
File without changes
@@ -1,259 +0,0 @@
1
-
2
- require 'test_helper'
3
- require 'webmock'
4
- require 'rr'
5
-
6
- WebMock.disable_net_connect!
7
-
8
- class ApplicationControllerTest < ActionController::TestCase
9
- include WebMock::API
10
- include RR::Adapters::TestUnit
11
-
12
- def setup
13
- body = rand(2) == 0 ? '{"error":{"type":"OAuthException"}}' :
14
- '{"error_code":104}'
15
-
16
- stub_request(:get, 'https://graph.facebook.com/me').
17
- to_return(:body => body)
18
- end
19
-
20
- def teardown
21
- RR.verify
22
- WebMock.reset!
23
- end
24
-
25
- def assert_url expected
26
- assert_equal(expected, normalize_url(assigns(:rc_facebook_authorize_url)))
27
- if @response.status == 200 # js redirect
28
- assert_equal(
29
- expected,
30
- normalize_url(
31
- @response.body.match(/window\.top\.location\.href = '(.+?)'/)[1]))
32
-
33
- assert_equal(
34
- CGI.escapeHTML(expected),
35
- normalize_url(
36
- @response.body.match(/content="0;url=(.+?)"/)[1], '&amp;'))
37
-
38
- assert_equal(
39
- CGI.escapeHTML(expected),
40
- normalize_url(
41
- @response.body.match(/<a href="(.+?)" target="_top">/)[1], '&amp;'))
42
- end
43
- end
44
-
45
- def test_index
46
- get(:index)
47
- assert_response :redirect
48
-
49
- url = normalize_url(
50
- 'https://graph.facebook.com/oauth/authorize?client_id=123&' \
51
- 'scope=&redirect_uri=http%3A%2F%2Ftest.host%2F')
52
-
53
- assert_url(url)
54
- end
55
-
56
- def test_canvas
57
- get(:canvas)
58
- assert_response :success
59
-
60
- url = normalize_url(
61
- 'https://graph.facebook.com/oauth/authorize?client_id=123&' \
62
- 'scope=publish_stream&' \
63
- 'redirect_uri=http%3A%2F%2Fapps.facebook.com%2Fcan%2Fcanvas')
64
-
65
- assert_url(url)
66
- end
67
-
68
- def test_diff_canvas
69
- get(:diff_canvas)
70
- assert_response :success
71
-
72
- url = normalize_url(
73
- 'https://graph.facebook.com/oauth/authorize?client_id=123&' \
74
- 'scope=email&' \
75
- 'redirect_uri=http%3A%2F%2Fapps.facebook.com%2FToT%2Fdiff_canvas')
76
-
77
- assert_url(url)
78
- end
79
-
80
- def test_iframe_canvas
81
- get(:iframe_canvas)
82
- assert_response :success
83
-
84
- url = normalize_url(
85
- 'https://graph.facebook.com/oauth/authorize?client_id=123&' \
86
- 'scope=&' \
87
- 'redirect_uri=http%3A%2F%2Fapps.facebook.com%2Fzzz%2Fiframe_canvas')
88
-
89
- assert_url(url)
90
- end
91
-
92
- def test_options
93
- get(:options)
94
- assert_response :redirect
95
-
96
- url = normalize_url(
97
- 'https://graph.facebook.com/oauth/authorize?client_id=123&' \
98
- 'scope=bogus&' \
99
- 'redirect_uri=http%3A%2F%2Ftest.host%2Foptions')
100
-
101
- assert_url(url)
102
- end
103
-
104
- def test_protected
105
- assert_nil @controller.public_methods.find{ |m| m.to_s =~ /^rc_/ }
106
- end
107
-
108
- def test_no_auto
109
- get(:no_auto)
110
- assert_response :success
111
- assert_equal 'XD', @response.body
112
- end
113
-
114
- def test_app_id
115
- get(:diff_app_id)
116
- assert_response :success
117
- assert_equal 'zzz', @response.body
118
- end
119
-
120
- def test_cache
121
- WebMock.reset!
122
- stub_request(:get, 'https://graph.facebook.com/cache').
123
- to_return(:body => '{"message":"ok"}')
124
-
125
- get(:cache)
126
- assert_response :success
127
- assert_equal '{"message":"ok"}', @response.body
128
- end
129
-
130
- def test_handler
131
- WebMock.reset!
132
- stub_request(:get, 'https://graph.facebook.com/me?access_token=aloha').
133
- to_return(:body => '["snowman"]')
134
-
135
- Rails.cache[:fbs] = RestCore::Facebook.new(:access_token => 'aloha').fbs
136
- get(:handler_)
137
- assert_response :success
138
- assert_equal '["snowman"]', @response.body
139
- ensure
140
- Rails.cache.clear
141
- end
142
-
143
- def test_session
144
- WebMock.reset!
145
- stub_request(:get, 'https://graph.facebook.com/me?access_token=wozilla').
146
- to_return(:body => '["fireball"]')
147
-
148
- @request.session[@controller.send(:rc_facebook_storage_key)] =
149
- RestCore::Facebook.new(:access_token => 'wozilla').fbs
150
-
151
- get(:session_)
152
- assert_response :success
153
- assert_equal '["fireball"]', @response.body
154
- end
155
-
156
- def test_cookies
157
- WebMock.reset!
158
- stub_request(:get, 'https://graph.facebook.com/me?access_token=blizzard').
159
- to_return(:body => '["yeti"]')
160
-
161
- @request.cookies[@controller.send(:rc_facebook_storage_key)] =
162
- RestCore::Facebook.new(:access_token => 'blizzard').fbs
163
-
164
- get(:cookies_)
165
- assert_response :success
166
- assert_equal '["yeti"]', @response.body
167
- end
168
-
169
- def test_wrong_session
170
- WebMock.reset!
171
- stub_request(:get, 'https://graph.facebook.com/me').
172
- to_return(:body => '{"error":{"type":"OAuthException"}}')
173
-
174
- session = @request.session
175
- key = @controller.send(:rc_facebook_storage_key)
176
- session[key] = 'bad'
177
-
178
- get(:session_)
179
- assert_equal nil, session[key]
180
- end
181
-
182
- def test_wrong_cookies
183
- WebMock.reset!
184
- stub_request(:get, 'https://graph.facebook.com/me').
185
- to_return(:body => '{"error":{"type":"OAuthException"}}')
186
-
187
- cookies = @request.cookies
188
- key = @controller.send(:rc_facebook_storage_key)
189
- session[key] = 'bad'
190
-
191
- get(:cookies_)
192
- assert_equal nil, cookies[key]
193
- end
194
-
195
- def test_error
196
- get(:error)
197
- rescue => e
198
- assert_equal RestCore::Facebook::Error, e.class
199
- end
200
-
201
- def test_reinitailize
202
- get(:reinitialize)
203
- assert_response :success
204
- assert_equal({'a' => 'b'}, YAML.load(@response.body))
205
- end
206
-
207
- def test_helper
208
- get(:helper)
209
- assert_response :success
210
- assert_equal "#{RestCore::Facebook.default_app_id}",
211
- @response.body.strip
212
- end
213
-
214
- def test_defaults
215
- get(:defaults)
216
- assert_response :success
217
- assert_equal 'true', @response.body.strip
218
- end
219
-
220
- def setup_cookies key
221
- cookies = {"#{key}_#{RC::Facebook.default_app_id}" => 'dummy'}
222
- stub(@controller).cookies{cookies}
223
- f = RC::Facebook.new
224
- stub(@controller).rc_facebook{f}
225
- mock(f).parse_cookies!(cookies)
226
- end
227
-
228
- def test_parse_cookies_fbs
229
- setup_cookies('fbs')
230
- get(:parse_cookies)
231
- end
232
-
233
- def test_parse_cookies_fbsr
234
- setup_cookies('fbsr')
235
- get(:parse_cookies)
236
- end
237
-
238
- # regression test
239
- def test_no_ns_pollution
240
- get(:no_ns_pollution)
241
- assert_response :success
242
- assert_equal 'Timeout::Error', @response.body.strip
243
- end
244
-
245
- def test_facebook_redirect_uri
246
- get(:redirect_uri, :query => '/')
247
- assert_response :success
248
- assert_equal 'http://test.host/redirect_uri?query=%2F',
249
- @response.body.strip
250
- end
251
-
252
- def test_facebook_redirect_uri_with_spaces
253
- get(:redirect_uri, :query => 'The user denied your request.')
254
- assert_response :success
255
- assert_equal \
256
- 'http://test.host/redirect_uri?query=The+user+denied+your+request.',
257
- @response.body.strip
258
- end
259
- end