diff --git a/.gitignore b/.gitignore index 31cafb5..1d3b2f4 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ tmp *.o *.a mkmf.log +wiki +samples diff --git a/lib/fb_graph2/application.rb b/lib/fb_graph2/application.rb index 91aad52..a00bfb5 100644 --- a/lib/fb_graph2/application.rb +++ b/lib/fb_graph2/application.rb @@ -23,5 +23,9 @@ module FbGraph2 super # TODO: handle custom attributes. end + + def self.app(access_token) + new(:app).authenticate access_token + end end end \ No newline at end of file diff --git a/lib/fb_graph2/edge/notifications.rb b/lib/fb_graph2/edge/notifications.rb index 28763f7..cb1df18 100644 --- a/lib/fb_graph2/edge/notifications.rb +++ b/lib/fb_graph2/edge/notifications.rb @@ -7,6 +7,12 @@ module FbGraph2 Notification.new notification[:id], notification end end + + def notification!(params = {}) + notification = self.post params, edge: :notifications + notification.include? :success + end + alias_method :notify!, :notification! end end end \ No newline at end of file diff --git a/lib/fb_graph2/edge/shared_posts.rb b/lib/fb_graph2/edge/shared_posts.rb index a130b24..6fafcae 100644 --- a/lib/fb_graph2/edge/shared_posts.rb +++ b/lib/fb_graph2/edge/shared_posts.rb @@ -2,7 +2,7 @@ module FbGraph2 class Edge module SharedPosts def shared_posts(params = {}) - posts = self.edge :posts, params + posts = self.edge :sharedposts, params posts.collect do |post| Post.new(post[:id], post).authenticate self.access_token end diff --git a/spec/fb_graph2/edge/friend_lists_spec.rb b/spec/fb_graph2/edge/friend_lists_spec.rb new file mode 100644 index 0000000..6b305f5 --- /dev/null +++ b/spec/fb_graph2/edge/friend_lists_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::FriendLists do + context 'included in Post' do + describe '#friend_lists' do + let(:me) { FbGraph2::User.me('token') } + it 'should return an Array of FbGraph2::FriendList' do + friend_lists = mock_graph :get, 'me/friendlists', 'user/friend_lists', access_token: 'token' do + me.friend_lists + end + friend_lists.should_not be_blank + friend_lists.each do |friend_list| + friend_list.should be_instance_of FbGraph2::FriendList + end + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/notifications_spec.rb b/spec/fb_graph2/edge/notifications_spec.rb new file mode 100644 index 0000000..779e0d6 --- /dev/null +++ b/spec/fb_graph2/edge/notifications_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Notifications do + context 'included in User' do + describe '#notifications' do + let(:me) { FbGraph2::User.me('token') } + + it 'should return an Array of FbGraph2::Notification' do + notifications = mock_graph :get, 'me/notifications', 'user/notifications', access_token: 'token' do + me.notifications + end + notifications.should_not be_blank + notifications.each do |notification| + notification.should be_instance_of FbGraph2::Notification + end + end + end + + describe '#notification!' do + let(:user) { FbGraph2::User.new('user_id') } + + it 'should return true' do + mock_graph :post, 'user_id/notifications', 'success_true', access_token: 'app_token', params: { + href: 'href', template: 'template' + } do + user.authenticate('app_token').notification! href: 'href', template: 'template' + end.should be_true + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/shared_posts_spec.rb b/spec/fb_graph2/edge/shared_posts_spec.rb new file mode 100644 index 0000000..718c1f5 --- /dev/null +++ b/spec/fb_graph2/edge/shared_posts_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::SharedPosts do + context 'included in Post' do + describe '#shared_posts' do + let(:post) { FbGraph2::Post.new('post_id').authenticate('token') } + it 'should return an Array of FbGraph2::Post' do + posts = mock_graph :get, 'post_id/sharedposts', 'post/shared_posts', access_token: 'token' do + post.shared_posts + end + posts.should_not be_blank + posts.each do |post| + post.should be_instance_of FbGraph2::Post + end + end + end + end +end \ No newline at end of file diff --git a/spec/mock_json/post/shared_posts.json b/spec/mock_json/post/shared_posts.json new file mode 100644 index 0000000..d57a286 --- /dev/null +++ b/spec/mock_json/post/shared_posts.json @@ -0,0 +1,50 @@ +{ + "data": [{ + "id": "689134294485152_695439827187932", + "from": { + "id": "689134294485152", + "name": "Shunya Iriki" + }, + "story": "Shunya Iriki shared a link.", + "story_tags": { + "0": [{ + "id": "689134294485152", + "name": "Shunya Iriki", + "offset": 0, + "length": 12, + "type": "user" + }] + }, + "picture": "https://fbexternal-a.akamaihd.net/safe_image.php?d=AQCtEdPdezKIoUxo&w=154&h=154&url=http%3A%2F%2Fi.yimg.jp%2Fi%2Fdocs%2Frelease%2Ffbicon.jpg", + "link": "http://docs.yahoo.co.jp/docs/info/terms/chapter1.html#cf2nd", + "name": "ヤフー株式会社 - サービス利用規約 第1編 基本ガイドライン", + "caption": "docs.yahoo.co.jp", + "description": "Yahoo! JAPANのサービス利用規約、第1編 基本ガイドラインは当社のサービスをご利用になるすべての方に共通して適用されます。", + "icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif", + "actions": [{ + "name": "Comment", + "link": "https://www.facebook.com/100001657627507/posts/695439827187932" + }, { + "name": "Like", + "link": "https://www.facebook.com/100001657627507/posts/695439827187932" + }], + "privacy": { + "value": "" + }, + "type": "link", + "status_type": "shared_story", + "application": { + "name": "Facebook for iPhone", + "namespace": "fbiphone", + "id": "6628568379" + }, + "created_time": "2014-06-02T12:46:26+0000", + "updated_time": "2014-06-02T12:46:26+0000" + }], + "paging": { + "cursors": { + "after": "Njk1NDM5ODI3MTg3OTMy", + "before": "Njk1NDM5ODI3MTg3OTMy" + } + } +} diff --git a/spec/mock_json/success_true.json b/spec/mock_json/success_true.json new file mode 100644 index 0000000..28e7be1 --- /dev/null +++ b/spec/mock_json/success_true.json @@ -0,0 +1,3 @@ +{ + "success": true +} \ No newline at end of file diff --git a/spec/mock_json/user/friend_lists.json b/spec/mock_json/user/friend_lists.json new file mode 100644 index 0000000..6cd15c4 --- /dev/null +++ b/spec/mock_json/user/friend_lists.json @@ -0,0 +1,98 @@ +{ + "data": [{ + "id": "10152338362087277", + "name": "CyberAgent America", + "list_type": "work" + }, { + "id": "10152338362072277", + "name": "Cerego Japan", + "list_type": "work" + }, { + "id": "10152142419302277", + "name": "Capy Inc.", + "list_type": "work" + }, { + "id": "10151887848997277", + "name": "Cerego Japan", + "list_type": "work" + }, { + "id": "10151870113532277", + "name": "Kyoto CtoG.org", + "list_type": "work" + }, { + "id": "10150348660692277", + "name": "同志社大学", + "list_type": "education" + }, { + "id": "10150346113542277", + "name": "Kawasaki-shi, Kanagawa, Japan Area", + "list_type": "current_city" + }, { + "id": "10150346085662277", + "name": "OpenID Foundation", + "list_type": "work" + }, { + "id": "10150346074892277", + "name": "OpenID Foundation Japan", + "list_type": "work" + }, { + "id": "10150341935447277", + "name": "株式会社ドリコム", + "list_type": "work" + }, { + "id": "10150336745462277", + "name": "Kyoto CtoG.org", + "list_type": "work" + }, { + "id": "10150336745457277", + "name": "Acquaintances", + "list_type": "acquaintances" + }, { + "id": "10150336744357277", + "name": "ドリコム", + "list_type": "work" + }, { + "id": "10150336526382277", + "name": "Doshisha University", + "list_type": "education" + }, { + "id": "10150336526227277", + "name": "Doshisha High School", + "list_type": "education" + }, { + "id": "10150336526222277", + "name": "Cerego Japan", + "list_type": "work" + }, { + "id": "10150336526217277", + "name": "Family", + "list_type": "family" + }, { + "id": "10150336526212277", + "name": "Close Friends", + "list_type": "close_friends" + }, { + "id": "10150287189437277", + "name": "Family", + "list_type": "user_created" + }, { + "id": "494503307276", + "name": "OpenStack", + "list_type": "user_created" + }, { + "id": "41968037276", + "name": "Doshisha", + "list_type": "user_created" + }, { + "id": "41967672276", + "name": "iKnow!", + "list_type": "user_created" + }, { + "id": "41967622276", + "name": "Drecom", + "list_type": "user_created" + }], + "paging": { + "next": "https://graph.facebook.com/v2.0/579612276/friendlists?limit=5000&offset=5000&__after_id=enc_AeyvnVCKex4_AhqGX7_QdptE11EjyFPx0CGxMGyRHvxS2SbnqjP7fJD8tL2VFjeodZA" + } +} diff --git a/spec/mock_json/user/notifications.json b/spec/mock_json/user/notifications.json new file mode 100644 index 0000000..10083c3 --- /dev/null +++ b/spec/mock_json/user/notifications.json @@ -0,0 +1,111 @@ +{ + "data": [{ + "id": "notif_579612276_360745635", + "from": { + "id": "10203663293120616", + "name": "Tatsuya Kurosaka" + }, + "to": { + "id": "579612276", + "name": "Nov Matake" + }, + "created_time": "2014-06-03T03:20:28+0000", + "updated_time": "2014-06-03T03:54:10+0000", + "title": "Tatsuya Kurosaka posted in クロサカさんの仕事部屋.", + "link": "http://www.facebook.com/groups/597190250369020/632381620183216/", + "application": { + "name": "Groups", + "id": "2361831622" + }, + "unread": 1, + "object": { + "name": "クロサカさんの仕事部屋", + "id": "597190250369020" + } + }, { + "id": "notif_579612276_360668511", + "from": { + "id": "824378870925480", + "name": "ちゃちゃき まさゆき" + }, + "to": { + "id": "579612276", + "name": "Nov Matake" + }, + "created_time": "2014-06-02T14:57:39+0000", + "updated_time": "2014-06-02T14:57:39+0000", + "title": "ちゃちゃき まさゆき posted in DevLOVE Park: \"こんにちは。..\"", + "link": "http://www.facebook.com/groups/devlovepark/763062600400231/", + "application": { + "name": "Groups", + "id": "2361831622" + }, + "unread": 1 + }, { + "id": "notif_579612276_360654609", + "from": { + "id": "689134294485152", + "name": "Shunya Iriki" + }, + "to": { + "id": "579612276", + "name": "Nov Matake" + }, + "created_time": "2014-06-02T12:46:26+0000", + "updated_time": "2014-06-02T12:46:26+0000", + "title": "Shunya Iriki shared your link.", + "link": "http://www.facebook.com/shunya.iriki/posts/695439827187932", + "application": { + "name": "Links", + "id": "2309869772" + }, + "unread": 1, + "object": { + "id": "689134294485152_695439827187932", + "from": { + "id": "689134294485152", + "name": "Shunya Iriki" + }, + "story": "Shunya Iriki shared a link.", + "story_tags": { + "0": [{ + "id": "689134294485152", + "name": "Shunya Iriki", + "offset": 0, + "length": 12, + "type": "user" + }] + }, + "picture": "https://fbexternal-a.akamaihd.net/safe_image.php?d=AQCtEdPdezKIoUxo&w=154&h=154&url=http%3A%2F%2Fi.yimg.jp%2Fi%2Fdocs%2Frelease%2Ffbicon.jpg", + "link": "http://docs.yahoo.co.jp/docs/info/terms/chapter1.html#cf2nd", + "name": "ヤフー株式会社 - サービス利用規約 第1編 基本ガイドライン", + "caption": "docs.yahoo.co.jp", + "description": "Yahoo! JAPANのサービス利用規約、第1編 基本ガイドラインは当社のサービスをご利用になるすべての方に共通して適用されます。", + "icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif", + "actions": [{ + "name": "Comment", + "link": "https://www.facebook.com/100001657627507/posts/695439827187932" + }, { + "name": "Like", + "link": "https://www.facebook.com/100001657627507/posts/695439827187932" + }], + "privacy": { + "value": "" + }, + "type": "link", + "status_type": "shared_story", + "application": { + "name": "Facebook for iPhone", + "namespace": "fbiphone", + "id": "6628568379" + }, + "created_time": "2014-06-02T12:46:26+0000", + "updated_time": "2014-06-02T12:46:26+0000" + } + }], + "paging": { + "previous": "https://graph.facebook.com/v2.0/579612276/notifications?limit=5000&since=1401765628&__paging_token=enc_Aeym53-nXWoBenYHHSSltWVXrHRbkZ5EGNZqVaacQApfA_a2VF0iAvQcjVx-jwo_UTLcO4e3kI7LJdGCggqD2OBS", + "next": "https://graph.facebook.com/v2.0/579612276/notifications?limit=5000&until=1401236040&__paging_token=enc_AexWonNPHkycgkJiATXUJ_5MzIfU8dVfjvWB0MxLEXkSEAByVh8rT8gqpKb29rj5O2TpyohRzt0iyg-Tcu6U7ImO" + }, + "summary": [] +}