Class: Tweetlr::Core
Class Method Summary collapse
- .crawl(config) ⇒ Object
- .log ⇒ Object
- .post_to_tumblr(tumblr_post, config) ⇒ Object
- .prepare_tumblr_config(config) ⇒ Object
- .prepare_twitter_config(config) ⇒ Object
- .process_and_post(tweets, config) ⇒ Object
- .process_response(response, config) ⇒ Object
Instance Method Summary collapse
-
#initialize(args) ⇒ Core
constructor
A new instance of Core.
Methods included from LogAware
Constructor Details
Class Method Details
.crawl(config) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tweetlr/core.rb', line 23 def self.crawl(config) log.debug "#{self}.crawl() using config: #{config.inspect}" twitter_config = prepare_twitter_config config tumblr_config = prepare_tumblr_config config twitter_config[:search_term] = URI::escape(twitter_config[:search_term]) if twitter_config[:search_term] log.info "starting tweetlr crawl..." response = {} response = Tweetlr::Processors::Twitter::lazy_search(twitter_config) if response process_response response, config # store the highest tweet id config[:since_id] = response['max_id'] else log.error "twitter search returned no response. hail the failwhale!" end log.info "finished tweetlr crawl." return config end |
.log ⇒ Object
13 14 15 |
# File 'lib/tweetlr/core.rb', line 13 def self.log Tweetlr::LogAware.log #TODO why doesn't the include make the log method accessible? end |
.post_to_tumblr(tumblr_post, config) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/tweetlr/core.rb', line 77 def self.post_to_tumblr(tumblr_post, config) log.debug "tumblr post: #{tumblr_post}" res = Tweetlr::Processors::Tumblr.post tumblr_post.merge(config) if res && res.code == "201" log.info "tumblr post created (tumblr response header: #{res.header}" elsif res log.warn "tumblr response: #{res.header} #{res.body}" else log.warn "there was no tumblr post response - most probably due to a missing oauth authorization" end end |
.prepare_tumblr_config(config) ⇒ Object
96 97 98 99 |
# File 'lib/tweetlr/core.rb', line 96 def self.prepare_tumblr_config(config) config[:tumblr_blog_hostname] ||= config[:group] config end |
.prepare_twitter_config(config) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/tweetlr/core.rb', line 88 def self.prepare_twitter_config(config) config[:since_id] ||= config[:start_at_tweet_id] config[:terms] ||= config[:search_term] config[:results_per_page] ||= Tweetlr::TWITTER_RESULTS_PER_PAGE config[:result_type] ||= Tweetlr::TWITTER_RESULTS_TYPE config[:api_endpoint_twitter] ||= Tweetlr::API_ENDPOINT_TWITTER config end |
.process_and_post(tweets, config) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/tweetlr/core.rb', line 67 def self.process_and_post(tweets, config) tweets.each do |tweet| tumblr_post = Tweetlr::Combinators::TwitterTumblr::generate_photo_post_from_tweet(tweet, {:whitelist => config[:whitelist], :embedly_key => config[:embedly_key], :group => config[:group]}) if tumblr_post.nil? || tumblr_post[:source].nil? log.warn "could not get image source: tweet: #{tweet} --- tumblr post: #{tumblr_post.inspect}" else post_to_tumblr tumblr_post, config end end end |
.process_response(response, config) ⇒ Object
63 64 65 66 |
# File 'lib/tweetlr/core.rb', line 63 def self.process_response(response, config) tweets = response['results'] process_and_post tweets, config if tweets end |