fb_graph 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -20,6 +20,11 @@ Almost all connections for each object are also supported. (Private message co
20
20
 
21
21
  Plus, you can play an Rails sample app here. http://fbgraphsample.heroku.com/
22
22
 
23
+ === Authentication
24
+
25
+ Both Facebook JavaScript SDK and normal OAuth2 flow is supported.
26
+ See http://github.com/nov/fb_graph_sample
27
+
23
28
  === GET
24
29
 
25
30
  ==== Basic Objects
@@ -61,14 +66,36 @@ Plus, you can play an Rails sample app here. http://fbgraphsample.heroku.com/
61
66
  me.home
62
67
  :
63
68
 
69
+ ==== Search
70
+
71
+ # all objects
72
+ FbGraph::Searchable.search("FbGraph") # => Array of Hash
73
+
74
+ # specify type
75
+ FbGraph::Page.search("FbGraph") # => Array of FbGraph::Page
76
+ FbGraph::User.search("matake", :access_token => ACCESS_TOKEN) # => Array of FbGraph::User
77
+
64
78
  ==== Pagination
65
79
 
80
+ # collection
66
81
  user = FbGraph::User.new('matake', :access_token => ACCESS_TOKEN)
67
82
  likes = user.likes # => Array of FbGraph::Like
68
- likes.next # => {:limit => 25, :until => '...'}
69
- likes.previous # => {:limit => 25, :since => '...'}
70
- user.likes(likes.next) # => Array of FbGraph::Like
71
- user.likes(likes.previous) # => Array of FbGraph::Like
83
+ likes.next # => Array of FbGraph::Like (next page)
84
+ likes.previous # => Array of FbGraph::Like (previous page)
85
+ likes.collection.next # => Hash for pagination options (ex. {"limit"=>"25", "until"=>"2010-08-08T03:17:21+0000"})
86
+ likes.collection.previous # => Hash for pagination options (ex. {"limit"=>"25", "since"=>"2010-08-08T06:28:20+0000"})
87
+ user.likes(likes.collection.next) # => same with likes.next
88
+ user.likes(likes.collection.previous) # => same with likes.previous
89
+
90
+ # search results
91
+ results = FbGraph::Page.search("FbGraph") # => Array of FbGraph::Page
92
+ results.next # => Array of FbGraph::Page (next page)
93
+ results.previous # => Array of FbGraph::Page (next page)
94
+ results.klass # => FbGraph::Page
95
+ results.collection.next # => Hash for pagination options (ex. {"limit"=>"25", "until"=>"2010-08-08T03:17:21+0000"})
96
+ results.collection.previous # => Hash for pagination options (ex. {"limit"=>"25", "since"=>"2010-08-08T06:28:20+0000"})
97
+ results.klass.search(results.query, results.collection.next) # => same with results.next
98
+ results.klass.search(results.query, results.collection.previous) # => same with results.previous
72
99
 
73
100
  === POST
74
101
 
@@ -147,6 +174,8 @@ Plus, you can play an Rails sample app here. http://fbgraphsample.heroku.com/
147
174
  :message => 'Hello, where is photo?'
148
175
  )
149
176
 
177
+ === DELETE
178
+
150
179
  ==== Delete an object
151
180
 
152
181
  post = FbGraph::Page.new(117513961602338).feed.first
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.6.0
data/fb_graph.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fb_graph}
8
- s.version = "0.5.0"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["nov matake"]
12
- s.date = %q{2010-08-07}
12
+ s.date = %q{2010-08-08}
13
13
  s.description = %q{A Ruby wrapper for Facebook Graph API}
14
14
  s.email = %q{nov@matake.jp}
