Module: Ambo::Contexts::Twitter

Included in:
Ambo::Context
Defined in:
lib/ambo/contexts/twitter.rb

Overview

Context methods for defining bots that send messages to Twitter.

Constant Summary collapse

CLIENT_CONFIG =
%i[
  consumer_key consumer_secret access_token access_token_secret
].freeze

Instance Method Summary collapse

Instance Method Details

#tweet_as(username) ⇒ Object

Examples:

Send messages via Twitter

tweet_as 'MyTwtrBot' # uses ENV["TWITTER_MY_TWTR_BOT_API_KEY"]

Parameters:

  • Twitter (String)

    username string; the API key ENV variable is inferred from this name


15
16
17
18
19
20
21
22
23
# File 'lib/ambo/contexts/twitter.rb', line 15

def tweet_as(username)
  @env_key_prefix = "TWITTER_#{username.underscore.upcase}"

  config.twitter = CLIENT_CONFIG.each.with_object({}) do |key, memo|
    memo[key] = ENV.fetch(env_key_for(key))
  end
rescue KeyError => e
  raise LoaderError, "ENV variable missing; #{e}"
end

#twitter?TrueClass, FalseClass

Returns check if Twitter is setup

Returns:

  • (TrueClass, FalseClass)

    check if Twitter is setup


26
27
28
# File 'lib/ambo/contexts/twitter.rb', line 26

def twitter?
  !config.twitter.blank?
end