rest-core 0.4.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/.travis.yml +2 -7
  2. data/CHANGES.md +13 -2
  3. data/Gemfile +0 -3
  4. data/README.md +30 -34
  5. data/Rakefile +5 -46
  6. data/lib/rest-core.rb +0 -6
  7. data/lib/rest-core/version.rb +1 -1
  8. data/rest-core.gemspec +5 -83
  9. metadata +11 -87
  10. data/example/rails2/Gemfile +0 -21
  11. data/example/rails2/README +0 -4
  12. data/example/rails2/Rakefile +0 -11
  13. data/example/rails2/app/controllers/application_controller.rb +0 -128
  14. data/example/rails2/app/views/application/helper.html.erb +0 -2
  15. data/example/rails2/config/boot.rb +0 -130
  16. data/example/rails2/config/environment.rb +0 -15
  17. data/example/rails2/config/environments/development.rb +0 -17
  18. data/example/rails2/config/environments/production.rb +0 -28
  19. data/example/rails2/config/environments/test.rb +0 -30
  20. data/example/rails2/config/initializers/cookie_verification_secret.rb +0 -7
  21. data/example/rails2/config/initializers/new_rails_defaults.rb +0 -21
  22. data/example/rails2/config/initializers/session_store.rb +0 -15
  23. data/example/rails2/config/preinitializer.rb +0 -23
  24. data/example/rails2/config/rest-core.yaml +0 -16
  25. data/example/rails2/config/routes.rb +0 -43
  26. data/example/rails2/log +0 -0
  27. data/example/rails2/test/functional/application_controller_test.rb +0 -197
  28. data/example/rails2/test/test_helper.rb +0 -18
  29. data/example/rails2/test/unit/rails_util_test.rb +0 -44
  30. data/example/rails3/Gemfile +0 -20
  31. data/example/rails3/README +0 -4
  32. data/example/rails3/Rakefile +0 -7
  33. data/example/rails3/app/controllers/application_controller.rb +0 -128
  34. data/example/rails3/app/views/application/helper.html.erb +0 -2
  35. data/example/rails3/config.ru +0 -4
  36. data/example/rails3/config/application.rb +0 -23
  37. data/example/rails3/config/environment.rb +0 -5
  38. data/example/rails3/config/environments/development.rb +0 -26
  39. data/example/rails3/config/environments/production.rb +0 -49
  40. data/example/rails3/config/environments/test.rb +0 -30
  41. data/example/rails3/config/initializers/secret_token.rb +0 -7
  42. data/example/rails3/config/initializers/session_store.rb +0 -8
  43. data/example/rails3/config/rest-core.yaml +0 -16
  44. data/example/rails3/config/routes.rb +0 -5
  45. data/example/rails3/test/functional/application_controller_test.rb +0 -197
  46. data/example/rails3/test/test_helper.rb +0 -18
  47. data/example/rails3/test/unit/rails_util_test.rb +0 -44
  48. data/example/sinatra/config.ru +0 -16
  49. data/lib/rest-core/client/facebook.rb +0 -251
  50. data/lib/rest-core/client/facebook/rails_util.rb +0 -333
  51. data/lib/rest-core/client/flurry.rb +0 -96
  52. data/lib/rest-core/client/flurry/rails_util.rb +0 -74
  53. data/lib/rest-core/client/github.rb +0 -18
  54. data/lib/rest-core/client/linkedin.rb +0 -59
  55. data/lib/rest-core/client/mixi.rb +0 -47
  56. data/lib/rest-core/client/twitter.rb +0 -101
  57. data/test/client/facebook/config/rest-core.yaml +0 -8
  58. data/test/client/facebook/test_api.rb +0 -97
  59. data/test/client/facebook/test_cache.rb +0 -58
  60. data/test/client/facebook/test_default.rb +0 -23
  61. data/test/client/facebook/test_error.rb +0 -65
  62. data/test/client/facebook/test_handler.rb +0 -84
  63. data/test/client/facebook/test_load_config.rb +0 -39
  64. data/test/client/facebook/test_misc.rb +0 -72
  65. data/test/client/facebook/test_oauth.rb +0 -38
  66. data/test/client/facebook/test_old.rb +0 -114
  67. data/test/client/facebook/test_page.rb +0 -106
  68. data/test/client/facebook/test_parse.rb +0 -128
  69. data/test/client/facebook/test_serialize.rb +0 -43
  70. data/test/client/facebook/test_timeout.rb +0 -22
  71. data/test/client/flurry/test_metrics.rb +0 -83
  72. data/test/client/twitter/test_api.rb +0 -37
