snoo 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/snoo.rb +1 -0
- data/lib/snoo/moderation.rb +38 -0
- data/lib/snoo/version.rb +1 -1
- data/snoo.gemspec +1 -1
- metadata +18 -2
data/lib/snoo.rb
CHANGED
data/lib/snoo/moderation.rb
CHANGED
@@ -57,5 +57,43 @@ module Snoo
|
|
57
57
|
post('/api/remove', body: {id: id, spam: spam, uh: @modhash})
|
58
58
|
end
|
59
59
|
|
60
|
+
# Gets a moderation log
|
61
|
+
# This is a tricky function, and may break a lot.
|
62
|
+
# Blame the lack of a real api
|
63
|
+
#
|
64
|
+
# @param subreddit [String] The subreddit to fetch from
|
65
|
+
# @param opts [Hash] Options to pass to reddit
|
66
|
+
# @option opts [Fixnum] :count (100) The number to get. Can't be higher than 100
|
67
|
+
# @option opts [String] :before The "fullname" to fetch before.
|
68
|
+
# @option opts [String] :after The "fullname" to fetch after.
|
69
|
+
# @option opts [String] :type See [reddit API docs](http://www.reddit.com/dev/api#GET_moderationlog)
|
70
|
+
# @option opts [String] :mod The moderator to get. Name, not ID
|
71
|
+
# @return [Hash] A hash consisting of the data, first fullname, last fullname, first date, and last date
|
72
|
+
def modlog subreddit, opts = {}
|
73
|
+
logged_in?
|
74
|
+
options = {
|
75
|
+
count: 100
|
76
|
+
}.merge opts
|
77
|
+
data = Nokogiri::HTML.parse(get("/r/#{subreddit}/about/log", query: options).body).css('.modactionlisting tr')
|
78
|
+
processed = {
|
79
|
+
data: [],
|
80
|
+
first: data[0]['data-fullname'],
|
81
|
+
first_date: Time.parse(data[0].children[0].child['datetime']),
|
82
|
+
last: data[-1]['data-fullname'],
|
83
|
+
last_date: Time.parse(data[-1].children[0].child['datetime'])
|
84
|
+
}
|
85
|
+
data.each do |tr|
|
86
|
+
|
87
|
+
processed[:data] << {
|
88
|
+
fullname: tr['data-fullname'],
|
89
|
+
time: Time.parse(tr.children[0].child['datetime']),
|
90
|
+
author: tr.children[1].child.content,
|
91
|
+
action: tr.children[2].child['class'].split[1],
|
92
|
+
description: tr.children[3].content
|
93
|
+
}
|
94
|
+
end
|
95
|
+
return processed
|
96
|
+
end
|
97
|
+
|
60
98
|
end
|
61
99
|
end
|
data/lib/snoo/version.rb
CHANGED
data/snoo.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.required_ruby_version = '>= 1.9'
|
17
17
|
gem.license = 'MIT'
|
18
18
|
|
19
|
-
['httparty'].each do |dependency|
|
19
|
+
['httparty', 'nokogiri'].each do |dependency|
|
20
20
|
gem.add_runtime_dependency dependency
|
21
21
|
end
|
22
22
|
['rspec'].each do |dependency|
|
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.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
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-08-
|
12
|
+
date: 2012-08-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: rspec
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|