Sha256: 6bf8d5914258f933f13c9188823c50d1b2e950f77304bcaadf5a35c521ca43c2
Contents?: true
Size: 1.51 KB
Versions: 4
Compression:
Stored size: 1.51 KB
Contents
require 'usaidwat/service' require 'usaidwat/ext/time' module USaidWat module Client class ReachabilityError < RuntimeError def initialize(msg = nil) super(msg || 'Reddit unreachable') end end class NoSuchUserError < StandardError; end class BaseRedditor attr_reader :username def initialize(username) @username = username end def comments user.comments(100) rescue NoMethodError raise NoSuchUserError, username rescue RuntimeError raise ReachabilityError end def link_karma about.link_karma end def comment_karma about.comment_karma end def created_at about.created_utc end def age (Time.now - created_at).ago end def to_s "#{username}" end def posts user.posts rescue NoMethodError raise NoSuchUserError, username rescue RuntimeError raise ReachabilityError end private def user @service.user(username) end def about user.about rescue NoMethodError raise NoSuchUserError, username end end class Redditor < BaseRedditor def initialize(username) @service = USaidWat::Service::RedditService.new super end end class TestRedditor < BaseRedditor def initialize(username) @service = USaidWat::Service::MockService.new super end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
usaidwat-1.6.1 | lib/usaidwat/client.rb |
usaidwat-1.6.0 | lib/usaidwat/client.rb |
usaidwat-1.5.1 | lib/usaidwat/client.rb |
usaidwat-1.5.0 | lib/usaidwat/client.rb |