Class: TweetManager::Tweet

Inherits:
Object
  • Object
show all
Defined in:
lib/tweet_manager.rb

Overview

Tweet content

Constant Summary collapse

AVALAIBLE_SERVICES =
%w[medium youtube].freeze
TYPES =
%w[last random].freeze

Instance Method Summary collapse

Constructor Details

#initialize(credentials, youtube_api_key) ⇒ Tweet

Returns a new instance of Tweet.



12
13
14
15
16
17
18
19
20
# File 'lib/tweet_manager.rb', line 12

def initialize(credentials, youtube_api_key)
  @client = Twitter::REST::Client.new do |config|
    config.consumer_key        = credentials[:consumer_key]
    config.consumer_secret     = credentials[:consumer_secret]
    config.access_token        = credentials[:access_token]
    config.access_token_secret = credentials[:access_token_secret]
  end
  @youtube_api_key = youtube_api_key
end

Instance Method Details

#action(service:, type:, target:, extras: []) ⇒ Object



22
23
24
25
26
27
# File 'lib/tweet_manager.rb', line 22

def action(service:, type:, target:, extras: [])
  raise 'Non existing service' unless AVALAIBLE_SERVICES.include? service
  raise 'Non existing type' unless TYPES.include? type
  result = send(service).send("#{type}_content", target)
  update(result, extras)
end