Module: Processors::Twitter

Includes:
LogAware
Defined in:
lib/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



18
19
20
21
22
23
# File 'lib/processors/twitter.rb', line 18

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



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/processors/twitter.rb', line 32

def self.lazy_search(config)
  response = nil
  if config
    search_url = "#{config[:api_endpoint_twitter]}?since_id=#{config[:since_id]}&ors=#{config[:search_term]}&result_type=#{config[:result_type]}&rpp=#{config[:results_per_page]}"
    log.info "lazy search using '#{search_url}'"
    response = Processors::Http::http_get_json search_url
  else
    log.error "#{self}.lazy_search: no config given!"
  end
  response
end

.logObject



8
9
10
# File 'lib/processors/twitter.rb', line 8

def self.log
  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)


13
14
15
# File 'lib/processors/twitter.rb', line 13

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

.search(config) ⇒ Object

fire a new search



26
27
28
29
# File 'lib/processors/twitter.rb', line 26

def self.search(config)
  search_call = "#{config[:api_endpoint_twitter]}?ors=#{config[:search_term]}&result_type=#{config[:result_type]}&rpp=#{config[:results_per_page]}"
  Processors::Http::http_get_json search_call
end