Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

Commit

Permalink
Merge pull request #55 from mzahir/feature/ftp
Browse files Browse the repository at this point in the history
Add FTP module
  • Loading branch information
Ruy Rocha committed Oct 25, 2013
2 parents 0518875 + 3732658 commit d67cd2d
Show file tree
Hide file tree
Showing 10 changed files with 526 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/lumberg/cpanel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ module Cpanel
require "lumberg/cpanel/locale"
require "lumberg/cpanel/mysql"
require "lumberg/cpanel/domain_keys"
require "lumberg/cpanel/ftp"
end
end
101 changes: 101 additions & 0 deletions lib/lumberg/cpanel/ftp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
module Lumberg
module Cpanel
class Ftp < Base
def self.api_module; "Ftp"; end

# Public: List FTP accounts associated with the authenticated user's account
#
# options - Hash options for API call params (default: {}):
# :include_acct_types - specify which FTP account types to include
# :skip_acct_types - specify which FTP account types to exclude
#
# Returns Hash API response.
def list_ftp(options = {})
perform_request({
api_function: "listftp"
}.merge(options))
end

# Public: Retrieve a list of FTP sessions associated with the account
#
# Returns Hash API response.
def list_ftp_sessions(options = {})
perform_request({
api_function: "listftpsessions"
}.merge(options))
end

# Public: Generate a list of FTP accounts associated with a cPanel account
# The list will contain each account's disk information
#
# options - Hash options for API call params (default: {}):
# :dirhtml - prepend the 'dir' return variable with a URL
# :include_acct_types - specify which FTP account types to include
# :skip_acct_types - specify which FTP account types to exclude
#
# Returns Hash API response.
def list_ftp_with_disk(options = {})
perform_request({
api_function: "listftpwithdisk"
}.merge(options))
end

# Public: Change an FTP account's password
#
# options - Hash options for API call params (default: {}):
# :user - The username portion of the FTP account
# :pass - The new password for the FTP account
#
# Returns Hash API response.
def passwd(options = {})
perform_request({
api_function: "passwd"
}.merge(options))
end

# Public: Add a new FTP account
#
# options - Hash options for API call params (default: {}):
# :user - The username portion of the new FTP account, without the domain
# :pass - The password for the new FTP account
# :quota - The new FTP account's quota. The default, 0, indicates that
# the account will not use a quota.
# :homedir - The path to the FTP account's root directory. This value
# should be relative to the account's home directory
#
# Returns Hash API response.
def add_ftp(options = {})
perform_request({
api_function: "addftp"
}.merge(options))
end

# Public: Change an FTP account's quota
#
# options - Hash options for API call params (default: {}):
# :user - The username portion of the FTP account
# :quota - The new quota (in megabytes) for the FTP account
#
# Returns Hash API response.
def set_quota(options = {})
perform_request({
api_function: "setquota"
}.merge(options))
end

# Public: Delete an FTP account
#
# options - Hash options for API call params (default: {}):
# :user - The name of the account to be removed
# :destroy - A boolean value that indicates whether or not the FTP account's
# home directory should also be deleted
#
# Returns Hash API response.
def del_ftp(options = {})
perform_request({
api_function: "delftp"
}.merge(options))
end
end
end
end
71 changes: 71 additions & 0 deletions spec/cpanel/ftp_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require "spec_helper"

module Lumberg
describe Cpanel::Ftp do
let(:server) { Whm::Server.new(host: @whm_host, hash: @whm_hash) }
let(:api_username) { "lumberg" }

let(:ftp) do
described_class.new(
server: server,
api_username: api_username
)
end

describe "#list_ftp" do
use_vcr_cassette("cpanel/ftp/listftp")

it "lists ftp accounts associated to the account" do
ftp.list_ftp[:params][:data][0][:user].should eq("hello")
end
end

describe "#list_ftp_sessions" do
use_vcr_cassette("cpanel/ftp/listftpsessions")

it "lists ftp sessions associated to the account" do
ftp.list_ftp_sessions[:params][:data][0][:status].should eq("IDLE")
end
end

describe "#list_ftp_with_disk" do
use_vcr_cassette("cpanel/ftp/listftpwithdisk")

it "lists ftp accounts with disk information" do
ftp.list_ftp_with_disk[:params][:data][0][:_diskused].should eq("0")
end
end

describe "#add_ftp" do
use_vcr_cassette("cpanel/ftp/addftp")

it "creates the account" do
ftp.add_ftp(user: 'bob', pass: 'boo')[:params][:data][0][:reason].should eq("OK")
end
end

describe "#passwd" do
use_vcr_cassette("cpanel/ftp/passwd")

it "changes the password of the account" do
ftp.passwd(user: 'bob', pass: 'boo')[:params][:data][0][:reason].should eq("OK")
end
end

describe "#setquota" do
use_vcr_cassette("cpanel/ftp/setquota")

it "sets a quota for the account" do
ftp.set_quota(user: 'bob', quota: '100')[:params][:data][0][:reason].should eq("OK")
end
end

describe "#del_ftp" do
use_vcr_cassette("cpanel/ftp/delftp")

it "removes the account" do
ftp.del_ftp(user: 'bob', destroy: '1')[:params][:data][0][:reason].should eq("OK")
end
end
end
end
43 changes: 43 additions & 0 deletions spec/vcr_cassettes/cpanel/ftp/addftp.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions spec/vcr_cassettes/cpanel/ftp/delftp.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions spec/vcr_cassettes/cpanel/ftp/listftp.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions spec/vcr_cassettes/cpanel/ftp/listftpsessions.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d67cd2d

Please sign in to comment.