@@ -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,16 +0,0 @@
1
-
2
- development: &default
3
- facebook:
4
- app_id: '123'
5
- secret: '456'
6
- canvas: 'can'
7
-
8
- flurry:
9
- api_key: 'key'
10
- access_code: 'code'
11
-
12
- production:
13
- *default
14
-
15
- test:
16
- *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,197 +0,0 @@
1
-
2
- require 'test_helper'
3
- require 'webmock'
4
-
5
- WebMock.disable_net_connect!
6
-
7
- class ApplicationControllerTest < ActionController::TestCase
8
- include WebMock::API
9
-
10
- def setup
11
- body = rand(2) == 0 ? '{"error":{"type":"OAuthException"}}' :
12
- '{"error_code":104}'
13
-
14
- stub_request(:get, 'https://graph.facebook.com/me').
15
- to_return(:body => body)
16
- end
17
-
18
- def teardown
19
- WebMock.reset!
20
- end
21
-
22
- def assert_url expected
23
- assert_equal(expected, normalize_url(assigns(:rc_facebook_authorize_url)))
24
- if @response.status == 200 # js redirect
25
- assert_equal(
26
- expected,
27
- normalize_url(
28
- @response.body.match(/window\.top\.location\.href = '(.+?)'/)[1]))
29
-
30
- assert_equal(
31
- CGI.escapeHTML(expected),
32
- normalize_url(
33
- @response.body.match(/content="0;url=(.+?)"/)[1], '&amp;'))
34
-
35
- assert_equal(
36
- CGI.escapeHTML(expected),
37
- normalize_url(
38
- @response.body.match(/<a href="(.+?)" target="_top">/)[1], '&amp;'))
39
- end
40
- end
41
-
42
- def test_index
43
- get(:index)
44
- assert_response :redirect
45
-
46
- url = normalize_url(
47
- 'https://graph.facebook.com/oauth/authorize?client_id=123&' \
48
- 'scope=&redirect_uri=http%3A%2F%2Ftest.host%2F')
49
-
50
- assert_url(url)
51
- end
52
-
53
- def test_canvas
54
- get(:canvas)
55
- assert_response :success
56
-
57
- url = normalize_url(
58
- 'https://graph.facebook.com/oauth/authorize?client_id=123&' \
59
- 'scope=publish_stream&' \
60
- 'redirect_uri=http%3A%2F%2Fapps.facebook.com%2Fcan%2Fcanvas')
61
-
62
- assert_url(url)
63
- end
64
-
65
- def test_diff_canvas
66
- get(:diff_canvas)
67
- assert_response :success
68
-
69
- url = normalize_url(
70
- 'https://graph.facebook.com/oauth/authorize?client_id=123&' \
71
- 'scope=email&' \
72
- 'redirect_uri=http%3A%2F%2Fapps.facebook.com%2FToT%2Fdiff_canvas')
73
-
74
- assert_url(url)
75
- end
76
-
77
- def test_iframe_canvas
78
- get(:iframe_canvas)
79
- assert_response :success
80
-
81
- url = normalize_url(
82
- 'https://graph.facebook.com/oauth/authorize?client_id=123&' \
83
- 'scope=&' \
84
- 'redirect_uri=http%3A%2F%2Fapps.facebook.com%2Fzzz%2Fiframe_canvas')
85
-
86
- assert_url(url)
87
- end
88
-
89
- def test_options
90
- get(:options)
91
- assert_response :redirect
92
-
93
- url = normalize_url(
94
- 'https://graph.facebook.com/oauth/authorize?client_id=123&' \
95
- 'scope=bogus&' \
96
- 'redirect_uri=http%3A%2F%2Ftest.host%2Foptions')
97
-
98
- assert_url(url)
99
- end
100
-
101
- def test_protected
102
- assert_nil @controller.public_methods.find{ |m| m.to_s =~ /^rest_graph/ }
103
- end
104
-
105
- def test_no_auto
106
- get(:no_auto)
107
- assert_response :success
108
- assert_equal 'XD', @response.body
109
- end
110
-
111
- def test_app_id
112
- get(:diff_app_id)
113
- assert_response :success
114
- assert_equal 'zzz', @response.body
115
- end
116
-
117
- def test_cache
118
- WebMock.reset!
119
- stub_request(:get, 'https://graph.facebook.com/cache').
120
- to_return(:body => '{"message":"ok"}')
121
-
122
- get(:cache)
123
- assert_response :success
124
- assert_equal '{"message":"ok"}', @response.body
125
- end
126
-
127
- def test_handler
128
- WebMock.reset!
129
- stub_request(:get, 'https://graph.facebook.com/me?access_token=aloha').
130
- to_return(:body => '["snowman"]')
131
-
132
- Rails.cache[:fbs] = RestCore::Facebook.new(:access_token => 'aloha').fbs
133
- get(:handler_)
134
- assert_response :success
135
- assert_equal '["snowman"]', @response.body
136
- ensure
137
- Rails.cache.clear
138
- end
139
-
140
- def test_session
141
- WebMock.reset!
142
- stub_request(:get, 'https://graph.facebook.com/me?access_token=wozilla').
143
- to_return(:body => '["fireball"]')
144
-
145
- @request.session[RestCore::Facebook::RailsUtil.rc_facebook_storage_key] =
146
- RestCore::Facebook.new(:access_token => 'wozilla').fbs
147
-
148
- get(:session_)
149
- assert_response :success
150
- assert_equal '["fireball"]', @response.body
151
- end
152
-
153
- def test_cookies
154
- WebMock.reset!
155
- stub_request(:get, 'https://graph.facebook.com/me?access_token=blizzard').
156
- to_return(:body => '["yeti"]')
157
-
158
- @request.cookies[RestCore::Facebook::RailsUtil.rc_facebook_storage_key] =
159
- RestCore::Facebook.new(:access_token => 'blizzard').fbs
160
-
161
- get(:cookies_)
162
- assert_response :success
163
- assert_equal '["yeti"]', @response.body
164
- end
165
-
166
- def test_error
167
- get(:error)
168
- rescue => e
169
- assert_equal RestCore::Facebook::Error, e.class
170
- end
171
-
172
- def test_reinitailize
173
- get(:reinitialize)
174
- assert_response :success
175
- assert_equal({'a' => 'b'}, YAML.load(@response.body))
176
- end
177
-
178
- def test_helper
179
- get(:helper)
180
- assert_response :success
181
- assert_equal "#{RestCore::Facebook.default_app_id}\n" \
182
- "#{RestCore::Flurry .default_api_key}",
183
- @response.body.strip
184
- end
185
-
186
- def test_no_ns_pollution
187
- get(:no_ns_pollution)
188
- assert_response :success
189
- assert_equal 'Timeout::Error', @response.body.strip
190
- end
191
-
192
- def test_defaults
193
- get(:defaults)
194
- assert_response :success
195
- assert_equal 'true', @response.body.strip
196
- end
197
- end
@@ -1,18 +0,0 @@
1
-
2
- ENV["RAILS_ENV"] = "test"
3
- require File.expand_path('../../config/environment', __FILE__)
4
- begin
5
- require 'rails/test_help'
6
- rescue LoadError # for rails2
7
- require 'test_help'
8
- end
9
-
10
- class ActiveSupport::TestCase
11
- def normalize_query query, amp='&'
12
- '?' + query[1..-1].split(amp).sort.join(amp)
13
- end
14
-
15
- def normalize_url url, amp='&'
16
- url.sub(/\?.+/){ |query| normalize_query(query, amp) }
17
- end
18
- end
@@ -1,44 +0,0 @@
1
-
2
- require 'test_helper'
3
- require 'rr'
4
-
5
- class RailsUtilTest < ActiveSupport::TestCase
6
- include RR::Adapters::TestUnit
7
-
8
- def setup_mock url
9
- mock(RestCore::Facebook::RailsUtil).rc_facebook_in_canvas?{ false }
10
- mock(RestCore::Facebook::RailsUtil).request{
11
- mock(Object.new).url{ url }
12
- }
13
- end
14
-
15
- def test_rest_graph_normalized_request_uri_0
16
- setup_mock( 'http://test.com/?code=123&lang=en')
17
- assert_equal('http://test.com/?lang=en',
18
- RestCore::Facebook::RailsUtil.rc_facebook_normalized_request_uri)
19
- end
20
-
21
- def test_rest_graph_normalized_request_uri_1
22
- setup_mock( 'http://test.com/?lang=en&code=123')
23
- assert_equal('http://test.com/?lang=en',
24
- RestCore::Facebook::RailsUtil.rc_facebook_normalized_request_uri)
25
- end
26
-
27
- def test_rest_graph_normalized_request_uri_2
28
- setup_mock( 'http://test.com/?session=abc&lang=en&code=123')
29
- assert_equal('http://test.com/?lang=en',
30
- RestCore::Facebook::RailsUtil.rc_facebook_normalized_request_uri)
31
- end
32
-
33
- def test_rest_graph_normalized_request_uri_3
34
- setup_mock( 'http://test.com/?code=123')
35
- assert_equal('http://test.com/',
36
- RestCore::Facebook::RailsUtil.rc_facebook_normalized_request_uri)
37
- end
38
-
39
- def test_rest_graph_normalized_request_uri_4
40
- setup_mock( 'http://test.com/?signed_request=abc&code=123')
41
- assert_equal('http://test.com/',
42
- RestCore::Facebook::RailsUtil.rc_facebook_normalized_request_uri)
43
- end
44
- end
@@ -1,20 +0,0 @@
1
-
2
- source 'http://rubygems.org'
3
-
4
- gem 'rails', '3.0.9'
5
-
6
- gem 'rest-client' # for rest-core
7
- gem 'rest-core', :path => '../../'
8
-
9
- group 'test' do
10
- gem 'rr'
11
- gem 'webmock'
12
- end
13
-
14
- platforms(:ruby) do
15
- gem 'yajl-ruby'
16
- end
17
-
18
- platforms(:jruby) do
19
- gem 'jruby-openssl'
20
- end
@@ -1,4 +0,0 @@
1
-
2
- Please fill config/rest-core.yaml with your app_id, secret, etc., to
3
- see if this example is working or not. The default setup is designed for
4
- standalone site with Facebook JavaScript SDK.
@@ -1,7 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require File.expand_path('../config/application', __FILE__)
5
- require 'rake'
6
-
7
- Rails3::Application.load_tasks
@@ -1,128 +0,0 @@
1
-
2
- class ApplicationController < ActionController::Base
3
- protect_from_forgery
4
-
5
- include RestCore::Facebook::RailsUtil
6
- include RestCore::Flurry::RailsUtil
7
-
8
- before_filter :filter_common , :only => [:index]
9
- before_filter :filter_canvas , :only => [:canvas]
10
- before_filter :filter_options , :only => [:options]
11
- before_filter :filter_no_auto , :only => [:no_auto]
12
- before_filter :filter_diff_app_id , :only => [:diff_app_id]
13
- before_filter :filter_diff_canvas , :only => [:diff_canvas]
14
- before_filter :filter_iframe_canvas, :only => [:iframe_canvas]
15
- before_filter :filter_cache , :only => [:cache]
16
- before_filter :filter_hanlder , :only => [:handler_]
17
- before_filter :filter_session , :only => [:session_]
18
- before_filter :filter_cookies , :only => [:cookies_]
19
-
20
- def index
21
- render :text => rc_facebook.get('me').to_json
22
- end
23
- alias_method :canvas , :index
24
- alias_method :options , :index
25
- alias_method :diff_canvas , :index
26
- alias_method :iframe_canvas, :index
27
- alias_method :handler_ , :index
28
- alias_method :session_ , :index
29
- alias_method :cookies_ , :index
30
-
31
- def no_auto
32
- rc_facebook.get('me')
33
- rescue RestCore::Facebook::Error
34
- render :text => 'XD'
35
- end
36
-
37
- def diff_app_id
38
- render :text => rc_facebook.app_id
39
- end
40
-
41
- def cache
42
- url = rc_facebook.url('cache')
43
- rc_facebook.get('cache')
44
- rc_facebook.get('cache')
45
- render :text => Rails.cache.read(Digest::MD5.hexdigest(url))
46
- end
47
-
48
- def error
49
- raise RestCore::Facebook::Error.new("don't rescue me")
50
- end
51
-
52
- def reinitialize
53
- rc_facebook_setup(:cache => {'a' => 'b'})
54
- render :text => YAML.dump(rc_facebook.cache)
55
- end
56
-
57
- def helper; end
58
-
59
- def no_ns_pollution
60
- render :text => Timeout::Error.name
61
- end
62
-
63
- def defaults
64
- rc_facebook_setup
65
- render :text => (rc_facebook.cache == Rails.cache &&
66
- rc_facebook.log_method.receiver == Rails.logger)
67
- end
68
-
69
- private
70
- def filter_common
71
- rc_facebook_setup(:auto_authorize => true, :canvas => '')
72
- end
73
-
74
- def filter_canvas
75
- rc_facebook_setup(:canvas => RestCore::Facebook.
76
- default_canvas,
77
- :auto_authorize_scope => 'publish_stream')
78
- end
79
-
80
- def filter_diff_canvas
81
- rc_facebook_setup(:canvas => 'ToT',
82
- :auto_authorize_scope => 'email')
83
- end
84
-
85
- def filter_iframe_canvas
86
- rc_facebook_setup(:canvas => 'zzz',
87
- :auto_authorize => true)
88
- end
89
-
90
- def filter_no_auto
91
- rc_facebook_setup(:auto_authorize => false)
92
- end
93
-
94
- def filter_diff_app_id
95
- rc_facebook_setup(:app_id => 'zzz',
96
- :auto_authorize => true)
97
- end
98
-
99
- def filter_options
100
- rc_facebook_setup(:auto_authorize_options => {:scope => 'bogus'},
101
- :canvas => nil)
102
- end
103
-
104
- def filter_cache
105
- rc_facebook_setup(:cache => Rails.cache)
106
- end
107
-
108
- def filter_hanlder
109
- rc_facebook_setup(:write_handler => method(:write_handler),
110
- :check_handler => method(:check_handler))
111
- end
112
-
113
- def write_handler fbs
114
- Rails.cache[:fbs] = fbs
115
- end
116
-
117
- def check_handler
118
- Rails.cache[:fbs]
119
- end
120
-
121
- def filter_session
122
- rc_facebook_setup(:write_session => true)
123
- end
124
-
125
- def filter_cookies
126
- rc_facebook_setup(:write_cookies => true)
127
- end
128
- end