snoo 0.0.7 → 0.1.0.pre.1

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.
data/lib/snoo/flair.rb CHANGED
@@ -59,30 +59,28 @@ module Snoo
59
59
 
60
60
  # Configures flair options for a subreddit. All options are required
61
61
  #
62
- # @param enabled [true, false] Flair enabled?
63
- # @param position [left, right] Position of user flair.
64
- # @param self_assign [true, false] Allow users to assign their own flair from templates
65
- # @param link_position [none, left, right] The position of link flair. Set to `none` to disable
66
- # @param link_assign [true, false] Allow a submitter to assign their own link flair
67
62
  # @param subreddit [String] The subreddit targeted.
63
+ # @param opts [Hash] An options hash
64
+ # @option opts [true, false] :flair_enabled (true) Flair enabled?
65
+ # @option opts [left, right] :flair_position ('right') Position of user flair.
66
+ # @option opts [true, false] :flair_self_assign_enabled (false) Allow users to assign their own flair from templates
67
+ # @option opts [none, left, right] :link_flair_position ('right') The position of link flair. Set to `none` to disable
68
+ # @option opts [true, false] :link_flair_self_assign_enabled (false) Allow a submitter to assign their own link flair
68
69
  # @return (see #clear_sessions)
69
- def flair_config enabled, position, self_assign, link_position, link_assign, subreddit
70
+ def flair_config subreddit, opts = {}
70
71
  logged_in?
71
- # Test the params
72
- tests = [true, false]
73
- raise "parameter error" unless tests.include?(enabled) && tests.include?(self_assign) && tests.include?(link_assign)
74
- tests << "none"
75
- raise "parameter error" unless tests.include?(link_position)
76
-
77
- post('/api/flairconfig', body: {
78
- flair_enabled: enabled,
79
- flair_position: position,
80
- flair_self_assign_enabled: self_assign,
81
- link_flair_position: link_position,
82
- link_flair_self_assign_enabled: link_assign,
72
+ options = {
73
+ flair_enabled: true,
74
+ flair_position: 'right',
75
+ flair_self_assign_enabled: false,
76
+ link_flair_position: 'right',
77
+ link_flair_self_assign_enabled: false,
83
78
  uh: @modhash,
84
79
  r: subreddit
85
- })
80
+ }
81
+ options.merge! opts
82
+
83
+ post('/api/flairconfig', body: options)
86
84
  end
87
85
 
88
86
  # Post flair in a CSV file to reddit
@@ -116,29 +114,28 @@ module Snoo
116
114
 
117
115
  # Create or edit a flair template.
118
116
  #
119
- # @param css_class [String] The list of css classes applied to this style, space separated
120
- # @param type [USER_FLAIR, LINK_FLAIR] The type of flair template.
121
- # @param text [String] The flair template's text.
122
- # @param user_editable [true, false] If the templ
123
117
  # @param subreddit [String] The subreddit targeted.ate allows users to specify their own text
124
- # @param template_id [String] The flair template ID, for editing. Get this from {#flair_template_list}
118
+ # @param opts [Hash] An options hash
119
+ # @option opts [String] css_class The list of css classes applied to this style, space separated
120
+ # @option opts [USER_FLAIR, LINK_FLAIR] flair_type ('USER_FLAIR') The type of flair template.
121
+ # @option opts [String] text The flair template's text.
122
+ # @option opts [true, false] text_editable (false) If the user is allowed to edit their flair text
123
+ # @option opts [String] template_id The flair template ID, for editing.
125
124
  # @return (see #clear_sessions)
126
- def flair_template css_class, type, text, user_editable, subreddit, template_id = nil
125
+ def flair_template subreddit, opts = {}
127
126
  logged_in?
128
- test = ['USER_FLAIR', 'LINK_FLAIR']
129
- raise ArgumentError, 'type is either USER_FLAIR or LINK_FLAIR' unless test.include?(type)
130
- test = [true, false]
131
- raise ArgumentError, 'user_editable needs to be true or false' unless test.include?(user_editable)
132
-
133
127
  params = {
134
- css_class: css_class,
135
- flair_type: type,
136
- text: text,
137
- text_editable: user_editable,
128
+ flair_type: 'USER_FLAIR',
129
+ text_editable: false,
138
130
  uh: @modhash,
139
131
  r: subreddit
140
132
  }
