async-rest 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/slack/clean.rb +56 -0
- data/lib/async/rest/resource.rb +2 -0
- data/lib/async/rest/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3adbfb21cd205efe945c0b0197e5eb84d7d70c132038537ac55e1328b0105f11
|
4
|
+
data.tar.gz: 22e7085cf862cea15fdcff5d539ca788dc127746938509e2a8e79d421c643c82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03af9605664643cb7f6e5a8d7adce8d2cbc265836749bb2652cb6ec329b68c52653e2f207947b187d4480976e7d9dbf6ea056569d72ce508b3f13e1b076dde41
|
7
|
+
data.tar.gz: 20c7bab7de8886462e3077ecbf6e30967ade6025b961d14e249b72d27a4f296267e96ffdf46c2ee19bc8ab65235782d043cc76227d9e168b70a223c9dc00dc4e
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pry'
|
4
|
+
require 'set'
|
5
|
+
|
6
|
+
def rate_limited?(response)
|
7
|
+
pp response
|
8
|
+
|
9
|
+
response[:error] == "ratelimited"
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'async/rest/resource'
|
13
|
+
|
14
|
+
URL = "https://slack.com/api"
|
15
|
+
TOKEN = "xoxp-your-api-token"
|
16
|
+
|
17
|
+
Async::REST::Resource.for(URL) do |resource|
|
18
|
+
authenticated = resource.with(parameters: {token: TOKEN})
|
19
|
+
delete = authenticated.with(path: "chat.delete")
|
20
|
+
|
21
|
+
page = 1
|
22
|
+
while true
|
23
|
+
search = authenticated.with(path: "search.messages", parameters: {page: page, count: 100, query: "from:@username before:2019-02-15"})
|
24
|
+
representation = search.get
|
25
|
+
|
26
|
+
messages = representation.value[:messages]
|
27
|
+
matches = messages[:matches]
|
28
|
+
|
29
|
+
puts "Found #{matches.count} messages on page #{page}..."
|
30
|
+
|
31
|
+
break if matches.empty?
|
32
|
+
|
33
|
+
matches.each do |message|
|
34
|
+
text = message[:text]
|
35
|
+
channel_id = message[:channel][:id]
|
36
|
+
channel_name = message[:channel][:name]
|
37
|
+
timestamp = message[:ts]
|
38
|
+
|
39
|
+
pp [timestamp, channel_name, text]
|
40
|
+
|
41
|
+
message_delete = Async::REST::Representation.new(
|
42
|
+
delete.with(parameters: {channel: channel_id, ts: timestamp})
|
43
|
+
)
|
44
|
+
|
45
|
+
response = message_delete.post
|
46
|
+
if rate_limited?(response.read)
|
47
|
+
puts "Rate limiting..."
|
48
|
+
Async::Task.current.sleep 1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
page += 1
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
puts "Done"
|
data/lib/async/rest/resource.rb
CHANGED
@@ -24,6 +24,8 @@ require 'async/http/accept_encoding'
|
|
24
24
|
require 'async/http/reference'
|
25
25
|
require 'async/http/url_endpoint'
|
26
26
|
|
27
|
+
require_relative 'representation'
|
28
|
+
|
27
29
|
module Async
|
28
30
|
module REST
|
29
31
|
# The key abstraction of information in REST is a resource. Any information that can be named can be a resource: a document or image, a temporal service (e.g. "today's weather in Los Angeles"), a collection of other resources, a non-virtual object (e.g. a person), and so on. In other words, any concept that might be the target of an author's hypertext reference must fit within the definition of a resource. A resource is a conceptual mapping to a set of entities, not the entity that corresponds to the mapping at any particular point in time.
|
data/lib/async/rest/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async-http
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- README.md
|
124
124
|
- Rakefile
|
125
125
|
- async-rest.gemspec
|
126
|
+
- examples/slack/clean.rb
|
126
127
|
- lib/async/rest.rb
|
127
128
|
- lib/async/rest/representation.rb
|
128
129
|
- lib/async/rest/resource.rb
|