fb_graph 0.0.6 → 0.0.7

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/README.rdoc CHANGED
@@ -70,7 +70,7 @@ Almost all connections for each object are also supported. (Private message co
70
70
 
71
71
  === POST
72
72
 
73
- ==== Status Update
73
+ ==== Update status (wall post)
74
74
 
75
75
  me = FbGraph::User.me(ACCESS_TOKEN)
76
76
  me.feed!(
@@ -81,6 +81,70 @@ Almost all connections for each object are also supported. (Private message co
81
81
  :description => 'A Ruby wrapper for Facebook Graph API'
82
82
  )
83
83
 
84
+ ==== Post a like/comment to a post
85
+
86
+ post = FbGraph::Page.new(117513961602338).feed.first
87
+ bool = post.like!(
88
+ :access_token => ACCESS_TOKEN
89
+ )
90
+ comment = post.comment!(
91
+ :access_token => ACCESS_TOKEN,
92
+ :message => 'Hey, I\'m testing you!'
93
+ )
94
+
95
+ ==== Post a note
96
+
97
+ page = FbGraph::Page.new(117513961602338)
98
+ note = page.note!(
99
+ :access_token => ACCESS_TOKEN,
100
+ :subject => 'testing',
101
+ :message => 'Hey, I\'m testing you!'
102
+ )
103
+
104
+ ==== Post a link
105
+
106
+ me = FbGraph::User.me(ACCESS_TOKEN)
107
+ link = me.link!(
108
+ :link => 'http://github.com/nov/fb_graph',
109
+ :message => 'A Ruby wrapper for Facebook Graph API.'
110
+ )
111
+
112
+ ==== Create Event, respond to it
113
+
114
+ me = FbGraph::User.me(ACCESS_TOKEN)
115
+ event = me.event!(
116
+ :name => 'FbGraph test event',
117
+ :start_time => 1.week.from_now.to_i,
118
+ :end_time => 2.week.from_now.to_i
119
+ )
120
+ bool = event.attending!(
121
+ :access_token => ACCESS_TOKEN
122
+ )
123
+ bool = event.maybe!(
124
+ :access_token => ACCESS_TOKEN
125
+ )
126
+ bool = event.declined!(
127
+ :access_token => ACCESS_TOKEN
128
+ )
129
+
130
+ ==== Create an album
131
+
132
+ me = FbGraph::User.me(ACCESS_TOKEN)
133
+ album = me.album!(
134
+ :name => 'FbGraph test',
135
+ :message => 'test test test'
136
+ ) # => now facebook Graph API returns weird response for this call
137
+
138
+ ==== Upload a photo to an album
139
+
140
+ me = FbGraph::User.me(ACCESS_TOKEN)
141
+ album = me.albums.first
142
+ album.photo!(
143
+ :access_token => ACCESS_TOKEN,
144
+ :image => File.new('/Users/nov/Desktop/nov.gif'),
145
+ :message => 'Hello, where is photo?'
146
+ )
147
+
84
148
  == Note on Patches/Pull Requests
85
149
 
86
150
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
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.0.6"
8
+ s.version = "0.0.7"
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-04-29}
12
+ s.date = %q{2010-04-30}
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 = [
@@ -4,7 +4,7 @@ module FbGraph
4
4
  def activities(options = {})
5
5
  activities = FbGraph::Collection.new(get(options.merge(:connection => 'activities')))
6
6
  activities.map! do |activity|
7
- Page.new(activity.delete(:id), activity)
7
+ FbGraph::Page.new(activity.delete(:id), activity)
8
8
  end
9
9
  end
10
10
  end
@@ -7,6 +7,11 @@ module FbGraph
7
7
  Album.new(album.delete(:id), album)
8
8
  end
9
9
  end
10
+
11
+ def album!(options = {})
12
+ album = post(options.merge(:connection => 'albums'))
13
+ Album.new(album.delete(:id), options.merge(album))
14
+ end
10
15
  end
11
16
  end
12
17
  end
@@ -11,6 +11,10 @@ module FbGraph
11
11
  end
12
12
  end
13
13
  end
14
+
15
+ def attending!(options = {})
16
+ post(options.merge(:connection => 'attending'))
17
+ end
14
18
  end
15
19
  end
16
20
  end
@@ -2,11 +2,23 @@ module FbGraph
2
2
  module Connections
3
3
  module Comments
4
4
  def comments(options = {})
5
- comments = FbGraph::Collection.new(get(options.merge(:connection => 'comment')))
5
+ comments = FbGraph::Collection.new(get(options.merge(:connection => 'comments')))
6
6
  comments.map! do |comment|
7
7
  Comment.new(comment.delete(:id), comment)
8
8
  end
9
9
  end
10
+
11
+ def comment!(options = {})
12
+ comment = post(options.merge(:connection => 'comments'))
13
+ Comment.new(comment.delete(:id), options.merge(comment))
14
+ end
15
+
16
+ # NOTE:
17
+ # the context of getting likes is User, but the context of posting like is not user.
18
+ # posting like is always in same context with comment!
19
+ def like!(options = {})
20
+ post(options.merge(:connection => 'likes'))
21
+ end
10
22
  end
11
23
  end
12
24
  end
@@ -11,6 +11,10 @@ module FbGraph
11
11
  end
12
12
  end
13
13
  end
14
+
15
+ def declined!(options = {})
16
+ post(options.merge(:connection => 'declined'))
17
+ end
14
18
  end
15
19
  end
16
20
  end
@@ -7,6 +7,11 @@ module FbGraph
7
7
  Event.new(event.delete(:id), event)
8
8
  end
9
9
  end
10
+
11
+ def event!(options = {})
12
+ event = post(options.merge(:connection => 'events'))
13
+ Event.new(event.delete(:id), options.merge(event))
14
+ end
10
15
  end
11
16
  end
12
17
  end
@@ -7,6 +7,8 @@ module FbGraph
7
7
  Page.new(like.delete(:id), like)
8
8
  end
9
9
  end
10
+
11
+ # NOTE: likes! is defined in fb_graph/connections/comments.rb
10
12
  end
11
13
  end
12
14
  end
@@ -7,6 +7,11 @@ module FbGraph
7
7
  Link.new(link.delete(:id), link)
8
8
  end
9
9
  end
10
+
11
+ def link!(options = {})
12
+ link = post(options.merge(:connection => 'links'))
13
+ Link.new(link.delete(:id), options.merge(link))
14
+ end
10
15
  end
11
16
  end
12
17
  end
@@ -11,6 +11,10 @@ module FbGraph
11
11
  end
12
12
  end
13
13
  end
14
+
15
+ def maybe!(options = {})
16
+ post(options.merge(:connection => 'maybe'))
17
+ end
14
18
  end
15
19
  end
16
20
  end
@@ -7,6 +7,11 @@ module FbGraph
7
7
  Note.new(note.delete(:id), note)
8
8
  end
9
9
  end
10
+
11
+ def note!(options = {})
12
+ note = post(options.merge(:connection => 'notes'))
13
+ Note.new(note.delete(:id), options.merge(note))
14
+ end
10
15
  end
11
16
  end
12
17
  end
@@ -7,6 +7,11 @@ module FbGraph
7
7
  Photo.new(photo.delete(:id), photo)
8
8
  end
9
9
  end
10
+
11
+ def photo!(options = {})
12
+ photo = post(options.merge(:connection => 'photos'))
13
+ Photo.new(photo.delete(:id), options.merge(photo))
14
+ end
10
15
  end
11
16
  end
12
17
  end
data/lib/fb_graph/node.rb CHANGED
@@ -12,12 +12,17 @@ module FbGraph
12
12
 
13
13
  def fetch(options = {})
14
14
  options[:access_token] ||= self.access_token if self.access_token
15
- self.class.fetch(self.identifier, options)
15
+ _fetched_ = get(options)
16
+ self.class.new(_fetched_.delete(:id), _fetched_)
16
17
  end
17
18
 
18
19
  def self.fetch(identifier, options = {})
19
- _fetched_ = new(identifier).send(:get, options)
20
- new(_fetched_.delete(:id), _fetched_)
20
+ new(identifier).fetch(options)
21
+ end
22
+
23
+ def destroy(options = {})
24
+ options[:access_token] ||= self.access_token if self.access_token
25
+ destory(self.identifier, options)
21
26
  end
22
27
 
23
28
  protected
@@ -32,6 +37,14 @@ module FbGraph
32
37
  def post(options = {})
33
38
  _endpoint_ = build_endpoint(options.merge!(:method => :post))
34
39
  handle_response RestClient.post(_endpoint_, options)
40
+
41
+ rescue RestClient::Exception => e
42
+ raise FbGraph::Exception.new(e.http_code, e.message, e.http_body)
43
+ end
44
+
45
+ def delete(options = {})
46
+ _endpoint_ = build_endpoint(options.merge!(:method => :delete))
47
+ handle_response RestClient.delete(_endpoint_, options)
35
48
  rescue RestClient::Exception => e
36
49
  raise FbGraph::Exception.new(e.http_code, e.message, e.http_body)
37
50
  end
@@ -55,18 +68,25 @@ module FbGraph
55
68
  end
56
69
 
57
70
  def handle_response(response)
58
- _response_ = JSON.parse(response.to_s).with_indifferent_access
59
- if _response_[:error]
60
- case _response_[:error][:type]
61
- when 'OAuthAccessTokenException'
62
- raise FbGraph::Unauthorized.new(401, _response_[:error][:message])
63
- when 'QueryParseException'
64
- raise FbGraph::NotFound.new(404, _response_[:error][:message])
71
+ case response.body
72
+ when 'true'
73
+ true
74
+ when 'false'
75
+ false
76
+ else
77
+ _response_ = JSON.parse(response.body).with_indifferent_access
78
+ if _response_[:error]
79
+ case _response_[:error][:type]
80
+ when 'OAuthAccessTokenException'
81
+ raise FbGraph::Unauthorized.new(401, _response_[:error][:message])
82
+ when 'QueryParseException'
83
+ raise FbGraph::NotFound.new(404, _response_[:error][:message])
84
+ else
85
+ raise FbGraph::Exception.new(400, "#{_response_[:error][:type]} :: #{_response_[:error][:message]}")
86
+ end
65
87
  else
66
- raise FbGraph::Exception.new(400, "#{_response_[:error][:type]} :: #{_response_[:error][:message]}")
88
+ _response_
67
89
  end
68
- else
69
- _response_
70
90
  end
71
91
  end
72
92
  end
data/lib/fb_graph.rb CHANGED
@@ -34,6 +34,7 @@ require 'fb_graph/connections'
34
34
 
35
35
  require 'fb_graph/node'
36
36
  require 'fb_graph/album'
37
+ require 'fb_graph/comment'
37
38
  require 'fb_graph/event'
38
39
  require 'fb_graph/group'
39
40
  require 'fb_graph/link'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 6
9
- version: 0.0.6
8
+ - 7
9
+ version: 0.0.7
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-04-29 00:00:00 +09:00
17
+ date: 2010-04-30 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency