facebook_oauth 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) Richard Taylor
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,70 @@
1
+ h1. Facebook OAuth Graph API client library for Ruby
2
+
3
+ h2. Install the gem
4
+
5
+ sudo gem install facebook_oauth
6
+
7
+ h2. Using the gem
8
+
9
+ To make authorized requests with the client library you'll need to "create a Facebook Application":http://www.facebook.com/developers/createapp.php.
10
+
11
+ h2. Authorized request example
12
+
13
+ To use the full power of the Facebook API you need to authorize your application and a valid Facebook user via OAuth.
14
+ An example showing how to update the status of an authorized user is below.
15
+
16
+ Firstly we need to create an instance of the client with your application client credentials you have been given by Facebook
17
+ when you set up your application.
18
+
19
+ <pre><code>client = FacebookOAuth::Client.new(
20
+ :application_id => 'YOUR_APPLICATION_ID',
21
+ :application_secret => 'YOUR_APP_SECRET_KEY',
22
+ :callback => 'http://example.com/facebook/callback'
23
+ )
24
+
25
+ client.authorize_url
26
+ => "https://graph.facebook.com/oauth/authorize?scope=SCOPE&client_id=ID&type=web_server&redirect_uri=CALLBACK"
27
+ </code></pre>
28
+
29
+ In your application your user would be redirected to Facebook to authorize the application at this point. The code continues below assuming the user has authorized your application, facebook will return to your callback URL with a <code>code</code> parameter.
30
+
31
+ <pre><code>access_token = client.authorize(:code => code)
32
+
33
+ client.me.info # returns your user information
34
+ </code></pre>
35
+
36
+ Now if you keep hold of the access_token.token (usually in the database) for this user you won't need to re-authorize them next time. When you create an instance of the client you can just pass in the access token and secret that you have stored.
37
+
38
+ <pre><code>access_token = @user.access_token # assuming @user
39
+ client = FacebookOAuth::Client.new(
40
+ :application_id => 'YOUR_APPLICATION_ID',
41
+ :application_secret => 'YOUR_APP_SECRET_KEY',
42
+ :callback => 'http://example.com/facebook/callback',
43
+ :token => access_token
44
+ )
45
+
46
+ client.me.info # returns your user information
47
+ </code></pre>
48
+
49
+
50
+ h2. Supported objects
51
+
52
+ * Me (a special object that represents the current authorized user)
53
+
54
+ * Album
55
+ * Event
56
+ * Group
57
+ * Link
58
+ * Note
59
+ * Page
60
+ * Photo
61
+ * Post
62
+ * Status
63
+ * User
64
+ * Video
65
+
66
+ You can access any object listed above in the same way via the API. For example, event attendees would be:
67
+
68
+ <code>client.event('event_id').attending</code>
69
+
70
+ Check out the "Facebook API Reference":http://developers.facebook.com/docs/reference/api/ to see what methods are available.
@@ -0,0 +1,8 @@
1
+ require 'oauth2'
2
+ require 'json'
3
+ require 'mime/types'
4
+
5
+ require 'facebook_oauth/client'
6
+
7
+ module FacebookOAuth
8
+ end
@@ -0,0 +1,59 @@
1
+ require 'facebook_oauth/objects'
2
+
3
+ module FacebookOAuth
4
+ class Client
5
+
6
+ def initialize(options = {})
7
+ @application_id = options[:application_id]
8
+ @application_secret = options[:application_secret]
9
+ @callback = options[:callback]
10
+ @token = options[:token]
11
+ end
12
+
13
+ def authorize_url(options = {})
14
+ options[:scope] ||= 'email,offline_access'
15
+ consumer.web_server.authorize_url(
16
+ :redirect_uri => options[:callback] || @callback,
17
+ :scope => options[:scope]
18
+ )
19
+ end
20
+
21
+ def authorize(options = {})
22
+ @access_token ||= consumer.web_server.get_access_token(
23
+ options[:code],
24
+ :redirect_uri => options[:callback] || @callback
25
+ )
26
+ @token ||= @access_token.token
27
+ @access_token
28
+ end
29
+
30
+ private
31
+ def consumer
32
+ @consumer ||= OAuth2::Client.new(
33
+ @application_id,
34
+ @application_secret,
35
+ { :site=>"https://graph.facebook.com" }
36
+ )
37
+ end
38
+
39
+ def access_token
40
+ @access_token ||= OAuth2::AccessToken.new(consumer, @token)
41
+ end
42
+
43
+ def _get(url)
44
+ oauth_response = access_token.get(url)
45
+ JSON.parse(oauth_response)
46
+ end
47
+
48
+ def _post(url, body = '', headers = {})
49
+ oauth_response = access_token.post(url, body, headers)
50
+ JSON.parse(oauth_response)
51
+ end
52
+
53
+ def _delete(url)
54
+ oauth_response = access_token.delete(url)
55
+ JSON.parse(oauth_response)
56
+ end
57
+ end
58
+ end
59
+
@@ -0,0 +1,70 @@
1
+ module FacebookOAuth
2
+ class Client
3
+
4
+ def me(id = 'me')
5
+ FacebookOAuth::FacebookObject.new(id, self)
6
+ end
7
+
8
+ def album(id)
9
+ FacebookOAuth::FacebookObject.new(id, self)
10
+ end
11
+
12
+ def event(id)
13
+ FacebookOAuth::FacebookObject.new(id, self)
14
+ end
15
+
16
+ def group(id)
17
+ FacebookOAuth::FacebookObject.new(id, self)
18
+ end
19
+
20
+ def link(id)
21
+ FacebookOAuth::FacebookObject.new(id, self)
22
+ end
23
+
24
+ def note(id)
25
+ FacebookOAuth::FacebookObject.new(id, self)
26
+ end
27
+
28
+ def page(id)
29
+ FacebookOAuth::FacebookObject.new(id, self)
30
+ end
31
+
32
+ def photo(id)
33
+ FacebookOAuth::FacebookObject.new(id, self)
34
+ end
35
+
36
+ def post(id)
37
+ FacebookOAuth::FacebookObject.new(id, self)
38
+ end
39
+
40
+ def status(id)
41
+ FacebookOAuth::FacebookObject.new(id, self)
42
+ end
43
+
44
+ def user(id)
45
+ FacebookOAuth::FacebookObject.new(id, self)
46
+ end
47
+
48
+ def video(id)
49
+ FacebookOAuth::FacebookObject.new(id, self)
50
+ end
51
+
52
+ end
53
+
54
+ class FacebookObject
55
+ def initialize(oid, client)
56
+ @oid = oid
57
+ @client = client
58
+ end
59
+
60
+ def info
61
+ @client.send(:_get, @oid)
62
+ end
63
+
64
+ def method_missing(a)
65
+ puts a.inspect
66
+ @client.send(:_get, "#{@oid}/#{a.to_s}")
67
+ end
68
+
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: facebook_oauth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Richard Taylor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-05-06 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: oauth2
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.8
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.9
34
+ - - <=
35
+ - !ruby/object:Gem::Version
36
+ version: 1.2.4
37
+ version:
38
+ - !ruby/object:Gem::Dependency
39
+ name: mime-types
40
+ type: :runtime
41
+ version_requirement:
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "1.16"
47
+ version:
48
+ - !ruby/object:Gem::Dependency
49
+ name: shoulda
50
+ type: :development
51
+ version_requirement:
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ - !ruby/object:Gem::Dependency
59
+ name: mocha
60
+ type: :development
61
+ version_requirement:
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ description: facebook_oauth is a Ruby client library for facebook using the oauth method.
69
+ email: moomerman@gmail.com
70
+ executables: []
71
+
72
+ extensions: []
73
+
74
+ extra_rdoc_files: []
75
+
76
+ files:
77
+ - LICENSE
78
+ - README.textile
79
+ - lib/facebook_oauth.rb
80
+ - lib/facebook_oauth/client.rb
81
+ - lib/facebook_oauth/objects.rb
82
+ has_rdoc: true
83
+ homepage: http://github.com/moomerman/facebook_oauth
84
+ licenses: []
85
+
86
+ post_install_message:
87
+ rdoc_options:
88
+ - --inline-source
89
+ - --charset=UTF-8
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ version:
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ version:
104
+ requirements: []
105
+
106
+ rubyforge_project: facebook_oauth
107
+ rubygems_version: 1.3.5
108
+ signing_key:
109
+ specification_version: 2
110
+ summary: facebook_oauth is a Ruby client library for facebook using the oauth method.
111
+ test_files: []
112
+