brutalismbot 0.3.1 → 0.4.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 +1 -2
- data/lib/brutalismbot.rb +17 -18
- data/lib/brutalismbot/r.rb +1 -1
- data/lib/brutalismbot/s3.rb +4 -4
- 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: 5adaf818709e409365f83810ea0ac9a883a0e24c5d91432adcce5c567fe0085d
|
4
|
+
data.tar.gz: 54010b835fdb82d057b21961fcd14be8e14087c31b49d3084849a101e95126bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfe6c521032918f9f0a5f908a4c14cf3f8cb0a8564168c08246c9600146fe8bdd92efd5b910720041d825fc4b8da4bfc72a8b8c6b27faca32fba67f16b488574
|
7
|
+
data.tar.gz: f8653819c8375a31ac16cd041a82f9d026d1b0e09792b2a99e77946c598a31d25f49cd499fc7349833348368a6253655537d83dfc6dbf6c38611e550f0cd9e7c
|
data/README.md
CHANGED
@@ -19,8 +19,7 @@ require "aws-sdk-s3"
|
|
19
19
|
require "brutalismbot"
|
20
20
|
|
21
21
|
bucket = Aws::S3::Bucket.new name: "my-bucket"
|
22
|
-
brutbot = Brutalismbot::S3::Client.new bucket: bucket,
|
23
|
-
prefix: "my/prefix/"
|
22
|
+
brutbot = Brutalismbot::S3::Client.new bucket: bucket, prefix: "my/prefix/"
|
24
23
|
|
25
24
|
# Get latest cached post
|
26
25
|
brutbot.posts.latest
|
data/lib/brutalismbot.rb
CHANGED
@@ -29,15 +29,13 @@ module Brutalismbot
|
|
29
29
|
class Error < StandardError
|
30
30
|
end
|
31
31
|
|
32
|
-
class Auth <
|
33
|
-
|
34
|
-
|
35
|
-
def incoming_webhook
|
36
|
-
IncomingWebhook.new dig("incoming_webhook")
|
32
|
+
class Auth < Hash
|
33
|
+
def channel_id
|
34
|
+
dig "incoming_webhook", "channel_id"
|
37
35
|
end
|
38
36
|
|
39
37
|
def post(body:, dryrun:nil)
|
40
|
-
uri = URI.parse
|
38
|
+
uri = URI.parse webhook_url
|
41
39
|
ssl = uri.scheme == "https"
|
42
40
|
Net::HTTP.start(uri.host, uri.port, use_ssl: ssl) do |http|
|
43
41
|
if dryrun
|
@@ -50,30 +48,31 @@ module Brutalismbot
|
|
50
48
|
end
|
51
49
|
end
|
52
50
|
end
|
53
|
-
end
|
54
51
|
|
55
|
-
|
56
|
-
|
52
|
+
def team_id
|
53
|
+
dig "team_id"
|
57
54
|
end
|
58
55
|
|
59
|
-
def
|
60
|
-
|
56
|
+
def webhook_url
|
57
|
+
dig "incoming_webhook", "url"
|
61
58
|
end
|
59
|
+
end
|
62
60
|
|
61
|
+
class Post < Hash
|
63
62
|
def created_after(time:)
|
64
|
-
|
63
|
+
created_utc.to_i > time.to_i
|
65
64
|
end
|
66
65
|
|
67
|
-
def
|
68
|
-
|
66
|
+
def created_utc
|
67
|
+
Time.at(dig("data", "created_utc").to_i).utc
|
69
68
|
end
|
70
69
|
|
71
70
|
def permalink
|
72
|
-
data
|
71
|
+
dig "data", "permalink"
|
73
72
|
end
|
74
73
|
|
75
74
|
def title
|
76
|
-
data
|
75
|
+
dig "data", "title"
|
77
76
|
end
|
78
77
|
|
79
78
|
def to_slack
|
@@ -103,13 +102,13 @@ module Brutalismbot
|
|
103
102
|
end
|
104
103
|
|
105
104
|
def url
|
106
|
-
images = data
|
105
|
+
images = dig "data", "preview", "images"
|
107
106
|
source = images.map{|x| x["source"] }.compact.max do |a,b|
|
108
107
|
a.slice("width", "height").values <=> b.slice("width", "height").values
|
109
108
|
end
|
110
109
|
CGI.unescapeHTML source.dig("url")
|
111
110
|
rescue NoMethodError
|
112
|
-
data
|
111
|
+
dig("data", "media_metadata")&.values&.first&.dig("s", "u")
|
113
112
|
end
|
114
113
|
end
|
115
114
|
end
|
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[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[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.
|
69
|
+
key = "#{@prefix}team=#{auth.team_id}/channel=#{auth.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[JSON.parse object.get.body.read]
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
def latest
|
82
|
-
Brutalismbot::Post
|
82
|
+
Brutalismbot::Post[JSON.parse max_key.get.body.read]
|
83
83
|
end
|
84
84
|
|
85
85
|
def max_key
|
data/lib/brutalismbot/version.rb
CHANGED
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.4.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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-s3
|