class Tbot::Bot

module Config

module Reply

module Search

Constants

API_CREDENTIALS

Public Class Methods

client() click to toggle source
# File lib/tbot/config.rb, line 15
def self.client
  @@client
end
client=(client) click to toggle source
# File lib/tbot/config.rb, line 11
def self.client=(client)
  @@client = Twitter::Client.new (!!client ? client : API_CREDENTIALS)
end
new() click to toggle source

Instance methods.

# File lib/tbot/bot.rb, line 21
def initialize
  raise NoClientError unless @@client
  @last_id = nil

  @@client
end

Public Instance Methods

follow(user) click to toggle source
# File lib/tbot/follow.rb, line 3
def follow(user)
  @@client.follow user.id
end
format_opts(opts) click to toggle source

DRY: Ensure correct data is passed to search, set instance variables as required.

# File lib/tbot/bot.rb, line 6
def format_opts(opts)
  if opts[:delay]
    @delay = opts.delete(:delay)
    # Minimum 60 seconds.
    @delay = (@delay < 60) ? 60 : @delay
  end

  if !!opts[:location]
    geo = Geocoder.search(opts.delete(:location)).first.geometry['location'].values.join(',')
    radius = opts.delete(:radius) || 15
    opts[:geocode] = "#{geo},#{radius}mi"
  end
end
reply(tweet, response = "") click to toggle source
# File lib/tbot/reply.rb, line 4
def reply(tweet, response = "")
  screen_name = tweet.user.screen_name

  if block_given?
    # pass user to block.  tweet already present to call reply.
    # force string response.
    # logic will be handled within this block.
    @@client.update "@#{screen_name} #{yield(tweet.user).to_s}", { :in_reply_to_status_id => tweet.id }
  else
    @@client.update "@#{screen_name} #{response}", { :in_reply_to_status_id => tweet.id }
  end
end
stop_search!() click to toggle source

> kill thread loop if it exists.

# File lib/tbot/search.rb, line 38
def stop_search!
  false unless !!@thread

  @thread.exit
  @thread = nil
end