-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
284 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class GoogleSearchResult < ApplicationRecord | ||
def public_image_url | ||
Rails.cache.fetch("#{cache_key_with_version}/#{self.id}", expires_in: 24.hours) do | ||
hydra = Typhoeus::Hydra.hydra | ||
request = Typhoeus::Request.new(self.image_url, followlocation: true) | ||
hydra.queue(request) | ||
hydra.run | ||
|
||
request.response.body | ||
end | ||
end | ||
|
||
def self.from_api_response(api_response) | ||
response = self.new | ||
response.text = api_response["text"] | ||
response.claimant = api_response["claimant"] | ||
response.claim_date = DateTime.parse(api_response["claimDate"]) unless api_response["claimDate"].nil? | ||
response.url = api_response["claimReview"].first["url"] | ||
response.review_date = DateTime.parse(api_response["claimReview"].first["reviewDate"]) unless api_response["claimReview"].first["reviewDate"].nil? | ||
response.rating = api_response["claimReview"].first["textualRating"] | ||
response.title = api_response["claimReview"].first["title"] | ||
response.language_code = api_response["claimReview"].first["languageCode"] | ||
response.publisher_name = api_response["claimReview"].first["publisher"]["name"] | ||
response.publisher_site = api_response["claimReview"].first["publisher"]["site"] | ||
|
||
response | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/views/media_vault/search/_google_search_result.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<div | ||
class="archive-item" | ||
data-publishing-platform="<%# publishing_platform_shortname %>" | ||
data-controller="media-vault--archive" | ||
data-media-vault--archive-caption-collapse-mode-value="<%# caption_is_collapsable ? 'collapsed' : 'static' %>" | ||
> | ||
<div class="archive-item__metadatum__label archive-item__inner flex gap-4 flex-row"> | ||
<img class="w-24 h-24 rounded-full" src="<%= media_vault_google_image_link_url(search_result.id) %>" alt="Rounded avatar"> | ||
<div class="flex flex-col gap-2"> | ||
<div class="flex flex-row gap-4"> | ||
<div> | ||
<div class="font-semibold">Claim By <%= search_result.claimant.nil? ? "A Post" : search_result.claimant %>:</div> | ||
<div><%= search_result.text %></div> | ||
</div> | ||
</div> | ||
|
||
<div class="font-semibold"><%= search_result.publisher_name %> rating: <span><%= search_result.rating %></span></div> | ||
<div><%= link_to search_result.title, search_result.url %></div> | ||
<% date_to_show = search_result.review_date.nil? ? search_result.claim_date : search_result.review_date %> | ||
<div style="color: #777;" class="text-sm"><span class="font-semibold">Reviewed:</span> <%= date_to_show.strftime("%-d %b %Y") %></div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class CreateGoogleSearchResults < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :google_search_results, id: :uuid do |t| | ||
t.text :text | ||
t.string :claimant | ||
t.datetime :claim_date | ||
t.string :url | ||
t.datetime :review_date | ||
t.string :rating | ||
t.string :title | ||
t.string :language_code | ||
t.string :publisher_name | ||
t.string :publisher_site | ||
t.string :image_url | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Oops, something went wrong.