Module: Tweetlr::Processors::Twitter

Includes:
LogAware
Defined in:
lib/tweetlr/processors/twitter.rb

Overview

utilities for dealing with twitter

Class Method Summary collapse

Methods included from LogAware

log=

Class Method Details

extract the links from a given tweet



20
21
22
23
24
25
# File 'lib/tweetlr/processors/twitter.rb', line 20

def self.extract_links(tweet)
  if tweet
    text = tweet['text']
    text.gsub(/https?:\/\/[\S]+/).to_a if text
  end
end

.lazy_search(config) ⇒ Object

lazy update - search for a term or refresh the search if a response is available already



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/tweetlr/processors/twitter.rb', line 37

def self.lazy_search(config)
  log.debug "#{self}::lazy_search called with config #{config}"
  response = nil
  if config
    search_term = config['search_term'] || config[:search_term] || config['terms'] || config[:terms]
    search_call = "#{search_term.gsub('+', ' OR ')} filter:links"
    log.info "lazy search using '#{search_call}, :since_id => #{config['since_id'] || config[:since_id]}, :count => #{config['results_per_page']}, :result_type => #{config['result_type']})'"
    response = self.call_twitter_api(search_call, config, :lazy)
  else
    log.error "#{self}.lazy_search: no config given!"
  end
  response
end

.logObject



10
11
12
# File 'lib/tweetlr/processors/twitter.rb', line 10

def self.log
  Tweetlr::LogAware.log #TODO why doesn't the include make the log method accessible?
end

.retweet?(message) ⇒ Boolean

checks if the message is a retweet

Returns:

  • (Boolean)


15
16
17
# File 'lib/tweetlr/processors/twitter.rb', line 15

def self.retweet?(message)
  message.index('RT @') || message.index(%{"@}) || message.index("\u201c@") || message.index('MT @') #detect retweets
end

.search(config) ⇒ Object

fire a new search



28
29
30
31
32
33
34
# File 'lib/tweetlr/processors/twitter.rb', line 28

def self.search(config)
  search_call = "#{config['search_term'].gsub('+', ' OR ')} filter:links"
  log.debug "#{self}::search search_call: #{search_call}"
  response = self.call_twitter_api(search_call, config)
  log.debug "#{self}::call_twitter_api response:    #{response.inspect}"
  response
end