shanesveller-webbynode-api 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/webbynode-api.rb +4 -1
- data/test/data/bad-auth.xml +1 -0
- data/test/data/webbies.xml +13 -0
- data/test/webbynode-api_test.rb +21 -0
- data/webbynode-api.gemspec +3 -1
- metadata +3 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/lib/webbynode-api.rb
CHANGED
@@ -18,9 +18,12 @@ class WebbyNode
|
|
18
18
|
|
19
19
|
# Uses HTTParty to submit a secure API request via email address and token
|
20
20
|
def auth_get(url, options = {})
|
21
|
+
raise ArgumentError, "No API information given" unless @email && @api_key
|
21
22
|
options[:query] ||= {}
|
22
23
|
options[:query].merge!(:email => @email, :token => @api_key)
|
23
|
-
self.class.get(url, options)
|
24
|
+
results = self.class.get(url, options)
|
25
|
+
raise ArgumentError, "Probable bad API information given" if results == {}
|
26
|
+
return results
|
24
27
|
end
|
25
28
|
|
26
29
|
# Catches simple requests for specific API data returned via a hash
|
@@ -0,0 +1 @@
|
|
1
|
+
Authentication required
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<hash>
|
3
|
+
<webbies type="array">
|
4
|
+
<webby>
|
5
|
+
<status>on</status>
|
6
|
+
<ip>222.111.222.111</ip>
|
7
|
+
<node>location-a01</node>
|
8
|
+
<plan>Webby_384</plan>
|
9
|
+
<name>webby1</name>
|
10
|
+
<notes nil="true"></notes>
|
11
|
+
</webby>
|
12
|
+
</webbies>
|
13
|
+
</hash>
|
data/test/webbynode-api_test.rb
CHANGED
@@ -1,11 +1,29 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class WebbynodeApiTest < Test::Unit::TestCase
|
4
|
+
context "with bad API token or email" do
|
5
|
+
setup do
|
6
|
+
@email ="example@email.com"
|
7
|
+
@api_key = "123456"
|
8
|
+
data_path = File.join(File.dirname(__FILE__), "data")
|
9
|
+
FakeWeb.clean_registry
|
10
|
+
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/client\?\w+/i, :body => File.read("#{data_path}/bad-auth.xml"))
|
11
|
+
end
|
12
|
+
should "raise ArgumentError if no API data given" do
|
13
|
+
assert_raise(ArgumentError){ WebbyNode::Client.new(nil, nil) }
|
14
|
+
assert_raise(ArgumentError){ WebbyNode::Client.new(@email, nil) }
|
15
|
+
assert_raise(ArgumentError){ WebbyNode::Client.new(nil, @api_key) }
|
16
|
+
end
|
17
|
+
should "raise ArgumentError if bad API data given" do
|
18
|
+
assert_raise(ArgumentError){ WebbyNode::Client.new(@email, @api_key) }
|
19
|
+
end
|
20
|
+
end
|
4
21
|
context "fetching client data from API" do
|
5
22
|
setup do
|
6
23
|
email = "example@email.com"
|
7
24
|
api_key = "123456"
|
8
25
|
data_path = File.join(File.dirname(__FILE__), "data")
|
26
|
+
FakeWeb.clean_registry
|
9
27
|
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/client\?.+/i, :body => File.read("#{data_path}/client.xml"))
|
10
28
|
@api = WebbyNode::Client.new(email, api_key)
|
11
29
|
end
|
@@ -48,6 +66,7 @@ class WebbynodeApiTest < Test::Unit::TestCase
|
|
48
66
|
api_key = "123456"
|
49
67
|
hostname = "webby1"
|
50
68
|
data_path = File.join(File.dirname(__FILE__), "data")
|
69
|
+
FakeWeb.clean_registry
|
51
70
|
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/start\?.+/i, :body => File.read("#{data_path}/webby-start.xml"))
|
52
71
|
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/shutdown\?.+/i, :body => File.read("#{data_path}/webby-shutdown.xml"))
|
53
72
|
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/reboot\?.+/i, :body => File.read("#{data_path}/webby-reboot.xml"))
|
@@ -88,6 +107,7 @@ class WebbynodeApiTest < Test::Unit::TestCase
|
|
88
107
|
email = "example@email.com"
|
89
108
|
api_key = "123456"
|
90
109
|
data_path = File.join(File.dirname(__FILE__), "data")
|
110
|
+
FakeWeb.clean_registry
|
91
111
|
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/dns\?.+/i, :body => File.read("#{data_path}/dns.xml"))
|
92
112
|
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\?.+/i, :body => File.read("#{data_path}/dns-1.xml"))
|
93
113
|
@dns = WebbyNode::DNS.new(email, api_key)
|
@@ -113,6 +133,7 @@ class WebbynodeApiTest < Test::Unit::TestCase
|
|
113
133
|
api_key = "123456"
|
114
134
|
id = 1
|
115
135
|
data_path = File.join(File.dirname(__FILE__), "data")
|
136
|
+
FakeWeb.clean_registry
|
116
137
|
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/dns\?.+/i, :body => File.read("#{data_path}/dns.xml"))
|
117
138
|
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\?.+/i, :body => File.read("#{data_path}/dns-1.xml"))
|
118
139
|
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\/records\?.+/i, :body => File.read("#{data_path}/dns-records.xml"))
|
data/webbynode-api.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{webbynode-api}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.5"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Shane Sveller"]
|
@@ -21,10 +21,12 @@ Gem::Specification.new do |s|
|
|
21
21
|
"VERSION",
|
22
22
|
"lib/webbynode-api.rb",
|
23
23
|
"lib/webbynode-api/data.rb",
|
24
|
+
"test/data/bad-auth.xml",
|
24
25
|
"test/data/client.xml",
|
25
26
|
"test/data/dns-1.xml",
|
26
27
|
"test/data/dns-records.xml",
|
27
28
|
"test/data/dns.xml",
|
29
|
+
"test/data/webbies.xml",
|
28
30
|
"test/data/webby-reboot.xml",
|
29
31
|
"test/data/webby-shutdown.xml",
|
30
32
|
"test/data/webby-start.xml",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shanesveller-webbynode-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Sveller
|
@@ -31,10 +31,12 @@ files:
|
|
31
31
|
- VERSION
|
32
32
|
- lib/webbynode-api.rb
|
33
33
|
- lib/webbynode-api/data.rb
|
34
|
+
- test/data/bad-auth.xml
|
34
35
|
- test/data/client.xml
|
35
36
|
- test/data/dns-1.xml
|
36
37
|
- test/data/dns-records.xml
|
37
38
|
- test/data/dns.xml
|
39
|
+
- test/data/webbies.xml
|
38
40
|
- test/data/webby-reboot.xml
|
39
41
|
- test/data/webby-shutdown.xml
|
40
42
|
- test/data/webby-start.xml
|