akamaized 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/akamaized.rb +2 -106
- data/lib/akamaized/connections.rb +92 -0
- data/lib/akamaized/exceptions.rb +19 -0
- data/lib/akamaized/version.rb +1 -1
- metadata +3 -1
data/lib/akamaized.rb
CHANGED
@@ -1,106 +1,2 @@
|
|
1
|
-
require "
|
2
|
-
require "
|
3
|
-
|
4
|
-
module Akamaized
|
5
|
-
|
6
|
-
def initialize(config)
|
7
|
-
Config.new(config)
|
8
|
-
end
|
9
|
-
|
10
|
-
module Config
|
11
|
-
attr_accessor :username, :password, :host, :base_dir
|
12
|
-
|
13
|
-
def initialize(opts = {})
|
14
|
-
opts = {
|
15
|
-
username: nil,
|
16
|
-
password: nil,
|
17
|
-
host: nil,
|
18
|
-
base_dir: nil
|
19
|
-
}.merge(opts)
|
20
|
-
|
21
|
-
self.username = opts.username
|
22
|
-
self.password = opts.password
|
23
|
-
self.host = opts.host
|
24
|
-
self.base_dir = opts.base_dir
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
module Connection
|
31
|
-
|
32
|
-
def initialize
|
33
|
-
begin
|
34
|
-
@connection = Net::FTP.new(Config.host)
|
35
|
-
@connection.passive = true
|
36
|
-
@connection.login(Config.username, Config.password)
|
37
|
-
@connection.chdir(Config.base_dir) if Config.base_dir
|
38
|
-
rescue Exception => e
|
39
|
-
raise AkamaizedException.connection_error
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
|
44
|
-
# Check to see if a file
|
45
|
-
def exists?(file, location = nil)
|
46
|
-
@connection.chdir(location) unless location.nil?
|
47
|
-
!@connection.nlist(file).empty?
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
# Take a local file and push it up to akamai
|
52
|
-
# Will raise an exception if unable to push the file up
|
53
|
-
# or the file is empty after upload (0 bytes)
|
54
|
-
def put(file, location = nil)
|
55
|
-
Tempfile.open(file) do |temp|
|
56
|
-
temp.write(yield)
|
57
|
-
temp.flush
|
58
|
-
|
59
|
-
@connection.chdir(location) unless location.nil?
|
60
|
-
|
61
|
-
@connection.put(temp.path, "#{file}.new")
|
62
|
-
@connection.rename("#{file}.new", file)
|
63
|
-
|
64
|
-
raise AkamaizedException.put_error(file) if !exists?(file, location)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
|
-
# Will attempt to login to the server an remove a file. Returns
|
70
|
-
# false if unable to delete the file
|
71
|
-
def delete(file, location = nil)
|
72
|
-
begin
|
73
|
-
@connection.chdir(location) unless location.nil?
|
74
|
-
@connection.delete(file)
|
75
|
-
rescue Exception => e
|
76
|
-
false
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
# Calls the delete method, however, will raise an exception if there was an issue
|
82
|
-
# whereas "delete" itself will swallow all errors
|
83
|
-
def delete!(file, location = nil)
|
84
|
-
raise AkamaizedException.delete_error(file) unless delete(file, location)
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
module AkamaizedException
|
91
|
-
|
92
|
-
def delete_error(file)
|
93
|
-
"unable to delete the file at #{file}"
|
94
|
-
end
|
95
|
-
|
96
|
-
def put_error(file)
|
97
|
-
"unable to push file at #{file}"
|
98
|
-
end
|
99
|
-
|
100
|
-
def connection_error
|
101
|
-
"unable to connect to Akamai. Please check your authentication credentials"
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
1
|
+
require "akamaized/exceptions"
|
2
|
+
require "akamaized/connections"
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "tempfile"
|
2
|
+
require "net/ftp"
|
3
|
+
|
4
|
+
module Akamaized
|
5
|
+
|
6
|
+
class Config
|
7
|
+
attr_accessor :username, :password, :host, :base_dir
|
8
|
+
|
9
|
+
def initialize(opts = {})
|
10
|
+
opts = {
|
11
|
+
username: nil,
|
12
|
+
password: nil,
|
13
|
+
host: nil,
|
14
|
+
base_dir: nil
|
15
|
+
}.merge(opts)
|
16
|
+
|
17
|
+
self.username = opts["username"]
|
18
|
+
self.password = opts["password"]
|
19
|
+
self.host = opts["host"]
|
20
|
+
self.base_dir = opts["base_dir"]
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
class Connection
|
26
|
+
|
27
|
+
include AkamaizedException
|
28
|
+
|
29
|
+
def initialize(config = {})
|
30
|
+
Config.new(config)
|
31
|
+
create_connection
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def create_connection
|
36
|
+
begin
|
37
|
+
@connection = Net::FTP.new(Config.host)
|
38
|
+
@connection.passive = true
|
39
|
+
@connection.login(Config.username, Config.password)
|
40
|
+
@connection.chdir(Config.base_dir) if Config.base_dir
|
41
|
+
rescue Exception => e
|
42
|
+
raise connection_error
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# Check to see if a file
|
48
|
+
def exists?(file, location = nil)
|
49
|
+
@connection.chdir(location) unless location.nil?
|
50
|
+
!@connection.nlist(file).empty?
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
# Take a local file and push it up to akamai
|
55
|
+
# Will raise an exception if unable to push the file up
|
56
|
+
# or the file is empty after upload (0 bytes)
|
57
|
+
def put(file, location = nil)
|
58
|
+
Tempfile.open(file) do |temp|
|
59
|
+
temp.write(yield)
|
60
|
+
temp.flush
|
61
|
+
|
62
|
+
@connection.chdir(location) unless location.nil?
|
63
|
+
|
64
|
+
@connection.put(temp.path, "#{file}.new")
|
65
|
+
@connection.rename("#{file}.new", file)
|
66
|
+
|
67
|
+
raise put_error(file) if !exists?(file, location)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
# Will attempt to login to the server an remove a file. Returns
|
73
|
+
# false if unable to delete the file
|
74
|
+
def delete(file, location = nil)
|
75
|
+
begin
|
76
|
+
@connection.chdir(location) unless location.nil?
|
77
|
+
@connection.delete(file)
|
78
|
+
rescue Exception => e
|
79
|
+
false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
# Calls the delete method, however, will raise an exception if there was an issue
|
85
|
+
# whereas "delete" itself will swallow all errors
|
86
|
+
def delete!(file, location = nil)
|
87
|
+
raise delete_error(file) unless delete(file, location)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Akamaized
|
2
|
+
|
3
|
+
module AkamaizedException
|
4
|
+
|
5
|
+
def delete_error(file)
|
6
|
+
"unable to delete the file at #{file}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def put_error(file)
|
10
|
+
"unable to push file at #{file}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def connection_error
|
14
|
+
"unable to connect to Akamai. Please check your authentication credentials"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/lib/akamaized/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: akamaized
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Brandon Hansen, Eric Casequin
|
@@ -29,6 +29,8 @@ files:
|
|
29
29
|
- Rakefile
|
30
30
|
- akamaized.gemspec
|
31
31
|
- lib/akamaized.rb
|
32
|
+
- lib/akamaized/connections.rb
|
33
|
+
- lib/akamaized/exceptions.rb
|
32
34
|
- lib/akamaized/version.rb
|
33
35
|
has_rdoc: true
|
34
36
|
homepage: https://github.com/ready4god2513/Akamaized
|