Skip to content

Commit

Permalink
use ogp gem instead of ogpr gem
Browse files Browse the repository at this point in the history
  • Loading branch information
pessi-v committed Jul 11, 2024
1 parent dbfeee9 commit 37c8be2
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ gem 'faraday_middleware'
gem 'feedjira'

# a ruby library to fetch and parse meta tags which represent OpenGraph Protocol and TwitterCard.
gem 'ogpr', git: 'https://github.com/pessi-v/ogpr', branch: 'master'
# gem 'ogpr', git: 'https://github.com/pessi-v/ogpr', branch: 'master'
gem 'ogp'

# Addressable is an alternative implementation to the URI implementation that is part of Ruby's standard library.
Expand Down
23 changes: 0 additions & 23 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
GIT
remote: https://github.com/pessi-v/ogpr
revision: 0cf586b4eee4d655be40f196eae3c82c78aa301b
branch: master
specs:
ogpr (1.1.0)
nokogiri (~> 1.8)
rest-client (~> 2.1.0)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -117,7 +108,6 @@ GEM
reline (>= 0.3.8)
dockerfile-rails (1.6.16)
rails (>= 3.0.0)
domain_name (0.6.20240107)
dotenv (3.1.2)
drb (2.2.1)
erubi (1.12.0)
Expand Down Expand Up @@ -165,9 +155,6 @@ GEM
bigdecimal
rake (>= 13)
guess_html_encoding (0.0.11)
http-accept (1.7.0)
http-cookie (1.0.6)
domain_name (~> 0.5)
httpclient (2.8.3)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
Expand All @@ -193,9 +180,6 @@ GEM
net-smtp
marcel (1.0.4)
matrix (0.4.2)
mime-types (3.5.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2024.0702)
mini_mime (1.1.5)
minitest (5.23.1)
msgpack (1.7.2)
Expand All @@ -210,7 +194,6 @@ GEM
timeout
net-smtp (0.5.0)
net-protocol
netrc (0.11.0)
nio4r (2.7.3)
node-runner (1.2.0)
nokogiri (1.16.5-aarch64-linux)
Expand Down Expand Up @@ -288,11 +271,6 @@ GEM
regexp_parser (2.9.2)
reline (0.5.8)
io-console (~> 0.5)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.8)
strscan (>= 3.0.9)
ruby-ll (2.1.3)
Expand Down Expand Up @@ -412,7 +390,6 @@ DEPENDENCIES
jbuilder
node-runner (~> 1.2)
ogp
ogpr!
pg (~> 1.1)
pg_search
puma (>= 5.0)
Expand Down
38 changes: 1 addition & 37 deletions app/service_objects/articles/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
# Generic article sources RSS job
module Articles
class CreateService
# def initialize(source, entry, regions, countries, country_classifier)
def initialize(source, entry)
@source = source
@entry = entry
@ogp = get_ogp
# @regions = regions
# @countries = countries
# @country_classifier = country_classifier
end

def create_article
Expand All @@ -21,7 +17,6 @@ def create_article
return if (@entry.categories.include?('Podcast') || @entry.categories.include?('Audio')) && !@source.allow_audio

create_summary
# check_og
set_image if @source.show_images

a = Article.new(
Expand All @@ -33,27 +28,18 @@ def create_article
source_id: @source.id,
published_at: published_at,
image_url: @image || nil
# user_id: 1,
# language: set_language,
# country: set_country,
# region: set_region,
# show_image: @source.show_image
)

a.save
end

def get_ogp
response = Faraday.get(@entry.url)
OGP::OpenGraph.new(response.body)
OGP::OpenGraph.new(response.body, required_attributes: [])
end

def set_image
if @ogp&.image.url.present?
# cleaned_url = asciify(@ogp.image.url)
# return unless cleaned_url

# request = Faraday.get(cleaned_url)
request = Faraday.get(@ogp.image.url)
if request.status == 200 && request.headers['content-type']&.match?('image') # Content-type header not always present!
@image = @ogp.image.url
Expand All @@ -75,28 +61,6 @@ def set_image
nil
end

# def set_country
# tagged_countries = (@entry.categories & @countries)

# @country =
# if tagged_countries.count.zero?
# prediction = @country_classifier.predict(@title)
# prediction.keys[0] if prediction.values[0] > 0.7
# elsif tagged_countries.count == 1
# tagged_countries[0]
# else
# 'International'
# end
# end

# def set_region
# if @country == 'International' || @country.nil?
# 'International'
# else
# @regions.select { |_key, value| value.include?(@country) }.keys[0]
# end
# end

def create_summary
text = @entry.summary || @entry.content

Expand Down

0 comments on commit 37c8be2

Please sign in to comment.