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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa4749e6ecc0ff20c91810a83f9c05578a2be3b410111d4be611e0f5608d3624
4
- data.tar.gz: c2cc5551515bacbd0279e7f2371896459db314db8c5821b58bbcc13c5483d82c
3
+ metadata.gz: 5adaf818709e409365f83810ea0ac9a883a0e24c5d91432adcce5c567fe0085d
4
+ data.tar.gz: 54010b835fdb82d057b21961fcd14be8e14087c31b49d3084849a101e95126bf
5
5
  SHA512:
6
- metadata.gz: 337ba44ba5a06d3503084b424d4dd66704a6b6bab5885b623415ae2f660468480a25507b42529fbc2d6ab1570ef04c44026f5b871c9f87d4eb3b1967e965bd79
7
- data.tar.gz: b5d514c2b8aff025d41ba32ecb151e26091000c957ad44aa7f58c6400c485353d0347a5c5abed53fb294a1a7d4221b482d1ae3f50f774f90878013fedb8aab57
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 < OpenStruct
33
- class IncomingWebhook < OpenStruct; end
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 incoming_webhook.url
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
- class Post < OpenStruct
56
- class Data < OpenStruct
52
+ def team_id
53
+ dig "team_id"
57
54
  end
58
55
 
59
- def created_utc
60
- Time.at(data.created_utc.to_i).utc
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
- data.created_utc.to_i > time.to_i
63
+ created_utc.to_i > time.to_i
65
64
  end
66
65
 
67
- def data
68
- Data.new dig("data")
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.permalink
71
+ dig "data", "permalink"
73
72
  end
74
73
 
75
74
  def title
76
- data.title
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.preview.dig "images"
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.media_metadata&.values&.first&.dig("s", "u")
111
+ dig("data", "media_metadata")&.values&.first&.dig("s", "u")
113
112
  end
114
113
  end
115
114
  end
@@ -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.new child
36
+ post = Brutalismbot::Post[child]
37
37
  yield post if post.created_after time: @min_time
38
38
  end
39
39
  end
@@ -44,7 +44,7 @@ module Brutalismbot
44
44
  class AuthCollection < Collection
45
45
  def each
46
46
  super do |object|
47
- yield Brutalismbot::Auth.new JSON.parse(object.get.body.read)
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.incoming_webhook.channel_id}/oauth.json"
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.new JSON.parse(object.get.body.read)
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.new JSON.parse(max_key.get.body.read)
82
+ Brutalismbot::Post[JSON.parse max_key.get.body.read]
83
83
  end
84
84
 
85
85
  def max_key
@@ -1,3 +1,3 @@
1
1
  module Brutalismbot
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  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.3.1
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-14 00:00:00.000000000 Z
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