-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.rb
46 lines (38 loc) · 788 Bytes
/
report.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
40
41
42
43
44
45
46
class Report < Struct.new(:url)
def save
file.save
end
def public_url
file.public_url
end
def file
@file ||= bucket.files.new(
key: key,
body: original,
public: true,
)
end
def key
directory_name + '/' + name
end
def name
url.split('/').last
end
def directory_name
Time.now.strftime('%m-%d-%Y')
end
def original
@original ||= Net::HTTP.get(URI(url))
end
def bucket
@bucket ||= connection.directories.get(ENV['S3_BUCKET'])
end
def connection
@connection ||= Fog::Storage.new({
provider: 'AWS',
aws_access_key_id: ENV['S3_ACCESS_KEY_ID'],
aws_secret_access_key: ENV['S3_SECRET_ACCESS_KEY'],
region: 'us-west-1',
})
end
end