ruby_fgraph 0.0.11
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/LICENSE +3 -0
- data/README +4 -0
- data/Rakefile +45 -0
- data/lib/ruby_fgraph.rb +5 -0
- data/lib/ruby_fgraph/connection.rb +84 -0
- data/spec/ruby_fgraph/connection_spec.rb +33 -0
- data/spec/spec_helper.rb +9 -0
- metadata +69 -0
data/LICENSE
ADDED
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#
|
2
|
+
# To change this template, choose Tools | Templates
|
3
|
+
# and open the template in the editor.
|
4
|
+
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'rake'
|
8
|
+
require 'rake/clean'
|
9
|
+
require 'rake/gempackagetask'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
require 'rake/testtask'
|
12
|
+
|
13
|
+
spec = Gem::Specification.new do |s|
|
14
|
+
s.name = 'ruby_fgraph'
|
15
|
+
s.version = '0.0.11'
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.extra_rdoc_files = ['README', 'LICENSE']
|
18
|
+
s.summary = 'Your summary here'
|
19
|
+
s.description = s.summary
|
20
|
+
s.author = 'randx'
|
21
|
+
s.email = 'railsonweb@gmail.com'
|
22
|
+
# s.executables = ['your_executable_here']
|
23
|
+
s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
|
24
|
+
s.require_path = "lib"
|
25
|
+
# s.bindir = "bin"
|
26
|
+
end
|
27
|
+
|
28
|
+
Rake::GemPackageTask.new(spec) do |p|
|
29
|
+
p.gem_spec = spec
|
30
|
+
p.need_tar = true
|
31
|
+
p.need_zip = true
|
32
|
+
end
|
33
|
+
|
34
|
+
Rake::RDocTask.new do |rdoc|
|
35
|
+
files =['README', 'LICENSE', 'lib/**/*.rb']
|
36
|
+
rdoc.rdoc_files.add(files)
|
37
|
+
rdoc.main = "README" # page to start on
|
38
|
+
rdoc.title = "FGraph Docs"
|
39
|
+
rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
|
40
|
+
rdoc.options << '--line-numbers'
|
41
|
+
end
|
42
|
+
|
43
|
+
Rake::TestTask.new do |t|
|
44
|
+
t.test_files = FileList['test/**/*.rb']
|
45
|
+
end
|
data/lib/ruby_fgraph.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "oauth2"
|
3
|
+
# Connection class
|
4
|
+
# for authentication
|
5
|
+
# and api queries
|
6
|
+
# based on oauth2 gem
|
7
|
+
module FGraph
|
8
|
+
class Connection
|
9
|
+
attr_writer :token
|
10
|
+
|
11
|
+
# Create Facebook connection object
|
12
|
+
# for future authorization
|
13
|
+
# and query requests
|
14
|
+
def initialize opt={}
|
15
|
+
@facebook_app = {
|
16
|
+
:api_url => "https://graph.facebook.com",
|
17
|
+
:app_id => "",
|
18
|
+
:app_secret => "",
|
19
|
+
:callback_url => "",
|
20
|
+
:access_token => "",
|
21
|
+
:scopes => 'email,offline_access,read_stream,user_about_me'
|
22
|
+
}
|
23
|
+
opt.each { |key, v| @facebook_app[key.to_sym] = v }
|
24
|
+
end
|
25
|
+
|
26
|
+
# check if connection
|
27
|
+
# authorized (get correct token)
|
28
|
+
def is_authorized?
|
29
|
+
valid_token? ? true : false
|
30
|
+
end
|
31
|
+
|
32
|
+
# get oauth2 client object
|
33
|
+
# for authorization
|
34
|
+
# so token can be recieved
|
35
|
+
def client
|
36
|
+
@client ||= OAuth2::Client.new @facebook_app[:app_id], @facebook_app[:app_secret], :site => @facebook_app[:api_url]
|
37
|
+
end
|
38
|
+
|
39
|
+
# get authorize url
|
40
|
+
# for redirection from app
|
41
|
+
def rails_authorize_redirect
|
42
|
+
client.web_server.authorize_url(
|
43
|
+
:redirect_uri => @facebook_app[:callback_url],
|
44
|
+
:scope => @facebook_app[:scopes]
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
# get token using code
|
49
|
+
# after auth passed
|
50
|
+
def accept_token code
|
51
|
+
token_obj = client.web_server.get_access_token(code, {:redirect_uri => @facebook_app[:callback_url]})
|
52
|
+
@token = token_obj.token
|
53
|
+
end
|
54
|
+
|
55
|
+
# get access token
|
56
|
+
# for auth queries
|
57
|
+
def get_access_token
|
58
|
+
@token
|
59
|
+
end
|
60
|
+
|
61
|
+
# check if token
|
62
|
+
# is valid
|
63
|
+
def valid_token?
|
64
|
+
begin
|
65
|
+
self.query
|
66
|
+
return true
|
67
|
+
rescue Exception => ex
|
68
|
+
return false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# authorization connect
|
73
|
+
# using token for future request
|
74
|
+
def auth_api_connect
|
75
|
+
@auth_api_connect ||= OAuth2::AccessToken.new client, @token
|
76
|
+
end
|
77
|
+
|
78
|
+
# get api response for query
|
79
|
+
# only for auth connections
|
80
|
+
def query string = '/me'
|
81
|
+
auth_api_connect.get(string)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe FGraph::Connection do
|
6
|
+
before(:each) do
|
7
|
+
@valid_params = {
|
8
|
+
:app_id => '149291415089452',
|
9
|
+
:app_secret => '4e13073ded8bfb0cc3279e86811121b0'
|
10
|
+
}
|
11
|
+
@valid_token = "149291415089452|0167f243d68e03b3d7ed89dc-1642845171|HIVODHHm-i9Ho3ccAr7yzucn8hM" #paste valid token here
|
12
|
+
|
13
|
+
@f_connection = FGraph::Connection.new
|
14
|
+
@f_connection_valid = FGraph::Connection.new @valid_params
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should create connection object even without params" do
|
18
|
+
@f_connection.class.name.should == "FGraph::Connection"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return oauth2 client object" do
|
22
|
+
@f_connection.client.class.name.should == "OAuth2::Client"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should say that you are not authorized without token" do
|
26
|
+
@f_connection.is_authorized?.should == false
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should pass validation of token if you provide correct one" do
|
30
|
+
@f_connection_valid.token = @valid_token
|
31
|
+
@f_connection_valid.is_authorized?.should == true
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_fgraph
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 11
|
9
|
+
version: 0.0.11
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- randx
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-09-29 00:00:00 +03:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Your summary here
|
22
|
+
email: railsonweb@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README
|
29
|
+
- LICENSE
|
30
|
+
files:
|
31
|
+
- LICENSE
|
32
|
+
- README
|
33
|
+
- Rakefile
|
34
|
+
- lib/ruby_fgraph.rb
|
35
|
+
- lib/ruby_fgraph/connection.rb
|
36
|
+
- spec/spec_helper.rb
|
37
|
+
- spec/ruby_fgraph/connection_spec.rb
|
38
|
+
has_rdoc: true
|
39
|
+
homepage:
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.3.6
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Your summary here
|
68
|
+
test_files: []
|
69
|
+
|