141
- params[:flair_template_id] = template_id if template_id
133
+ params.merge! opts
134
+ test = ['USER_FLAIR', 'LINK_FLAIR']
135
+ raise ArgumentError, 'type is either USER_FLAIR or LINK_FLAIR' unless test.include?(params[:flair_type])
136
+ test = [true, false]
137
+ raise ArgumentError, 'user_editable needs to be true or false' unless test.include?(params[:text_editable])
138
+
142
139
  post('/api/flairtemplate', body: params)
143
140
  end
144
141
 
@@ -123,6 +123,7 @@ module Snoo
123
123
  logged_in?
124
124
  post('/api/unmarknsfw', body: {id: id, uh: @modhash})
125
125
  end
126
+ alias_method :mark_sfw, :unmark_nsfw
126
127
 
127
128
  # Vote on a comment or link
128
129
  #
@@ -138,14 +139,23 @@ module Snoo
138
139
  # Upvote
139
140
  # An alias for `vote 1, id`
140
141
  #
142
+ def upvote id
143
+ vote 1, id
144
+ end
141
145
 
142
146
  # Downvote
143
147
  # An alias for `vote -1, id`
144
148
  #
149
+ def downvote id
150
+ vote -1, id
151
+ end
145
152
 
146
153
  # Sidevote (clear your vote)
147
154
  # An alias for `vote 0, id`
148
155
  #
156
+ def sidevote id
157
+ vote 0, id
158
+ end
149
159
 
150
160
  end
151
161
  end
data/lib/snoo/listings.rb CHANGED
@@ -8,18 +8,20 @@ module Snoo
8
8
  #
9
9
  # @param link_id [String] The link id of the comment thread. Must always be present
10
10
  # @param (see LinksComments#info)
11
+ # @option opts [String] :subreddit The subreddit to fetch the comments of
12
+ # @option opts [String] :link_id The link to get the comments of
11
13
  # @option opts [String] :comment_id The parent comment of a thread.
12
14
  # @option opts [Fixnum] :context The context of the thread, that is, how far above the `comment_id` to return
13
15
  # @option opts [Fixnum] :limit (100) The total number of comments to return. If you have gold this can include the whole thread, but is buggy. Recommend no more than 1000
14
16
  # @option opts [Fixnum] :depth How deep to render a comment thread.
15
17
  # @option opts [old, new, hot, top, controversial, best] :sort The sort used.
16
18
  # @return (see #clear_sessions)
17
- def get_comments link_id, opts = {}
19
+ def get_comments opts = {}
18
20
  sorts = %w{old new hot top controversial best}
19
21
  raise ArgumentError, "sort cannot be #{sort}" unless sorts.include?(opts[:sort]) or opts[:sort].nil?
20
22
  query = { limit: 100 }
21
23
  query.merge! opts
22
- url = "/comments/%s%s.json" % [link_id, ('/' + opts[:comment_id] if opts[:comment_id])]
24
+ url = "%s/comments/%s%s.json" % [('/r/' + opts[:subreddit] if opts[:subreddit]), opts[:link_id], ('/' + opts[:comment_id] if opts[:comment_id])]
23
25
  get(url, query: query)
24
26
  end
25
27
 
@@ -27,7 +29,7 @@ module Snoo
27
29
  #
28
30
  # @param (see LinksComments#info)
29
31
  # @option opts [String] :subreddit The subreddit targeted. Can be psuedo-subreddits like `all` or `mod`. If blank, the front page
30
- # @option opts [new, controversial, top] :page The page to view.
32
+ # @option opts [new, controversial, top, saved] :page The page to view.
31
33
  # @option opts [new, rising] :sort The sorting method. Only relevant on the `new` page
32
34
  # @option opts [hour, day, week, month, year] :t The timeframe. Only relevant on some pages, such as `top`. Leave empty for all time
33
35
  # @option opts [1..100] :limit The number of things to return.
@@ -35,7 +37,7 @@ module Snoo
35
37
  # @option opts [String] :before Get things *before* this thing id
36
38
  # @return (see #clear_sessions)
37
39
  def get_listing opts = {}
38
- pages = %w{new controversial top}
40
+ pages = %w{new controversial top saved}
39
41
  sorts = %w{new rising}
