-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathlog.rb
39 lines (36 loc) · 1.18 KB
/
log.rb
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
class Log
def self.save(login)
# login is the payload decoded from Login.decode_auth_code
R.rpush "indieauth::logs", login.to_json
end
def self.flush
while entry = R.lindex("indieauth::logs", 0) do
begin
entry = JSON.parse entry
# puts "Sending log entry: #{entry}"
# puts "me=#{entry['me']}"
response = HTTParty.post "#{SiteConfig.stats.server}/report", {
:headers => { 'Authorization' => "Bearer #{SiteConfig.stats.token}" },
:body => {
:me => entry['me'],
:provider => entry['provider'],
:profile => entry['profile'],
:scope => entry['scope'],
:redirect_uri => entry['redirect_uri'],
:client_id => entry['client_id']
}
}
# jj response.parsed_response
if response && response.code == 200 && response.parsed_response['result'] == 'ok'
R.lpop "indieauth::logs"
else
puts "Something went wrong trying to flush the stats. Stop for now."
raise Exception.new "StatsError"
end
rescue => e
puts "Error saving entry! Stop for now."
raise e
end
end
end
end