Skip to content

Commit cee66aa

Browse files
committed
Merge pull request #51 from site5/refactor/tomdoc
RDoc => TomDoc
2 parents e194dc7 + fc04637 commit cee66aa

12 files changed

+413
-206
lines changed

.document

-5
This file was deleted.

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ Gemfile.lock
88

99
.rvmrc
1010
.rbenv-version
11+
12+
/.yardoc/*

Gemfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
source "http://rubygems.org"
22

3-
# Specify your gem's dependencies in lol.gemspec
3+
gem 'rake-tomdoc', github: 'site5/rake-tomdoc'
4+
45
gemspec

README.markdown

+9-11
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ This library was first created for internal use at [Site5 LLC][].
66

77
SolusVM has been tested on MRI 1.9.2, MRI 1.9.3 and 1.9-compatible JRuby.
88

9+
Documentation is available in [TomDoc][] format.
10+
911
[Site5 LLC]: http://www.site5.com
1012
[SolusVM Admin::API]: http://wiki.solusvm.com/index.php/API:Admin
1113
[Build Status]: http://travis-ci.org/site5/solusvm
1214
[Build Icon]: https://secure.travis-ci.org/site5/solusvm.png?branch=master
15+
[TomDoc]: http://site5.github.io/solusvm/
1316

1417
Basic Examples
1518
--------------
@@ -131,12 +134,9 @@ The command line utility, solusvm, will look for a .solusvm.yml file in ~/. You
131134
Requirements
132135
------------
133136

134-
* xml-simple
135-
136-
Documentation
137-
-------------
138-
139-
* http://solusvm.rubyforge.org/solusvm/
137+
* [xml-simple](https://github.com/maik/xml-simple)
138+
* [thor](https://github.com/erikhuda/thor)
139+
* [faraday](https://github.com/lostisland/faraday)
140140

141141
Installation
142142
------------
@@ -146,11 +146,9 @@ Installation
146146
Contributors
147147
------------
148148

149-
* [Justin Mazzi](http://github.com/jmazzi)
150-
* [Maran H.](http://github.com/maran)
151-
* [Joshua Priddle](http://github.com/itspriddle)
152-
* [Vince Stratful](http://github.com/Vincepbell)
153-
* [Rubem Nakamura](http://github.com/rubemz)
149+
SolusVM was originall written by [jmazzi](https://github.com/site5/jmazzi) for
150+
internal use at Site5 LLC. Additional contributors are [listed on
151+
GitHub](https://github.com/site5/solusvm/graphs/contributors).
154152

155153
Note on Patches/Pull Requests
156154
-----------------------------

Rakefile

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
require 'rubygems'
22
require 'rake'
33
require 'bundler/gem_tasks'
4-
54
require 'rake/testtask'
5+
require 'rake-tomdoc'
66

77
Rake::TestTask.new(:test) do |test|
88
test.libs << 'lib' << 'test'
@@ -23,21 +23,5 @@ rescue LoadError
2323
end
2424
end
2525

26-
begin
27-
require 'rdoc/task'
28-
Rake::RDocTask.new do |rdoc|
29-
version = Solusvm::VERSION
30-
31-
rdoc.rdoc_dir = 'rdoc'
32-
rdoc.title = "solusvm #{version}"
33-
rdoc.rdoc_files.include('README*')
34-
rdoc.rdoc_files.include('lib/**/*.rb')
35-
end
36-
rescue LoadError
37-
task :rdoc do
38-
abort "rdoc is not available. In order to run rdoc, you must: sudo gem install rdoc"
39-
end
40-
end
41-
4226
task :default => :test
4327
task :spec => :test

lib/solusvm/base.rb

+80-31
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,24 @@ def initialize(config = {})
99
@config = config
1010
end
1111

12-
# Prepares and sends the API request to the URL specificed in Solusvm.config
12+
# Public: Prepares and sends the API request to the URL specified in
13+
# `Solusvm.config`.
1314
#
14-
# class MyClass < Base
15-
# def create_server(name)
16-
# perform_request(:action => "name", :id => 1)
17-
# end
18-
# end
15+
# options - A Hash of options. Any options not listed below are
16+
# converted to HTTP query arguments and are passed along to
17+
# the API.
18+
# :action - Specifies which API method to execute
19+
# force_array - see parse_response
1920
#
20-
# Options:
21-
# * <tt>:action</tt> - Specifies which API method to execute
22-
# All other options passed in are converted to http query arguments and are passed along to the API
21+
# Example
2322
#
24-
# <tt>force_array</tt> - see parse_response
23+
# class MyClass < Base
24+
# def create_server(name)
25+
# perform_request(:action => "name", :id => 1)
26+
# end
27+
# end
28+
#
29+
# Returns true if the request was successful.
2530
def perform_request(options = {}, force_array = false)
2631
options.reject! {|_,v| v.nil? }
2732

