-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheventsapi.rb
More file actions
63 lines (54 loc) · 1.64 KB
/
eventsapi.rb
File metadata and controls
63 lines (54 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'date'
require 'json'
require 'net/http'
require 'uri'
# For more information, check out our support page
# https://support.1password.com/events-reporting
api_token = ENV['EVENTS_API_TOKEN']
url = 'https://events.1password.com'
start_time = DateTime.now - 24
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer #{api_token}"
}
payload = {
"limit": 20,
"start_time": start_time.strftime("%FT%TZ")
}
# Alternatively, use the cursor returned from previous responses to get any new events
# payload = { "cursor": cursor }
uri = URI.parse(url+"/api/v1/signinattempts")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Post.new(uri.request_uri, headers)
req.body = payload.to_json
res = http.request(req)
if (res.code == '200')
puts(JSON.parse(res.body))
else
puts("Error getting sign in attempts: status code #{res.code}")
end
uri = URI.parse(url+"/api/v1/itemusages")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Post.new(uri.request_uri, headers)
req.body = payload.to_json
res = http.request(req)
if (res.code == '200')
puts(JSON.parse(res.body))
else
puts("Error getting item usages: status code #{res.code}")
end
uri = URI.parse(url+"/api/v1/auditevents")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Post.new(uri.request_uri, headers)
req.body = payload.to_json
res = http.request(req)
if (res.code == '200')
puts(JSON.parse(res.body))
else
puts("Error getting audit events: status code #{res.code}")
end
# For more information on the response, check out our support page
# https://support.1password.com/cs/events-api-reference/