brutalismbot 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/README.md +10 -7
- data/lib/brutalismbot/r.rb +1 -1
- data/lib/brutalismbot/s3.rb +4 -4
- data/lib/brutalismbot/version.rb +1 -1
- data/lib/brutalismbot.rb +20 -19
- metadata +3 -4
- data/Rakefile +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e14bb3fedb5cfd683191d7ec1aa24d05531af880e55889752b0b344ef56fe785
|
4
|
+
data.tar.gz: bd3d5795d5026c738cc7977a15ff7b725fe7a7451174effeecba4c9de7019bbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67e7c40d478a7e5f3ce89d7bd6bb7f96d10318605db269ad5960d1bfc56eac911d3783d0a292e1dfb15b00fe99544d9ef3f563586b49202180d5b727fcf58515
|
7
|
+
data.tar.gz: 2b6216569f77784d4937f87f1c8c3b1e8ef47d4030533ff3653896df7e5b95bbf96dec12d2691b0a767a7669c914b6eca48cccd20da331d7ac6e56c60ad85921
|
data/README.md
CHANGED
@@ -22,17 +22,20 @@ bucket = Aws::S3::Bucket.new name: "my-bucket"
|
|
22
22
|
brutbot = Brutalismbot::S3::Client.new bucket: bucket,
|
23
23
|
prefix: "my/prefix/"
|
24
24
|
|
25
|
-
# Get new posts after a given time
|
26
|
-
brutbot.subreddit.new_posts.after Time.parse("2019-06-01 12:00:00Z")
|
27
|
-
|
28
|
-
# Get current top post
|
29
|
-
brutbot.subreddit.top_post
|
30
|
-
|
31
25
|
# Get latest cached post
|
32
26
|
brutbot.posts.latest
|
33
27
|
|
34
|
-
# Get
|
28
|
+
# Get latest post as S3 Object
|
35
29
|
brutbot.posts.max_key
|
30
|
+
|
31
|
+
# Get post-time of latest cached post
|
32
|
+
limit = brutbot.posts.max_time
|
33
|
+
|
34
|
+
# Get newest post after a given time
|
35
|
+
brutbot.subreddit.posts(:new).since(time: limit).first
|
36
|
+
|
37
|
+
# Get current top post
|
38
|
+
brutbot.subreddit.posts(:top).first
|
36
39
|
```
|
37
40
|
|
38
41
|
## Contributing
|
data/lib/brutalismbot/r.rb
CHANGED
@@ -33,7 +33,7 @@ module Brutalismbot
|
|
33
33
|
response = JSON.parse http.request(request).body
|
34
34
|
children = response.dig("data", "children") || []
|
35
35
|
children.reverse.each do |child|
|
36
|
-
post = Brutalismbot::Post
|
36
|
+
post = Brutalismbot::Post.new child
|
37
37
|
yield post if post.created_after time: @min_time
|
38
38
|
end
|
39
39
|
end
|
data/lib/brutalismbot/s3.rb
CHANGED
@@ -44,7 +44,7 @@ module Brutalismbot
|
|
44
44
|
class AuthCollection < Collection
|
45
45
|
def each
|
46
46
|
super do |object|
|
47
|
-
yield Brutalismbot::Auth
|
47
|
+
yield Brutalismbot::Auth.new JSON.parse(object.get.body.read)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -66,7 +66,7 @@ module Brutalismbot
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def put(auth:, dryrun:nil)
|
69
|
-
key = "#{@prefix}team=#{auth.team_id}/channel=#{auth.channel_id}/oauth.json"
|
69
|
+
key = "#{@prefix}team=#{auth.team_id}/channel=#{auth.incoming_webhook.channel_id}/oauth.json"
|
70
70
|
super key: key, body: auth.to_json, dryrun: dryrun
|
71
71
|
end
|
72
72
|
end
|
@@ -74,12 +74,12 @@ module Brutalismbot
|
|
74
74
|
class PostCollection < Collection
|
75
75
|
def each
|
76
76
|
super do |object|
|
77
|
-
yield Brutalismbot::Post
|
77
|
+
yield Brutalismbot::Post.new JSON.parse(object.get.body.read)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
def latest
|
82
|
-
Brutalismbot::Post
|
82
|
+
Brutalismbot::Post.new JSON.parse(max_key.get.body.read)
|
83
83
|
end
|
84
84
|
|
85
85
|
def max_key
|
data/lib/brutalismbot/version.rb
CHANGED
data/lib/brutalismbot.rb
CHANGED
@@ -29,50 +29,51 @@ module Brutalismbot
|
|
29
29
|
class Error < StandardError
|
30
30
|
end
|
31
31
|
|
32
|
-
class Auth <
|
33
|
-
|
34
|
-
|
32
|
+
class Auth < OpenStruct
|
33
|
+
class IncomingWebhook < OpenStruct; end
|
34
|
+
|
35
|
+
def incoming_webhook
|
36
|
+
IncomingWebhook.new dig("incoming_webhook")
|
35
37
|
end
|
36
38
|
|
37
39
|
def post(body:, dryrun:nil)
|
38
|
-
uri = URI.parse
|
40
|
+
uri = URI.parse incoming_webhook.url
|
39
41
|
ssl = uri.scheme == "https"
|
40
42
|
Net::HTTP.start(uri.host, uri.port, use_ssl: ssl) do |http|
|
41
43
|
if dryrun
|
42
|
-
Brutalismbot.logger
|
44
|
+
Brutalismbot.logger.info "POST DRYRUN #{uri}"
|
43
45
|
else
|
44
|
-
Brutalismbot.logger
|
46
|
+
Brutalismbot.logger.info "POST #{uri}"
|
45
47
|
req = Net::HTTP::Post.new uri, "content-type" => "application/json"
|
46
48
|
req.body = body
|
47
49
|
http.request req
|
48
50
|
end
|
49
51
|
end
|
50
52
|
end
|
53
|
+
end
|
51
54
|
|
52
|
-
|
53
|
-
|
55
|
+
class Post < OpenStruct
|
56
|
+
class Data < OpenStruct
|
54
57
|
end
|
55
58
|
|
56
|
-
def
|
57
|
-
|
59
|
+
def created_utc
|
60
|
+
Time.at(data.created_utc.to_i).utc
|
58
61
|
end
|
59
|
-
end
|
60
62
|
|
61
|
-
class Post < Hash
|
62
63
|
def created_after(time:)
|
63
|
-
created_utc.to_i > time.to_i
|
64
|
+
data.created_utc.to_i > time.to_i
|
64
65
|
end
|
65
66
|
|
66
|
-
def
|
67
|
-
|
67
|
+
def data
|
68
|
+
Data.new dig("data")
|
68
69
|
end
|
69
70
|
|
70
71
|
def permalink
|
71
|
-
|
72
|
+
data.permalink
|
72
73
|
end
|
73
74
|
|
74
75
|
def title
|
75
|
-
|
76
|
+
data.title
|
76
77
|
end
|
77
78
|
|
78
79
|
def to_slack
|
@@ -102,13 +103,13 @@ module Brutalismbot
|
|
102
103
|
end
|
103
104
|
|
104
105
|
def url
|
105
|
-
images =
|
106
|
+
images = data.preview.dig "images"
|
106
107
|
source = images.map{|x| x["source"] }.compact.max do |a,b|
|
107
108
|
a.slice("width", "height").values <=> b.slice("width", "height").values
|
108
109
|
end
|
109
110
|
CGI.unescapeHTML source.dig("url")
|
110
111
|
rescue NoMethodError
|
111
|
-
|
112
|
+
data.media_metadata&.values&.first&.dig("s", "u")
|
112
113
|
end
|
113
114
|
end
|
114
115
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brutalismbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Mancevice
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-s3
|
@@ -118,7 +118,6 @@ extra_rdoc_files: []
|
|
118
118
|
files:
|
119
119
|
- LICENSE.txt
|
120
120
|
- README.md
|
121
|
-
- Rakefile
|
122
121
|
- lib/brutalismbot.rb
|
123
122
|
- lib/brutalismbot/r.rb
|
124
123
|
- lib/brutalismbot/s3.rb
|
@@ -142,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
141
|
- !ruby/object:Gem::Version
|
143
142
|
version: '0'
|
144
143
|
requirements: []
|
145
|
-
rubygems_version: 3.0.
|
144
|
+
rubygems_version: 3.0.4
|
146
145
|
signing_key:
|
147
146
|
specification_version: 4
|
148
147
|
summary: Mirror posts from /r/brutalism to Slack
|