15
15
  s.extra_rdoc_files = [
@@ -72,6 +72,7 @@ Gem::Specification.new do |s|
72
72
  "lib/fb_graph/page.rb",
73
73
  "lib/fb_graph/photo.rb",
74
74
  "lib/fb_graph/post.rb",
75
+ "lib/fb_graph/searchable.rb",
75
76
  "lib/fb_graph/status.rb",
76
77
  "lib/fb_graph/tag.rb",
77
78
  "lib/fb_graph/user.rb",
data/lib/fb_graph.rb CHANGED
@@ -50,6 +50,7 @@ require 'fb_graph/comparison'
50
50
  require 'fb_graph/collection'
51
51
  require 'fb_graph/connection'
52
52
  require 'fb_graph/connections'
53
+ require 'fb_graph/searchable'
53
54
 
54
55
  require 'fb_graph/node'
55
56
  require 'fb_graph/album'
@@ -1,25 +1,27 @@
1
1
  module FbGraph
2
2
  class Connection < Collection
3
- attr_accessor :collection, :connection, :owner
3
+ attr_accessor :collection, :connection, :owner, :options
4
4
 
5
- def initialize(owner, connection, collection = FbGraph::Collection.new)
5
+ def initialize(owner, connection, options = {})
6
6
  @owner = owner
7
+ @options = options
7
8
  @connection = connection
8
- @collection = collection
9
+ @collection = options.delete(:collection) || FbGraph::Collection.new
9
10
  replace collection
10
11
  end
11
12
 
12
- def next(options = {})
13
+ def next(_options_ = {})
13
14
  if self.collection.next.present?
14
- self.owner.send(self.connection, options.merge(self.collection.next))
15
+ self.owner.send(self.connection, self.options.merge(_options_).merge(self.collection.next))
15
16
  else
16
17
  self.class.new(self.owner, self.connection)
17
18
  end
18
19
  end
19
20
 
20
- def previous(options = {})
21
+ def previous(_options_ = {})
22
+ puts self.options.inspect
21
23
  if self.collection.previous.present?
22
- self.owner.send(self.connection, options.merge(self.collection.previous))
24
+ self.owner.send(self.connection, self.options.merge(_options_).merge(self.collection.previous))
23
25
  else
24
26
  self.class.new(self.owner, self.connection)
25
27
  end
@@ -7,6 +7,7 @@ module FbGraph
7
7
  include Connections::Attending
8
8
  include Connections::Declined
9
9
  include Connections::Picture
10
+ extend Searchable
10
11
 
11
12
  attr_accessor :owner, :name, :description, :start_time, :end_time, :location, :venue, :privacy, :updated_time
12
13
 
@@ -3,6 +3,7 @@ module FbGraph
3
3
  include Connections::Feed
4
4
  include Connections::Members
5
5
  include Connections::Picture
6
+ include Searchable
6
7
 
7
8
  attr_accessor :owner, :name, :description, :link, :venue, :privacy, :updated_time
8
9
 
data/lib/fb_graph/node.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module FbGraph
2
2
  class Node
3
- include FbGraph::Comparison
3
+ include Comparison
4
4
 
5
5
  attr_accessor :identifier, :endpoint, :access_token
6
6
 
@@ -22,7 +22,7 @@ module FbGraph
22
22
 
23
23
  def connection(connection, options = {})
24
24
  collection = FbGraph::Collection.new(get(options.merge(:connection => connection)))
25
- Connection.new(self, connection, collection)
25
+ Connection.new(self, connection, options.merge(:collection => collection))
26
26
  end
27
27
 
28
28
  def destroy(options = {})
@@ -65,7 +65,7 @@ module FbGraph
65
65
  _endpoint_ = if params[:connection]
66
66
  File.join(self.endpoint, params.delete(:connection).to_s)
67
67
  else
68
- self.endpoint
68
+ params[:endpoint] || self.endpoint
69
69
  end
70
70
 
71
71
  params.delete_if do |k, v|
data/lib/fb_graph/page.rb CHANGED
@@ -12,6 +12,7 @@ module FbGraph
12
12
  include Connections::Notes
13
13
  include Connections::Posts
14
14
  include Connections::Events
15
+ extend Searchable
15
16
 
16
17
  attr_accessor :name, :category
17
18
 
data/lib/fb_graph/post.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module FbGraph
2
2
  class Post < Node
3
3
  include Connections::Comments
4
+ extend Searchable
4
5
 
5
6
  attr_accessor :from, :to, :message, :picture, :link, :name, :caption, :description, :source, :icon, :attribution, :actions, :likes, :created_time, :updated_time
6
7
 
@@ -0,0 +1,51 @@
1
+ module FbGraph
2
+ module Searchable
3
+ def self.search(query, options = {})
4
+ klass = options.delete(:class) || FbGraph::Searchable
5
+ collection = FbGraph::Collection.new(
6
+ FbGraph::Node.new(:search).send(:get, options.merge(:q => query))
7
+ )
8
+ yield collection if block_given?
9
+ FbGraph::Searchable::Result.new(query, klass, options.merge(:collection => collection))
10
+ end
11
+
12
+ def search(query, options = {})
13
+ type = self.to_s.underscore.split('/').last
14
+ FbGraph::Searchable.search(query, options.merge(:type => type, :class => self)) do |collection|
15
+ collection.map! do |obj|
16
+ self.new(obj.delete(:id), obj.merge(
17
+ :access_token => options[:access_token]
18
+ ))
19
+ end
20
+ end
21
+ end
22
+
23
+ class Result < Collection
24
+ attr_accessor :query, :klass, :collection, :options
25
+
26
+ def initialize(query, klass, options = {})
27
+ @klass = klass
28
+ @query = query
29
+ @options = options
30
+ @collection = options.delete(:collection) || FbGraph::Collection.new
31
+ replace @collection
32
+ end
33
+
34
+ def next(_options_ = {})
35
+ if self.collection.next.present?
36
+ self.klass.search(self.query, self.options.merge(_options_).merge(self.collection.next))
37
+ else
38
+ self.class.new(self.query, self.klass)
39
+ end
40
+ end
41
+
42
+ def previous(_options_ = {})
43
+ if self.collection.previous.present?
44
+ self.klassf.search(self.query, self.options.merge(_options_).merge(self.collection.previous))
45
+ else
46
+ self.class.new(self.query, self.klass)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
data/lib/fb_graph/user.rb CHANGED
@@ -21,6 +21,7 @@ module FbGraph
21
21
  include Connections::Links
22
22
  include Connections::Notes
23
23
  include Connections::Events
24
+ extend Searchable
24
25
 
25
26
  # TODO:
26
27
  # include Connections::Inbox
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 5
7
+ - 6
8
8
  - 0
9
- version: 0.5.0
9
+ version: 0.6.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - nov matake
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-07 00:00:00 +09:00
17
+ date: 2010-08-08 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -169,6 +169,7 @@ files:
169
169
  - lib/fb_graph/page.rb
170
170
  - lib/fb_graph/photo.rb
171
171
  - lib/fb_graph/post.rb
172
+ - lib/fb_graph/searchable.rb
172
173
  - lib/fb_graph/status.rb
173
174
  - lib/fb_graph/tag.rb
174
175
  - lib/fb_graph/user.rb