Class: Feed2Thread::PublishesPosts

Inherits:
Object
  • Object
show all
Defined in:
lib/feed2thread/publishes_posts.rb

Instance Method Summary collapse

Instance Method Details

#publish(posts, config, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/feed2thread/publishes_posts.rb', line 5

def publish(posts, config, options)
  post_limit = options.limit || posts.size
  puts "Publishing #{post_limit} posts to Threads" if options.verbose

  # reverse to post oldest first (most Atom feeds are reverse-chronological)
  posts.reverse.take(post_limit).map { |post|
    begin
      puts "Publishing thread for: #{post.url}" if options.verbose
      publish_thread(post, config, options)
    rescue => e
      warn "Failed to post #{post.url}: #{e.message}"
      e.backtrace.join("\n").each_line { |line| warn line }
      Result.new(post: post, status: :failed)
    end
  }
end