Class: Brutalismbot::Twitter::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/brutalismbot/twitter/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: nil) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
19
20
# File 'lib/brutalismbot/twitter/client.rb', line 13

def initialize(client:nil)
  @client = client || ::Twitter::REST::Client.new do |config|
    config.access_token        = ENV["TWITTER_ACCESS_TOKEN"]
    config.access_token_secret = ENV["TWITTER_ACCESS_TOKEN_SECRET"]
    config.consumer_key        = ENV["TWITTER_CONSUMER_KEY"]
    config.consumer_secret     = ENV["TWITTER_CONSUMER_SECRET"]
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



11
12
13
# File 'lib/brutalismbot/twitter/client.rb', line 11

def client
  @client
end

Instance Method Details

#push(post, dryrun: nil) ⇒ Object



22
23
24
25
# File 'lib/brutalismbot/twitter/client.rb', line 22

def push(post, dryrun:nil)
  method = post.is_self? ? :push_text : :push_image
  send(method, post, dryrun: dryrun)
end

#push_image(post, dryrun: nil) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/brutalismbot/twitter/client.rb', line 32

def push_image(post, dryrun:nil)
  Brutalismbot.logger.info("GET #{post.media_uri}")
  Brutalismbot.logger.info("PUSH #{"DRYRUN " if dryrun}twitter://@brutalismbot")
  post.media_uri.open do |media|
    @client.update_with_media(post.to_twitter, media)
  end unless dryrun
end

#push_text(post, dryrun: nil) ⇒ Object



27
28
29
30
# File 'lib/brutalismbot/twitter/client.rb', line 27

def push_text(post, dryrun:nil)
  Brutalismbot.logger.info("PUSH #{"DRYRUN " if dryrun}twitter://@brutalismbot")
  @client.update(post.to_twitter) unless dryrun
end