class Rubbit_Poster

Public Class Methods

instance(name=nil) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 101
def self.instance(name=nil)
        if(@@instance==nil)
                if(name!=nil)
                        @@instance = new(name)
                else
                        return nil
                end
        end
        return @@instance
end

Private Class Methods

new(net_name) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 84
def initialize(net_name)
        Reddit_Net_Wrapper.instance(net_name)
        @logged_in_user = nil
end

Public Instance Methods

clear_sessions(curpass) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 130
def clear_sessions(curpass)
        params = {}
        params['api_type']='json'
        params['curpass'] = curpass
        params['uh']=get_modhash

        response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/clear_sessions/',params)

        return JSON.parse(response.body)
end
comment(parent,text) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 187
def comment(parent,text)
        params = {}
        params['api_type']='json'
        params['thing_id']=parent
        params['text']=text
        params['uh']=get_modhash

        response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/comment',params)

        return JSON.parse(response.body)
end
create_live(title,description='',nsfw=false) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 241
def create_live(title,description='',nsfw=false)
        params = {}

        params['api_type']='json'
        params['title']=title
        params['description']=description
        params['nsfw']=nsfw
        params['uh']=get_modhash

        response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/live/create',params)

        return Live_Thread.new(JSON.parse(response.body)['json']['data']['id'])
end
create_subreddit(name,other_params) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 316
def create_subreddit(name,other_params)
        params = {}
        params['link_type']='any'
        params['wikimode']='disabled'
        params['type'] = 'public'
        params['name'] = name
        other_params.keys.each do |k|
                params[k] = other_params[k]
        end
        params['uh']=get_modhash
        
        response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/site_admin',params)
        
        return response.body
end
delete(id) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 209
def delete(id)
        params = {}
        params['id'] = id
        params['uh']=get_modhash
        
        response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/del',params)

        return JSON.parse(response.body)
end
delete_user(user,passwd,message) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 141
def delete_user(user,passwd,message)
        params = {}
        params['api_type']='json'
        params['user']=user
        params['passwd']=passwd
        params['message']=message
        params['uh']=get_modhash

        response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/delete_user/',params)
        return JSON.parse(response.body)
end
edit(id,text) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 219
def edit(id,text)
        params = {}
        params['api_type']='json'
        params['text']=text
        params['id'] = id
        params['uh']=get_modhash
        
        response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/editusertext',params)

        return JSON.parse(response.body)
end
friend(type,user,container,info=nil,duration=nil) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 267
def friend(type,user,container,info=nil,duration=nil)
        params = {}
        params['api_type']='json'
        params['type']=type
        params['name']=user
        params['uh']=get_modhash
        case type
        when 'friend'
                params['note']=info
                params['container']=container
        when 'moderator'
                params['container']=container
                params['permissions']=info
        when 'moderator_invite'
                params['container']=container
                params['permissions']=info
        when 'contributor'
                params['container']=container
                params['r']=info
        when 'banned'
                params['container']=container
                params['note']=info
                params['duration']=duration
        when 'wikibanned'
                params['container']=container
                params['note']=info
                params['duration']=duration
        when 'wikicontributor'
                params['container']=container
        end
        
        response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/friend',params)

        return JSON.parse(response.body)
end
get_modhash() click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 332
def get_modhash
        if(@logged_in_user==nil)
                raise LoginException, 'Not logged in.'
        end
        response = Reddit_Net_Wrapper.instance.make_request('get','http://www.reddit.com/user/'+@logged_in_user+'/about.json',{})
        data = JSON.parse(response.body)
        return data['data']['modhash']
end
hide(id) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 199
def hide(id)
        params = {}
        params['id'] = id
        params['uh']=get_modhash
        
        response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/hide',params)

        return JSON.parse(response.body)
end
login(user,passwd) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 112
def login(user,passwd)
        params = {}
        params['op']='login'
        params['user']=user
        params['passwd']=passwd
        params['api-type']='json'
        
        login_status = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/login/',params).code

        if(login_status=='200')
                user = Rubbit_Object_Builder.instance.build_user(user)
                @logged_in_user = user.name
                return user
        else
                raise InvalidUserException, "Could not validate login credentials"
        end
end
mark_nsfw(id) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 231
def mark_nsfw(id)
        params = {}
        params['id'] = id
        params['uh']=get_modhash
        
        response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/marknsfw',params)

        return JSON.parse(response.body)
end
set_subreddit_sticky(post_id,state) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 89
def set_subreddit_sticky(post_id,state)
        params = {}
        params['api_type']='json'
        params['id']=post_id
        params['state']=state
        params['uh']=get_modhash
        
        response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/set_subreddit_sticky/',params)
        
        return JSON.parse(response.body)
end
submit(sr,title,url=nil,text=nil,kind='self',resubmit=nil,save=false,sendreplies=true) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 167
def submit(sr,title,url=nil,text=nil,kind='self',resubmit=nil,save=false,sendreplies=true)
        params = {}
        params['api_type']='json'
        params['extension']=nil
        params['kind']=kind
        params['resubmit']=resubmit
        params['save']=save
        params['sendreplies']=sendreplies
        params['id']='#newlink'
        params['sr']=sr
        params['r']=sr
        params['text']=text
        params['title']=title
        params['uh']=get_modhash
        params['url']=url

        response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/submit/',params)
        return JSON.parse(response.body)
end
unfriend(type,user,container) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 303
def unfriend(type,user,container)
        params = {}
        params['api_type']='json'
        params['type']=type
        params['name']=user
        params['uh']=get_modhash
        params['container']=container

        response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/unfriend',params)

        return response.body
end
update(email,newpass,curpass,verify,verpass) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 153
def update(email,newpass,curpass,verify,verpass)
        params = {}
        params['api_type']='json'
        params['curpass']=curpass
        params['email']=email
        params['newpass']=newpass
        params['verify']=verify
        params['verpass']=verpass
        params['uh']=get_modhash

        response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/update/',params)
        return JSON.parse(response.body)
end
update_live(id,body) click to toggle source
# File lib/Rubbit/Rubbit_Construction_Layer.rb, line 255
def update_live(id,body)
        params = {}

        params['api_type']='json'
        params['body']=body
        params['uh']=get_modhash

        response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/live/'+id+'/update',params)

        return JSON.parse(response.body)
end