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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0300595812c2edd2e92f2f192eef2c8a3b69cad1e7b335e3f969aa8301d90006'
4
- data.tar.gz: 8ea2640345f8c912b4596b0545c5d98306fb301ab956d2d2133ce3cb04d49e6a
3
+ metadata.gz: 057aa6155c1a5f25a7f27392384ca6d1ad2610bb1c930d0d0e7bd293e7ef1140
4
+ data.tar.gz: 5e610795ea0c3ccb8cbf96d3b332c0031640632c1b07ad405102dddacc2ee312
5
5
  SHA512:
6
- metadata.gz: 34bd0c9f5d52de396494e4f60dddfb971df9aa4f2edb521acd1585cab75c2d77ce982ec4f7d7fe660f49855b1e0abc83a034e8bcc70c6a4f7965c05c8ead8132
7
- data.tar.gz: 8936ced573ccf98e970a2bf7b20562101489d0f9c6e5c12e8c232a2cdb8fb0005bf8a20f1e2382f62c57ac165364689bf025c3c1350e91572fa9f8aa6a36cfee
6
+ metadata.gz: ca0daf3e9ceca0db0841f8bd235cc73fec57c91d4908d609dea9699f0006aaf3a14f3986cc70adf96b447f3f9711c0dc13d6560316bf58ef1e54e56bce5a6d9f
7
+ data.tar.gz: d11f03af3411f675538fb9c8061289191c0b865874caabcc0379888b526b3ef7ac91089c290f9f5956fa5edb9295197b8154eca8e7946befcade8a7f4ed8cb33
@@ -16,7 +16,7 @@ module Brutalismbot
16
16
 
17
17
  def lag_time
18
18
  lag = ENV["BRUTALISMBOT_LAG_TIME"].to_s
19
- lag.empty? ? 7200 : lag.to_i
19
+ lag.empty? ? 9000 : lag.to_i
20
20
  end
21
21
 
22
22
  def pull(min_time:nil, max_time:nil, dryrun:nil)
@@ -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
- class << self
7
- def stub(&block)
8
- client = new(prefix: "data/test/posts/")
9
- client.instance_variable_set(:@stubbed, true)
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
- block = -> { [Reddit::Post.stub] } unless block_given?
12
- items = block.call.map{|x| [client.key_for(x), x.to_h] }.to_h
20
+ @client.stub_responses :get_object, -> (context) do
21
+ {body: StringIO.new(items.fetch(context.params[:key]).to_json)}
22
+ end
13
23
 
14
- client.client.stub_responses :list_objects, -> (context) do
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
- client.client.stub_responses :get_object, -> (context) do
20
- {body: StringIO.new(items.fetch(context.params[:key]).to_json)}
21
- end
26
+ self
27
+ end
22
28
 
23
- client
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: unless url.nil?
66
- [
67
- {
68
- type: "image",
69
- title: {
70
- type: "plain_text",
71
- text: "/r/brutalism",
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
- else
88
- [
89
- {
90
- type: "section",
91
- text: {
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
- accessory: {
96
- type: "image",
97
- image_url: "https://brutalismbot.com/logo-red-ppl.png",
98
- alt_text: "/r/brutalism"
99
- }
100
- }
101
- ]
102
- end
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.objects(prefix: prefix).each do |object|
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
- class << self
7
- def stub(&block)
8
- client = new(prefix: "data/test/auths/")
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
- block = -> { [Auth.stub] } unless block_given?
12
- items = block.call.map{|x| [client.key_for(x), x.to_h] }.to_h
14
+ @client = Aws::S3::Client.new(stub_responses: true)
15
+ @bucket = Aws::S3::Bucket.new(name: @bucket.name, client: @client)
13
16
 
14
- client.client.stub_responses :list_objects, -> (context) do
15
- {contents: items.keys.map{|x| {key:x} }}
16
- end
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
- client.client.stub_responses :get_object, -> (context) do
19
- {body: StringIO.new(items.fetch(context.params[:key]).to_json)}
20
- end
22
+ @client.stub_responses :get_object, -> (context) do
23
+ {body: StringIO.new(items.fetch(context.params[:key]).to_json)}
24
+ end
21
25
 
22
- client
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
@@ -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
- if post.url.nil?
26
- @client.update(status) unless dryrun
27
- else
28
- uri = URI.parse(post.url)
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
@@ -1,3 +1,3 @@
1
1
  module Brutalismbot
2
- VERSION = "1.0.0.beta.1"
2
+ VERSION = "1.0.0.beta.2"
3
3
  end
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.1
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.1.0.pre3
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