@@ -32,23 +37,34 @@ def perform_request(options = {}, force_array = false)
3237
successful?
3338
end
3439

35-
# Creates a Faraday connection and returns it.
40+
# Public: Creates a Faraday connection.
41+
#
42+
# Returns a Faraday::Connection.
3643
def conn
3744
@conn ||= Faraday.new(ssl: ssl_option) do |c|
3845
c.request :retry if @config.fetch(:retry_request, false)
3946
c.adapter :net_http
4047
end
4148
end
4249

50+
# Public: SSL options used when creating a Faraday connection.
51+
#
52+
# Returns a Hash.
4353
def ssl_option
44-
ca_path = File.join(File.dirname(__FILE__), "..", "cacert.pem")
45-
{verify: true, ca_file: File.expand_path(ca_path)}
54+
{
55+
verify: true,
56+
ca_file: File.expand_path("../../cacert.pem", __FILE__)
57+
}
4658
end
4759

48-
# Converts the XML response to a Hash
60+
# Public: Converts the XML response to a Hash.
4961
#
50-
# <tt>force_array</tt> - Parses the xml element as an array; can be a string with the element name
51-
# or an array with element names
62+
# status - Faraday::Response#status
63+
# body - Faraday::Response#body
64+
# force_array - Parses the xml element as an array; can be a string with
65+
# the element name or an array with element names
66+
#
67+
# Returns a Hash.
5268
def parse_response(status, body, force_array = false)
5369
parse_error(status, body) || begin
5470
force_array = Array(force_array) if force_array
@@ -57,14 +73,23 @@ def parse_response(status, body, force_array = false)
5773
end
5874
end
5975

60-
# Parses a returned_parameters value as a list, if present.
76+
# Public: Parses a returned_parameters value as a list, if present.
77+
#
78+
# attribute - The attribute to check
79+
#
80+
# Returns an Array or nil.
6181
def parse_returned_params_as_list(attribute)
6282
if returned_parameters[attribute] && !returned_parameters[attribute].empty?
6383
returned_parameters[attribute].to_s.split(",")
6484
end
6585
end
6686

67-
# Parses error responses.
87+
# Public: Parses error responses.
88+
#
89+
# status - HTTP status code
90+
# body - Raw body
91+
#
92+
# Returns a Hash or nil.
6893
def parse_error(status, body)
6994
if (200..299).include?(status)
7095
# Checks for application errors
@@ -81,49 +106,65 @@ def parse_error(status, body)
81106
end
82107
end
83108

84-
# Returns true when a request has been successful
109+
# Public: Check if the request was successful.
110+
#
111+
# my_class = MyClass.new
112+
# my_class.create_server("example.com")
113+
# my_class.successful? # => true
85114
#
86-
# my_class = MyClass.new
87-
# my_class.create_server("example.com")
88-
# my_class.successful? # => true
115+
# Returns true if the request was successful.
89116
def successful?
90117
returned_parameters["status"].nil? || returned_parameters["status"] == "success"
91118
end
92119

93-
# Returns the API endpoint set in the instance configuration. Otherwise,
94-
# it returns the default configuration.
120+
# Public: Returns the API endpoint set in the instance configuration.
121+
# Otherwise, it returns the default configuration.
95122
#
96123
# Returns a String
97124
def api_endpoint
98125
@config.fetch(:url)
99126
end
100127

101-
# Returns the API id set in the instance configuration. Otherwise,
128+
# Public: Returns the API id set in the instance configuration. Otherwise,
102129
# it returns the default configuration.
103130
#
104131
# Returns a String
105132
def api_id
106133
@config.fetch(:api_id)
107134
end
108135

109-
# Returns the API key set in the instance configuration. Otherwise,
110-
# it returns the default configuration.
136+
# Public: Returns the API key set in the instance configuration.
137+
# Otherwise, it returns the default configuration.
111138
#
112-
# Returns a String
139+
# Returns a String.
113140
def api_key
114141
@config.fetch(:api_key)
115142
end
116143

