fanny_pack 0.1.0 → 0.1.1
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.
- data/lib/fanny_pack/errors.rb +7 -1
- data/lib/fanny_pack/ip.rb +46 -65
- data/lib/fanny_pack/request.rb +27 -10
- data/lib/fanny_pack/version.rb +1 -1
- data/lib/fanny_pack.rb +6 -2
- data/spec/fanny_pack/ip_spec.rb +6 -8
- data/spec/spec_helper.rb +4 -0
- metadata +28 -17
data/lib/fanny_pack/errors.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module FannyPack
|
2
|
-
module Errors
|
2
|
+
module Errors
|
3
3
|
# Fault codes and error messages that are returned by the Fantastico API
|
4
4
|
FAULT_CODES = {
|
5
5
|
1302 => "You have specified an invalid hash.",
|
@@ -17,5 +17,11 @@ module FannyPack
|
|
17
17
|
super "Must set FannyPack.account_hash"
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
class MissingArgument < ArgumentError
|
22
|
+
def initialize(param = nil)
|
23
|
+
super "Missing required parameter: #{param}"
|
24
|
+
end
|
25
|
+
end
|
20
26
|
end
|
21
27
|
end
|
data/lib/fanny_pack/ip.rb
CHANGED
@@ -11,20 +11,18 @@ module FannyPack
|
|
11
11
|
|
12
12
|
# Add an IP address to your Fantastico account.
|
13
13
|
#
|
14
|
-
#
|
15
|
-
#
|
14
|
+
# @param [String] ip
|
15
|
+
# The IP address to add
|
16
16
|
#
|
17
|
-
#
|
17
|
+
# @param [Symbol] ip_type
|
18
|
+
# The type of IP address (+:vps+ or +:normal+)
|
18
19
|
#
|
19
|
-
#
|
20
|
-
# * +ip_type* - The type of IP address (:vps or :normal)
|
20
|
+
# @return [Hash]
|
21
21
|
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# # Add normal IP
|
22
|
+
# @example Add normal IP
|
25
23
|
# FannyPack::IP.add '127.0.0.1'
|
26
24
|
#
|
27
|
-
#
|
25
|
+
# @example Add vps IP
|
28
26
|
# FannyPack::IP.add '127.0.0.1', :vps
|
29
27
|
def self.add(ip, ip_type = :normal)
|
30
28
|
Request.new.commit :addIp, :ip => ip, :type => IP_TYPES[ip_type]
|
@@ -32,16 +30,15 @@ module FannyPack
|
|
32
30
|
|
33
31
|
# Edit an IP address, replacing +ip+ with +new_ip+
|
34
32
|
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
# ==== Options
|
33
|
+
# @param [String] ip
|
34
|
+
# The current IP address
|
39
35
|
#
|
40
|
-
#
|
41
|
-
#
|
36
|
+
# @param [String] new_ip
|
37
|
+
# The new IP address
|
42
38
|
#
|
43
|
-
#
|
39
|
+
# @return [Hash]
|
44
40
|
#
|
41
|
+
# @example
|
45
42
|
# FannyPack::IP.edit '127.0.0.1', '127.0.0.2'
|
46
43
|
def self.edit(ip, new_ip)
|
47
44
|
Request.new.commit :editIp, :ip => ip, :new_ip => new_ip
|
@@ -50,42 +47,38 @@ module FannyPack
|
|
50
47
|
# Get a list of IP addresses on your Fantastico account
|
51
48
|
#
|
52
49
|
# The Fantastico API allows you to filter for only normal IPs, or only
|
53
|
-
# vps IPs. Use +list_type+
|
54
|
-
# IPs, or
|
55
|
-
#
|
56
|
-
# Raises ArgumentError if list_type is invalid
|
57
|
-
#
|
58
|
-
# If +details+ is false:
|
59
|
-
# Returns an Array containing IP addresses
|
50
|
+
# vps IPs. Use +list_type+ +:all+ to get all IPs, +:normal+ to get only
|
51
|
+
# normal IPs, or +:vps+ to get only vps IPs.
|
60
52
|
#
|
61
|
-
#
|
62
|
-
#
|
53
|
+
# @param [Symbol] list_type
|
54
|
+
# The list type, one of +:normal+, +:vps+, +:all+
|
63
55
|
#
|
64
|
-
#
|
56
|
+
# @param [Boolean] details
|
57
|
+
# Set to true to return details for each IP
|
65
58
|
#
|
66
|
-
#
|
59
|
+
# @raise [ArgumentError]
|
60
|
+
# Raised if list_type is invalid
|
67
61
|
#
|
68
|
-
#
|
69
|
-
#
|
62
|
+
# @return [Array]
|
63
|
+
# If +details+ is false, an array of IPs as +Strings+ is returned. If
|
64
|
+
# +details+ is true, an array of IPs as Hashes is returned.
|
70
65
|
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
# # Show all IPs (simple list)
|
66
|
+
# @example Show all IPs (simple list)
|
74
67
|
# FannyPack::IP.list :all
|
75
68
|
#
|
76
|
-
#
|
69
|
+
# @example Show all IPs (detailed list)
|
77
70
|
# FannyPack::IP.list :all, true
|
78
71
|
#
|
79
|
-
#
|
72
|
+
# @example Show normal IPs (simple list)
|
80
73
|
# FannyPack::IP.list :normal
|
81
74
|
#
|
82
|
-
#
|
75
|
+
# @example Show normal IPs (detailed list)
|
83
76
|
# FannyPack::IP.list :normal, true
|
84
77
|
#
|
85
|
-
#
|
78
|
+
# @example Show vps IPs (simple list)
|
86
79
|
# FannyPack::IP.list :vps
|
87
80
|
#
|
88
|
-
#
|
81
|
+
# @example Show normal IPs (detailed list)
|
89
82
|
# FannyPack::IP.list :vps, true
|
90
83
|
def self.list(list_type, details = false)
|
91
84
|
cmd = details ? :getIpListDetailed : :getIpList
|
@@ -97,15 +90,12 @@ module FannyPack
|
|
97
90
|
|
98
91
|
# Delete an IP address from your Fantastico Account
|
99
92
|
#
|
100
|
-
#
|
101
|
-
#
|
102
|
-
#
|
103
|
-
# ==== Options
|
104
|
-
#
|
105
|
-
# * +ip+ - The IP address to delete
|
93
|
+
# @param [String] ip
|
94
|
+
# The IP address to delete
|
106
95
|
#
|
107
|
-
#
|
96
|
+
# @return [Hash]
|
108
97
|
#
|
98
|
+
# @example
|
109
99
|
# FannyPack::IP.delete '127.0.0.1'
|
110
100
|
def self.delete(ip)
|
111
101
|
Request.new.commit :deleteIp, :ip => ip
|
@@ -113,15 +103,12 @@ module FannyPack
|
|
113
103
|
|
114
104
|
# Reactivate a deactivated IP address
|
115
105
|
#
|
116
|
-
#
|
117
|
-
#
|
106
|
+
# @param [String] ip
|
107
|
+
# The IP address to reactivate
|
118
108
|
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
# * +ip+ - The IP address to reactivate
|
122
|
-
#
|
123
|
-
# ==== Example
|
109
|
+
# @return [Hash]
|
124
110
|
#
|
111
|
+
# @example
|
125
112
|
# FannyPack::IP.reactivate '127.0.0.1'
|
126
113
|
def self.reactivate(ip)
|
127
114
|
Request.new.commit :reactivateIp, :ip => ip
|
@@ -129,15 +116,12 @@ module FannyPack
|
|
129
116
|
|
130
117
|
# Deactivate an IP address
|
131
118
|
#
|
132
|
-
#
|
133
|
-
#
|
134
|
-
#
|
135
|
-
# ==== Options
|
119
|
+
# @param [String] ip
|
120
|
+
# The IP address to deactivate
|
136
121
|
#
|
137
|
-
#
|
138
|
-
#
|
139
|
-
# ==== Example
|
122
|
+
# @return [Hash]
|
140
123
|
#
|
124
|
+
# @example
|
141
125
|
# FannyPack::IP.deactivate '127.0.0.1'
|
142
126
|
def self.deactivate(ip)
|
143
127
|
Request.new.commit :deactivateIp, :ip => ip
|
@@ -145,15 +129,12 @@ module FannyPack
|
|
145
129
|
|
146
130
|
# Get details for an IP address
|
147
131
|
#
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
# ==== Options
|
152
|
-
#
|
153
|
-
# * +ip+ - The IP address to lookup
|
132
|
+
# @param [String] ip
|
133
|
+
# The IP address to look up
|
154
134
|
#
|
155
|
-
#
|
135
|
+
# @return [Hash]
|
156
136
|
#
|
137
|
+
# @example
|
157
138
|
# FannyPack::IP.details '127.0.0.1'
|
158
139
|
def self.details(ip)
|
159
140
|
Request.new.commit :getIpDetails, :ip => ip
|
data/lib/fanny_pack/request.rb
CHANGED
@@ -7,7 +7,15 @@ module FannyPack
|
|
7
7
|
# FannyPack::Request handles forming the XML request to be sent to the
|
8
8
|
# Fantastico API, and parsing the response.
|
9
9
|
class Request
|
10
|
-
|
10
|
+
# Parameters for the API request
|
11
|
+
#
|
12
|
+
# @return [Hash]
|
13
|
+
attr_reader :params
|
14
|
+
|
15
|
+
# The parsed API response
|
16
|
+
#
|
17
|
+
# @return [Hash]
|
18
|
+
attr_reader :response
|
11
19
|
|
12
20
|
# The Fantastico API supports these methods
|
13
21
|
VALID_ACTIONS = [
|
@@ -28,10 +36,13 @@ module FannyPack
|
|
28
36
|
#
|
29
37
|
# Returns a Hash or Array, depending on the response from Fantastico
|
30
38
|
#
|
31
|
-
#
|
39
|
+
# @param [Symbol] action
|
40
|
+
# The action to perform, one of +VALID_ACTIONS+
|
32
41
|
#
|
33
|
-
#
|
34
|
-
#
|
42
|
+
# @param [Hash]
|
43
|
+
# Parameters for the API method
|
44
|
+
#
|
45
|
+
# @return [Hash, Array]
|
35
46
|
def commit(action, params = {})
|
36
47
|
unless VALID_ACTIONS.include? action.to_sym
|
37
48
|
raise "Invalid action"
|
@@ -50,9 +61,10 @@ module FannyPack
|
|
50
61
|
#
|
51
62
|
# Returns an Array or Hash depending on the API method called
|
52
63
|
#
|
53
|
-
#
|
64
|
+
# @param [String] data
|
65
|
+
# The XML response from Fantastico
|
54
66
|
#
|
55
|
-
#
|
67
|
+
# @return [Hash, Array]
|
56
68
|
def parse(data)
|
57
69
|
res = find_key_in_hash(Crack::XML.parse(data), 'item')
|
58
70
|
if @action.to_sym == :getIpListDetailed
|
@@ -69,12 +81,16 @@ module FannyPack
|
|
69
81
|
res
|
70
82
|
end
|
71
83
|
|
72
|
-
# Returns true
|
84
|
+
# Returns true if a commit was successful
|
85
|
+
#
|
86
|
+
# @return [Boolean]
|
73
87
|
def success?
|
74
88
|
@success
|
75
89
|
end
|
76
90
|
|
77
91
|
# Builds the SOAP Envelope to be sent to Fantastico for this request
|
92
|
+
#
|
93
|
+
# @return [String]
|
78
94
|
def to_xml
|
79
95
|
xml = Builder::XmlMarkup.new :indent => 2
|
80
96
|
xml.instruct!
|
@@ -95,10 +111,11 @@ module FannyPack
|
|
95
111
|
|
96
112
|
# Finds +index+ in +hash+ by searching recursively
|
97
113
|
#
|
98
|
-
#
|
114
|
+
# @param [Hash] hash
|
115
|
+
# The hash to search
|
99
116
|
#
|
100
|
-
#
|
101
|
-
#
|
117
|
+
# @param index
|
118
|
+
# The hash key to look for
|
102
119
|
def find_key_in_hash(hash, index)
|
103
120
|
hash.each do |key, val|
|
104
121
|
if val.respond_to? :has_key?
|
data/lib/fanny_pack/version.rb
CHANGED
data/lib/fanny_pack.rb
CHANGED
@@ -5,8 +5,12 @@ module FannyPack
|
|
5
5
|
autoload :IP, 'fanny_pack/ip'
|
6
6
|
|
7
7
|
class << self
|
8
|
-
#
|
9
|
-
#
|
8
|
+
# Your Fantastico account hash, used for API authentication
|
9
|
+
#
|
10
|
+
# @param [String] hash
|
11
|
+
# Your Fantastico account hash
|
12
|
+
#
|
13
|
+
# @return [String]
|
10
14
|
attr_accessor :account_hash
|
11
15
|
end
|
12
16
|
|
data/spec/fanny_pack/ip_spec.rb
CHANGED
@@ -21,9 +21,7 @@ describe FannyPack::IP do
|
|
21
21
|
|
22
22
|
describe "::add" do
|
23
23
|
it "raises ArgumentError without IP" do
|
24
|
-
|
25
|
-
FannyPack::IP.add
|
26
|
-
}.to raise_error(ArgumentError)
|
24
|
+
requires_ip { FannyPack::IP.add }
|
27
25
|
end
|
28
26
|
|
29
27
|
it "returns a Hash" do
|
@@ -35,7 +33,7 @@ describe FannyPack::IP do
|
|
35
33
|
|
36
34
|
describe "::edit" do
|
37
35
|
it "raises ArgumentError without IP" do
|
38
|
-
|
36
|
+
requires_ip { FannyPack::IP.edit }
|
39
37
|
end
|
40
38
|
|
41
39
|
it "edits the IP" do
|
@@ -47,7 +45,7 @@ describe FannyPack::IP do
|
|
47
45
|
|
48
46
|
describe "::list" do
|
49
47
|
it "raises ArgumentError without type" do
|
50
|
-
|
48
|
+
requires_ip { FannyPack::IP.list }
|
51
49
|
end
|
52
50
|
|
53
51
|
it "raises error with invalid type" do
|
@@ -79,7 +77,7 @@ describe FannyPack::IP do
|
|
79
77
|
|
80
78
|
describe "::delete" do
|
81
79
|
it "raises ArgumentError without IP" do
|
82
|
-
|
80
|
+
requires_ip { FannyPack::IP.delete }
|
83
81
|
end
|
84
82
|
|
85
83
|
it "deletes the IP" do
|
@@ -94,7 +92,7 @@ describe FannyPack::IP do
|
|
94
92
|
%w[reactivate deactivate].each do |method|
|
95
93
|
describe "::#{method}" do
|
96
94
|
it "raises ArgumentError without IP" do
|
97
|
-
|
95
|
+
requires_ip { FannyPack::IP.send(method) }
|
98
96
|
end
|
99
97
|
|
100
98
|
it "#{method}s the IP" do
|
@@ -110,7 +108,7 @@ describe FannyPack::IP do
|
|
110
108
|
|
111
109
|
describe "::details" do
|
112
110
|
it "raises ArgumentError without IP" do
|
113
|
-
|
111
|
+
requires_ip { FannyPack::IP.details }
|
114
112
|
end
|
115
113
|
|
116
114
|
it "returns a hash of IP details" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: fanny_pack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Joshua Priddle
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-31 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -19,9 +19,9 @@ dependencies:
|
|
19
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
20
20
|
none: false
|
21
21
|
requirements:
|
22
|
-
- -
|
22
|
+
- - ~>
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version:
|
24
|
+
version: 3.0.0
|
25
25
|
type: :runtime
|
26
26
|
version_requirements: *id001
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -30,66 +30,77 @@ dependencies:
|
|
30
30
|
requirement: &id002 !ruby/object:Gem::Requirement
|
31
31
|
none: false
|
32
32
|
requirements:
|
33
|
-
- -
|
33
|
+
- - ~>
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version:
|
35
|
+
version: 0.1.8
|
36
36
|
type: :runtime
|
37
37
|
version_requirements: *id002
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
|
-
name:
|
39
|
+
name: rake
|
40
40
|
prerelease: false
|
41
41
|
requirement: &id003 !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
43
43
|
requirements:
|
44
44
|
- - ~>
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: 0.8.7
|
47
47
|
type: :development
|
48
48
|
version_requirements: *id003
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
|
-
name:
|
50
|
+
name: rspec
|
51
51
|
prerelease: false
|
52
52
|
requirement: &id004 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
54
54
|
requirements:
|
55
55
|
- - ~>
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version:
|
57
|
+
version: 2.6.0
|
58
58
|
type: :development
|
59
59
|
version_requirements: *id004
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
|
-
name:
|
61
|
+
name: fakeweb
|
62
62
|
prerelease: false
|
63
63
|
requirement: &id005 !ruby/object:Gem::Requirement
|
64
64
|
none: false
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 1.3.0
|
69
69
|
type: :development
|
70
70
|
version_requirements: *id005
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
|
-
name:
|
72
|
+
name: awesome_print
|
73
73
|
prerelease: false
|
74
74
|
requirement: &id006 !ruby/object:Gem::Requirement
|
75
75
|
none: false
|
76
76
|
requirements:
|
77
77
|
- - ~>
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version:
|
79
|
+
version: 0.4.0
|
80
80
|
type: :development
|
81
81
|
version_requirements: *id006
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
|
-
name:
|
83
|
+
name: rcov
|
84
84
|
prerelease: false
|
85
85
|
requirement: &id007 !ruby/object:Gem::Requirement
|
86
86
|
none: false
|
87
87
|
requirements:
|
88
88
|
- - ~>
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: "
|
90
|
+
version: "0.9"
|
91
91
|
type: :development
|
92
92
|
version_requirements: *id007
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: metric_fu
|
95
|
+
prerelease: false
|
96
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: "2.1"
|
102
|
+
type: :development
|
103
|
+
version_requirements: *id008
|
93
104
|
description: " Ruby bindings for the Fantastico API\n"
|
94
105
|
email: jpriddle@site5.com
|
95
106
|
executables: []
|