API: return post oEmbed data
This commit is contained in:
parent
5921cd0176
commit
b1f357849b
4 changed files with 26 additions and 2 deletions
|
|
@ -34,7 +34,8 @@ class PostPresenter < BasePresenter
|
|||
photos: build_photos_json,
|
||||
root: root_api_response,
|
||||
own_interaction_state: build_own_interaction_state,
|
||||
open_graph_object: open_graph_object_api_response
|
||||
open_graph_object: open_graph_object_api_response,
|
||||
oembed: @post.o_embed_cache.try(:data)
|
||||
}.compact
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -328,6 +328,15 @@
|
|||
},
|
||||
"required": ["url", "type", "title", "image"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"oembed": {
|
||||
"type": "object",
|
||||
"description": "An oEmbed response according to 2.3.4 of the oEmbed spec.",
|
||||
"properties": {
|
||||
"trusted_endpoint_url": { "type": "string" }
|
||||
},
|
||||
"required": ["trusted_endpoint_url"],
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": ["guid", "created_at", "title", "body", "public", "nsfw", "author", "interaction_counters", "own_interaction_state", "mentioned_people", "photos"]
|
||||
|
|
|
|||
|
|
@ -292,7 +292,12 @@ FactoryGirl.define do
|
|||
|
||||
factory(:o_embed_cache) do
|
||||
url "http://youtube.com/kittens"
|
||||
data {{'data' => 'foo'}}
|
||||
data {
|
||||
{
|
||||
"data" => "foo",
|
||||
"trusted_endpoint_url" => "https://www.youtube.com/oembed?scheme=https"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
factory(:open_graph_cache) do
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ describe Api::V1::PostsController do
|
|||
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.o_embed_cache = FactoryGirl.create(:o_embed_cache)
|
||||
status_message.save
|
||||
|
||||
get(
|
||||
|
|
@ -696,6 +697,7 @@ describe Api::V1::PostsController do
|
|||
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)
|
||||
confirm_oembed(post["oembed"], reference_post.o_embed_cache)
|
||||
end
|
||||
|
||||
def confirm_post_top_level(post, reference_post)
|
||||
|
|
@ -773,6 +775,13 @@ describe Api::V1::PostsController do
|
|||
expect(object["video_url"]).to eq(ref_cache.video_url)
|
||||
end
|
||||
|
||||
def confirm_oembed(response, ref_cache)
|
||||
return unless ref_cache
|
||||
|
||||
expect(response).to eq(ref_cache.data)
|
||||
expect(response["trusted_endpoint_url"]).to_not be_nil
|
||||
end
|
||||
|
||||
def confirm_reshare_format(post, root_post, root_poster)
|
||||
root = post["root"]
|
||||
expect(root.has_key?("guid")).to be_truthy
|
||||
|
|
|
|||
Loading…
Reference in a new issue