shanesveller-webbynode-api 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +0 -2
- data/.gitignore +3 -0
- data/README.rdoc +9 -1
- data/Rakefile +4 -0
- data/VERSION +1 -1
- data/lib/webbynode-api/data.rb +48 -5
- data/lib/webbynode-api.rb +36 -1
- data/webbynode-api.gemspec +1 -1
- metadata +1 -1
data/.document
CHANGED
data/README.rdoc
CHANGED
@@ -11,6 +11,10 @@ All previous methods/initializers used named/ordered arguments. New API
|
|
11
11
|
interactions are designed to use hashes of arguments instead. Older API
|
12
12
|
models will be converted to this new design pattern soon.
|
13
13
|
|
14
|
+
Also, any new/improved documentation will instead be visible in the
|
15
|
+
{YARD documentation}[http://rdoc.info/projects/shanesveller/webbynode-api]
|
16
|
+
hosted at {rdoc.info}[http://rdoc.info].
|
17
|
+
|
14
18
|
== Currently Supported API functionality
|
15
19
|
* Client information such as account status, contact/address info, credit
|
16
20
|
* Webby information (status) and simple actions (start, shutdown, reboot)
|
@@ -62,8 +66,12 @@ models will be converted to this new design pattern soon.
|
|
62
66
|
require 'webbynode-api'
|
63
67
|
email = "example@email.com"
|
64
68
|
api_key = "1234567890abcdef"
|
65
|
-
@new_zone = WebbyNode::DNS.new_zone(:email => email, :token =>
|
69
|
+
@new_zone = WebbyNode::DNS.new_zone(:email => email, :token => api_key, :domain => "mynewdomain.com.", :ttl => 86400)
|
66
70
|
pp @new_zone["id"]
|
71
|
+
# => 171
|
72
|
+
|
73
|
+
WebbyNode::DNS.delete_zone(:email => email, :token => api_key, :id => 171)
|
74
|
+
# => true
|
67
75
|
|
68
76
|
== Copyright
|
69
77
|
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/lib/webbynode-api/data.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
class WebbyNode
|
2
2
|
# Represents the account-holder's information
|
3
|
+
#
|
4
|
+
# @author Shane Sveller
|
5
|
+
# @since 0.0.1
|
3
6
|
class Client < WebbyNode::APIObject
|
4
7
|
def initialize(email, api_key)
|
5
8
|
super(email, api_key)
|
@@ -9,11 +12,23 @@ class WebbyNode
|
|
9
12
|
|
10
13
|
# Represents an individual webby with status, reboot/shutdown/start functionality
|
11
14
|
# via +method_missing+
|
15
|
+
#
|
16
|
+
# @author Shane Sveller
|
17
|
+
# @since 0.0.1
|
12
18
|
class Webby < WebbyNode::APIObject
|
13
19
|
attr_accessor :hostname
|
14
20
|
|
15
|
-
#
|
16
|
-
#
|
21
|
+
# Fetches either an array of Webbies' data or an individual Webby's data.
|
22
|
+
#
|
23
|
+
# @param [String] email E-mail address used for API access
|
24
|
+
# @param [String] api_key API token used for API access
|
25
|
+
# @param [optional, String] hostname Hostname used to look up an individual
|
26
|
+
# Webby. When absent or nil, the newly instantiated object instead
|
27
|
+
# represents an Array of Webbies.
|
28
|
+
# @example Fetch data for a Webby named "webby1"
|
29
|
+
# WebbyNode::Webby.new(email, api_key, "webby1")
|
30
|
+
# @example Fetch an Array of Webbies
|
31
|
+
# WebbyNode::Webby.new(email, api_key)
|
17
32
|
def initialize(email, api_key, hostname = nil)
|
18
33
|
super(email, api_key)
|
19
34
|
if hostname
|
@@ -23,6 +38,8 @@ class WebbyNode
|
|
23
38
|
end
|
24
39
|
end
|
25
40
|
|
41
|
+
# Provides status, start/shutdown/reboot functionality for an individual
|
42
|
+
# Webby. Provides list functionality for an Array of Webbies.
|
26
43
|
def method_missing(method)
|
27
44
|
if method.to_s == "status"
|
28
45
|
return auth_get("/api/xml/webby/#{@hostname}/status")["hash"]["status"]
|
@@ -31,16 +48,25 @@ class WebbyNode
|
|
31
48
|
elsif method.to_s == "list"
|
32
49
|
return @data
|
33
50
|
else
|
34
|
-
raise "No such action possible on a Webby."
|
51
|
+
raise ArgumentError, "No such action possible on a Webby."
|
35
52
|
end
|
36
53
|
end
|
37
54
|
end
|
38
55
|
|
56
|
+
# Represents the DNS zones present on the API account
|
57
|
+
#
|
58
|
+
# @author Shane Sveller
|
59
|
+
# @since 0.0.2
|
39
60
|
class DNS < WebbyNode::APIObject
|
61
|
+
# Holds the ID used internally at WebbyNode that represents a given zone.
|
40
62
|
attr_accessor :id
|
41
63
|
|
42
|
-
#
|
43
|
-
#
|
64
|
+
# Fetches either a single zone or an Array of all zones based on the presence
|
65
|
+
# of the id parameter.
|
66
|
+
#
|
67
|
+
# @param [String] email E-mail address used for API access
|
68
|
+
# @param [String] api_key API token used for API access
|
69
|
+
# @param [option, Integer] id ID that represents an individual zone
|
44
70
|
def initialize(email, api_key, id = nil)
|
45
71
|
super(email, api_key)
|
46
72
|
if id
|
@@ -51,11 +77,21 @@ class WebbyNode
|
|
51
77
|
end
|
52
78
|
end
|
53
79
|
|
80
|
+
# @since 0.0.3
|
81
|
+
# @return [Array<Hash>] Array of a zones' records, each individually is a Hash.
|
54
82
|
def records
|
55
83
|
raise "This method should only be called on DNS instances with an id" unless @id
|
56
84
|
auth_get("/api/xml/dns/#{@id}/records")["hash"]["records"]
|
57
85
|
end
|
58
86
|
|
87
|
+
# @since 0.0.6
|
88
|
+
# @option options [String] :email E-mail address used for API access
|
89
|
+
# @option options [String] :token API token used for API access
|
90
|
+
# @option options [optional, String] :status Optional argument to set the
|
91
|
+
# status of the zone. Valid values include 'Active' or 'Inactive' only.
|
92
|
+
# @return [Hash] Hash of the new zone's information
|
93
|
+
# @raise [ArgumentError] Raises ArgumentError if :token, :email, :domain,
|
94
|
+
# or :ttl are missing from the options parameter.
|
59
95
|
def self.new_zone(options = {})
|
60
96
|
raise ArgumentError, "API access information via :email and :token are required arguments" unless options[:email] && options[:token]
|
61
97
|
raise ArgumentError, ":domain and :ttl are required arguments" unless options[:domain] && options[:ttl]
|
@@ -73,6 +109,13 @@ class WebbyNode
|
|
73
109
|
return zone_data["hash"]
|
74
110
|
end
|
75
111
|
|
112
|
+
# @since 0.0.6
|
113
|
+
# @option options [String] :email E-mail address used for API access
|
114
|
+
# @option options [String] :token API token used for API access
|
115
|
+
# @option options [Integer] :id WebbyNode's internally-used ID that idenftifies the zone
|
116
|
+
# @return [Boolean] Returns true upon succesful deletion of the zone.
|
117
|
+
# @raise [ArgumentError] Raises ArgumentError if :token, :email, or :id are
|
118
|
+
# missing from the options parameter.
|
76
119
|
def self.delete_zone(options = {})
|
77
120
|
raise ArgumentError, "API access information via :email and :token are required arguments" unless options[:email] && options[:token]
|
78
121
|
raise ArgumentError, ":id is a required argument" unless options[:id]
|
data/lib/webbynode-api.rb
CHANGED
@@ -2,21 +2,38 @@ require 'rubygems'
|
|
2
2
|
gem 'httparty'
|
3
3
|
require 'httparty'
|
4
4
|
|
5
|
+
# @author Shane Sveller
|
5
6
|
class WebbyNode
|
7
|
+
|
8
|
+
# @author Shane Sveller
|
9
|
+
# @since 0.0.1
|
6
10
|
class APIObject
|
7
11
|
include HTTParty
|
8
12
|
base_uri "https://manager.webbynode.com"
|
9
13
|
format :xml
|
10
14
|
|
11
|
-
|
15
|
+
# E-mail address used to access the WebbyNode API
|
16
|
+
attr_accessor :email
|
17
|
+
# API token used to access the WebbyNode API, visible at https://manager.webbynode.com/account
|
18
|
+
attr_accessor :api_key
|
19
|
+
# Stores the results of the HTTParty API interactions
|
20
|
+
attr_accessor :data
|
12
21
|
|
13
22
|
# Creates a new API object secured by e-mail address and API token
|
23
|
+
#
|
24
|
+
# @param [String] email e-mail address with API access
|
25
|
+
# @param [String] api_key API token that matches the included e-mail address
|
26
|
+
# @example Instantiates a new API access object
|
27
|
+
# WebbyNode::APIObject.new("example@email.com", "123456abcdef")
|
14
28
|
def initialize(email, api_key)
|
15
29
|
@email = email
|
16
30
|
@api_key = api_key
|
17
31
|
end
|
18
32
|
|
19
33
|
# Uses HTTParty to submit a secure API request via email address and token
|
34
|
+
# @param [String] url URL to GET using HTTParty
|
35
|
+
# @param [Hash] options Hash of additional HTTParty parameters
|
36
|
+
# @option options [Hash] :query query hash used to build the final URL
|
20
37
|
def auth_get(url, options = {})
|
21
38
|
raise ArgumentError, "API information is missing or incomplete" unless @email && @api_key
|
22
39
|
options[:query] ||= {}
|
@@ -30,6 +47,19 @@ class WebbyNode
|
|
30
47
|
self.class.auth_post(url, options)
|
31
48
|
end
|
32
49
|
|
50
|
+
# Uses HTTParty to submit a secure API POST request via email address and token.
|
51
|
+
# API access information should be included via the :email and :token hash keys,
|
52
|
+
# in a hash on the :query key of the options hash passed as the second argument
|
53
|
+
# in the method call.
|
54
|
+
#
|
55
|
+
# @param [String] url The URL to post to using HTTParty
|
56
|
+
# @option options [String] :query query hash used to build the final URL
|
57
|
+
# Should include :email and :token keys with the e-mail address
|
58
|
+
# and API token with access rights
|
59
|
+
# @return [Hash] returns a Hash of nested XML elements using string-based keys
|
60
|
+
# @example Queries the API data for the client account
|
61
|
+
# WebbyNode::APIObject.auth_post("/api/xml/client", :query => {:email => ""example@email.com",
|
62
|
+
# :token => "1234567abcde", :posted_data => "test"})
|
33
63
|
def self.auth_post(url, options = {})
|
34
64
|
options[:query] ||= {}
|
35
65
|
raise ArgumentError, "API information is missing or incomplete" unless options[:query][:email] && options[:query][:token]
|
@@ -39,6 +69,11 @@ class WebbyNode
|
|
39
69
|
end
|
40
70
|
|
41
71
|
# Catches simple requests for specific API data returned via a hash
|
72
|
+
#
|
73
|
+
# @return [Object, nil] If the @data instance variable is set, and contains a hash
|
74
|
+
# with a key matching the missing method, return the value from that hash key.
|
75
|
+
# Said value may be typecast into a Ruby object if the XML is formatted properly.
|
76
|
+
# Otherwise returns nil.
|
42
77
|
def method_missing(method)
|
43
78
|
key = @data[method.to_s] if @data
|
44
79
|
key
|
data/webbynode-api.gemspec
CHANGED