Skip to content

Commit

Permalink
API: return post oEmbed data
Browse files Browse the repository at this point in the history
  • Loading branch information
jhass committed Feb 2, 2020
1 parent 5921cd0 commit b1f3578
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/presenters/post_presenter.rb
Expand Up @@ -34,7 +34,8 @@ def as_api_response # rubocop:disable Metrics/AbcSize
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

Expand Down
9 changes: 9 additions & 0 deletions lib/schemas/api_v1.json
Expand Up @@ -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"]
Expand Down
7 changes: 6 additions & 1 deletion spec/factories.rb
Expand Up @@ -292,7 +292,12 @@ def r_str

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
Expand Down
9 changes: 9 additions & 0 deletions spec/integration/api/posts_controller_spec.rb
Expand Up @@ -88,6 +88,7 @@
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(
Expand Down Expand Up @@ -696,6 +697,7 @@ def confirm_post_format(post, user, reference_post, mentions=[])
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)
Expand Down Expand Up @@ -773,6 +775,13 @@ def confirm_open_graph_object(object, ref_cache)
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
Expand Down

0 comments on commit b1f3578

Please sign in to comment.