Remove service model

This commit is contained in:
Andreas Nedbal 2023-02-05 18:03:52 +01:00 committed by Andreas Nedbal
parent c327eee38e
commit d520755bc2
4 changed files with 0 additions and 74 deletions

View File

@ -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

View File

@ -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

View File

@ -33,7 +33,6 @@ class User < ApplicationRecord # rubocop:disable Metrics/ClassLength
has_many :comments, dependent: :destroy_async has_many :comments, dependent: :destroy_async
has_many :inboxes, dependent: :destroy_async has_many :inboxes, dependent: :destroy_async
has_many :smiles, class_name: "Appendable::Reaction", 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 :notifications, foreign_key: :recipient_id, dependent: :destroy_async
has_many :reports, dependent: :destroy_async has_many :reports, dependent: :destroy_async
has_many :lists, dependent: :destroy_async has_many :lists, dependent: :destroy_async

View File

@ -30,8 +30,6 @@ en:
location: "Location" location: "Location"
motivation_header: "Motivation header" motivation_header: "Motivation header"
website: "Website" website: "Website"
service:
post_tag: "Tag"
theme: theme:
background_color: "Background colour" background_color: "Background colour"
body_text: "Body text colour" body_text: "Body text colour"
@ -90,8 +88,6 @@ en:
profile: profile:
anon_display_name: "This name will be used for questions asked to you by anonymous users." 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!" 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: theme:
danger_color: "Colour used for errors or critical actions like deleting something." danger_color: "Colour used for errors or critical actions like deleting something."
info_color: "Colour used for informational popups or messages." info_color: "Colour used for informational popups or messages."