API: return post open graph metadata
This commit is contained in:
parent
8cae234f45
commit
5921cd0176
4 changed files with 49 additions and 1 deletions
|
|
@ -33,7 +33,8 @@ class PostPresenter < BasePresenter
|
|||
mentioned_people: build_mentioned_people_json,
|
||||
photos: build_photos_json,
|
||||
root: root_api_response,
|
||||
own_interaction_state: build_own_interaction_state
|
||||
own_interaction_state: build_own_interaction_state,
|
||||
open_graph_object: open_graph_object_api_response
|
||||
}.compact
|
||||
end
|
||||
|
||||
|
|
@ -112,6 +113,20 @@ class PostPresenter < BasePresenter
|
|||
@post.open_graph_cache.try(:as_api_response, :backbone)
|
||||
end
|
||||
|
||||
def open_graph_object_api_response
|
||||
cache = @post.open_graph_cache
|
||||
return unless cache
|
||||
|
||||
{
|
||||
type: cache.ob_type,
|
||||
url: cache.url,
|
||||
title: cache.title,
|
||||
image: cache.image,
|
||||
description: cache.description,
|
||||
video_url: cache.video_url
|
||||
}
|
||||
end
|
||||
|
||||
def build_mentioned_people_json
|
||||
@post.mentioned_people.map {|m| PersonPresenter.new(m).as_api_json }
|
||||
end
|
||||
|
|
|
|||
|
|
@ -315,6 +315,19 @@
|
|||
},
|
||||
"required": ["address", "lat", "lng"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"open_graph_object": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"url": { "type": "string" },
|
||||
"type": { "type": "string" },
|
||||
"title": { "type": "string" },
|
||||
"image": { "type": "string" },
|
||||
"description": { "type": "string" },
|
||||
"video_url": { "type": "string" }
|
||||
},
|
||||
"required": ["url", "type", "title", "image"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"required": ["guid", "created_at", "title", "body", "public", "nsfw", "author", "interaction_counters", "own_interaction_state", "mentioned_people", "photos"]
|
||||
|
|
|
|||
|
|
@ -87,6 +87,8 @@ describe Api::V1::PostsController do
|
|||
merged_params = merged_params.merge(poll_params)
|
||||
merged_params = merged_params.merge(photos: @alice_photo_ids)
|
||||
status_message = StatusMessageCreationService.new(alice).create(merged_params)
|
||||
status_message.open_graph_cache = FactoryGirl.create(:open_graph_cache, video_url: "http://example.org")
|
||||
status_message.save
|
||||
|
||||
get(
|
||||
api_v1_post_path(status_message.guid),
|
||||
|
|
@ -693,6 +695,7 @@ describe Api::V1::PostsController do
|
|||
confirm_poll(post["poll"], reference_post.poll, false) if reference_post.poll
|
||||
confirm_location(post["location"], reference_post.location) if reference_post.location
|
||||
confirm_photos(post["photos"], reference_post.photos) if reference_post.photos
|
||||
confirm_open_graph_object(post["open_graph_object"], reference_post.open_graph_cache)
|
||||
end
|
||||
|
||||
def confirm_post_top_level(post, reference_post)
|
||||
|
|
@ -759,6 +762,17 @@ describe Api::V1::PostsController do
|
|||
end
|
||||
end
|
||||
|
||||
def confirm_open_graph_object(object, ref_cache)
|
||||
return unless ref_cache
|
||||
|
||||
expect(object["type"]).to eq(ref_cache.ob_type)
|
||||
expect(object["url"]).to eq(ref_cache.url)
|
||||
expect(object["title"]).to eq(ref_cache.title)
|
||||
expect(object["image"]).to eq(ref_cache.image)
|
||||
expect(object["description"]).to eq(ref_cache.description)
|
||||
expect(object["video_url"]).to eq(ref_cache.video_url)
|
||||
end
|
||||
|
||||
def confirm_reshare_format(post, root_post, root_poster)
|
||||
root = post["root"]
|
||||
expect(root.has_key?("guid")).to be_truthy
|
||||
|
|
|
|||
|
|
@ -214,6 +214,12 @@ describe PostPresenter do
|
|||
post = FactoryGirl.create(:status_message, public: true, open_graph_cache: open_graph_cache)
|
||||
expect(PostPresenter.new(post).send(:build_open_graph_cache)).to eq(open_graph_cache.as_api_response(:backbone))
|
||||
end
|
||||
|
||||
it "returns the open graph data in the api" do
|
||||
open_graph_cache = FactoryGirl.create(:open_graph_cache)
|
||||
post = FactoryGirl.create(:status_message, public: true, open_graph_cache: open_graph_cache)
|
||||
expect(PostPresenter.new(post).as_api_response[:open_graph_object][:url]).to eq(open_graph_cache.url)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue