diff --git a/lib/fb_graph2/edge/ratings.rb b/lib/fb_graph2/edge/ratings.rb new file mode 100644 index 0000000..904d7dc --- /dev/null +++ b/lib/fb_graph2/edge/ratings.rb @@ -0,0 +1,12 @@ +module FbGraph2 + class Edge + module Ratings + def ratings(params = {}) + ratings = self.edge :ratings, params + ratings.collect! do |rating| + Struct::Rating.new rating + end + end + end + end +end diff --git a/lib/fb_graph2/page.rb b/lib/fb_graph2/page.rb index 97f12d1..f6c1d02 100644 --- a/lib/fb_graph2/page.rb +++ b/lib/fb_graph2/page.rb @@ -16,6 +16,7 @@ module FbGraph2 include Edge::Photos include Edge::Posts include Edge::PromotablePosts + include Edge::Ratings include Edge::Roles::PageContext include Edge::Settings include Edge::Statuses @@ -79,4 +80,4 @@ module FbGraph2 end end end -end \ No newline at end of file +end diff --git a/lib/fb_graph2/struct/rating.rb b/lib/fb_graph2/struct/rating.rb new file mode 100644 index 0000000..33fd943 --- /dev/null +++ b/lib/fb_graph2/struct/rating.rb @@ -0,0 +1,12 @@ +module FbGraph2 + class Struct + class Rating < Struct + register_attributes( + raw: [:has_rating, :has_review, :rating, :review_text], + datetime: [:created_time], + user: [:reviewer], + custom: [:open_graph_story] + ) + end + end +end diff --git a/spec/fb_graph2/edge/ratings_spec.rb b/spec/fb_graph2/edge/ratings_spec.rb new file mode 100644 index 0000000..05a3a83 --- /dev/null +++ b/spec/fb_graph2/edge/ratings_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Ratings do + let(:page) { FbGraph2::Page.new('page_id').authenticate('page_token') } + + describe '#ratings' do + it 'should return an Array of FbGraph2::Struct::Rating' do + ratings = mock_graph :get, 'page_id/ratings', 'page/ratings', access_token: 'page_token' do + page.ratings + end + ratings.should be_instance_of FbGraph2::Edge + ratings.should_not be_blank + ratings.each do |rating| + rating.should be_instance_of FbGraph2::Struct::Rating + end + end + end +end diff --git a/spec/mock_json/page/ratings.json b/spec/mock_json/page/ratings.json new file mode 100644 index 0000000..e9b57e5 --- /dev/null +++ b/spec/mock_json/page/ratings.json @@ -0,0 +1,42 @@ +{ + "data": [ + { + "created_time": "2014-10-13T02:04:49+0000", + "reviewer": { + "id": "10206374744997522", + "name": "Shigeru Takagaki" + }, + "rating": 5 + }, + { + "created_time": "2014-07-09T13:39:31+0000", + "reviewer": { + "id": "585838138182211", + "name": "Teruko Kaneshiro" + }, + "rating": 5 + }, + { + "created_time": "2013-11-10T08:21:29+0000", + "reviewer": { + "id": "10152917500568292", + "name": "Lyn Yeoh" + }, + "rating": 5 + }, + { + "created_time": "2013-07-08T11:28:20+0000", + "reviewer": { + "id": "10152167763779825", + "name": "Hayashi Tatsuya" + }, + "rating": 5 + } + ], + "paging": { + "cursors": { + "before": "MTUzNDY1MDA1NzoxMzkyOTYxMDYwOTU4Mjk=", + "after": "NzcyNjg5ODI0OjEzOTI5NjEwNjA5NTgyOQ==" + } + } +}