Class: Snoo::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/snoo.rb

Overview

Snoo reddit API wrapper

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Creates a new instance of Snoo.

As of 0.1.0.pre.4, you can auth or log-in via initializers, saving you from having to run the log-in or auth command seperately. Simply pass username-password options, OR modhash-cookie options (you cannot do both)

Parameters:

  • opts (Hash) (defaults to: {})

    A hash of options

Options Hash (opts):

  • :url (String)

    The base url of the reddit instance to use. Only change this if you have a private reddit

  • :useragent (String)

    The useragent the bot uses. Please change this if you write your own complex bot

  • :username (String)

    The username the bot will log in as

  • :password (String)

    The password the bot will log in with

  • :modhash (String)

    The modhash the bot will auth with

  • :cookies (String)

    The cookie string the bot will auth with



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/snoo.rb', line 35

def initialize( opts = {} )
  options = {url: "http://www.reddit.com", useragent: "Snoo ruby reddit api wrapper v#{VERSION}" }.merge opts
  @baseurl = options[:url]
  self.class.base_uri options[:url]
  @headers = {'User-Agent' => options[:useragent] }
  self.class.headers @headers
  @cookies = nil
  @modhash = nil

  if !(options[:username].nil? && options[:password].nil?)
    self. options[:username], options[:password]
  elsif !(options[:modhash].nil? && options[:cookies].nil?)
    self.auth options[:modhash], options[:cookies]
  end
end

Instance Attribute Details

#cookiesObject (readonly)

Returns the value of attribute cookies.



20
21
22
# File 'lib/snoo.rb', line 20

def cookies
  @cookies
end

#modhashObject (readonly)

Returns the value of attribute modhash.



20
21
22
# File 'lib/snoo.rb', line 20

def modhash
  @modhash
end

#useridObject (readonly)

Returns the value of attribute userid.



20
21
22
# File 'lib/snoo.rb', line 20

def userid
  @userid
end

#usernameObject (readonly)

Returns the value of attribute username.



20
21
22
# File 'lib/snoo.rb', line 20

def username
  @username
end