akamaized 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/lib/akamaized.rb +2 -2
- data/lib/akamaized/{connections.rb → connection.rb} +28 -27
- data/lib/akamaized/exception.rb +37 -0
- data/lib/akamaized/version.rb +1 -1
- data/spec/connection_spec.rb +47 -0
- data/spec/spec_helper.rb +6 -0
- metadata +9 -6
- data/lib/akamaized/exceptions.rb +0 -19
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/lib/akamaized.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require "akamaized/
|
2
|
-
require "akamaized/
|
1
|
+
require "akamaized/exception"
|
2
|
+
require "akamaized/connection"
|
@@ -8,23 +8,23 @@ module Akamaized
|
|
8
8
|
|
9
9
|
def initialize(opts = {})
|
10
10
|
opts = {
|
11
|
-
username
|
12
|
-
password
|
13
|
-
host
|
14
|
-
base_dir
|
11
|
+
"username" => "",
|
12
|
+
"password" => "",
|
13
|
+
"host" => "",
|
14
|
+
"base_dir" => ""
|
15
15
|
}.merge(opts)
|
16
16
|
|
17
|
-
self.username = opts[
|
18
|
-
self.password = opts[
|
19
|
-
self.host = opts[
|
20
|
-
self.base_dir = opts[
|
17
|
+
self.username = opts["username"]
|
18
|
+
self.password = opts["password"]
|
19
|
+
self.host = opts["host"]
|
20
|
+
self.base_dir = opts["base_dir"]
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
24
24
|
|
25
25
|
class Connection
|
26
26
|
|
27
|
-
include
|
27
|
+
include Exception
|
28
28
|
|
29
29
|
def initialize(config = {})
|
30
30
|
@config = Config.new(config)
|
@@ -38,16 +38,21 @@ module Akamaized
|
|
38
38
|
@connection.passive = true
|
39
39
|
@connection.login(@config.username, @config.password)
|
40
40
|
@connection.chdir(@config.base_dir) if @config.base_dir
|
41
|
-
rescue
|
42
|
-
raise
|
41
|
+
rescue IOError, SystemCallError, Net::FTPError => e
|
42
|
+
raise ConnectionError.new(e.message)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
|
47
47
|
# Check to see if a file
|
48
48
|
def exists?(file, location = nil)
|
49
|
-
|
50
|
-
|
49
|
+
begin
|
50
|
+
@connection.chdir(location) unless location.nil?
|
51
|
+
!@connection.nlst(file).empty?
|
52
|
+
rescue Net::FTPPermError => e
|
53
|
+
return false if e.message.include?("not exist")
|
54
|
+
raise
|
55
|
+
end
|
51
56
|
end
|
52
57
|
|
53
58
|
|
@@ -55,19 +60,15 @@ module Akamaized
|
|
55
60
|
# Will raise an exception if unable to push the file up
|
56
61
|
# or the file is empty after upload (0 bytes)
|
57
62
|
def put(file, location = nil)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
temp.close
|
68
|
-
|
69
|
-
raise put_error(file) if !exists?(file, location)
|
70
|
-
end
|
63
|
+
@connection.chdir(location) unless location.nil?
|
64
|
+
@connection.put(file, File.basename(file))
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
# Get a file off of the server
|
69
|
+
def get(remote, local, location = nil)
|
70
|
+
@connection.chdir(location) unless location.nil?
|
71
|
+
@connection.get(remote, "#{local}/#{File.basename(remote)}")
|
71
72
|
end
|
72
73
|
|
73
74
|
|
@@ -86,7 +87,7 @@ module Akamaized
|
|
86
87
|
# Calls the delete method, however, will raise an exception if there was an issue
|
87
88
|
# whereas "delete" itself will swallow all errors
|
88
89
|
def delete!(file, location = nil)
|
89
|
-
raise
|
90
|
+
raise DeleteError.new(file) unless delete(file, location)
|
90
91
|
end
|
91
92
|
|
92
93
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Akamaized
|
2
|
+
|
3
|
+
module Exception
|
4
|
+
|
5
|
+
class DeleteError < StandardError
|
6
|
+
def initialize(file)
|
7
|
+
@file = file
|
8
|
+
end
|
9
|
+
|
10
|
+
def message
|
11
|
+
"unable to delete the file at #{@file}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class PutError < StandardError
|
16
|
+
def initialize(file)
|
17
|
+
@file = file
|
18
|
+
end
|
19
|
+
|
20
|
+
def message
|
21
|
+
"unable to push file at #{file}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class ConnectionError < StandardError
|
26
|
+
def initialize(message)
|
27
|
+
@message = message
|
28
|
+
end
|
29
|
+
|
30
|
+
def message
|
31
|
+
"Unable to connect to Akamai. Please check your authentication credentials and internet cable. Message: #{@message}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/lib/akamaized/version.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "yaml"
|
3
|
+
|
4
|
+
# This test requires the following files/directories
|
5
|
+
# config/akamai.yml
|
6
|
+
# config/test-file.txt
|
7
|
+
# config/downloads/
|
8
|
+
|
9
|
+
describe Akamaized do
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
@config = YAML::load(File.open(File.expand_path("../../config/akamai.yml", __FILE__)))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should not connect without valid credentials" do
|
16
|
+
expect {Akamaized::Connection.new}.to raise_error(Akamaized::Exception::ConnectionError)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should connect with valid credentials" do
|
20
|
+
expect {Akamaized::Connection.new(@config)}.to_not raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not allow changing directories to directories that do not exist" do
|
24
|
+
@config["base_dir"] = "this/directory/does/not/exist"
|
25
|
+
expect {Akamaized::Connection.new(@config)}.to raise_error(Akamaized::Exception::ConnectionError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not be able to find a file that does not exist" do
|
29
|
+
connection = Akamaized::Connection.new(@config)
|
30
|
+
connection.exists?("a-file-that-does-not-exist.no-file").should == false
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should put the file up on the server" do
|
34
|
+
connection = Akamaized::Connection.new(@config)
|
35
|
+
connection.delete("test-file.txt")
|
36
|
+
connection.exists?("test-file.txt").should == false
|
37
|
+
connection.put(File.expand_path("../../config/test-file.txt", __FILE__))
|
38
|
+
connection.exists?("test-file.txt").should == true
|
39
|
+
connection.get("test-file.txt", File.expand_path("../../config/downloads/", __FILE__))
|
40
|
+
File.exists?(File.expand_path("../../config/downloads/test-file.txt", __FILE__))
|
41
|
+
|
42
|
+
IO.read(File.expand_path("../../config/downloads/test-file.txt", __FILE__)).should == IO.read(File.expand_path("../../config//test-file.txt", __FILE__))
|
43
|
+
connection.delete("test-file.txt")
|
44
|
+
connection.exists?("test-file.txt").should == false
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
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.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Brandon Hansen, Eric Casequin
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-29 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -29,9 +29,11 @@ files:
|
|
29
29
|
- Rakefile
|
30
30
|
- akamaized.gemspec
|
31
31
|
- lib/akamaized.rb
|
32
|
-
- lib/akamaized/
|
33
|
-
- lib/akamaized/
|
32
|
+
- lib/akamaized/connection.rb
|
33
|
+
- lib/akamaized/exception.rb
|
34
34
|
- lib/akamaized/version.rb
|
35
|
+
- spec/connection_spec.rb
|
36
|
+
- spec/spec_helper.rb
|
35
37
|
has_rdoc: true
|
36
38
|
homepage: https://github.com/ready4god2513/Akamaized
|
37
39
|
licenses: []
|
@@ -60,5 +62,6 @@ rubygems_version: 1.6.2
|
|
60
62
|
signing_key:
|
61
63
|
specification_version: 3
|
62
64
|
summary: Manage data and files on Akamai's CDN
|
63
|
-
test_files:
|
64
|
-
|
65
|
+
test_files:
|
66
|
+
- spec/connection_spec.rb
|
67
|
+
- spec/spec_helper.rb
|
data/lib/akamaized/exceptions.rb
DELETED
@@ -1,19 +0,0 @@
|
|
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
|