faceb 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/README.md +25 -7
- data/VERSION +1 -1
- data/faceb.gemspec +3 -2
- data/features/step_definitions/facebook-session_steps.rb +1 -1
- data/lib/faceb/base.rb +1 -1
- data/lib/faceb/rails.rb +3 -2
- data/lib/faceb/rails/generators/config/templates/faceb.yml +8 -3
- data/lib/faceb/rails/tasks/faceb.tasks +9 -2
- data/lib/faceb/rails/tasks/tunnel.tasks +1 -1
- data/lib/faceb/session.rb +15 -0
- data/spec/faceb_base_spec.rb +4 -4
- data/spec/faceb_session_spec.rb +25 -1
- metadata +4 -3
data/CHANGELOG
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
- 0.1.1 (April 6st, 2010)
|
2
|
+
- Added some Rails 2.3.x compatibility
|
3
|
+
- Allow to reset the current session via 'reset!' instance method
|
4
|
+
- Renamed 'FaceB#current_session' in 'FaceB#session'
|
5
|
+
- Allow FaceB::Session to call Facebook API method dynamically.
|
6
|
+
eg :
|
7
|
+
session.users.getInfo :fields => 'name', :uids => 12345
|
8
|
+
=> session.call('users.getInfo', :fields => 'name', :uids => 12345)
|
data/README.md
CHANGED
@@ -20,28 +20,46 @@ Or if you call more than once API methods, you can create a persistent session l
|
|
20
20
|
|
21
21
|
require 'faceb'
|
22
22
|
FaceB.new('api-key', 'secret-key')
|
23
|
-
FaceB.
|
24
|
-
FaceB.
|
23
|
+
FaceB.session.call('users.getInfo', :fields => 'name', :uids => 123456)
|
24
|
+
FaceB.session.call('users.getInfo', :fields => 'name', :uids => 123456)
|
25
|
+
|
26
|
+
Or you can even call API method dynamically :
|
27
|
+
|
28
|
+
require 'faceb'
|
29
|
+
FaceB.new('api-key', 'secret-key')
|
30
|
+
FaceB.session.users.getInfo(:fields => 'name', :uids => 123456)
|
31
|
+
|
25
32
|
|
26
33
|
### Rails integration
|
27
34
|
|
28
|
-
|
35
|
+
#### Rails 3 initialization
|
29
36
|
|
30
|
-
First thing to do is to add FaceB as dependency of your new project, add this line
|
37
|
+
First thing to do is to add FaceB as dependency of your new project, add this line at the end of your `Gemfile` file :
|
31
38
|
|
32
39
|
gem 'faceb'
|
33
40
|
|
34
41
|
Then call the initialization script like this :
|
35
42
|
|
36
|
-
$ ./script/rails generate face_b:config
|
43
|
+
$ ./script/rails generate face_b:config --api-key=xxxx --secret-key=xxxx
|
37
44
|
|
38
45
|
This generator will create a new file named `faceb.yml` in your `config` directory.
|
39
46
|
Edit this new file with your Facebook application properties.
|
40
47
|
|
41
48
|
|
42
|
-
|
49
|
+
#### Rails 2.3.x initialization
|
50
|
+
|
51
|
+
In your `config/environment.rb` add this line :
|
52
|
+
|
53
|
+
Rails::Initializer.run do |config|
|
54
|
+
[...]
|
55
|
+
config.gem 'faceb'
|
56
|
+
[...]
|
57
|
+
end
|
58
|
+
|
59
|
+
And run the following rake task :
|
60
|
+
|
61
|
+
rake face_b:config API_KEY=xxxx SECRET_KEY=xxxx
|
43
62
|
|
44
|
-
A version compatible with Rails 2.3.x is in progress.
|
45
63
|
|
46
64
|
|
47
65
|
## TODO
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/faceb.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{faceb}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mathieu Fosse"]
|
12
|
-
s.date = %q{2010-04-
|
12
|
+
s.date = %q{2010-04-06}
|
13
13
|
s.default_executable = %q{console}
|
14
14
|
s.description = %q{Facebook library}
|
15
15
|
s.email = %q{mathieu@tigerlilyapps.com}
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.files = [
|
22
22
|
".document",
|
23
23
|
".gitignore",
|
24
|
+
"CHANGELOG",
|
24
25
|
"Gemfile",
|
25
26
|
"LICENSE",
|
26
27
|
"README.md",
|
data/lib/faceb/base.rb
CHANGED
data/lib/faceb/rails.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
+
require 'faceb/rails/base'
|
2
|
+
|
1
3
|
if Rails.version >= "3.0"
|
2
4
|
require 'faceb/rails/railtie'
|
3
5
|
require 'faceb/rails/generators'
|
6
|
+
require 'faceb/rails/api'
|
4
7
|
elsif Rails.version >= "2.3"
|
5
8
|
require 'faceb/rails/rails_23_init'
|
6
9
|
else
|
7
10
|
raise "Sorry, but FaceB needs Rails 2.3 or later"
|
8
11
|
end
|
9
12
|
|
10
|
-
require 'faceb/rails/base'
|
11
|
-
require 'faceb/rails/api'
|
12
13
|
require 'faceb/rails/controller'
|
@@ -1,6 +1,11 @@
|
|
1
1
|
development: &DEVELOPMENT
|
2
|
-
api_key: <%= options.api_key %>
|
3
|
-
secret_key: <%= options.secret_key %>
|
2
|
+
api_key: <%= ENV['API_KEY'] || options.api_key %>
|
3
|
+
secret_key: <%= ENV['SECRET_KEY'] || options.secret_key %>
|
4
|
+
tunnel:
|
5
|
+
public_host:
|
6
|
+
public_host_username:
|
7
|
+
public_port:
|
8
|
+
local_port:
|
4
9
|
|
5
10
|
test:
|
6
|
-
<<: *DEVELOPMENT
|
11
|
+
<<: *DEVELOPMENT
|
@@ -1,6 +1,13 @@
|
|
1
|
-
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
namespace :face_b do
|
2
4
|
desc "Configure environment to use FaceB"
|
3
5
|
task :config => :environment do
|
4
|
-
|
6
|
+
ENV['API_KEY'] ||= ""
|
7
|
+
ENV['SECRET_KEY'] ||= ""
|
8
|
+
config_file = File.dirname(__FILE__) + '/../generators/config/templates/faceb.yml'
|
9
|
+
File.open(File.join(Rails.root, 'config', 'faceb.yml'), 'w') do |f|
|
10
|
+
f.write ERB.new(IO.read(config_file)).result(binding)
|
11
|
+
end
|
5
12
|
end
|
6
13
|
end
|
data/lib/faceb/session.rb
CHANGED
@@ -15,6 +15,10 @@ module FaceB
|
|
15
15
|
@current_session = nil
|
16
16
|
end
|
17
17
|
|
18
|
+
def reset!
|
19
|
+
self.class.reset!
|
20
|
+
end
|
21
|
+
|
18
22
|
def initialize(api_key, secret_key, session_key = nil)
|
19
23
|
@api_key = api_key
|
20
24
|
@secret_key = secret_key
|
@@ -23,6 +27,7 @@ module FaceB
|
|
23
27
|
end
|
24
28
|
|
25
29
|
def call(method, params ={})
|
30
|
+
@scope = nil
|
26
31
|
Api.new(self).call(method, params)
|
27
32
|
end
|
28
33
|
|
@@ -34,5 +39,15 @@ module FaceB
|
|
34
39
|
def secured?
|
35
40
|
!!@user_facebook_uid
|
36
41
|
end
|
42
|
+
|
43
|
+
# Allow session to dynamically call API method
|
44
|
+
def method_missing(method_name, args={})
|
45
|
+
if !!@scope
|
46
|
+
self.call("#{@scope}.#{method_name}", args)
|
47
|
+
else
|
48
|
+
@scope = method_name
|
49
|
+
self
|
50
|
+
end
|
51
|
+
end
|
37
52
|
end
|
38
53
|
end
|
data/spec/faceb_base_spec.rb
CHANGED
@@ -2,12 +2,12 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
3
3
|
describe FaceB do
|
4
4
|
|
5
|
-
describe "#
|
5
|
+
describe "#session" do
|
6
6
|
before(:each) do
|
7
7
|
@session = FaceB.new('api-key', 'secret-key')
|
8
8
|
end
|
9
9
|
|
10
|
-
subject { FaceB.
|
10
|
+
subject { FaceB.session }
|
11
11
|
|
12
12
|
it { should be_an_instance_of(FaceB::Session) }
|
13
13
|
it { should == @session }
|
@@ -29,7 +29,7 @@ describe FaceB do
|
|
29
29
|
|
30
30
|
it "should be able to reset the current session" do
|
31
31
|
FaceB::Session.reset!
|
32
|
-
FaceB.
|
32
|
+
FaceB.session.should be_nil
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -38,7 +38,7 @@ describe FaceB do
|
|
38
38
|
it "should be able to call the api without create a session before" do
|
39
39
|
mock.instance_of(FaceB::Session).call('method', :params => 1) { "response" }
|
40
40
|
FaceB.call('api-key', 'secret-key', 'method', :params => 1).should == "response"
|
41
|
-
FaceB.
|
41
|
+
FaceB.session.should be_nil
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
data/spec/faceb_session_spec.rb
CHANGED
@@ -3,6 +3,25 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
3
3
|
module FaceB
|
4
4
|
describe Session do
|
5
5
|
|
6
|
+
# Dynamic API call
|
7
|
+
context "When call API" do
|
8
|
+
before(:each) do
|
9
|
+
@session = FaceB::Session.new('api-key', 'secret-key')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be able to call an API method" do
|
13
|
+
mock(FaceB::Api).post(FaceB::Api::API_SERVER_URL, is_a(Hash)) { "data" }
|
14
|
+
response = @session.call('scope.api_method', :param1 => 'value1')
|
15
|
+
response.should be_an_instance_of(FaceB::Api::Response)
|
16
|
+
response.data.should == "data"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be able to dynamically build an API method" do
|
20
|
+
mock(@session).call('scope.api_method', :param1 => 'value1')
|
21
|
+
response = @session.scope.api_method(:param1 => 'value1')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
6
25
|
# Create session
|
7
26
|
context "When create session" do
|
8
27
|
before(:each) do
|
@@ -20,10 +39,15 @@ module FaceB
|
|
20
39
|
FaceB::Session.current.should == @session
|
21
40
|
end
|
22
41
|
|
23
|
-
it "should be able to reset the current session" do
|
42
|
+
it "should be able to reset the current session by class method" do
|
24
43
|
FaceB::Session.reset!
|
25
44
|
FaceB::Session.current.should be_nil
|
26
45
|
end
|
46
|
+
|
47
|
+
it "should be able to reset the current session by instance method" do
|
48
|
+
FaceB::Session.current.reset!
|
49
|
+
FaceB::Session.current.should be_nil
|
50
|
+
end
|
27
51
|
end
|
28
52
|
|
29
53
|
# New session
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mathieu Fosse
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-06 00:00:00 +02:00
|
18
18
|
default_executable: console
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -111,6 +111,7 @@ extra_rdoc_files:
|
|
111
111
|
files:
|
112
112
|
- .document
|
113
113
|
- .gitignore
|
114
|
+
- CHANGELOG
|
114
115
|
- Gemfile
|
115
116
|
- LICENSE
|
116
117
|
- README.md
|