Module: Akamai
- Defined in:
- lib/akamai.rb,
lib/akamai/errors.rb,
lib/akamai/version.rb,
lib/akamai/connection.rb,
lib/akamai/configuration.rb
Defined Under Namespace
Classes: Configuration, Connection, Error, PurgeError
Constant Summary
collapse
- VERSION =
"0.2"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
12
13
14
|
# File 'lib/akamai.rb', line 12
def configuration
@configuration
end
|
.connection ⇒ Object
21
22
23
|
# File 'lib/akamai.rb', line 21
def self.connection
@connection ||= Connection.new(configuration)
end
|
Class Method Details
16
17
18
19
|
# File 'lib/akamai.rb', line 16
def self.configure
self.configuration ||= Configuration.new
yield(configuration)
end
|
.purge(*urls) ⇒ Object
25
26
27
|
# File 'lib/akamai.rb', line 25
def self.purge(*urls)
connection.purge(*urls)
end
|
.put(location, filename) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/akamai.rb', line 29
def self.put(location, filename)
Tempfile.open(filename) do |tempfile|
tempfile.write(yield)
tempfile.flush
puts "Tempfile generated for #{filename} at #{tempfile.path}."
put_file(tempfile.path, location, filename)
tempfile.close
puts "Generated file deleted from tmp."
end
end
|
.put_file(local_path, location, filename) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/akamai.rb', line 46
def self.put_file(local_path, location, filename)
ftp = Net::FTP::new(self.configuration.netstorage_ftp_host)
ftp.passive = true
ftp.login(self.configuration.netstorage_username, self.configuration.netstorage_password)
ftp.chdir(self.configuration.netstorage_basedir) if self.configuration.netstorage_basedir
ftp.chdir(location)
ftp.put(local_path, "#{filename}.new")
ftp.delete(filename) unless ftp.ls(filename)
ftp.rename("#{filename}.new", filename)
ftp.close
puts "Akamai upload completed for #{filename}."
puts "Sending purge request"
purge_result = purge("http://#{self.configuration.netstorage_public_host}/#{location}/#{filename}")
puts "Purge request #{ purge_result ? 'was successful' : 'failed' }."
end
|