panelbeater 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ spec = Gem::Specification.new do |s|
17
17
 
18
18
  # Change these as appropriate
19
19
  s.name = "panelbeater"
20
- s.version = "0.1.2"
20
+ s.version = "0.1.3"
21
21
  s.summary = "A gem for communicating with the cPanel and WHM API's"
22
22
  s.author = "Jamie Dyer"
23
23
  s.email = "jamie@kernowsoul.com"
@@ -17,11 +17,7 @@ module CpanelApi
17
17
  http.start do |http|
18
18
  req = Net::HTTP::Get.new "/json-api/#{command}#{map_options_to_url(options)}"
19
19
  req.add_field 'Authorization', "WHM #{username}:#{api_key}"
20
- # req.each_header {|k,v| @log.info "#{k}: #{v}"}
21
20
  http.request(req)
22
- # puts response.to_yaml
23
- # response.value
24
- # response.body
25
21
  end
26
22
  end
27
23
 
@@ -29,10 +25,7 @@ module CpanelApi
29
25
  options = key_mappings(mappings, options) unless mappings.nil?
30
26
  options = filter_options(options)
31
27
  response = connect self.base_url, self.port, command, self.user, self.api_key, options
32
- # if response.code == '200'
33
- # response.json = JSON.parse(response.body)
34
- # end
35
- CpanelApi::Response.new(response)
28
+ CpanelApi::Response.new(command, response)
36
29
  end
37
30
 
38
31
  def map_options_to_url(options={})
@@ -1,12 +1,23 @@
1
1
  module CpanelApi
2
2
  class Response
3
3
 
4
- def initialize(response)
4
+ @@response_types = {
5
+ :applist => 'app',
6
+ :createacct => 'result',
7
+ :passwd => 'passwd'
8
+ }
9
+
10
+ def initialize(command, response)
11
+ @command = command
5
12
  @response = response
6
13
  end
7
14
 
8
15
  def success?
9
- json['result'].first['status'] == 1
16
+ json[node_name].first['status'] == 1
17
+ end
18
+
19
+ def code
20
+ @response.code
10
21
  end
11
22
 
12
23
  def json
@@ -14,8 +25,15 @@ module CpanelApi
14
25
  end
15
26
 
16
27
  def method_missing(method, *args)
17
- @response.send(method) if @response.respond_to?(method)
28
+ # check for a key in the json response
29
+ return(json[node_name].first[method.to_s]) if json[node_name].first.has_key?(method.to_s)
18
30
  end
19
31
 
32
+ private
33
+
34
+ def node_name
35
+ @node_name ||= @@response_types[@command.to_sym]
36
+ end
37
+
20
38
  end
21
39
  end
data/panelbeater.gemspec CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{panelbeater}
5
- s.version = "0.1.2"
5
+ s.version = "0.1.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jamie Dyer"]
9
- s.date = %q{2010-04-03}
9
+ s.date = %q{2010-04-05}
10
10
  s.email = %q{jamie@kernowsoul.com}
