akamaized 0.0.1

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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in akamaized.gemspec
4
+ gemspec
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "akamaized/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "akamaized"
7
+ s.version = Akamaized::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Brandon Hansen, Eric Casequin"]
10
+ s.email = ["brandon@morethanaprogrammer.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Manage data and files on Akamai's CDN}
13
+ s.description = %q{Manage data and files on Akamai's CDN}
14
+
15
+ s.rubyforge_project = "akamaized"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,106 @@
1
+ require "tempfile"
2
+ require "net/ftp"
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
@@ -0,0 +1,3 @@
1
+ module Akamaized
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: akamaized
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Brandon Hansen, Eric Casequin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-03-28 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Manage data and files on Akamai's CDN
18
+ email:
19
+ - brandon@morethanaprogrammer.com
20
+ executables: []
21
+
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
26
+ files:
27
+ - .gitignore
28
+ - Gemfile
29
+ - Rakefile
30
+ - akamaized.gemspec
31
+ - lib/akamaized.rb
32
+ - lib/akamaized/version.rb
33
+ has_rdoc: true
34
+ homepage: ""
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ requirements: []
55
+
56
+ rubyforge_project: akamaized
57
+ rubygems_version: 1.6.2
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: Manage data and files on Akamai's CDN
61
+ test_files: []
62
+