144+
# Public: API options
145+
#
146+
# option - Key to fetch
147+
#
148+
# Returns the given option.
117149
def api_options(option)
118150
if options = @config[:options]
119151
options[option.to_sym]
120152
end
121153
end
122154

155+
# Public: API login information.
156+
#
157+
# Returns a Hash.
123158
def api_login
124-
{id: api_id, key: api_key}
159+
{ id: api_id, key: api_key }
125160
end
126161

162+
# Public: Logs API actions to the configured logger.
163+
#
164+
# options - A Hash of options
165+
# :action - the API action
166+
#
167+
# Returns nothing.
127168
def log_messages(options)
128169
logger, logger_method = api_options(:logger), api_options(:logger_method)
129170

@@ -136,12 +177,20 @@ def log_messages(options)
136177
end
137178
end
138179

139-
# API response message
180+
# Public: API response message
181+
#
182+
# Returns a String.
140183
def statusmsg
141184
returned_parameters["statusmsg"]
142185
end
143186

144-
# Validates the server type.
187+
# Public: Validates the server type.
188+
#
189+
# type - The server type to check
190+
#
191+
# Yields a required block if given server type is valid.
192+
#
193+
# Returns the result of the block, or false if the server type is invalid.
145194
def validate_server_type(type, &block)
146195
type = type.strip
147196

lib/solusvm/client.rb

+41-19
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,65 @@
11
module Solusvm
22
# Solusvm::Client is the class for working with clients.
33
class Client < Base
4-
# Creates a client.
4+
# Public: Creates a client.
55
#
6-
# Options:
6+
# options - A Hash of options:
7+
# :username
8+
# :password
9+
# :email
10+
# :firstname
11+
# :lastname
12+
# :company
713
#
8-
# * <tt>:username</tt>
9-
# * <tt>:password</tt>
10-
# * <tt>:email</tt>
11-
# * <tt>:firstname</tt>
12-
# * <tt>:lastname</tt>
13-
# * <tt>:company</tt>
14-
def create(options ={})
14+
# Returns a Hash with the new client info, or false if the client was not
15+
# created successfully.
16+
def create(options = {})
1517
perform_request(options.merge(action: 'client-create')) && returned_parameters
1618
end
1719

18-
# Change client password for the solus admin.
20+
# Public: Change client password for the Solus admin.
21+
#
22+
# username - The client's username
23+
# new_password - The new password
24+
#
25+
# Returns true if the client's password was successfully changed.
1926
def change_password(username, new_password)
20-
perform_request({action: "client-updatepassword", username: username, password: new_password})
27+
perform_request(action: "client-updatepassword", username: username, password: new_password)
2128
end
2229

23-
# Checks wether a specific client exists.
30+
# Public: Checks if a specific client exists.
31+
#
32+
# username - The client's username
33+
#
34+
# Returns true if the client exists.
2435
def exists?(username)
25-
perform_request({action: 'client-checkexists', username: username})
36+
perform_request(action: 'client-checkexists', username: username)
2637
end
2738

28-
# Verify a clients login. Returns true when the specified login is correct.
39+
# Public: Verify a client's login.
40+
#
41+
# username - The client's username
42+
# password - The client's password
43+
#
44+
# Returns true if the given credentials are correct.
2945
def authenticate(username, password)
30-
perform_request({action: 'client-authenticate', username: username, password: password})
46+
perform_request(action: 'client-authenticate', username: username, password: password)
3147
end
3248

33-
# Deletes an existing client.
49+
# Public: Deletes an existing client.
50+
#
51+
# username - The client's username
52+
#
53+
# Returns true if the client was successfully deleted.
3454
def delete(username)
35-
perform_request({action: "client-delete", username: username})
55+
perform_request(action: "client-delete", username: username)
3656
end
3757

38-
# Lists existing clients.
58+
# Public: Lists existing clients.
59+
#
60+
# Returns an Array.
3961
def list
40-
perform_request({action: "client-list"}, "client")
62+
perform_request({ action: "client-list" }, "client")
4163

4264
if returned_parameters["clients"] && returned_parameters["clients"]["client"]
4365
returned_parameters["clients"]["client"]

0 commit comments

Comments
 (0)