fbgraph 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest ADDED
@@ -0,0 +1,12 @@
1
+ README
2
+ Rakefile
3
+ lib/fbgraph.rb
4
+ lib/fbgraph/authorization.rb
5
+ lib/fbgraph/base.rb
6
+ lib/fbgraph/client.rb
7
+ lib/fbgraph/search.rb
8
+ lib/fbgraph/selection.rb
9
+ specs/lib/fbauth/authorization_spec.rb
10
+ specs/lib/fbauth/base_spec.rb
11
+ specs/lib/fbauth/search_spec.rb
12
+ Manifest
data/README ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('fbgraph', '0.0.2') do |p|
6
+ p.description = "A Gem for Facebook Open Graph API"
7
+ p.url = "http://github.com/nsanta/fbgraph"
8
+ p.author = "Nicolas Santa"
9
+ p.email = "nicolas55ar@gmail.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = ['oauth2']
12
+ end
data/fbgraph.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{fbgraph}
5
+ s.version = "0.0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Nicolas Santa"]
9
+ s.date = %q{2010-05-07}
10
+ s.description = %q{A Gem for Facebook Open Graph API}
11
+ s.email = %q{nicolas55ar@gmail.com}
12
+ s.extra_rdoc_files = ["README", "lib/fbgraph.rb", "lib/fbgraph/authorization.rb", "lib/fbgraph/base.rb", "lib/fbgraph/client.rb", "lib/fbgraph/search.rb", "lib/fbgraph/selection.rb"]
13
+ s.files = ["README", "Rakefile", "lib/fbgraph.rb", "lib/fbgraph/authorization.rb", "lib/fbgraph/base.rb", "lib/fbgraph/client.rb", "lib/fbgraph/search.rb", "lib/fbgraph/selection.rb", "specs/lib/fbauth/authorization_spec.rb", "specs/lib/fbauth/base_spec.rb", "specs/lib/fbauth/search_spec.rb", "Manifest", "fbgraph.gemspec"]
14
+ s.homepage = %q{http://github.com/nsanta/fbgraph}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Fbgraph", "--main", "README"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{fbgraph}
18
+ s.rubygems_version = %q{1.3.5}
19
+ s.summary = %q{A Gem for Facebook Open Graph API}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ s.add_development_dependency(%q<oauth2>, [">= 0"])
27
+ else
28
+ s.add_dependency(%q<oauth2>, [">= 0"])
29
+ end
30
+ else
31
+ s.add_dependency(%q<oauth2>, [">= 0"])
32
+ end
33
+ end
data/lib/fbgraph.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'oauth2'
2
+
3
+
4
+ require 'fbgraph/client'
5
+ require 'fbgraph/base'
6
+ require 'fbgraph/authorization'
7
+ require 'fbgraph/selection'
8
+ require 'fbgraph/search'
9
+
10
+
@@ -0,0 +1,20 @@
1
+ module FBGraph
2
+
3
+ class Authorization
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ def authorize_url(params = {})
10
+ @client.oauth_client.web_server.authorize_url(params)
11
+ end
12
+
13
+
14
+ def process_callback(code, options = {})
15
+ @client.consumer = @client.oauth_client.web_server.get_access_token(code, options)
16
+ @client.access_token = @client.consumer.token
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,65 @@
1
+ module FBGraph
2
+
3
+ class Base
4
+
5
+ attr_reader :objects , :connection_type
6
+
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+
12
+
13
+ def find(objects)
14
+ @objects = objects
15
+ return self
16
+ end
17
+
18
+
19
+ def connection(connection_type)
20
+ @connection_type = connection_type
21
+ return self
22
+ end
23
+
24
+ def params(params)
25
+ @params = params
26
+ return self
27
+ end
28
+
29
+
30
+ def info(parsed = true)
31
+ if @objects.is_a? Array
32
+ @params.merge!({:ids => ids.join(',')})
33
+ uri = build_open_graph_uri(nil , nil , @params)
34
+ elsif @objects.is_a? String
35
+ uri = build_open_graph_uri(@objects , @connection_type , @params)
36
+ end
37
+ result = @client.consumer.get(uri)
38
+ return parsed ? JSON.parse(result) : result
39
+ end
40
+
41
+
42
+ def publish(parsed = true)
43
+ consume!(:post , parsed)
44
+ end
45
+
46
+ def delete(parsed = true)
47
+ @params = {:method => 'delete'}
48
+ consume!(:post, parsed)
49
+ end
50
+
51
+ private
52
+
53
+ def build_open_graph_uri(id,connection_type = nil, params = {})
54
+ request = "/" + [id , connection_type].compact.join('/')
55
+ request += "?"+params.to_a.map{|p| p.join('=')}.join('&')
56
+ request
57
+ end
58
+
59
+ def consume!(verb, parse)
60
+ uri = build_open_graph_uri(@objects , @connection_type , @params)
61
+ result = @client.consumer.send(verb,uri)
62
+ return parsed ? JSON.parse(result) : result
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,35 @@
1
+ module FBGraph
2
+
3
+ class Client
4
+ attr_accessor :client_id , :secret_id , :facebook_uri , :access_token , :consumer
5
+
6
+
7
+ def initialize(options)
8
+ self.client_id , self.secret_id = options[:client_id] , options[:secret_id]
9
+ @facebook_uri = 'https://graph.facebook.com'
10
+ if self.access_token = options[:token]
11
+ self.consumer = OAuth2::AccessToken.new(oauth_client , self.access_token)
12
+ end
13
+ return true
14
+ end
15
+
16
+
17
+ def authorization
18
+ FBGraph::Authorization.new(self)
19
+ end
20
+
21
+ def selection
22
+ FBGraph::Selection.new(self)
23
+ end
24
+
25
+ def search
26
+ FBGraph::Search.new(self)
27
+ end
28
+
29
+
30
+ def oauth_client
31
+ OAuth2::Client.new(client_id, secret_id, :site => facebook_uri)
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,18 @@
1
+ module FBGraph
2
+ class Search < Base
3
+
4
+ def query(q)
5
+ @objects = 'search'
6
+ @params = {:q => q}
7
+ return self
8
+ end
9
+
10
+ def on(type)
11
+ @params.merge!({:type => type})
12
+ return self
13
+ end
14
+
15
+
16
+
17
+ end
18
+ end
@@ -0,0 +1,40 @@
1
+ module FBGraph
2
+ class Selection < Base
3
+
4
+ def me
5
+ find('me')
6
+ end
7
+
8
+ OBJECTS = %w(user album event group link note page photo post status video).freeze
9
+
10
+ CONNECTION_TYPES = %w(home photos comments feed noreply
11
+ maybe invited attending declined picture
12
+ members picture tagged links groups albums
13
+ statuses videos notes posts events friends
14
+ activities interests music books movies television
15
+ likes inbox outbox updates).freeze
16
+
17
+ OBJECTS.each do |object|
18
+ class_eval <<-METHOD
19
+ def #{object}(object)
20
+ find(object)
21
+ self
22
+ end
23
+ METHOD
24
+ end
25
+
26
+ CONNECTION_TYPES.each do |object|
27
+ class_eval <<-METHOD
28
+ def #{object}(object)
29
+ connection(object)
30
+ self
31
+ end
32
+ METHOD
33
+ end
34
+
35
+ def metadata
36
+ @params.merge!({:metadata => '1'})
37
+ self
38
+ end
39
+ end
40
+ end
File without changes
File without changes
File without changes
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fbgraph
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Santa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-05-07 00:00:00 -03:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: oauth2
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: A Gem for Facebook Open Graph API
26
+ email: nicolas55ar@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ - lib/fbgraph.rb
34
+ - lib/fbgraph/authorization.rb
35
+ - lib/fbgraph/base.rb
36
+ - lib/fbgraph/client.rb
37
+ - lib/fbgraph/search.rb
38
+ - lib/fbgraph/selection.rb
39
+ files:
40
+ - README
41
+ - Rakefile
42
+ - lib/fbgraph.rb
43
+ - lib/fbgraph/authorization.rb
44
+ - lib/fbgraph/base.rb
45
+ - lib/fbgraph/client.rb
46
+ - lib/fbgraph/search.rb
47
+ - lib/fbgraph/selection.rb
48
+ - specs/lib/fbauth/authorization_spec.rb
49
+ - specs/lib/fbauth/base_spec.rb
50
+ - specs/lib/fbauth/search_spec.rb
51
+ - Manifest
52
+ - fbgraph.gemspec
53
+ has_rdoc: true
54
+ homepage: http://github.com/nsanta/fbgraph
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --line-numbers
60
+ - --inline-source
61
+ - --title
62
+ - Fbgraph
63
+ - --main
64
+ - README
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "1.2"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project: fbgraph
82
+ rubygems_version: 1.3.5
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: A Gem for Facebook Open Graph API
86
+ test_files: []
87
+