brutalismbot 1.7.1 → 1.8.0

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: 330b378211b26eab38e4c41fc8016b5939266cf66c6e00e81d6b96e23f448ba4
4
- data.tar.gz: 761046e07bf707bb25bd6ced9887aee73389febb877cd85b51b568e1d714bed1
3
+ metadata.gz: fc9aa96ddf426ba53cd94234a85ab6b3b11237dcdfb8414ca522f983a58c807c
4
+ data.tar.gz: 87ccc44e65a2565e31a3e60c399ab2d6725f6594a12da582c273e9b95292020d
5
5
  SHA512:
6
- metadata.gz: e77f992ec2e4a2a599109af96c6d4d93ad086eacba4efbfbbf83e6d921c883b69dff9e92e1920a40574c4304b71e894d7eb393e40918fd9c82a2f3a029a23ae5
7
- data.tar.gz: 787d16aed3f829819106b6608318790eac5ae72ab03151a063d5cc72bb491c953678d09439b93001d2b58984ba0b172740e1bea3d1eda36746c73766e835c179
6
+ metadata.gz: a8160fd997677a8ab632be035009b1cea925c4791cc45109c9cba086eda92408b4d931394efa92a1b438357a9784206b2479ccf191397dd66f0beeb809af7d6f
7
+ data.tar.gz: bba9c3dda2a30a14209d74599a4bcd01e0cce55caa138970135fd001a0a9db79272c8acdb4d0bef6dce89970ac0cda8bbfca181d7d4febb0bcb8103e581e96f0
@@ -108,6 +108,19 @@ module Brutalismbot
108
108
  is_self? ? to_slack_text : to_slack_image
109
109
  end
110
110
 
111
+ def to_twitter
112
+ max = 280 - permalink.length - 1
113
+ status = title.length <= max ? title : "#{title[0...max - 1]}…"
114
+ status << "\n#{permalink}"
115
+ {status: status, media_url: is_self? ? nil : media_url}
116
+ end
117
+
118
+ def url
119
+ data["url"]
120
+ end
121
+
122
+ private
123
+
111
124
  def to_slack_image
112
125
  {
113
126
  blocks: [
@@ -152,16 +165,6 @@ module Brutalismbot
152
165
  ],
153
166
  }
154
167
  end
155
-
156
- def to_twitter
157
- max = 280 - permalink.length - 1
158
- text = title.length <= max ? title : "#{title[0...max - 1]}…"
159
- [text, permalink].join("\n")
160
- end
161
-
162
- def url
163
- data["url"]
164
- end
165
168
  end
166
169
  end
167
170
  end
@@ -20,22 +20,6 @@ module Brutalismbot
20
20
  File.join("team=#{team_id}", "channel=#{channel_id}", "oauth.json")
21
21
  end
22
22
 
23
- def push(post, dryrun:nil)
24
- body = post.to_slack.to_json
25
- uri = URI.parse(webhook_url)
26
- Brutalismbot.logger.info("POST #{"DRYRUN " if dryrun}#{uri}")
27
- unless dryrun
28
- ssl = uri.scheme == "https"
29
- req = Net::HTTP::Post.new(uri, "content-type" => "application/json")
30
- req.body = body
31
- Net::HTTP.start(uri.host, uri.port, use_ssl: ssl) do |http|
32
- http.request(req)
33
- end
34
- else
35
- Net::HTTPOK.new("1.1", "204", "ok")
36
- end
37
- end
38
-
39
23
  def team_id
40
24
  @item.dig("team_id")
41
25
  end
@@ -37,11 +37,16 @@ module Brutalismbot
37
37
  end
38
38
  end
39
39
 
40
- def push(post, dryrun:nil)
41
- list.map do |auth|
42
- key = key_for(auth)
43
- Brutalismbot.logger.info("PUSH #{"DRYRUN " if dryrun}s3://#{@bucket}/#{key}")
44
- auth.push(post, dryrun: dryrun)
40
+ def push(body:, webhook_url:, dryrun:nil)
41
+ Brutalismbot.logger.info("POST #{"DRYRUN " if dryrun}#{webhook_url}")
42
+ unless dryrun
43
+ uri = URI.parse(webhook_url)
44
+ ssl = uri.scheme == "https"
45
+ req = Net::HTTP::Post.new(uri, "content-type" => "application/json")
46
+ req.body = body.to_json
47
+ Net::HTTP.start(uri.host, uri.port, use_ssl: ssl) {|http| http.request(req) }
48
+ else
49
+ Net::HTTPOK.new("1.1", "204", "ok")
45
50
  end
46
51
  end
47
52
 
@@ -19,22 +19,15 @@ module Brutalismbot
19
19
  end
20
20
  end
21
21
 
22
- def push(post, dryrun:nil)
23
- method = post.is_self? ? :push_text : :push_image
24
- send(method, post, dryrun: dryrun)
25
- end
26
-
27
- def push_text(post, dryrun:nil)
28
- Brutalismbot.logger.info("PUSH #{"DRYRUN " if dryrun}twitter://@brutalismbot")
29
- @client.update(post.to_twitter) unless dryrun
30
- end
31
-
32
- def push_image(post, dryrun:nil)
33
- Brutalismbot.logger.info("GET #{post.media_uri}")
34
- Brutalismbot.logger.info("PUSH #{"DRYRUN " if dryrun}twitter://@brutalismbot")
35
- post.media_uri.open do |media|
36
- @client.update_with_media(post.to_twitter, media)
37
- end unless dryrun
22
+ def push(status:, media_url:nil, dryrun:nil)
23
+ if media_url.nil?
24
+ Brutalismbot.logger.info("PUSH #{"DRYRUN " if dryrun}twitter://@brutalismbot")
25
+ @client.update(status) unless dryrun
26
+ else
27
+ Brutalismbot.logger.info("GET #{media_url}")
28
+ Brutalismbot.logger.info("PUSH #{"DRYRUN " if dryrun}twitter://@brutalismbot")
29
+ URI.open(media_url) {|media| @client.update_with_media(status, media) } unless dryrun
30
+ end
38
31
  end
39
32
  end
40
33
  end
@@ -1,3 +1,3 @@
1
1
  module Brutalismbot
2
- VERSION = "1.7.1"
2
+ VERSION = "1.8.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: 1.7.1
4
+ version: 1.8.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: 2020-08-12 00:00:00.000000000 Z
11
+ date: 2020-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: twitter