vestacp 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 15b1b629a74550b2c26b71b0bb7097f75a1d1eb7
4
+ data.tar.gz: 54df1114e6fced6ea19a0225534a637d8ab42573
5
+ SHA512:
6
+ metadata.gz: 7d3f7c445f1cbd68d53b6693d4f7686ce2ee7b55def06b6205c26859819ad6d2c4785462c03016b02861759b0faca334aaedded088620ebfea0f523f479810e4
7
+ data.tar.gz: e9cc9587fd638f722aa34a72c202f824fd9554c16f9995e862f9ed86febd1e1f3ffe9adf027c1508696c54ebd1e3af74ceafc4457f0f8264d4fd7d77e572f15e
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vestacp.gemspec
4
+ gemspec
5
+
6
+ gem 'faraday'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Dmitry K.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Vestacp
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'vestacp'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install vestacp
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/vestacp/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/lib/vestacp.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "vestacp/version"
2
+
3
+ module Vestacp
4
+ autoload :Config, "vestacp/config"
5
+ autoload :Base, "vestacp/base"
6
+ autoload :Account, "vestacp/account"
7
+
8
+ class << self
9
+ attr_accessor :config
10
+ end
11
+
12
+ self.config ||= Config.new
13
+
14
+ # Pass a block to configure the Vestacp API
15
+ #
16
+ # Vestacp.configure do |config|
17
+ # config.api_username = 'admin'
18
+ # config.api_password = 'n0passw0rd'
19
+ # config.api_url = 'https://example.com:8083/api/'
20
+ # end
21
+
22
+ def self.configure
23
+ yield config
24
+ config
25
+ end
26
+ end
27
+
28
+
@@ -0,0 +1,49 @@
1
+ module Vestacp
2
+ # Vestacp::Account is the class for managing clients
3
+ class Account < Base
4
+
5
+ # Create User Account
6
+ #
7
+ # Parameters:
8
+ #
9
+ # * <tt>:username</tt>
10
+ # * <tt>:password</tt>
11
+ # * <tt>:email</tt>
12
+ # * <tt>:package</tt>
13
+ # * <tt>:first_name</tt>
14
+ # * <tt>:last_name</tt>
15
+ #
16
+ # See:
17
+ #
18
+ # http://vestacp.com/docs/api/#add_user
19
+ def self.add_client(raw = {})
20
+ args = {
21
+ username: 'arg1',
22
+ password: 'arg2',
23
+ email: 'arg3',
24
+ package: 'arg4',
25
+ first_name: 'arg5',
26
+ last_name: 'arg6'
27
+ }
28
+ params = {}
29
+ raw.each {|key, value| params[args[key].to_sym] = value }
30
+ params.merge!(cmd: 'v-add-user')
31
+ send_request(params, raw)
32
+ end
33
+
34
+ # Delete User Account
35
+ #
36
+ # Parameters:
37
+ #
38
+ # * <tt>:username</tt>
39
+ def self.delete_user(raw = {})
40
+ args = {
41
+ username: 'arg1',
42
+ }
43
+ params = {}
44
+ raw.each {|key, value| params[args[key].to_sym] = value }
45
+ params.merge!(cmd: 'v-delete-user')
46
+ send_request(params, raw)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,85 @@
1
+ require 'faraday'
2
+
3
+ module Vestacp
4
+ # Vestacp::Base is the main class used to subclass Vestacp API resources
5
+ class Base
6
+
7
+ # Sends an API request to the Vestacp API
8
+ #
9
+ # Parameters:
10
+ # * <tt>:cmd</tt> - The API action to perform
11
+ #
12
+ # All other paramters are passed along as HTTP POST variables
13
+ def self.send_request(params = {}, raw = {})
14
+ if params[:cmd].blank?
15
+ raise "No API command set"
16
+ end
17
+
18
+ if raw.server && raw.server.api_username && raw.server.api_password && aw.server.api_url
19
+ params.merge!(
20
+ :user => raw.server.api_username,
21
+ :password => raw.server.api_password
22
+ )
23
+
24
+ url = URI.parse(raw.server.api_url)
25
+ else
26
+ params.merge!(
27
+ :user => Vestacp.config.api_username,
28
+ :password => Vestacp.config.api_password
29
+ )
30
+
31
+ url = URI.parse(Vestacp.config.api_url)
32
+ end
33
+
34
+ params.merge!(returncode: 'yes')
35
+
36
+ # SSL without is really bad design. In order to support even self-signed
37
+ # certificates I should do that.
38
+ conn = Faraday.new(:url => url, ssl: { verify: false }) do |faraday|
39
+ faraday.request :url_encoded # form-encode POST params
40
+ faraday.response :logger # log requests to STDOUT
41
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
42
+ end
43
+
44
+ response = conn.post do |req|
45
+ req.body = params
46
+ end
47
+
48
+ parse_response(response.body)
49
+ end
50
+
51
+ # Parse VestaCP responses.
52
+ # TODO: add more responses.
53
+ #
54
+ # See: http://vestacp.com/docs/api/#return_codes
55
+ def self.parse_response(raw)
56
+ case raw
57
+ when '0'
58
+ {
59
+ error: false, value: raw, name: 'OK',
60
+ comment: 'Command has been successfuly performed.'
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
+ }
77
+ else
78
+ {
79
+ error: true, value: '-1', name: 'E_UNKNOWN',
80
+ comment: "Unknown response: #{raw}"
81
+ }
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,20 @@
1
+ module Vestacp
2
+ # Vestacp::Config stores configuration data for connecting to the Vestacp API
3
+ class Config
4
+ # The Vestacp API username
5
+ attr_accessor :api_username
6
+
7
+ # The Vestacp API password
8
+ attr_accessor :api_password
9
+
10
+ # The Vestacp API URL
11
+ attr_accessor :api_url
12
+
13
+ # Create a new config object
14
+ def initialize
15
+ @api_username = 'example_user'
16
+ @api_password = 'example_pass'
17
+ @api_url = 'https://example.com:8083/api/'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Vestacp
2
+ VERSION = "0.0.2"
3
+ end
data/vestacp.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vestacp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vestacp"
8
+ spec.version = Vestacp::VERSION
9
+ spec.authors = ["Dmitry K."]
10
+ spec.email = ["a@kdas.me"]
11
+ spec.summary = %q{VestaCP API bindings}
12
+ spec.description = %q{Developed and tested on version 0.9.8-14}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "faraday", ">= 0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vestacp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Dmitry K.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Developed and tested on version 0.9.8-14
56
+ email:
57
+ - a@kdas.me
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/vestacp.rb
68
+ - lib/vestacp/account.rb
69
+ - lib/vestacp/base.rb
70
+ - lib/vestacp/config.rb
71
+ - lib/vestacp/version.rb
72
+ - vestacp.gemspec
73
+ homepage: ''
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.8
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: VestaCP API bindings
97
+ test_files: []