40
42
  times = %w{hour day week month year}
41
43
  # Invalid Page
@@ -16,12 +16,12 @@ module Snoo
16
16
  # Distinguish a thing
17
17
  #
18
18
  # @param (see #approve)
19
- # @param how [yes, no, admin, special] Determines how to distinguish something. Only works for the permissions you have.
19
+ # @param how [yes, no, admin, special] (yes) Determines how to distinguish something. Only works for the permissions you have.
20
20
  # @return (see #clear_sessions)
21
- def distinguish id, how
21
+ def distinguish id, how = "yes"
22
22
  logged_in?
23
23
  hows = %w{yes no admin special}
24
- raise ArgumentError, "how should be one of #{hows * ', '}, is #{how}" if hows.include?(how)
24
+ raise ArgumentError, "how should be one of #{hows * ', '}, is #{how}" unless hows.include?(how)
25
25
  post('/api/distinguish', body: {id: id, how: how, uh: @modhash})
26
26
  end
27
27
 
@@ -50,7 +50,7 @@ module Snoo
50
50
  # @param (see #approve)
51
51
  # @param spam [true, false] Mark this removal as a spam removal (and train the spamfilter)
52
52
  # @return (see #clear_sessions)
53
- def remove id, spam
53
+ def remove id, spam = false
54
54
  logged_in?
55
55
  spams = [true, false]
56
56
  raise ArgumentError, "spam should be boolean, is #{spam}" unless spams.include?(spam)
data/lib/snoo/pms.rb CHANGED
@@ -54,10 +54,6 @@ module Snoo
54
54
  # @return (see #clear_sessions)
55
55
  def get_messages where = "inbox", opts = {},
56
56
  bools = [true, false]
57
- wheres = %w{inbox unread sent}
58
- raise ArgumentError, "where must be #{wheres * ', '}, is #{where}" unless wheres.include?(where)
59
- raise ArgumentError, "mark must be boolean, is #{opts[:mark]}" unless bools.include?(opts[:mark]) or opts[:mark].nil?
60
- raise ArgumentError, "limit must be 1..100, is #{opts[:limit]}" unless (1..100).include?(opts[:limit]) or opts[:limit].nil?
61
57
 
62
58
  query = {
63
59
  mark: false
@@ -238,5 +238,13 @@ module Snoo
238
238
  logged_in?
239
239
  get("/r/#{subreddit}/about/banned.json")
240
240
  end
241
+
242
+ # Accept a moderatorship
243
+ #
244
+ # @param subreddit [String] The subreddit to accept in. You must have been invited
245
+ def accept_moderator subreddit
246
+ logged_in?
247
+ post('/api/accept_moderator_invite', body: {r: subreddit, uh: @modhash})
248
+ end
241
249
  end
242
250
  end
data/lib/snoo/users.rb CHANGED
@@ -47,9 +47,6 @@ module Snoo
47
47
  # @option opts [1..100] :limit Number of results to return
48
48
  # @return (see #clear_sessions)
49
49
  def get_user_listing username, opts = {}
50
- raise ArgumentError, "type is invalid" unless %w{overview submitted commented liked disliked hidden saved}.include?(opts[:type]) or opts[:type].nil?
51
- raise ArgumentError, "sort is invalid" unless %w{new hot top controversial}.include?(opts[:sort]) or opts[:type].nil?
52
- raise ArgumentError, "limit must be within 1..100; is #{opts[:limit]}" unless (1..100).include?(opts[:limit]) or opts[:limit].nil?
53
50
  opts[:type] = 'overview' if opts[:type].nil?
54
51
  url = "/user/%s%s.json" % [username, ('/' + opts[:type] if opts[:type] != 'overview')]
55
52
  opts.delete :type
data/lib/snoo/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Snoo
2
2
  # The version string (duh)
3
- VERSION = "0.0.7"
3
+ VERSION = "0.1.0.pre.1"
4
4
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
5
- prerelease:
4
+ version: 0.1.0.pre.1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jeff Sandberg
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-04 00:00:00.000000000 Z
12
+ date: 2012-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -112,9 +112,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
115
- - - ! '>='
115
+ - - ! '>'
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: 1.3.1
118
118
  requirements: []
119
119
  rubyforge_project:
120
120
  rubygems_version: 1.8.24