rfgraph 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.md +48 -0
- data/lib/rfgraph.rb +19 -0
- data/lib/rfgraph/auth.rb +26 -0
- data/lib/rfgraph/request.rb +82 -0
- metadata +65 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2010 Conor Hunt <conor.hunt@gmail.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
Ruby Facebook Graph API Wrapper
|
2
|
+
===============================
|
3
|
+
|
4
|
+
A simple Ruby wrapper to help use the Facebook Graph API.
|
5
|
+
|
6
|
+
Documentation on the Graph API is available here:
|
7
|
+
http://developers.facebook.com/docs/
|
8
|
+
|
9
|
+
Install
|
10
|
+
-------
|
11
|
+
|
12
|
+
gem install rfgraph
|
13
|
+
|
14
|
+
Example
|
15
|
+
-------
|
16
|
+
|
17
|
+
require 'rfgraph'
|
18
|
+
fauth = RFGraph::Auth.new(APP_ID, APP_SECRET)
|
19
|
+
|
20
|
+
# Get the URL to redirect your user to in their web browser
|
21
|
+
auth_url = fauth.authorize_url("http://yourwebsite.com/callback")
|
22
|
+
|
23
|
+
# Get the code that facebook returns after the user auths your app and turn that into a auth token
|
24
|
+
auth_token = fauth.authorize("http://yourwebsite.com/callback", FACEBOOK_CODE)
|
25
|
+
|
26
|
+
# Make some requests
|
27
|
+
request = RFGraph::Request.new(auth_token)
|
28
|
+
request.get_object("me")
|
29
|
+
|
30
|
+
# Returns something like
|
31
|
+
#{
|
32
|
+
# "id" => "57373737593",
|
33
|
+
# "name" => "Some User",
|
34
|
+
# "first_name" => "Some",
|
35
|
+
# "last_name" => "User",
|
36
|
+
# "link" => "http://www.facebook.com/someuser",
|
37
|
+
# "timezone" => -4,
|
38
|
+
# "verified" => true,
|
39
|
+
# "updated_time" => "2010-03-30T01:27:19+0000"
|
40
|
+
# }
|
41
|
+
|
42
|
+
request.put_wall_post("Awesome message!")
|
43
|
+
|
44
|
+
COPYRIGHT
|
45
|
+
---------
|
46
|
+
|
47
|
+
Copyright (c) 2010 Conor Hunt <conor.hunt@gmail.com>
|
48
|
+
Released under the MIT license
|
data/lib/rfgraph.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rfgraph/request'
|
2
|
+
require 'rfgraph/auth'
|
3
|
+
|
4
|
+
module RFGraph
|
5
|
+
BASE_URL = "https://graph.facebook.com"
|
6
|
+
|
7
|
+
def self.get_user_from_cookie(cookies, app_id, app_secret)
|
8
|
+
# TODO
|
9
|
+
end
|
10
|
+
|
11
|
+
class RFGraphError < RuntimeError
|
12
|
+
attr_accessor :code
|
13
|
+
|
14
|
+
def initialize(code, message)
|
15
|
+
@code = code
|
16
|
+
super(message)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/rfgraph/auth.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'cgi'
|
3
|
+
|
4
|
+
module RFGraph
|
5
|
+
class Auth
|
6
|
+
attr_accessor :app_id
|
7
|
+
attr_accessor :app_secret
|
8
|
+
attr_accessor :access_token
|
9
|
+
attr_accessor :expires
|
10
|
+
|
11
|
+
def initialize(app_id, app_secret)
|
12
|
+
@app_id = app_id
|
13
|
+
@app_secret = app_secret
|
14
|
+
end
|
15
|
+
|
16
|
+
def authorize_url(callback_url)
|
17
|
+
"#{BASE_URL}/oauth/authorize?client_id=#{app_id}&redirect_uri=#{callback_url}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def authorize(callback_url, code)
|
21
|
+
data = open("#{BASE_URL}/oauth/access_token?client_id=#{app_id}&redirect_uri=#{CGI.escape callback_url}&client_secret=#{app_secret}&code=#{CGI.escape code}").read
|
22
|
+
@expires = data.match(/expires=([^&]+)/)[1]
|
23
|
+
@access_token = data.match(/access_token=([^&]+)/)[1]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
|
5
|
+
module RFGraph
|
6
|
+
class Request
|
7
|
+
attr_accessor :access_token
|
8
|
+
|
9
|
+
def initialize(access_token = nil)
|
10
|
+
@access_token = access_token
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_object(id, args = {})
|
14
|
+
request(id, args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_objects(ids, args = {})
|
18
|
+
args["ids"] = ids.join(",")
|
19
|
+
return request("", args)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_connections(id, connection_name, args = {})
|
23
|
+
return request(id + "/" + connection_name, args)
|
24
|
+
end
|
25
|
+
|
26
|
+
def put_object(parent_object, connection_name, data = {})
|
27
|
+
raise RFGraphError.new(-1, "Access token required for put requests") if access_token.nil?
|
28
|
+
post_request(parent_object + "/" + connection_name, data)
|
29
|
+
end
|
30
|
+
|
31
|
+
def put_wall_post(message, attachment = {}, profile_id = "me")
|
32
|
+
put_object(profile_id, "feed", attachment.merge({'message' => message}))
|
33
|
+
end
|
34
|
+
|
35
|
+
def put_comment(object_id, message)
|
36
|
+
put_object(object_id, "comments", {"message" => message})
|
37
|
+
end
|
38
|
+
|
39
|
+
def put_like(object_id)
|
40
|
+
put_object(object_id, "likes")
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete_object(id)
|
44
|
+
post_request(id, {"method"=> "delete"})
|
45
|
+
end
|
46
|
+
|
47
|
+
def post_request(path, post_args = {})
|
48
|
+
request(path, {}, post_args)
|
49
|
+
end
|
50
|
+
|
51
|
+
def request(path, url_args = {}, post_args = nil)
|
52
|
+
if access_token
|
53
|
+
if post_args
|
54
|
+
post_args["access_token"] = access_token
|
55
|
+
else
|
56
|
+
url_args["access_token"] = access_token
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
encoded_url_args = url_args.collect {|k,v| "#{CGI.escape k}=#{CGI.escape v}" }.join("&")
|
61
|
+
url = URI.parse("#{BASE_URL}/#{path}?#{encoded_url_args}")
|
62
|
+
http = Net::HTTP.new(url.host, url.port)
|
63
|
+
http.use_ssl = true
|
64
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
65
|
+
|
66
|
+
response = if post_args
|
67
|
+
encoded_post_args = post_args.collect {|k,v| "#{CGI.escape k}=#{CGI.escape v}" }.join("&")
|
68
|
+
http.post("#{url.path}?#{url.query}", encoded_post_args)
|
69
|
+
else
|
70
|
+
http.get("#{url.path}?#{url.query}")
|
71
|
+
end
|
72
|
+
|
73
|
+
response = JSON.parse(response.body)
|
74
|
+
|
75
|
+
if response["error"]
|
76
|
+
raise RFGraphError.new(response["error"]["code"], response["error"]["message"])
|
77
|
+
end
|
78
|
+
|
79
|
+
response
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rfgraph
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
version: "0.1"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Conor Hunt
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2010-04-21 00:00:00 -04:00
|
17
|
+
default_executable:
|
18
|
+
dependencies: []
|
19
|
+
|
20
|
+
description: Ruby wrapper for Facebook Graph API
|
21
|
+
email: conor.hunt@gmail.com
|
22
|
+
executables: []
|
23
|
+
|
24
|
+
extensions: []
|
25
|
+
|
26
|
+
extra_rdoc_files: []
|
27
|
+
|
28
|
+
files:
|
29
|
+
- README.md
|
30
|
+
- LICENSE
|
31
|
+
- lib/rfgraph/auth.rb
|
32
|
+
- lib/rfgraph/request.rb
|
33
|
+
- lib/rfgraph.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/conorh/rfgraph
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
version: "0"
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.3.6
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Ruby wrapper for Facebook Graph API
|
64
|
+
test_files: []
|
65
|
+
|