-
Notifications
You must be signed in to change notification settings - Fork 275
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
6 changed files
with
112 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class EmbedsController < ApplicationController | ||
|
||
def twitter | ||
@tweet = TwitterEmbed.new(params[:url]) | ||
end | ||
|
||
def instagram | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
class TwitterEmbed | ||
|
||
attr_reader :url | ||
|
||
def initialize(url) | ||
@url = url | ||
end | ||
|
||
def name | ||
data.dig("author_name") | ||
end | ||
|
||
def screen_name | ||
"@#{user}" | ||
end | ||
|
||
def tweet_url | ||
data.dig("url") | ||
end | ||
|
||
def date | ||
Date.parse document.search("blockquote > a").text | ||
end | ||
|
||
def content | ||
document.search("p").to_s | ||
end | ||
|
||
def profile_image_url | ||
"https://twitter.com/#{user}/profile_image?size=bigger" | ||
end | ||
|
||
def author_url | ||
data.dig("author_url") | ||
end | ||
|
||
private | ||
|
||
TWITTER_URL = "https://publish.twitter.com/oembed" | ||
|
||
def user | ||
@user ||= data.dig("author_url") && data.dig("author_url").split("/").last | ||
end | ||
|
||
def document | ||
@document ||= Nokogiri::HTML5.fragment(data.dig("html")) | ||
end | ||
|
||
def data | ||
@data ||= begin | ||
options = { | ||
params: { | ||
url: url, | ||
omit_script: true | ||
} | ||
} | ||
HTTP.get(TWITTER_URL, options).parse | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<div class="tweet"> | ||
<header class="tweet-header"> | ||
<%= link_to @tweet.tweet_url, target: "_blank", title: "View on Twitter" do %> | ||
<%= image_tag_with_fallback(image_url("favicon-profile-default.png"), @tweet.profile_image_url, size: "47x47", alt: "") %> | ||
<% end %> | ||
<h1> | ||
<a href="<%= @tweet.author_url %>" target="_blank" class="link"> | ||
<strong><%= @tweet.name %></strong> | ||
<%= @tweet.screen_name %> | ||
</a> | ||
<span class="tweet-actions"> | ||
<%= link_to @tweet.tweet_url, target: "_blank", title: "View on Twitter", class: "twitter-link" do %> | ||
<%= svg_tag "icon-twitter" %> | ||
<% end %> | ||
</span> | ||
</h1> | ||
<p class="post-meta"> | ||
<%= link_to @tweet.tweet_url, target: "_blank", title: "View on Twitter" do %> | ||
<time datetime="<%= @tweet.date.iso8601 %>"> | ||
<%= @tweet.date.to_s(:full_human) %> | ||
</time> | ||
<% end %> | ||
</p> | ||
</header> | ||
|
||
<div class="tweet-body"> | ||
<%= @tweet.content.html_safe %> | ||
</div> | ||
|
||
</div> |
Empty file.
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