class Myredditnews::Entry
Public Instance Methods
self_post?()
click to toggle source
# File lib/myredditnews.rb, line 68 def self_post? self_post end
submit(reddit, subreddit)
click to toggle source
# File lib/myredditnews.rb, line 45 def submit(reddit, subreddit) opts = {} if self_post? opts[:kind] = 'self' opts[:text] = @content else opts[:kind] = 'link' opts[:url] = @url end $logger.info("Submitting #{opts[:kind]}: #{self}") puts "Dryness: #{Myredditnews.dry}" unless Myredditnews.dry response = reddit.submit(@title, subreddit, opts) $logger.info(response) throw_if_error response # TODO rate limiting should be smarter than this puts "Sleeping for #{Myredditnews.delay}" sleep Myredditnews.delay end end
to_json(*a)
click to toggle source
# File lib/myredditnews.rb, line 71 def to_json(*a) { "author" => @author, "content" => @content, "url" => @url, "date" => @date, "summary" => @summary, "title" => @title, }.to_json(*a) end
to_s()
click to toggle source
# File lib/myredditnews.rb, line 65 def to_s return "[#{truncate(@author, 10)}, #{truncate(@url, 20)}]" end
Private Instance Methods
throw_if_error(response)
click to toggle source
# File lib/myredditnews.rb, line 84 def throw_if_error response unless response['json']['errors'].empty? raise RedditError, response['json']['errors'] end end
truncate(str, width)
click to toggle source
# File lib/myredditnews.rb, line 81 def truncate str, width str.size > width ? (str[0..width-1] + "...") : str end