From d520755bc2e0f00ae34d8a1d9db8e286cbe8f903 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sun, 5 Feb 2023 18:03:52 +0100 Subject: [PATCH] Remove service model --- app/models/service.rb | 41 ------------------------------ app/models/services/twitter.rb | 28 -------------------- app/models/user.rb | 1 - config/locales/activerecord.en.yml | 4 --- 4 files changed, 74 deletions(-) delete mode 100644 app/models/service.rb delete mode 100644 app/models/services/twitter.rb diff --git a/app/models/service.rb b/app/models/service.rb deleted file mode 100644 index 7cdf4524..00000000 --- a/app/models/service.rb +++ /dev/null @@ -1,41 +0,0 @@ -class Service < ApplicationRecord - attr_accessor :provider, :info - - belongs_to :user - validates_uniqueness_of :uid, scope: :type - validates_length_of :post_tag, maximum: 20 - - class << self - - def first_from_omniauth(auth_hash) - @@auth = auth_hash - where(type: service_type, uid: options[:uid]).first - end - - def initialize_from_omniauth(auth_hash) - @@auth = auth_hash - service_type.constantize.new(options) - end - - private - - def auth - @@auth - end - - def service_type - "Services::#{options[:provider].camelize}" - end - - def options - { - nickname: auth['info']['nickname'], - access_token: auth['credentials']['token'], - access_secret: auth['credentials']['secret'], - uid: auth['uid'], - provider: auth['provider'], - info: auth['info'] - } - end - end -end diff --git a/app/models/services/twitter.rb b/app/models/services/twitter.rb deleted file mode 100644 index 388c316d..00000000 --- a/app/models/services/twitter.rb +++ /dev/null @@ -1,28 +0,0 @@ -class Services::Twitter < Service - include Rails.application.routes.url_helpers - include SocialHelper::TwitterMethods - - def provider - "twitter" - end - - def post(answer) - Rails.logger.debug "posting to Twitter {'answer' => #{answer.id}, 'user' => #{self.user_id}}" - post_tweet answer - end - - private - - def client - @client ||= Twitter::REST::Client.new( - consumer_key: APP_CONFIG['sharing']['twitter']['consumer_key'], - consumer_secret: APP_CONFIG['sharing']['twitter']['consumer_secret'], - access_token: self.access_token, - access_token_secret: self.access_secret - ) - end - - def post_tweet(answer) - client.update! prepare_tweet(answer, self.post_tag) - end -end diff --git a/app/models/user.rb b/app/models/user.rb index fb32d232..df628cc5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -33,7 +33,6 @@ class User < ApplicationRecord # rubocop:disable Metrics/ClassLength has_many :comments, dependent: :destroy_async has_many :inboxes, dependent: :destroy_async has_many :smiles, class_name: "Appendable::Reaction", dependent: :destroy_async - has_many :services, dependent: :destroy_async has_many :notifications, foreign_key: :recipient_id, dependent: :destroy_async has_many :reports, dependent: :destroy_async has_many :lists, dependent: :destroy_async diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index 2b1b178e..3a0a0742 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -30,8 +30,6 @@ en: location: "Location" motivation_header: "Motivation header" website: "Website" - service: - post_tag: "Tag" theme: background_color: "Background colour" body_text: "Body text colour" @@ -90,8 +88,6 @@ en: profile: anon_display_name: "This name will be used for questions asked to you by anonymous users." motivation_header: "Shown in the header of the question box on your profile. Motivate users to ask you questions!" - services/twitter: - post_tag: "Automatically append a tag to your shared answers. A # symbol is not automatically prepended." theme: danger_color: "Colour used for errors or critical actions like deleting something." info_color: "Colour used for informational popups or messages."