vestacp 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.
- checksums.yaml +4 -4
- data/lib/vestacp/account.rb +70 -3
- data/lib/vestacp/base.rb +52 -41
- data/lib/vestacp/version.rb +1 -1
- data/vestacp.gemspec +2 -2
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b4f32a13eaa09b2bc9ca6612f8281cc12a86b911
|
|
4
|
+
data.tar.gz: af5bf3ef6c92df6aa11f809d383826e4653586df
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b2d62353a4af574ec5ac7493a3908cccecf0776ec793f25543b1c070d7c34c79fa4d5f4dc4e8f957d70077af792131492968d5977652ef9551d09394121cf17f
|
|
7
|
+
data.tar.gz: 2892bbd153234608da0577943b123eb2db20d98318395e12275ea042dcec8d06becf3cdafd99002fc225dab9499b284b60b6905a24acf6643350f10db9416b2d
|
data/lib/vestacp/account.rb
CHANGED
|
@@ -16,7 +16,7 @@ module Vestacp
|
|
|
16
16
|
# See:
|
|
17
17
|
#
|
|
18
18
|
# http://vestacp.com/docs/api/#add_user
|
|
19
|
-
def self.
|
|
19
|
+
def self.add(raw = {})
|
|
20
20
|
args = {
|
|
21
21
|
username: 'arg1',
|
|
22
22
|
password: 'arg2',
|
|
@@ -36,14 +36,81 @@ module Vestacp
|
|
|
36
36
|
# Parameters:
|
|
37
37
|
#
|
|
38
38
|
# * <tt>:username</tt>
|
|
39
|
-
def self.
|
|
39
|
+
def self.delete(raw = {})
|
|
40
40
|
args = {
|
|
41
|
-
username: 'arg1'
|
|
41
|
+
username: 'arg1'
|
|
42
42
|
}
|
|
43
43
|
params = {}
|
|
44
44
|
raw.each {|key, value| params[args[key].to_sym] = value }
|
|
45
45
|
params.merge!(cmd: 'v-delete-user')
|
|
46
46
|
send_request(params, raw)
|
|
47
47
|
end
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# Suspend User Account
|
|
51
|
+
#
|
|
52
|
+
# Parameters:
|
|
53
|
+
#
|
|
54
|
+
# * <tt>:username</tt>
|
|
55
|
+
def self.suspend(raw = {})
|
|
56
|
+
args = {
|
|
57
|
+
username: 'arg1'
|
|
58
|
+
}
|
|
59
|
+
params = {}
|
|
60
|
+
raw.each {|key, value| params[args[key].to_sym] = value }
|
|
61
|
+
params.merge!(cmd: 'v-suspend-user')
|
|
62
|
+
send_request(params, raw)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
# Suspend User Account
|
|
67
|
+
#
|
|
68
|
+
# Parameters:
|
|
69
|
+
#
|
|
70
|
+
# * <tt>:username</tt>
|
|
71
|
+
def self.unsuspend(raw = {})
|
|
72
|
+
args = {
|
|
73
|
+
username: 'arg1'
|
|
74
|
+
}
|
|
75
|
+
params = {}
|
|
76
|
+
raw.each {|key, value| params[args[key].to_sym] = value }
|
|
77
|
+
params.merge!(cmd: 'v-unsuspend-user')
|
|
78
|
+
send_request(params, raw)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
# List User Account Information
|
|
83
|
+
#
|
|
84
|
+
# Returns JSON.
|
|
85
|
+
#
|
|
86
|
+
# Parameters:
|
|
87
|
+
#
|
|
88
|
+
# * <tt>:username</tt>
|
|
89
|
+
def self.information(raw = {})
|
|
90
|
+
args = {
|
|
91
|
+
username: 'arg1'
|
|
92
|
+
}
|
|
93
|
+
params = {}
|
|
94
|
+
raw.each {|key, value| params[args[key].to_sym] = value }
|
|
95
|
+
params.merge!(cmd: 'v-list-user', arg2: 'json')
|
|
96
|
+
send_request(params, raw, true)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Check User Account Credentials
|
|
100
|
+
#
|
|
101
|
+
# Parameters:
|
|
102
|
+
#
|
|
103
|
+
# * <tt>:username</tt>
|
|
104
|
+
# * <tt>:password</tt>
|
|
105
|
+
def self.check_credentials(raw = {})
|
|
106
|
+
args = {
|
|
107
|
+
username: 'arg1',
|
|
108
|
+
password: 'arg2'
|
|
109
|
+
}
|
|
110
|
+
params = {}
|
|
111
|
+
raw.each {|key, value| params[args[key].to_sym] = value }
|
|
112
|
+
params.merge!(cmd: 'v-list-user')
|
|
113
|
+
send_request(params, raw)
|
|
114
|
+
end
|
|
48
115
|
end
|
|
49
116
|
end
|
data/lib/vestacp/base.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'faraday'
|
|
2
|
+
require 'json'
|
|
2
3
|
|
|
3
4
|
module Vestacp
|
|
4
5
|
# Vestacp::Base is the main class used to subclass Vestacp API resources
|
|
@@ -10,28 +11,28 @@ module Vestacp
|
|
|
10
11
|
# * <tt>:cmd</tt> - The API action to perform
|
|
11
12
|
#
|
|
12
13
|
# All other paramters are passed along as HTTP POST variables
|
|
13
|
-
def self.send_request(params = {}, raw = {})
|
|
14
|
+
def self.send_request(params = {}, raw = {}, json_response = false)
|
|
14
15
|
if params[:cmd].blank?
|
|
15
16
|
raise "No API command set"
|
|
16
17
|
end
|
|
17
18
|
|
|
18
|
-
if raw
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
:
|
|
22
|
-
|
|
19
|
+
if !raw[:server]
|
|
20
|
+
raise "No server as argument and server configuration!" unless Vestacp.config
|
|
21
|
+
raw[:server] = {
|
|
22
|
+
api_username: Vestacp.config.api_username,
|
|
23
|
+
api_password: Vestacp.config.api_password,
|
|
24
|
+
api_url: Vestacp.config.api_url
|
|
25
|
+
}
|
|
26
|
+
end
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
:password => Vestacp.config.api_password
|
|
29
|
-
)
|
|
28
|
+
params.merge!(
|
|
29
|
+
user: raw[:server][:api_username],
|
|
30
|
+
password: raw[:server][:api_password]
|
|
31
|
+
)
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
end
|
|
33
|
+
# params.merge!(returncode: 'yes') unless params[:returncode]
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
url = URI.parse(raw[:server][:api_url])
|
|
35
36
|
|
|
36
37
|
# SSL without is really bad design. In order to support even self-signed
|
|
37
38
|
# certificates I should do that.
|
|
@@ -45,41 +46,51 @@ module Vestacp
|
|
|
45
46
|
req.body = params
|
|
46
47
|
end
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
binding.pry
|
|
50
|
+
parse_response(json_response ? JSON.parse(response.body) : response.body)
|
|
49
51
|
end
|
|
50
52
|
|
|
51
53
|
# Parse VestaCP responses.
|
|
52
54
|
# TODO: add more responses.
|
|
53
55
|
#
|
|
54
56
|
# See: http://vestacp.com/docs/api/#return_codes
|
|
55
|
-
def self.parse_response(raw)
|
|
57
|
+
def self.parse_response(raw, json_response = false)
|
|
56
58
|
case raw
|
|
57
|
-
when '
|
|
58
|
-
{
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
when '1'
|
|
63
|
-
{
|
|
64
|
-
error: true, value: raw, name: 'E_ARGS',
|
|
65
|
-
comment: 'Not enough arguments provided.'
|
|
66
|
-
}
|
|
67
|
-
when '2'
|
|
68
|
-
{
|
|
69
|
-
error: true, value: raw, name: 'E_INVALID',
|
|
70
|
-
comment: 'Object or argument is not valid.'
|
|
71
|
-
}
|
|
72
|
-
when '3'
|
|
73
|
-
{
|
|
74
|
-
error: true, value: raw, name: 'E_NOTEXIST',
|
|
75
|
-
comment: "Object doesn't exist."
|
|
76
|
-
}
|
|
59
|
+
when 'OK'
|
|
60
|
+
{error: false, response: raw}
|
|
61
|
+
when /^Error/
|
|
62
|
+
{error: true, response: raw}
|
|
77
63
|
else
|
|
78
|
-
{
|
|
79
|
-
error: true, value: '-1', name: 'E_UNKNOWN',
|
|
80
|
-
comment: "Unknown response: #{raw}"
|
|
81
|
-
}
|
|
64
|
+
{error: false, response: raw}
|
|
82
65
|
end
|
|
66
|
+
|
|
67
|
+
# case raw
|
|
68
|
+
# when '0'
|
|
69
|
+
# {
|
|
70
|
+
# error: false, value: raw, name: 'OK',
|
|
71
|
+
# comment: 'Command has been successfuly performed.'
|
|
72
|
+
# }
|
|
73
|
+
# when '1'
|
|
74
|
+
# {
|
|
75
|
+
# error: true, value: raw, name: 'E_ARGS',
|
|
76
|
+
# comment: 'Not enough arguments provided.'
|
|
77
|
+
# }
|
|
78
|
+
# when '2'
|
|
79
|
+
# {
|
|
80
|
+
# error: true, value: raw, name: 'E_INVALID',
|
|
81
|
+
# comment: 'Object or argument is not valid.'
|
|
82
|
+
# }
|
|
83
|
+
# when '3'
|
|
84
|
+
# {
|
|
85
|
+
# error: true, value: raw, name: 'E_NOTEXIST',
|
|
86
|
+
# comment: "Object doesn't exist."
|
|
87
|
+
# }
|
|
88
|
+
# else
|
|
89
|
+
# {
|
|
90
|
+
# error: true, value: '-1', name: 'E_UNKNOWN',
|
|
91
|
+
# comment: "Unknown response: #{raw}"
|
|
92
|
+
# }
|
|
93
|
+
# end
|
|
83
94
|
end
|
|
84
95
|
end
|
|
85
96
|
end
|
data/lib/vestacp/version.rb
CHANGED
data/vestacp.gemspec
CHANGED
|
@@ -6,10 +6,10 @@ require 'vestacp/version'
|
|
|
6
6
|
Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "vestacp"
|
|
8
8
|
spec.version = Vestacp::VERSION
|
|
9
|
-
spec.authors = ["Dmitry
|
|
9
|
+
spec.authors = ["Dmitry Knyazev"]
|
|
10
10
|
spec.email = ["a@kdas.me"]
|
|
11
11
|
spec.summary = %q{VestaCP API bindings}
|
|
12
|
-
spec.description = %q{Developed and tested on version 0.9.8-14}
|
|
12
|
+
spec.description = %q{Developed and tested on version 0.9.8-14. Only to do simple things with user accounts. That's not a problem to make them more complicated :)}
|
|
13
13
|
spec.homepage = ""
|
|
14
14
|
spec.license = "MIT"
|
|
15
15
|
|
metadata
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vestacp
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
- Dmitry
|
|
7
|
+
- Dmitry Knyazev
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
@@ -52,7 +52,8 @@ dependencies:
|
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '10.0'
|
|
55
|
-
description: Developed and tested on version 0.9.8-14
|
|
55
|
+
description: Developed and tested on version 0.9.8-14. Only to do simple things with
|
|
56
|
+
user accounts. That's not a problem to make them more complicated :)
|
|
56
57
|
email:
|
|
57
58
|
- a@kdas.me
|
|
58
59
|
executables: []
|