Module: Tweetlr::Combinators::TwitterTumblr

Includes:
LogAware
Defined in:
lib/tweetlr/combinators/twitter_tumblr.rb

Class Method Summary collapse

Methods included from LogAware

log=

Class Method Details

.extract_image_url(tweet, embedly_key = nil) ⇒ Object

extract a linked image file’s url from a tweet. first found image will be used.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/tweetlr/combinators/twitter_tumblr.rb', line 14

def self.extract_image_url(tweet, embedly_key=nil)
  links = Tweetlr::Processors::Twitter::extract_links tweet
  image_url = nil
  if links
    links.each do |link|
      image_url = Tweetlr::Processors::PhotoService::find_image_url(link, embedly_key)
      return image_url if Tweetlr::Processors::PhotoService::photo? image_url
    end
  end
  image_url
end

.generate_photo_post_from_tweet(tweet, options = {}) ⇒ Object

generate the data for a tumblr photo entry by parsing a tweet



26
27
28
29
# File 'lib/tweetlr/combinators/twitter_tumblr.rb', line 26

def self.generate_photo_post_from_tweet(tweet, options = {})
  log.debug "#{self}.generate_photo_post_from_tweet with options: #{options.inspect}"
  process_options_and_tweet options, tweet
end

.logObject



10
11
12
# File 'lib/tweetlr/combinators/twitter_tumblr.rb', line 10

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

.prepare_tumblr_post(options, tweet, whitelist) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/tweetlr/combinators/twitter_tumblr.rb', line 39

def self.prepare_tumblr_post(options, tweet, whitelist)
  tumblr_post = {}
  tumblr_post[:tumblr_blog_hostname] = options[:tumblr_blog_hostname] || options[:group]
  tumblr_post[:type] = 'photo'
  tumblr_post[:date] = tweet['created_at']
  tumblr_post[:source] = extract_image_url tweet, options[:embedly_key]
  user = tweet['from_user']
  tumblr_post[:tags] = user
  tweet_id = tweet['id']
  if !whitelist || whitelist.size == 0 || whitelist.member?(user.downcase)
    state = 'published'
  else
    state = 'draft'
  end
  tumblr_post[:state] = state
  shouts = " #{@shouts}" if @shouts
  tumblr_post[:caption] = %?<a href="http://twitter.com/#{user}/statuses/#{tweet_id}" alt="tweet">@#{user}</a>#{shouts}: #{tweet['text']}? 
  #TODO make the caption a bigger matter of yml/ general configuration
  tumblr_post  
end

.process_options_and_tweet(options, tweet) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/tweetlr/combinators/twitter_tumblr.rb', line 31

def self.process_options_and_tweet(options, tweet)
  whitelist = options[:whitelist]
  whitelist.each {|entry| entry.downcase!} if (whitelist && whitelist.size != 0)
  if !Tweetlr::Processors::Twitter::retweet? tweet['text']
    log.debug "tweet: #{tweet}"
    tumblr_post = prepare_tumblr_post options, tweet, whitelist
  end
end