diff --git a/lib/fb_graph2/page.rb b/lib/fb_graph2/page.rb index 706996d..cfe5d88 100644 --- a/lib/fb_graph2/page.rb +++ b/lib/fb_graph2/page.rb @@ -39,7 +39,12 @@ module FbGraph2 def initialize(id, attributes = {}) super - # TODO: handle custom attributes. + if attributes.include? :category_list + attributes[:category_list].collect do |page_category| + PageCategory.new page_category[:id], page_category + end + end + # TODO: handle other custom attributes. end end end \ No newline at end of file diff --git a/lib/fb_graph2/page_category.rb b/lib/fb_graph2/page_category.rb new file mode 100644 index 0000000..6318c0c --- /dev/null +++ b/lib/fb_graph2/page_category.rb @@ -0,0 +1,7 @@ +module FbGraph2 + class PageCategory < Node + register_attributes( + raw: [:name] + ) + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/books_spec.rb b/spec/fb_graph2/edge/books_spec.rb new file mode 100644 index 0000000..e858dab --- /dev/null +++ b/spec/fb_graph2/edge/books_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Books do + context 'included in User' do + describe '#books' do + let(:me) { FbGraph2::User.me('token') } + it 'should return an Array of FbGraph2::Page with page token' do + pages = mock_graph :get, 'me/books', 'user/books', access_token: 'token' do + me.books + end + pages.should_not be_blank + pages.each do |page| + page.should be_instance_of FbGraph2::Page + end + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/interests_spec.rb b/spec/fb_graph2/edge/interests_spec.rb new file mode 100644 index 0000000..1eefb48 --- /dev/null +++ b/spec/fb_graph2/edge/interests_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Interests do + context 'included in User' do + describe '#interests' do + let(:me) { FbGraph2::User.me('token') } + it 'should return an Array of FbGraph2::Page with page token' do + pages = mock_graph :get, 'me/interests', 'user/interests', access_token: 'token' do + me.interests + end + pages.should_not be_blank + pages.each do |page| + page.should be_instance_of FbGraph2::Page + end + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/movies_spec.rb b/spec/fb_graph2/edge/movies_spec.rb new file mode 100644 index 0000000..67658d9 --- /dev/null +++ b/spec/fb_graph2/edge/movies_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Movies do + context 'included in User' do + describe '#movies' do + let(:me) { FbGraph2::User.me('token') } + it 'should return an Array of FbGraph2::Page with page token' do + pages = mock_graph :get, 'me/movies', 'user/movies', access_token: 'token' do + me.movies + end + pages.should_not be_blank + pages.each do |page| + page.should be_instance_of FbGraph2::Page + end + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/music_spec.rb b/spec/fb_graph2/edge/music_spec.rb new file mode 100644 index 0000000..8e557df --- /dev/null +++ b/spec/fb_graph2/edge/music_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Music do + context 'included in User' do + describe '#music' do + let(:me) { FbGraph2::User.me('token') } + it 'should return an Array of FbGraph2::Page with page token' do + pages = mock_graph :get, 'me/music', 'user/music', access_token: 'token' do + me.music + end + pages.should_not be_blank + pages.each do |page| + page.should be_instance_of FbGraph2::Page + 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 index 779e0d6..3d9a262 100644 --- a/spec/fb_graph2/edge/notifications_spec.rb +++ b/spec/fb_graph2/edge/notifications_spec.rb @@ -4,7 +4,6 @@ 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 @@ -18,7 +17,6 @@ describe FbGraph2::Edge::Notifications do 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' diff --git a/spec/fb_graph2/edge/television_spec.rb b/spec/fb_graph2/edge/television_spec.rb new file mode 100644 index 0000000..39c6bad --- /dev/null +++ b/spec/fb_graph2/edge/television_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Television do + context 'included in User' do + describe '#television' do + let(:me) { FbGraph2::User.me('token') } + it 'should return an Array of FbGraph2::Page with page token' do + pages = mock_graph :get, 'me/television', 'user/television', access_token: 'token' do + me.television + end + pages.should_not be_blank + pages.each do |page| + page.should be_instance_of FbGraph2::Page + end + end + end + end +end \ No newline at end of file diff --git a/spec/mock_json/user/books.json b/spec/mock_json/user/books.json new file mode 100644 index 0000000..1535aad --- /dev/null +++ b/spec/mock_json/user/books.json @@ -0,0 +1,11 @@ +{ + "data": [{ + "category": "Book", + "name": "Predictably Irrational", + "created_time": "2011-07-27T15:49:06+0000", + "id": "113167718696752" + }], + "paging": { + "next": "https://graph.facebook.com/v2.0/579612276/books?limit=25&offset=25&__after_id=enc_AewjHX22qV_-BoIxoRMWHPno7BxZHunbqYgaxlHlJnH0x_Gza1bYpFD6V7Vve1HL-21x7kD5E_3QMLzdjM9pmK_f" + } +} diff --git a/spec/mock_json/user/interests.json b/spec/mock_json/user/interests.json new file mode 100644 index 0000000..fc7af2d --- /dev/null +++ b/spec/mock_json/user/interests.json @@ -0,0 +1,41 @@ +{ + "data": [{ + "category": "Interest", + "name": "#idcon 14th ~ BYOResume or DEAD! ~", + "created_time": "2012-09-03T17:18:16+0000", + "id": "309562105809363" + }, { + "category": "Interest", + "name": "Heroku Meetup #6 Japan Heroku Lab", + "created_time": "2012-09-03T03:07:14+0000", + "id": "102424793243222" + }, { + "category": "Interest", + "name": "Activity Streams", + "created_time": "2011-06-30T22:57:47+0000", + "id": "114998808528822" + }, { + "category": "Company", + "name": "Social Web", + "created_time": "2011-06-18T02:52:35+0000", + "id": "105645299472577" + }, { + "category": "Interest", + "name": "Open ID", + "created_time": "2011-01-05T00:21:56+0000", + "id": "106260522746492" + }, { + "category": "Interest", + "name": "Open Social", + "created_time": "2011-01-05T00:21:52+0000", + "id": "107119605991729" + }, { + "category": "Interest", + "name": "OAuth", + "created_time": "2010-07-04T06:17:52+0000", + "id": "104064209632570" + }], + "paging": { + "next": "https://graph.facebook.com/v2.0/579612276/interests?limit=25&offset=25&__after_id=enc_AezLYldJHiKEyShbuOdR82cv0TtL4DwoXvFHvxocLB9dyJjlw96DIz3jwBNiERXgDjzAH_sT_ZhHU9QGJNxiOe3P" + } +} diff --git a/spec/mock_json/user/movies.json b/spec/mock_json/user/movies.json new file mode 100644 index 0000000..85e2fb5 --- /dev/null +++ b/spec/mock_json/user/movies.json @@ -0,0 +1,11 @@ +{ + "data": [{ + "category": "Movie", + "name": "The Social Network", + "created_time": "2011-01-05T00:17:17+0000", + "id": "105460422821089" + }], + "paging": { + "next": "https://graph.facebook.com/v2.0/579612276/movies?limit=25&offset=25&__after_id=enc_AewDz_Z8KNKb51zhWhUMYOJjref9qTPZpk1jT2P9sAXIzWmNSJSUU56XyMbJASE2c8qPbE1-WoFS8o6eCgs6K4Ui" + } +} diff --git a/spec/mock_json/user/music.json b/spec/mock_json/user/music.json new file mode 100644 index 0000000..a66f81f --- /dev/null +++ b/spec/mock_json/user/music.json @@ -0,0 +1,45 @@ +{ + "data": [{ + "category": "Music", + "name": "斉藤和義", + "created_time": "2011-07-31T05:30:44+0000", + "id": "108827045813193" + }, { + "category": "Musician/band", + "name": "L'arc~en~Ciel", + "created_time": "2011-07-31T05:28:30+0000", + "id": "12039028077" + }, { + "category": "Musician/band", + "name": "Utada Hikaru", + "created_time": "2010-05-10T06:57:25+0000", + "id": "105806242793688" + }, { + "category": "Musician/band", + "category_list": [{ + "id": "180164648685982", + "name": "Bands & Musicians" + }], + "name": "Avril Lavigne", + "created_time": "2009-01-22T18:03:07+0000", + "id": "5413509299" + }, { + "category": "Musician/band", + "name": "Bank Band", + "created_time": "2009-01-22T17:47:26+0000", + "id": "28534671472" + }, { + "category": "Musician/band", + "name": "The Yellow Monkey", + "created_time": "2009-01-22T17:36:46+0000", + "id": "32548904409" + }, { + "category": "Musician/band", + "name": "Mr. Children", + "created_time": "2009-01-22T17:36:26+0000", + "id": "27868140174" + }], + "paging": { + "next": "https://graph.facebook.com/v2.0/579612276/music?limit=25&offset=25&__after_id=enc_AeyVKBfCEuM8ZXcswQ4tW_IGxEZSp9qkwAdtOM37T5EWpk1I8POJ2Kn5tSqM2lWyx0Q" + } +} diff --git a/spec/mock_json/user/television.json b/spec/mock_json/user/television.json new file mode 100644 index 0000000..9aef8ef --- /dev/null +++ b/spec/mock_json/user/television.json @@ -0,0 +1,11 @@ +{ + "data": [{ + "category": "Tv show", + "name": "Mobile Suit Zeta Gundam", + "created_time": "2014-06-03T06:08:35+0000", + "id": "105508046150348" + }], + "paging": { + "next": "https://graph.facebook.com/v2.0/579612276/television?limit=25&offset=25&__after_id=enc_AewK-s0422fW15xZjOu3LxDtrkej8NQumXBW2ugVt3EuK52YArNQIKzoyq72k0V_vQ3_DGUsIp7COPzF82p_h4BK" + } +} \ No newline at end of file