Sha256: 8b4b026f58ddb15a64ffdc386b9d4295e9d3138fc50786c20256bb9d350d9ac4
Contents?: true
Size: 1.6 KB
Versions: 3
Compression:
Stored size: 1.6 KB
Contents
require 'snooby' require 'usaidwat/service' require 'usaidwat/ext/time' module USaidWat module Client class ReachabilityError < RuntimeError; 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 TypeError raise ReachabilityError, "Reddit unreachable" end def link_karma about('link_karma') end def comment_karma about('comment_karma') end def created_at Time.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 TypeError raise ReachabilityError, "Reddit unreachable" end private def user @service.user(username) end def about(key) user.about[key] rescue NoMethodError raise NoSuchUserError, username rescue TypeError raise ReachabilityError, "Reddit unreachable" end end class Redditor < BaseRedditor def initialize(username) @service = Snooby::Client.new("usaidwat v#{USaidWat::VERSION}") super end end class TestRedditor < BaseRedditor def initialize(username) @service = USaidWat::Service::MockService.new super end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
usaidwat-1.4.2 | lib/usaidwat/client.rb |
usaidwat-1.4.1 | lib/usaidwat/client.rb |
usaidwat-1.4.0 | lib/usaidwat/client.rb |