mirror of
https://github.com/nov/fb_graph2
synced 2023-03-27 23:22:15 -04:00
page ratings
This commit is contained in:
parent
49eb927b84
commit
bd83d4f087
5 changed files with 86 additions and 1 deletions
12
lib/fb_graph2/edge/ratings.rb
Normal file
12
lib/fb_graph2/edge/ratings.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
12
lib/fb_graph2/struct/rating.rb
Normal file
12
lib/fb_graph2/struct/rating.rb
Normal file
|
@ -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
|
18
spec/fb_graph2/edge/ratings_spec.rb
Normal file
18
spec/fb_graph2/edge/ratings_spec.rb
Normal file
|
@ -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
|
42
spec/mock_json/page/ratings.json
Normal file
42
spec/mock_json/page/ratings.json
Normal file
|
@ -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=="
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue