snoo 0.1.0.pre.3 → 0.1.0.pre.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/snoo.rb +20 -7
  2. data/lib/snoo/version.rb +1 -1
  3. metadata +2 -2
data/lib/snoo.rb CHANGED
@@ -22,17 +22,30 @@ module Snoo
22
22
 
23
23
  # Creates a new instance of Snoo.
24
24
  #
25
- # Please change the useragent if you write your own program.
25
+ # 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.
26
+ # Simply pass username-password options, OR modhash-cookie options (you cannot do both)
26
27
  #
27
- # @param url [String] url The base url of reddit.
28
- # @param useragent [String] The User-Agent this bot will use.
29
- def initialize( url = "http://www.reddit.com", useragent = "Snoo ruby reddit api wrapper v#{VERSION}" )
30
- @baseurl = url
31
- self.class.base_uri url
32
- @headers = {'User-Agent' => useragent }
28
+ # @param opts [Hash] A hash of options
29
+ # @option opts [String] :url The base url of the reddit instance to use. Only change this if you have a private reddit
30
+ # @option opts [String] :useragent The useragent the bot uses. Please change this if you write your own complex bot
31
+ # @option opts [String] :username The username the bot will log in as
32
+ # @option opts [String] :password The password the bot will log in with
33
+ # @option opts [String] :modhash The modhash the bot will auth with
34
+ # @option opts [String] :cookies The cookie string the bot will auth with
35
+ def initialize( opts = {} )
36
+ options = {url: "http://www.reddit.com", useragent: "Snoo ruby reddit api wrapper v#{VERSION}" }.merge opts
37
+ @baseurl = options[:url]
38
+ self.class.base_uri options[:url]
39
+ @headers = {'User-Agent' => options[:useragent] }
33
40
  self.class.headers @headers
34
41
  @cookies = nil
35
42
  @modhash = nil
43
+
44
+ if !(options[:username].nil? && options[:password].nil?)
45
+ self.log_in options[:username], options[:password]
46
+ elsif !(options[:modhash].nil? && options[:cookies].nil?)
47
+ self.auth options[:modhash], options[:cookies]
48
+ end
36
49
  end
37
50
  end
38
51
  end
data/lib/snoo/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Snoo
2
2
  # The version string (duh)
3
- VERSION = "0.1.0.pre.3"
3
+ VERSION = "0.1.0.pre.4"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.3
4
+ version: 0.1.0.pre.4
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-30 00:00:00.000000000 Z
12
+ date: 2012-11-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty