class Forrst::User

Constants

INFO_RESOURCE

Attributes

id[R]
raw_data[R]
username[R]

Public Class Methods

find(id) click to toggle source
# File lib/forrst/user.rb, line 14
def self.find(id)
  (id.is_a? Fixnum) ? self.find_by_user_id(id) : self.find_by_username(id)
end
new(uri) click to toggle source
# File lib/forrst/user.rb, line 18
def initialize(uri)
  begin
    response = RestClient.get uri

    if response.code == 200
      @raw_data = Yajl::Parser.parse(response.body)['resp']
      @username = @raw_data['username']
      @id       = @raw_data['id'].to_i # Should be a Fixnum from the start
    end
  rescue RestClient::ResourceNotFound
    raise Exceptions::UserNotFound
  end
end

Private Class Methods

find_by_user_id(user_id) click to toggle source
# File lib/forrst/user.rb, line 38
def self.find_by_user_id(user_id)
  raise Exceptions::InvalidId unless user_id.is_a? Fixnum
  self.new("#{INFO_RESOURCE}?id=#{user_id}")
end
find_by_username(username) click to toggle source
# File lib/forrst/user.rb, line 43
def self.find_by_username(username)
  raise Exceptions::InvalidUsername unless username.is_a? String
  self.new("#{INFO_RESOURCE}?username=#{username}")
end

Public Instance Methods

public_posts() click to toggle source
# File lib/forrst/user.rb, line 32
def public_posts
  @posts ||= PublicPosts.new(username)
  @posts.retrieve
end