Module: Combinators::TwitterTumblr
- Includes:
- LogAware
- Defined in:
- lib/combinators/twitter_tumblr.rb
Class Method Summary collapse
-
.extract_image_url(tweet, embedly_key = nil) ⇒ Object
extract a linked image file’s url from a tweet.
-
.generate_photo_post_from_tweet(tweet, options = {}) ⇒ Object
generate the data for a tumblr photo entry by parsing a tweet.
- .log ⇒ Object
Methods included from LogAware
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/combinators/twitter_tumblr.rb', line 14 def self.extract_image_url(tweet, =nil) links = Processors::Twitter::extract_links tweet image_url = nil if links links.each do |link| image_url = Processors::PhotoService::find_image_url(link, ) return image_url if 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/combinators/twitter_tumblr.rb', line 26 def self.generate_photo_post_from_tweet(tweet, = {}) log.debug "#{self}.generate_photo_post_from_tweet with options: #{options.inspect}" tumblr_post = nil = tweet['text'] whitelist = [:whitelist] whitelist.each {|entry| entry.downcase!} if (whitelist && whitelist.size != 0) if !Processors::Twitter::retweet? log.debug "tweet: #{tweet}" tumblr_post = {} tumblr_post[:group] = [:group] tumblr_post[:type] = 'photo' tumblr_post[:date] = tweet['created_at'] tumblr_post[:source] = extract_image_url tweet, [: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 end tumblr_post end |
.log ⇒ Object
10 11 12 |
# File 'lib/combinators/twitter_tumblr.rb', line 10 def self.log LogAware.log #TODO why doesn't the include make the log method accessible? end |