From 37c8be23870be305bbab0e9e7befdaf279f3c8c2 Mon Sep 17 00:00:00 2001 From: pessi-v Date: Thu, 11 Jul 2024 16:29:38 +0200 Subject: [PATCH] use ogp gem instead of ogpr gem --- Gemfile | 2 +- Gemfile.lock | 23 ----------- .../articles/create_service.rb | 38 +------------------ 3 files changed, 2 insertions(+), 61 deletions(-) diff --git a/Gemfile b/Gemfile index 5eec91d..b53fef6 100644 --- a/Gemfile +++ b/Gemfile @@ -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. diff --git a/Gemfile.lock b/Gemfile.lock index 964f5fb..5b7966d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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: @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -412,7 +390,6 @@ DEPENDENCIES jbuilder node-runner (~> 1.2) ogp - ogpr! pg (~> 1.1) pg_search puma (>= 5.0) diff --git a/app/service_objects/articles/create_service.rb b/app/service_objects/articles/create_service.rb index 5689989..b684869 100644 --- a/app/service_objects/articles/create_service.rb +++ b/app/service_objects/articles/create_service.rb @@ -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 @@ -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( @@ -33,11 +28,6 @@ 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 @@ -45,15 +35,11 @@ def create_article 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 @@ -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