11
- s.files = ["lib", "lib/panelbeater", "lib/panelbeater/cpanel", "lib/panelbeater/cpanel/commands.rb", "lib/panelbeater/fixture_helper.rb", "lib/panelbeater/model.rb", "lib/panelbeater/remote.rb", "lib/panelbeater/response.rb", "lib/panelbeater/whm", "lib/panelbeater/whm/commands.rb", "lib/panelbeater.rb", "panelbeater.gemspec", "pkg", "pkg/panelbeater-0.1.0.gem", "pkg/panelbeater-0.1.1.gem", "Rakefile", "Readme.markdown", "test", "test/fixtures", "test/fixtures/applist.json", "test/fixtures/createacct_fail.json", "test/fixtures/createacct_success.json", "test/fixtures/passwd_fail.json", "test/fixtures/passwd_success.json", "test/test_helper.rb", "test/whm_test.rb", "~"]
11
+ s.files = ["lib", "lib/panelbeater", "lib/panelbeater/cpanel", "lib/panelbeater/cpanel/commands.rb", "lib/panelbeater/fixture_helper.rb", "lib/panelbeater/model.rb", "lib/panelbeater/remote.rb", "lib/panelbeater/response.rb", "lib/panelbeater/whm", "lib/panelbeater/whm/commands.rb", "lib/panelbeater.rb", "panelbeater.gemspec", "pkg", "pkg/panelbeater-0.1.0.gem", "pkg/panelbeater-0.1.1.gem", "pkg/panelbeater-0.1.2.gem", "Rakefile", "Readme.markdown", "test", "test/fixtures", "test/fixtures/applist.json", "test/fixtures/createacct_fail.json", "test/fixtures/createacct_success.json", "test/fixtures/passwd_fail.json", "test/fixtures/passwd_success.json", "test/test_helper.rb", "test/whm_test.rb", "~"]
12
12
  s.homepage = %q{http://kernowsoul.com}
13
13
  s.require_paths = ["lib"]
14
14
  s.rubygems_version = %q{1.3.6}
Binary file
data/test/whm_test.rb CHANGED
@@ -12,7 +12,9 @@ class WhmTest < Test::Unit::TestCase
12
12
 
13
13
  context "404 error handling" do
14
14
  setup do
15
- stub_request(:get, "#{@expected_url}applist?").with(:headers => { 'Authorization' => @expected_auth_header }).to_return(:status => "404")
15
+ stub_request(:get, "#{@expected_url}applist?").
16
+ with(:headers => { 'Authorization' => @expected_auth_header }).
17
+ to_return(:status => "404")
16
18
  @response = @connection.applist
17
19
  end
18
20
 
@@ -21,13 +23,12 @@ class WhmTest < Test::Unit::TestCase
21
23
  end
22
24
  end
23
25
 
24
-
25
26
  context "returning a successful response" do
26
27
  setup do
27
- stub_request(:get, "#{@expected_url}applist?").
28
+ stub_request(:get, "#{@expected_url}createacct?cpmod=x3&maxlst=0&hasshell=n&reseller=0&featurelist=default&ip=n&username=amos&cgi=y&frontpage=n").
28
29
  with(:headers => { 'Authorization' => @expected_auth_header }).
29
30
  to_return(:body => fixture('createacct_success'))
30
- @response = @connection.applist
31
+ @response = @connection.createacct :username => 'amos'
31
32
  end
32
33
 
33
34
  should "return true" do
@@ -35,13 +36,12 @@ class WhmTest < Test::Unit::TestCase
35
36
  end
36
37
  end
37
38
 
38
-
39
39
  context "returning a unsuccessful response" do
40
40
  setup do
41
- stub_request(:get, "#{@expected_url}applist?").
41
+ stub_request(:get, "#{@expected_url}createacct?cpmod=x3&maxlst=0&hasshell=n&reseller=0&featurelist=default&ip=n&username=amos&cgi=y&frontpage=n").
42
42
  with(:headers => { 'Authorization' => @expected_auth_header }).
43
43
  to_return(:body => fixture('createacct_fail'))
44
- @response = @connection.applist
44
+ @response = @connection.createacct :username => 'amos'
45
45
  end
46
46
 
47
47
  should "return false" do
@@ -49,6 +49,18 @@ class WhmTest < Test::Unit::TestCase
49
49
  end
50
50
  end
51
51
 
52
+ context "getting cpanel data from the cpanel response" do
53
+ setup do
54
+ stub_request(:get, "#{@expected_url}createacct?cpmod=x3&maxlst=0&hasshell=n&reseller=0&featurelist=default&ip=n&username=amos&cgi=y&frontpage=n").
55
+ with(:headers => { 'Authorization' => @expected_auth_header }).
56
+ to_return(:body => fixture('createacct_success'))
57
+ @response = @connection.createacct :username => 'amos'
58
+ end
59
+
60
+ should "return the status message" do
61
+ assert_equal @response.statusmsg, 'Account Creation Ok'
62
+ end
63
+ end
52
64
 
53
65
  context "getting a list of commands the server supports" do
54
66
  setup do
@@ -63,7 +75,6 @@ class WhmTest < Test::Unit::TestCase
63
75
  end
64
76
  end
65
77
 
66
-
67
78
  context "creating a new account" do
68
79
  setup do
69
80
  stub_request(:get, "#{@expected_url}createacct?cpmod=x3&maxlst=0&hasshell=n&reseller=0&featurelist=default&ip=n&username=amos&cgi=y&frontpage=n").
@@ -77,7 +88,6 @@ class WhmTest < Test::Unit::TestCase
77
88
  end
78
89
  end
79
90
 
80
-
81
91
  context "creating a new account with key mappings" do
82
92
  setup do
83
93
  stub_request(:get, "#{@expected_url}createacct?cpmod=x3&maxlst=0&hasshell=n&reseller=0&featurelist=default&ip=n&username=amos&cgi=y&frontpage=n").
@@ -91,7 +101,6 @@ class WhmTest < Test::Unit::TestCase
91
101
  end
92
102
  end
93
103
 
94
-
95
104
  context "changing a users password" do
96
105
  setup do
97
106
  stub_request(:get, "#{@expected_url}passwd?user=bob&pass=hello").
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 2
9
- version: 0.1.2
8
+ - 3
9
+ version: 0.1.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jamie Dyer
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-03 00:00:00 +01:00
17
+ date: 2010-04-05 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -72,6 +72,7 @@ files:
72
72
  - panelbeater.gemspec
73
73
  - pkg/panelbeater-0.1.0.gem
74
74
  - pkg/panelbeater-0.1.1.gem
75
+ - pkg/panelbeater-0.1.2.gem
75
76
  - Rakefile
76
77
  - Readme.markdown
77
78
  - test/fixtures/applist.json