koala 0.9.0 → 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.
- data/.gitignore +3 -0
- data/CHANGELOG +47 -7
- data/Gemfile +3 -0
- data/LICENSE +1 -1
- data/Manifest +10 -15
- data/Rakefile +13 -13
- data/koala.gemspec +36 -16
- data/lib/koala/graph_api.rb +188 -123
- data/lib/koala/http_services.rb +93 -18
- data/lib/koala/rest_api.rb +73 -6
- data/lib/koala/test_users.rb +85 -0
- data/lib/koala/uploadable_io.rb +115 -0
- data/lib/koala.rb +114 -116
- data/readme.md +32 -18
- data/spec/cases/api_base_spec.rb +101 -0
- data/spec/cases/graph_and_rest_api_spec.rb +31 -0
- data/spec/cases/graph_api_spec.rb +25 -0
- data/spec/cases/http_services/http_service_spec.rb +54 -0
- data/spec/cases/http_services/net_http_service_spec.rb +350 -0
- data/spec/cases/http_services/typhoeus_service_spec.rb +144 -0
- data/spec/cases/oauth_spec.rb +409 -0
- data/spec/cases/realtime_updates_spec.rb +184 -0
- data/spec/cases/rest_api_spec.rb +25 -0
- data/spec/cases/test_users_spec.rb +221 -0
- data/spec/cases/uploadable_io_spec.rb +151 -0
- data/spec/fixtures/beach.jpg +0 -0
- data/spec/{facebook_data.yml → fixtures/facebook_data.yml} +18 -14
- data/spec/{mock_facebook_responses.yml → fixtures/mock_facebook_responses.yml} +314 -241
- data/spec/spec_helper.rb +18 -0
- data/spec/support/graph_api_shared_examples.rb +424 -0
- data/spec/support/live_testing_data_helper.rb +40 -0
- data/spec/{mock_http_service.rb → support/mock_http_service.rb} +94 -80
- data/spec/support/rest_api_shared_examples.rb +161 -0
- data/spec/support/setup_mocks_or_live.rb +52 -0
- data/spec/support/uploadable_io_shared_examples.rb +76 -0
- metadata +140 -55
- data/examples/oauth_playground/Capfile +0 -2
- data/examples/oauth_playground/LICENSE +0 -22
- data/examples/oauth_playground/Rakefile +0 -4
- data/examples/oauth_playground/config/deploy.rb +0 -39
- data/examples/oauth_playground/config/facebook.yml +0 -13
- data/examples/oauth_playground/config.ru +0 -27
- data/examples/oauth_playground/lib/load_facebook.rb +0 -3
- data/examples/oauth_playground/lib/oauth_playground.rb +0 -187
- data/examples/oauth_playground/readme.md +0 -8
- data/examples/oauth_playground/spec/oauth_playground_spec.rb +0 -35
- data/examples/oauth_playground/spec/spec_helper.rb +0 -36
- data/examples/oauth_playground/tmp/restart.txt +0 -0
- data/examples/oauth_playground/views/index.erb +0 -206
- data/examples/oauth_playground/views/layout.erb +0 -39
- data/init.rb +0 -2
- data/spec/koala/api_base_tests.rb +0 -95
- data/spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb +0 -10
- data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +0 -11
- data/spec/koala/graph_api/graph_api_no_access_token_tests.rb +0 -114
- data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +0 -150
- data/spec/koala/graph_api/graph_collection_tests.rb +0 -104
- data/spec/koala/live_testing_data_helper.rb +0 -15
- data/spec/koala/net_http_service_tests.rb +0 -181
- data/spec/koala/oauth/oauth_tests.rb +0 -440
- data/spec/koala/realtime_updates/realtime_updates_tests.rb +0 -187
- data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +0 -94
- data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +0 -36
- data/spec/koala_spec.rb +0 -18
- data/spec/koala_spec_helper.rb +0 -31
- data/spec/koala_spec_without_mocks.rb +0 -19
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
|
2
|
-
|
|
3
|
-
require 'rubygems'
|
|
4
|
-
require 'sinatra'
|
|
5
|
-
require 'erb'
|
|
6
|
-
|
|
7
|
-
class OAuthPlayground < Sinatra::Application
|
|
8
|
-
|
|
9
|
-
set :root, APP_ROOT
|
|
10
|
-
|
|
11
|
-
include Koala
|
|
12
|
-
|
|
13
|
-
layout :layout
|
|
14
|
-
|
|
15
|
-
get "/" do
|
|
16
|
-
@app_data = FACEBOOK_INFO.merge("callback_url" => "#{request.scheme}://#{request.host}/")
|
|
17
|
-
@oauth = Facebook::OAuth.new(@app_data["app_id"], @app_data["secret_key"], @app_data["callback_url"])
|
|
18
|
-
|
|
19
|
-
# get authentication info
|
|
20
|
-
set_facebook_cookies
|
|
21
|
-
set_oauth_data
|
|
22
|
-
set_access_token
|
|
23
|
-
|
|
24
|
-
unless (@permissions = params[:permissions]) && @permissions.length > 0
|
|
25
|
-
@active_permissions = (get_active_permissions || {}).inject([]) do |active, perm|
|
|
26
|
-
# collect our active permissions
|
|
27
|
-
active << perm[0].to_sym if perm[1] == 1
|
|
28
|
-
active
|
|
29
|
-
end
|
|
30
|
-
@fetched_permissions = true
|
|
31
|
-
else
|
|
32
|
-
@active_permissions = @permissions.collect {|p| p.to_sym}
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
@available_permissions = [
|
|
36
|
-
{:name => "User Activity", :perms => ACTIVITY_PERMISSIONS},
|
|
37
|
-
{:name => "User Info", :perms => USER_PERMISSIONS},
|
|
38
|
-
{:name => "Friend Info", :perms => FRIEND_PERMISSIONS}
|
|
39
|
-
]
|
|
40
|
-
|
|
41
|
-
erb :index
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
get "/subscriptions" do
|
|
45
|
-
# validate that this is a valid response
|
|
46
|
-
# it will automatically render the result of the verification
|
|
47
|
-
# e.g. either the challenge phrase or false
|
|
48
|
-
subscription = Facebook::RealtimeUpdates.meet_challenge(params) do |verification_token|
|
|
49
|
-
token_parts = verification_token.split("|")
|
|
50
|
-
expected = Digest::MD5.hexdigest("#{token_parts.first}~koala")
|
|
51
|
-
logger.info "expected: #{expected}"
|
|
52
|
-
logger.info "got: #{token_parts.last}"
|
|
53
|
-
# determine if this is a valid token -- that is, if the send part is a properly encoding of the first
|
|
54
|
-
expected == token_parts.last
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
helpers do
|
|
59
|
-
def logger
|
|
60
|
-
LOGGER
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# helpers
|
|
65
|
-
|
|
66
|
-
# set up our understanding of the user's session
|
|
67
|
-
|
|
68
|
-
def set_access_token
|
|
69
|
-
# get the access token from wherever we can
|
|
70
|
-
@access_token ||= (set_oauth_data && @oauth_access_token) || (set_facebook_cookies && @cookie_access_token)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def set_oauth_data
|
|
74
|
-
unless @oauth_access_token
|
|
75
|
-
if (@code = params[:code]) && @raw_access_response = @oauth.send(:fetch_token_string, {:code => @code, :redirect_uri => @app_data["callback_url"]})
|
|
76
|
-
parsed = @oauth.send(:parse_access_token, @raw_access_response)
|
|
77
|
-
@oauth_access_token = parsed["access_token"]
|
|
78
|
-
@expiration = parsed["expires"] || "Does not expire (offline)"
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
@oauth_access_token
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def set_facebook_cookies
|
|
86
|
-
unless @facebook_cookies
|
|
87
|
-
if @facebook_cookies = @oauth.get_user_from_cookie(request.cookies)
|
|
88
|
-
@cookie_access_token = @facebook_cookies["access_token"]
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
@facebook_cookies
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def set_uid
|
|
96
|
-
# get the OAuth data, including fetching the access token, if available and necessary
|
|
97
|
-
# e.g. if we have an OAuth token and no cookie data
|
|
98
|
-
unless @uid
|
|
99
|
-
if @facebook_cookies
|
|
100
|
-
@uid = @facebook_cookies["uid"]
|
|
101
|
-
elsif token = set_access_token
|
|
102
|
-
# we have to fetch the info
|
|
103
|
-
@graph = Facebook::GraphAPI.new(token)
|
|
104
|
-
result = @graph.get_object("me")
|
|
105
|
-
@uid = result["id"]
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
@uid
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
# fetch the active permissions about the user
|
|
112
|
-
def get_active_permissions
|
|
113
|
-
set_access_token
|
|
114
|
-
if @access_token && !@permissions && set_uid
|
|
115
|
-
# if we don't have permissions set but have an access token
|
|
116
|
-
# grab the user's info
|
|
117
|
-
@rest = Facebook::RestAPI.new(@access_token)
|
|
118
|
-
result = @rest.fql_query("select #{all_permissions.join(",")} from permissions where uid = #{@uid.to_s}")
|
|
119
|
-
result.first
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
# list of permissions
|
|
124
|
-
|
|
125
|
-
def all_permissions
|
|
126
|
-
ACTIVITY_PERMISSIONS + USER_PERMISSIONS + FRIEND_PERMISSIONS
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
ACTIVITY_PERMISSIONS = [
|
|
130
|
-
:publish_stream, # Enables your application to post content, comments, and likes to a user's stream and to the streams of the user's friends, without prompting the user each time.
|
|
131
|
-
:create_event, # Enables your application to create and modify events on the user's behalf
|
|
132
|
-
:rsvp_event, # Enables your application to RSVP to events on the user's behalf
|
|
133
|
-
:sms, # Enables your application to send messages to the user and respond to messages from the user via text message
|
|
134
|
-
:offline_access # Enables your application to perform authorized requests on behalf of the user at any time. By default, most access tokens expire after a short time period to ensure applications only make requests on behalf of the user when the are actively using the application. This permission makes the access token returned by our OAuth endpoint long-lived.
|
|
135
|
-
]
|
|
136
|
-
|
|
137
|
-
USER_PERMISSIONS = [
|
|
138
|
-
:email, # Provides access to the user's primary email address in the email property. Do not spam users. Your use of email must comply both with Facebook policies and with the CAN-SPAM Act.
|
|
139
|
-
:read_insights, # Provides read access to the Insights data for pages, applications, and domains the user owns.
|
|
140
|
-
:read_stream, # Provides access to all the posts in the user's News Feed and enables your application to perform searches against the user's News Feed
|
|
141
|
-
:user_about_me, # Provides access to the "About Me" section of the profile in the about property
|
|
142
|
-
:user_activities, # Provides access to the user's list of activities as the activities connection
|
|
143
|
-
:user_birthday, # Provides access to the full birthday with year as the birthday_date property
|
|
144
|
-
:user_education_history, # Provides access to education history as the education property
|
|
145
|
-
:user_events, # Provides access to the list of events the user is attending as the events connection
|
|
146
|
-
:user_groups, # Provides access to the list of groups the user is a member of as the groups connection
|
|
147
|
-
:user_hometown, # Provides access to the user's hometown in the hometown property
|
|
148
|
-
:user_interests, # Provides access to the user's list of interests as the interests connection
|
|
149
|
-
:user_likes, # Provides access to the list of all of the pages the user has liked as the likes connection
|
|
150
|
-
:user_location, # Provides access to the user's current location as the current_location property
|
|
151
|
-
:user_notes, # Provides access to the user's notes as the notes connection
|
|
152
|
-
:user_online_presence, # Provides access to the user's online/offline presence
|
|
153
|
-
:user_photo_video_tags, # Provides access to the photos the user has been tagged in as the photos connection
|
|
154
|
-
:user_photos, # Provides access to the photos the user has uploaded
|
|
155
|
-
:user_relationships, # Provides access to the user's family and personal relationships and relationship status
|
|
156
|
-
:user_religion_politics, # Provides access to the user's religious and political affiliations
|
|
157
|
-
:user_status, # Provides access to the user's most recent status message
|
|
158
|
-
:user_videos, # Provides access to the videos the user has uploaded
|
|
159
|
-
:user_website, # Provides access to the user's web site URL
|
|
160
|
-
:user_work_history # Provides access to work history as the work property
|
|
161
|
-
]
|
|
162
|
-
|
|
163
|
-
FRIEND_PERMISSIONS = [
|
|
164
|
-
:read_friendlists, # Provides read access to the user's friend lists
|
|
165
|
-
:read_requests, # Provides read access to the user's friend requests
|
|
166
|
-
:friends_about_me, # Provides access to the "About Me" section of the profile in the about property
|
|
167
|
-
:friends_activities, # Provides access to the user's list of activities as the activities connection
|
|
168
|
-
:friends_birthday, # Provides access to the full birthday with year as the birthday_date property
|
|
169
|
-
:friends_education_history, # Provides access to education history as the education property
|
|
170
|
-
:friends_events, # Provides access to the list of events the user is attending as the events connection
|
|
171
|
-
:friends_groups, # Provides access to the list of groups the user is a member of as the groups connection
|
|
172
|
-
:friends_hometown, # Provides access to the user's hometown in the hometown property
|
|
173
|
-
:friends_interests, # Provides access to the user's list of interests as the interests connection
|
|
174
|
-
:friends_likes, # Provides access to the list of all of the pages the user has liked as the likes connection
|
|
175
|
-
:friends_location, # Provides access to the user's current location as the current_location property
|
|
176
|
-
:friends_notes, # Provides access to the user's notes as the notes connection
|
|
177
|
-
:friends_online_presence, # Provides access to the user's online/offline presence
|
|
178
|
-
:friends_photo_video_tags, # Provides access to the photos the user has been tagged in as the photos connection
|
|
179
|
-
:friends_photos, # Provides access to the photos the user has uploaded
|
|
180
|
-
:friends_relationships, # Provides access to the user's family and personal relationships and relationship status
|
|
181
|
-
:friends_religion_politics, # Provides access to the user's religious and political affiliations
|
|
182
|
-
:friends_status, # Provides access to the user's most recent status message
|
|
183
|
-
:friends_videos, # Provides access to the videos the user has uploaded
|
|
184
|
-
:friends_website, # Provides access to the user's web site URL
|
|
185
|
-
:friends_work_history # Provides access to work history as the work property
|
|
186
|
-
]
|
|
187
|
-
end
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
A simple OAuth Playground chock full of the info you need to test your OAuth-based Facebook application.
|
|
2
|
-
|
|
3
|
-
To Do's
|
|
4
|
-
=======
|
|
5
|
-
|
|
6
|
-
* Extend the permissions controls to cover all available permissions
|
|
7
|
-
* Make expiration dates human-readable
|
|
8
|
-
* Let people plug in their own app (updating the app's connect properties through setAppProperties)
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'ruby-debug'
|
|
3
|
-
|
|
4
|
-
describe 'OAuthPlayground' do
|
|
5
|
-
before :each do
|
|
6
|
-
@hydra = Typhoeus::Hydra.hydra
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
after :each do
|
|
10
|
-
@hydra.clear_stubs
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it 'should load the index' do
|
|
14
|
-
get '/'
|
|
15
|
-
last_response.should be_ok
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
=begin
|
|
19
|
-
# unfortunately, this fails when you pass the get method a param named code!
|
|
20
|
-
# fixing this will require some mucking around in Rack::Test
|
|
21
|
-
|
|
22
|
-
it "should make a request to Facebook's OAuth server when passed a code" do
|
|
23
|
-
test_string = Regexp.new("The time is #{Time.now.to_i}")
|
|
24
|
-
|
|
25
|
-
# stub out the request and make sure it's returned
|
|
26
|
-
@hydra.stub("https://#{Koala::Facebook::GRAPH_SERVER}/oauth/access_token", "get").and_return(test_string)
|
|
27
|
-
|
|
28
|
-
get "/", {"code" => "foo_bar"}
|
|
29
|
-
|
|
30
|
-
# make sure the body includes the request string
|
|
31
|
-
last_response.body.should =~ test_string
|
|
32
|
-
end
|
|
33
|
-
=end
|
|
34
|
-
end
|
|
35
|
-
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
require 'rubygems'
|
|
2
|
-
require 'sinatra'
|
|
3
|
-
require 'rack/test'
|
|
4
|
-
require 'typhoeus'
|
|
5
|
-
require 'koala'
|
|
6
|
-
|
|
7
|
-
require File.join(File.dirname(__FILE__), '..', 'lib', 'oauth_playground.rb')
|
|
8
|
-
require File.join(File.dirname(__FILE__), '..', 'lib', 'load_facebook.rb')
|
|
9
|
-
|
|
10
|
-
OAuthPlayground.set(
|
|
11
|
-
:environment => :test,
|
|
12
|
-
:run => false,
|
|
13
|
-
:raise_errors => true,
|
|
14
|
-
:logging => false
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
module TestHelper
|
|
18
|
-
|
|
19
|
-
def app
|
|
20
|
-
# change to your app class if using the 'classy' style
|
|
21
|
-
OAuthPlayground
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def body
|
|
25
|
-
last_response.body
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def status
|
|
29
|
-
last_response.status
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
include Rack::Test::Methods
|
|
33
|
-
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
include TestHelper
|
|
File without changes
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
<div id="header">
|
|
2
|
-
<h1>Facebook OAuth Playground</h1>
|
|
3
|
-
<h4>Powered by <a href="http://github.com/arsduo/koala" target="_blank">Koala</a></h2>
|
|
4
|
-
<h4>For novelty use only. Remember, the application's secret key is public.</h4>
|
|
5
|
-
</div>
|
|
6
|
-
|
|
7
|
-
<style>
|
|
8
|
-
#header {
|
|
9
|
-
text-align: center;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
h1, h2, h3, h4 { margin: 0; }
|
|
13
|
-
|
|
14
|
-
.section {
|
|
15
|
-
border: 1px solid black;
|
|
16
|
-
padding: 10px;
|
|
17
|
-
-moz-border-radius: 9px;
|
|
18
|
-
-webkit-border-radius: 9px;
|
|
19
|
-
margin-bottom: 10px;
|
|
20
|
-
width: 100%;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
#contents {
|
|
24
|
-
border: 2px solid #CCC;
|
|
25
|
-
border-width: 2px 0;
|
|
26
|
-
background-color: #EEE;
|
|
27
|
-
padding: 14px 3px 8px 8px;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
#configurationInfo {
|
|
31
|
-
float:left;
|
|
32
|
-
margin-right: 2.5%;
|
|
33
|
-
width: 25%;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
#configurationInfo .section {
|
|
37
|
-
background-color: #CCC;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
#permissions .header {
|
|
41
|
-
margin-bottom: 5px;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
#permissions .list {
|
|
45
|
-
height: 380px;
|
|
46
|
-
overflow: auto;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
#generatedInfo {
|
|
50
|
-
float: left;
|
|
51
|
-
width: 70%;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
#generatedInfo .section {
|
|
55
|
-
border-color: gray;
|
|
56
|
-
background: #DDD;
|
|
57
|
-
overflow: auto;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
.clearFloat {
|
|
61
|
-
height: 1px;
|
|
62
|
-
height: 0px;
|
|
63
|
-
clear: both;
|
|
64
|
-
overflow: hidden;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
ul, li { margin: 0; padding: 0; list-style: none; }
|
|
68
|
-
ul { margin: 12px 0; }
|
|
69
|
-
|
|
70
|
-
.code {
|
|
71
|
-
font-family: Courier, fixed;
|
|
72
|
-
font-size: 1.15em;
|
|
73
|
-
width: 100%;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
.explanation {
|
|
77
|
-
font-size: 0.9em;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
.datumName {
|
|
81
|
-
font-weight: bold;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
.permissionType {
|
|
85
|
-
font-style: italic;
|
|
86
|
-
}
|
|
87
|
-
</style>
|
|
88
|
-
|
|
89
|
-
</style>
|
|
90
|
-
|
|
91
|
-
<div id="contents">
|
|
92
|
-
|
|
93
|
-
<div id="configurationInfo">
|
|
94
|
-
<div id="fbApp" class="section">
|
|
95
|
-
<h3>Facebook App Info</h3>
|
|
96
|
-
<ul>
|
|
97
|
-
<% @app_data.each_pair do |key, value| %>
|
|
98
|
-
<li><span class="datumName"><%= key %>:</span> <%= value %></li>
|
|
99
|
-
<% end %>
|
|
100
|
-
</ul>
|
|
101
|
-
</div>
|
|
102
|
-
|
|
103
|
-
<div id="permissions" class="section">
|
|
104
|
-
<form method="get">
|
|
105
|
-
<div class="header">
|
|
106
|
-
<h3>Permissions</h3>
|
|
107
|
-
<input type="submit" value="Update permissions" />
|
|
108
|
-
<a href="/">Reset Selection</a>
|
|
109
|
-
<div class="explanation">Choose permissions for the OAuth URL and the fb:login button.</div>
|
|
110
|
-
<% if @fetched_permissions %>
|
|
111
|
-
<div class="permissionType">Showing currently-active permissions</div>
|
|
112
|
-
<div class="explanation">(These were fetched by Koala as the page loaded!)</div>
|
|
113
|
-
<% else %>
|
|
114
|
-
<div class="permissionType">Showing selected permissions</div>
|
|
115
|
-
<% end %>
|
|
116
|
-
</div>
|
|
117
|
-
|
|
118
|
-
<div class="list">
|
|
119
|
-
<% @available_permissions.each do |permissions| %>
|
|
120
|
-
<h4><%= permissions[:name] %> Permissions</h4>
|
|
121
|
-
<ul>
|
|
122
|
-
<% permissions[:perms].each do |p| %>
|
|
123
|
-
<li>
|
|
124
|
-
<input type="checkbox" id="permission<%= p %>" name="permissions[]" value="<%= p %>" <%= @active_permissions.include?(p) ? "checked='checked'" : "" %> />
|
|
125
|
-
<label for="permission<%= p %>"><%= p %></a> (<a href="#" onclick="FB.api({method: 'auth.revokeExtendedPermission', perm: '<%= p %>'}, function(response) { alert(response) }); return false;">revoke</a>)
|
|
126
|
-
</li>
|
|
127
|
-
<% end %>
|
|
128
|
-
</ul>
|
|
129
|
-
<% end %>
|
|
130
|
-
</div>
|
|
131
|
-
</form>
|
|
132
|
-
</div>
|
|
133
|
-
</div>
|
|
134
|
-
|
|
135
|
-
<div id="generatedInfo">
|
|
136
|
-
<div id="oauthURLs" class="section">
|
|
137
|
-
<h3>OAuth URLs</h3>
|
|
138
|
-
<ul>
|
|
139
|
-
<li><span class="datumName">Generate a code:</span> <a href="<%= @oauth.url_for_oauth_code(:permissions => @permissions) %>"><%= @oauth.url_for_oauth_code(:permissions => @permissions) %></a></li>
|
|
140
|
-
<li><span class="datumName">OAuth code:</span> <%= @code || "click on the link above" %></li>
|
|
141
|
-
<li>
|
|
142
|
-
<span class="datumName">Access token:</span> <%= @oauth_access_token || "click on the link above" %>
|
|
143
|
-
<% if @oauth_access_token %><div class="explanation">This was fetched by Koala as the page loaded!</div><% end %>
|
|
144
|
-
</li>
|
|
145
|
-
<li><span class="datumName">Expiration:</span> <%= @expiration || "click on the link above" %></li>
|
|
146
|
-
<li><span class="datumName">Raw access response:</span> <%= @raw_access_response || "click on the link above" %></li>
|
|
147
|
-
<li><span class="datumName">URL for access code:</span>
|
|
148
|
-
<% if @code %>
|
|
149
|
-
<a href="<%= @oauth.url_for_access_token(@code) %>"><%= @oauth.url_for_access_token(@code) %></a>
|
|
150
|
-
<% else %>
|
|
151
|
-
click on the link above
|
|
152
|
-
<% end %>
|
|
153
|
-
</li>
|
|
154
|
-
</ul>
|
|
155
|
-
</div>
|
|
156
|
-
|
|
157
|
-
<div id="jsLogin" class="section">
|
|
158
|
-
<h3>Javascript Login (e.g. Facebook Connect)</h3>
|
|
159
|
-
<p>
|
|
160
|
-
<fb:login-button onlogin="location.reload()" perms="<%= (@permissions || []).join(",") %>"></fb:login-button>
|
|
161
|
-
<% if @permissions %>
|
|
162
|
-
and prompt for <%= @permissions.join(", ") %>
|
|
163
|
-
<% end %>
|
|
164
|
-
<% if @facebook_cookies %>
|
|
165
|
-
<div class="logout">
|
|
166
|
-
<a href="#" onclick="FB.logout(function() { location.reload() }); return false;">Logout</a>
|
|
167
|
-
</div>
|
|
168
|
-
<% end %>
|
|
169
|
-
</p>
|
|
170
|
-
</div>
|
|
171
|
-
|
|
172
|
-
<div id="cookieInfo" class="section">
|
|
173
|
-
<h3>Cookie info</h3>
|
|
174
|
-
<ul>
|
|
175
|
-
<% if @facebook_cookies %>
|
|
176
|
-
<% @facebook_cookies.each_pair do |key, value| %>
|
|
177
|
-
<li><span class="datumName"><%= key %>:</span> <%= value %></li>
|
|
178
|
-
<% end %>
|
|
179
|
-
<% else %>
|
|
180
|
-
<li>You're not signed in via Javascript. Login below.</li>
|
|
181
|
-
<% end %>
|
|
182
|
-
<li><span class="datumName">Raw hash</span>:
|
|
183
|
-
<div class="code"><%= request.cookies.inspect %></div>
|
|
184
|
-
</li>
|
|
185
|
-
</ul>
|
|
186
|
-
</div>
|
|
187
|
-
|
|
188
|
-
<div id="koala" class="section">
|
|
189
|
-
<h3>Koala</h3>
|
|
190
|
-
<ul>
|
|
191
|
-
<li><span class="datumName">GraphAPI:</span>
|
|
192
|
-
<div class="code"><%= @access_token ? "@graph = Koala::Facebook::GraphAPI.new(\"#{@access_token}\")" : "sign in above" %></div>
|
|
193
|
-
</li>
|
|
194
|
-
<li><span class="datumName">OAuth:</span>
|
|
195
|
-
<div class="code">@oauth = Koala::Facebook::OAuth.new(<%= @app_data["app_id"] %>, "<%= @app_data["secret_key"] %>", "<%= @app_data["callback_url"] %>")</div>
|
|
196
|
-
</li>
|
|
197
|
-
</ul>
|
|
198
|
-
</div>
|
|
199
|
-
</div>
|
|
200
|
-
|
|
201
|
-
<div class="clearFloat"> </div>
|
|
202
|
-
</div>
|
|
203
|
-
|
|
204
|
-
<center>
|
|
205
|
-
<h5>Check out the playground's code at <a href="http://github.com/arsduo/oauth_playground">http://github.com/arsduo/oauth_playground</a>!</h5>
|
|
206
|
-
</center>
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
<head>
|
|
3
|
-
<title>Facebook OAuth Playground</title>
|
|
4
|
-
<meta name="description" content="Making it easier to play with Facebook's new Graph API and OAuth authentication."></meta>
|
|
5
|
-
<style>
|
|
6
|
-
body {
|
|
7
|
-
font-family: verdana, arial, sans-serif;
|
|
8
|
-
font-size: 12px;
|
|
9
|
-
margin: 0px;
|
|
10
|
-
}
|
|
11
|
-
</style>
|
|
12
|
-
</head>
|
|
13
|
-
<body>
|
|
14
|
-
|
|
15
|
-
<script type="text/javascript">
|
|
16
|
-
|
|
17
|
-
var _gaq = _gaq || [];
|
|
18
|
-
_gaq.push(['_setAccount', 'UA-16395421-1']);
|
|
19
|
-
_gaq.push(['_trackPageview']);
|
|
20
|
-
|
|
21
|
-
(function() {
|
|
22
|
-
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
23
|
-
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
|
24
|
-
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
25
|
-
})();
|
|
26
|
-
|
|
27
|
-
</script>
|
|
28
|
-
|
|
29
|
-
<%= yield %>
|
|
30
|
-
|
|
31
|
-
<div id="fb-root"></div>
|
|
32
|
-
<script src="http://connect.facebook.net/en_US/all.js"></script>
|
|
33
|
-
<script>
|
|
34
|
-
FB.init({ appId: <%= @app_data["app_id"] %>, cookie: true, status: true, xfbml: true });
|
|
35
|
-
</script>
|
|
36
|
-
|
|
37
|
-
</body>
|
|
38
|
-
|
|
39
|
-
</html>
|
data/init.rb
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
class ApiBaseTests < Test::Unit::TestCase
|
|
2
|
-
describe "Koala API base class" do
|
|
3
|
-
before(:each) do
|
|
4
|
-
@service = Koala::Facebook::API.new
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
it "should not include an access token if none was given" do
|
|
8
|
-
Koala.should_receive(:make_request).with(
|
|
9
|
-
anything,
|
|
10
|
-
hash_not_including('access_token' => 1),
|
|
11
|
-
anything,
|
|
12
|
-
anything
|
|
13
|
-
).and_return(Koala::Response.new(200, "", ""))
|
|
14
|
-
|
|
15
|
-
@service.api('anything')
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "should include an access token if given" do
|
|
19
|
-
token = 'adfadf'
|
|
20
|
-
service = Koala::Facebook::API.new token
|
|
21
|
-
|
|
22
|
-
Koala.should_receive(:make_request).with(
|
|
23
|
-
anything,
|
|
24
|
-
hash_including('access_token' => token),
|
|
25
|
-
anything,
|
|
26
|
-
anything
|
|
27
|
-
).and_return(Koala::Response.new(200, "", ""))
|
|
28
|
-
|
|
29
|
-
service.api('anything')
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "should get the attribute of a Koala::Response given by the http_component parameter" do
|
|
33
|
-
http_component = :method_name
|
|
34
|
-
|
|
35
|
-
response = mock('Mock KoalaResponse', :body => '', :status => 200)
|
|
36
|
-
response.should_receive(http_component).and_return('')
|
|
37
|
-
|
|
38
|
-
Koala.stub(:make_request).and_return(response)
|
|
39
|
-
|
|
40
|
-
@service.api('anything', 'get', {}, :http_component => http_component)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it "should return the body of the request as JSON if no http_component is given" do
|
|
44
|
-
response = stub('response', :body => 'body', :status => 200)
|
|
45
|
-
Koala.stub(:make_request).and_return(response)
|
|
46
|
-
|
|
47
|
-
json_body = mock('JSON body')
|
|
48
|
-
JSON.stub(:parse).and_return([json_body])
|
|
49
|
-
|
|
50
|
-
@service.api('anything').should == json_body
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it "should execute a block with the response body if passed one" do
|
|
54
|
-
body = '{}'
|
|
55
|
-
Koala.stub(:make_request).and_return(Koala::Response.new(200, body, {}))
|
|
56
|
-
|
|
57
|
-
yield_test = mock('Yield Tester')
|
|
58
|
-
yield_test.should_receive(:pass)
|
|
59
|
-
|
|
60
|
-
@service.api('anything') do |arg|
|
|
61
|
-
yield_test.pass
|
|
62
|
-
arg.should == JSON.parse(body)
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it "should raise an API error if the HTTP response code is greater than or equal to 500" do
|
|
67
|
-
Koala.stub(:make_request).and_return(Koala::Response.new(500, 'response body', {}))
|
|
68
|
-
|
|
69
|
-
lambda { @service.api('anything') }.should raise_exception(Koala::Facebook::APIError)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "should handle rogue true/false as responses" do
|
|
73
|
-
Koala.should_receive(:make_request).and_return(Koala::Response.new(200, 'true', {}))
|
|
74
|
-
@service.api('anything').should be_true
|
|
75
|
-
|
|
76
|
-
Koala.should_receive(:make_request).and_return(Koala::Response.new(200, 'false', {}))
|
|
77
|
-
@service.api('anything').should be_false
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
describe "with regard to leading slashes" do
|
|
81
|
-
it "should add a leading / to the path if not present" do
|
|
82
|
-
path = "anything"
|
|
83
|
-
Koala.should_receive(:make_request).with("/#{path}", anything, anything, anything).and_return(Koala::Response.new(200, 'true', {}))
|
|
84
|
-
@service.api(path)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
it "shouldn't change the path if a leading / is present" do
|
|
88
|
-
path = "/anything"
|
|
89
|
-
Koala.should_receive(:make_request).with(path, anything, anything, anything).and_return(Koala::Response.new(200, 'true', {}))
|
|
90
|
-
@service.api(path)
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
end
|
|
95
|
-
end
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
class GraphAndRestAPINoTokenTests < Test::Unit::TestCase
|
|
2
|
-
describe "Koala GraphAndRestAPI without an access token" do
|
|
3
|
-
before(:each) do
|
|
4
|
-
@api = Koala::Facebook::GraphAndRestAPI.new
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
it_should_behave_like "Koala RestAPI without an access token"
|
|
8
|
-
it_should_behave_like "Koala GraphAPI without an access token"
|
|
9
|
-
end
|
|
10
|
-
end
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
class GraphAndRestAPIWithTokenTests < Test::Unit::TestCase
|
|
2
|
-
describe "Koala GraphAndRestAPI without an access token" do
|
|
3
|
-
it_should_behave_like "live testing examples"
|
|
4
|
-
it_should_behave_like "Koala RestAPI with an access token"
|
|
5
|
-
it_should_behave_like "Koala GraphAPI with an access token"
|
|
6
|
-
|
|
7
|
-
before(:each) do
|
|
8
|
-
@api = Koala::Facebook::GraphAndRestAPI.new(@token)
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|