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 +65 -1
- data/VERSION +1 -1
- data/fb_graph.gemspec +2 -2
- data/lib/fb_graph/connections/activities.rb +1 -1
- data/lib/fb_graph/connections/albums.rb +5 -0
- data/lib/fb_graph/connections/attending.rb +4 -0
- data/lib/fb_graph/connections/comments.rb +13 -1
- data/lib/fb_graph/connections/declined.rb +4 -0
- data/lib/fb_graph/connections/events.rb +5 -0
- data/lib/fb_graph/connections/likes.rb +2 -0
- data/lib/fb_graph/connections/links.rb +5 -0
- data/lib/fb_graph/connections/maybe.rb +4 -0
- data/lib/fb_graph/connections/notes.rb +5 -0
- data/lib/fb_graph/connections/photos.rb +5 -0
- data/lib/fb_graph/node.rb +33 -13
- data/lib/fb_graph.rb +1 -0
- metadata +3 -3
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
|
-
====
|
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.
|
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.
|
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-
|
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
|
@@ -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 => '
|
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
|
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
|
-
|
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
|
-
|
20
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
88
|
+
_response_
|
67
89
|
end
|
68
|
-
else
|
69
|
-
_response_
|
70
90
|
end
|
71
91
|
end
|
72
92
|
end
|
data/lib/fb_graph.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
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-
|
17
|
+
date: 2010-04-30 00:00:00 +09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|