brutalismbot 1.0.0.beta.1 → 1.0.0.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brutalismbot/client.rb +1 -1
- data/lib/brutalismbot/posts/client.rb +2 -1
- data/lib/brutalismbot/posts/stub.rb +22 -14
- data/lib/brutalismbot/reddit/post.rb +40 -34
- data/lib/brutalismbot/slack/client.rb +2 -1
- data/lib/brutalismbot/slack/stub.rb +28 -13
- data/lib/brutalismbot/stub.rb +10 -5
- data/lib/brutalismbot/twitter/client.rb +14 -8
- data/lib/brutalismbot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 057aa6155c1a5f25a7f27392384ca6d1ad2610bb1c930d0d0e7bd293e7ef1140
|
4
|
+
data.tar.gz: 5e610795ea0c3ccb8cbf96d3b332c0031640632c1b07ad405102dddacc2ee312
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca0daf3e9ceca0db0841f8bd235cc73fec57c91d4908d609dea9699f0006aaf3a14f3986cc70adf96b447f3f9711c0dc13d6560316bf58ef1e54e56bce5a6d9f
|
7
|
+
data.tar.gz: d11f03af3411f675538fb9c8061289191c0b865874caabcc0379888b526b3ef7ac91089c290f9f5956fa5edb9295197b8154eca8e7946befcade8a7f4ed8cb33
|
data/lib/brutalismbot/client.rb
CHANGED
@@ -35,7 +35,7 @@ module Brutalismbot
|
|
35
35
|
Brutalismbot.logger.info("GET s3://#{@bucket.name}/#{prefix}*")
|
36
36
|
|
37
37
|
# Go up a level in prefix if no keys found
|
38
|
-
until (keys = @bucket.objects(prefix: prefix)).any?
|
38
|
+
until (keys = @bucket.objects(prefix: prefix)).any? || prefix == @prefix
|
39
39
|
prefix = prefix.split(/[^\/]+\/\z/).first
|
40
40
|
Brutalismbot.logger.info("GET s3://#{@bucket.name}/#{prefix}*")
|
41
41
|
end
|
@@ -46,6 +46,7 @@ module Brutalismbot
|
|
46
46
|
|
47
47
|
def max_time
|
48
48
|
max_key.key[/(\d+).json\z/, -1].to_i
|
49
|
+
rescue NoMethodError
|
49
50
|
end
|
50
51
|
|
51
52
|
def push(post, dryrun:nil)
|
@@ -1,26 +1,34 @@
|
|
1
|
+
require "aws-sdk-s3"
|
2
|
+
|
1
3
|
require "brutalismbot/reddit/post"
|
2
4
|
|
3
5
|
module Brutalismbot
|
4
6
|
module Posts
|
5
7
|
class Client
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def stub!(items = nil)
|
9
|
+
items ||= [Reddit::Post.stub]
|
10
|
+
items = items.map{|x| [key_for(x), x.to_h] }.to_h
|
11
|
+
|
12
|
+
@client = Aws::S3::Client.new(stub_responses: true)
|
13
|
+
@bucket = Aws::S3::Bucket.new(name: @bucket.name, client: @client)
|
14
|
+
|
15
|
+
@client.stub_responses :list_objects_v2, -> (context) do
|
16
|
+
keys = items.keys.select{|x| x.start_with? context.params[:prefix] }
|
17
|
+
{contents: keys.map{|x| {key:x} }}
|
18
|
+
end
|
10
19
|
|
11
|
-
|
12
|
-
|
20
|
+
@client.stub_responses :get_object, -> (context) do
|
21
|
+
{body: StringIO.new(items.fetch(context.params[:key]).to_json)}
|
22
|
+
end
|
13
23
|
|
14
|
-
|
15
|
-
keys = items.keys.select{|x| x.start_with? context.params[:prefix] }
|
16
|
-
{contents: keys.map{|x| {key:x} }}
|
17
|
-
end
|
24
|
+
@stubbed = true
|
18
25
|
|
19
|
-
|
20
|
-
|
21
|
-
end
|
26
|
+
self
|
27
|
+
end
|
22
28
|
|
23
|
-
|
29
|
+
class << self
|
30
|
+
def stub(items = nil)
|
31
|
+
new(prefix: "data/test/posts/").stub!(items)
|
24
32
|
end
|
25
33
|
end
|
26
34
|
end
|
@@ -61,45 +61,51 @@ module Brutalismbot
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def to_slack
|
64
|
+
url.nil? ? to_slack_text : to_slack_image
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_slack_image
|
64
68
|
{
|
65
|
-
blocks:
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
emoji: true,
|
73
|
-
},
|
74
|
-
image_url: url,
|
75
|
-
alt_text: title,
|
76
|
-
},
|
77
|
-
{
|
78
|
-
type: "context",
|
79
|
-
elements: [
|
80
|
-
{
|
81
|
-
type: "mrkdwn",
|
82
|
-
text: "<#{permalink}|#{title}>",
|
83
|
-
},
|
84
|
-
],
|
69
|
+
blocks: [
|
70
|
+
{
|
71
|
+
type: "image",
|
72
|
+
title: {
|
73
|
+
type: "plain_text",
|
74
|
+
text: "/r/brutalism",
|
75
|
+
emoji: true,
|
85
76
|
},
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
77
|
+
image_url: url,
|
78
|
+
alt_text: title,
|
79
|
+
},
|
80
|
+
{
|
81
|
+
type: "context",
|
82
|
+
elements: [
|
83
|
+
{
|
92
84
|
type: "mrkdwn",
|
93
85
|
text: "<#{permalink}|#{title}>",
|
94
86
|
},
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
87
|
+
],
|
88
|
+
},
|
89
|
+
],
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
def to_slack_text
|
94
|
+
{
|
95
|
+
blocks: [
|
96
|
+
{
|
97
|
+
type: "section",
|
98
|
+
text: {
|
99
|
+
type: "mrkdwn",
|
100
|
+
text: "<#{permalink}|#{title}>",
|
101
|
+
},
|
102
|
+
accessory: {
|
103
|
+
type: "image",
|
104
|
+
image_url: "https://brutalismbot.com/logo-red-ppl.png",
|
105
|
+
alt_text: "/r/brutalism",
|
106
|
+
},
|
107
|
+
},
|
108
|
+
],
|
103
109
|
}
|
104
110
|
end
|
105
111
|
|
@@ -41,7 +41,8 @@ module Brutalismbot
|
|
41
41
|
|
42
42
|
def uninstall(auth, dryrun:nil)
|
43
43
|
prefix = File.join(@prefix, "team=#{auth.team_id}/")
|
44
|
-
@bucket.
|
44
|
+
Brutalismbot.logger.info("LIST s3://#{@bucket.name}/#{prefix}*")
|
45
|
+
@bucket.objects(prefix: prefix).map do |object|
|
45
46
|
Brutalismbot.logger.info("DELETE #{"DRYRUN " if dryrun}s3://#{@bucket.name}/#{object.key}")
|
46
47
|
object.delete unless dryrun
|
47
48
|
end
|
@@ -1,25 +1,40 @@
|
|
1
1
|
require "securerandom"
|
2
2
|
|
3
|
+
require "aws-sdk-s3"
|
4
|
+
|
5
|
+
require "brutalismbot/slack/auth"
|
6
|
+
|
3
7
|
module Brutalismbot
|
4
8
|
module Slack
|
5
9
|
class Client
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
client.instance_variable_set(:@stubbed, true)
|
10
|
+
def stub!(items = nil)
|
11
|
+
items ||= [Auth.stub]
|
12
|
+
items = items.map{|x| [key_for(x), x.to_h] }.to_h
|
10
13
|
|
11
|
-
|
12
|
-
|
14
|
+
@client = Aws::S3::Client.new(stub_responses: true)
|
15
|
+
@bucket = Aws::S3::Bucket.new(name: @bucket.name, client: @client)
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
@client.stub_responses :list_objects_v2, -> (context) do
|
18
|
+
keys = items.keys.select{|x| x.start_with? context.params[:prefix] }
|
19
|
+
{contents: keys.map{|x| {key:x} }}
|
20
|
+
end
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
@client.stub_responses :get_object, -> (context) do
|
23
|
+
{body: StringIO.new(items.fetch(context.params[:key]).to_json)}
|
24
|
+
end
|
21
25
|
|
22
|
-
|
26
|
+
@client.stub_responses :delete_object, -> (context) do
|
27
|
+
{version_id: context.params[:key]}
|
28
|
+
end
|
29
|
+
|
30
|
+
@stubbed = true
|
31
|
+
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
class << self
|
36
|
+
def stub(items = nil)
|
37
|
+
new(prefix: "data/test/auths/").stub!(items)
|
23
38
|
end
|
24
39
|
end
|
25
40
|
end
|
data/lib/brutalismbot/stub.rb
CHANGED
@@ -7,12 +7,17 @@ Aws.config.update(stub_responses: true)
|
|
7
7
|
|
8
8
|
module Brutalismbot
|
9
9
|
class Client
|
10
|
+
def stub!(posts:nil, slack:nil)
|
11
|
+
@posts = Posts::Client.stub(posts)
|
12
|
+
@slack = Slack::Client.stub(posts)
|
13
|
+
@stubbed = true
|
14
|
+
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
10
18
|
class << self
|
11
|
-
def stub
|
12
|
-
new(
|
13
|
-
posts: Posts::Client.stub,
|
14
|
-
slack: Slack::Client.stub,
|
15
|
-
)
|
19
|
+
def stub(posts:nil, slack:nil)
|
20
|
+
new.stub!(posts: posts, slack: slack)
|
16
21
|
end
|
17
22
|
end
|
18
23
|
end
|
@@ -21,15 +21,21 @@ module Brutalismbot
|
|
21
21
|
|
22
22
|
def push(post, dryrun:nil)
|
23
23
|
Brutalismbot.logger.info("PUSH #{"DRYRUN " if dryrun}twitter://@brutalismbot")
|
24
|
+
method = post.url.nil? ? :push_text : :push_image
|
25
|
+
send(method, post, dryrun: dryrun)
|
26
|
+
end
|
27
|
+
|
28
|
+
def push_text(post, dryrun:nil)
|
29
|
+
status = post.to_twitter
|
30
|
+
@client.update(status) unless dryrun
|
31
|
+
end
|
32
|
+
|
33
|
+
def push_image(post, dryrun:nil)
|
24
34
|
status = post.to_twitter
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
Brutalismbot.logger.info("GET #{uri}")
|
30
|
-
uri.open do |media|
|
31
|
-
@client.update_with_media(status, media) unless dryrun
|
32
|
-
end
|
35
|
+
uri = URI.parse(post.url)
|
36
|
+
Brutalismbot.logger.info("GET #{uri}")
|
37
|
+
uri.open do |media|
|
38
|
+
@client.update_with_media(status, media) unless dryrun
|
33
39
|
end
|
34
40
|
end
|
35
41
|
end
|
data/lib/brutalismbot/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brutalismbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.beta.
|
4
|
+
version: 1.0.0.beta.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Mancevice
|
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
183
|
- !ruby/object:Gem::Version
|
184
184
|
version: 1.3.1
|
185
185
|
requirements: []
|
186
|
-
rubygems_version: 3.
|
186
|
+
rubygems_version: 3.0.6
|
187
187
|
signing_key:
|
188
188
|
specification_version: 4
|
189
189
|
summary: Mirror posts from /r/brutalism to Slack
|