gandi 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03cabc205450daa43e8823cbe616881362d2452c
4
- data.tar.gz: 583cd1c60f49f56658b8516977096b06b18bc332
3
+ metadata.gz: d0f56a4da17599f294e2585cefc0fe2b57578e7f
4
+ data.tar.gz: 954d58aabef46fc4aa89f1fb4b5218485529a72b
5
5
  SHA512:
6
- metadata.gz: 197f1ee4200c4bc6f99890f50c0bb7c158533b02babef3a83b09165597e244cf369c520596579a199a687f97e63806ed2755771547477f530ba9fca001225f73
7
- data.tar.gz: 49c05a69c7be1e4c97b5078f9180fad4e233c6343b9fc504ccf3eacb9a6c83d813e78754ab13efff6542034379a073faf0741a652e2e202237aa54bed85577bb
6
+ metadata.gz: 0439ee26dd62e7694cc619c2fbf82f96acb2849bd075d75021e745b9ef8f3c99583445fdc003a3e5b455fdf4a7abf410a845efa2907bf89f22df7079934af05f
7
+ data.tar.gz: 57c9b39b504e7f790fab6993c902d93b84d62925adf53aa06e75b804e8d74abcd78ba07ce9cae46c4e08da3d0ebca7cf0b9243a1239d6af3a392564d17c1acfb
data/README.md CHANGED
@@ -48,6 +48,23 @@ api.domain.list
48
48
 
49
49
  For further information see the Gandi API documention at http://doc.rpc.gandi.net/
50
50
 
51
+ ### Fault codes
52
+
53
+ When the XMLRPC call returns an error, an exception is raised.
54
+ `Gandi::DataError` is raised if the error is due to faulty user input and `Gandi::ServerError` is raised if it is caused by a server-side internal error.
55
+
56
+ All the possible fault codes can be found in [Gandi API manual](http://doc.rpc.gandi.net/errors/fault_codes.html).
57
+
58
+ Both exceptions contain a `Gandi::FaultCode` object which stores the object name and the cause of the error:
59
+ ```ruby
60
+ fault_code = Gandi::FaultCode.parse(505237)
61
+ # => #<Gandi::FaultCode::Data:...>
62
+ fault_code.object
63
+ # => :object_fqdn
64
+ fault_code.cause
65
+ # => :cause_badparameter
66
+ ```
67
+
51
68
  ## Contributing
52
69
 
53
70
  1. Fork it
@@ -5,6 +5,7 @@ require 'hashie'
5
5
  require 'xmlrpc/client'
6
6
  require 'gandi/session'
7
7
  require 'gandi/errors'
8
+ require 'gandi/fault_code'
8
9
 
9
10
  module Gandi
10
11
  VERSION = '2.1.1'
@@ -1,4 +1,14 @@
1
1
  module Gandi
2
- class DataError < ArgumentError ; end
3
- class ServerError < RuntimeError ; end
4
- end
2
+ class FaultCodeError < StandardError
3
+ attr_reader :fault_code
4
+
5
+ def initialize(msg, fault_code)
6
+ super msg
7
+ @fault_code = fault_code
8
+ end
9
+ end
10
+
11
+ class DataError < FaultCodeError; end
12
+ class ServerError < FaultCodeError; end
13
+ class UnknownError < FaultCodeError; end
14
+ end
@@ -0,0 +1,30 @@
1
+ require 'gandi/fault_code/data'
2
+ require 'gandi/fault_code/server'
3
+ require 'gandi/fault_code/unknown'
4
+
5
+ module Gandi
6
+ class FaultCode
7
+ QUALIF = {Server::QUALIF => Server, Data::QUALIF => Data}
8
+
9
+ def self.parse(code, msg = nil)
10
+ qualif = code / 100000
11
+ object = code % 100000 / 100
12
+ cause = code % 100
13
+
14
+ klass = QUALIF.key?(qualif) ? QUALIF[qualif] : Unknown
15
+ klass.new(object, cause, msg)
16
+ end
17
+
18
+ attr_reader :object, :cause, :msg
19
+
20
+ def initialize(object, cause, msg = nil)
21
+ @object = self.class::OBJECT[object] || :object_invalid
22
+ @cause = self.class::CAUSE[cause] || :cause_invalid
23
+ @msg = msg
24
+ end
25
+
26
+ def exception
27
+ self.class::ERROR.new(msg, self)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,238 @@
1
+ module Gandi
2
+ class FaultCode
3
+ class Data < FaultCode
4
+ QUALIF = 5
5
+ ERROR = Gandi::DataError
6
+
7
+ OBJECT = {
8
+ 0 => :object_unknown,
9
+ 1 => :object_password,
10
+ 2 => :object_session,
11
+ 3 => :object_login,
12
+ 10 => :object_integer,
13
+ 11 => :object_boolean,
14
+ 12 => :object_string,
15
+ 13 => :object_date,
16
+ 14 => :object_list,
17
+ 15 => :object_struct,
18
+ 16 => :object_method,
19
+ 17 => :object_key,
20
+ 18 => :object_float,
21
+ 19 => :object_duration,
22
+ 50 => :object_email,
23
+ 51 => :object_url,
24
+ 52 => :object_fqdn,
25
+ 53 => :object_ipv4,
26
+ 54 => :object_web_redirection,
27
+ 55 => :object_transfer,
28
+ 56 => :object_transferout,
29
+ 57 => :object_ipv6,
30
+ 58 => :object_cidr,
31
+ 100 => :object_domain,
32
+ 101 => :object_account,
33
+ 102 => :object_operation,
34
+ 103 => :object_mailbox,
35
+ 104 => :object_forward,
36
+ 105 => :object_mailzone,
37
+ 106 => :object_host,
38
+ 107 => :object_status,
39
+ 108 => :object_dnssec_key,
40
+ 109 => :object_mail,
41
+ 110 => :object_reachability,
42
+ 111 => :object_claims,
43
+ 140 => :object_company_name,
44
+ 141 => :object_body_name,
45
+ 142 => :object_association_name,
46
+ 150 => :object_phone,
47
+ 151 => :object_french_department,
48
+ 152 => :object_country_code,
49
+ 153 => :object_contact_type,
50
+ 154 => :object_contact_class,
51
+ 155 => :object_iso_language,
52
+ 156 => :object_contact_lang,
53
+ 157 => :object_state_code,
54
+ 160 => :object_auth_code,
55
+ 161 => :object_contact,
56
+ 162 => :object_corpo,
57
+ 163 => :object_lang,
58
+ 164 => :object_registry,
59
+ 165 => :object_eoi,
60
+ 166 => :object_tld,
61
+ 167 => :object_phase,
62
+ 168 => :object_changeowner,
63
+ 169 => :object_reseller,
64
+ 170 => :object_sudo,
65
+ 200 => :object_redirection_type,
66
+ 201 => :object_buyrenew_period,
67
+ 210 => :object_autorenew,
68
+ 211 => :object_prepaid,
69
+ 212 => :object_transaction,
70
+ 220 => :object_packmail,
71
+ 230 => :object_document,
72
+ 231 => :object_documentrequest,
73
+ 232 => :object_ssl,
74
+ 233 => :object_country,
75
+ 234 => :object_auto_credit,
76
+ 235 => :object_smd,
77
+ 236 => :object_zip,
78
+ 237 => :object_goodie,
79
+ 238 => :object_autofoa,
80
+ 239 => :object_delete,
81
+ 240 => :object_foa,
82
+ 250 => :object_operation_state,
83
+ 251 => :object_operation_type,
84
+ 252 => :object_operation_event,
85
+ 300 => :object_hosting_account,
86
+ 302 => :object_vm,
87
+ 303 => :object_meta,
88
+ 304 => :object_disk,
89
+ 305 => :object_os,
90
+ 306 => :object_meta_conf,
91
+ 307 => :object_vm_conf,
92
+ 308 => :object_vm_ip,
93
+ 309 => :object_vm_shares,
94
+ 310 => :object_flex,
95
+ 311 => :object_flex_shares,
96
+ 312 => :object_flex_date_start,
97
+ 313 => :object_flex_date_end,
98
+ 314 => :object_flex_op,
99
+ 315 => :object_flex_action,
100
+ 316 => :object_vm_trigger,
101
+ 317 => :object_iface,
102
+ 318 => :object_ip,
103
+ 319 => :object_bandwidth,
104
+ 320 => :object_lb,
105
+ 321 => :object_lbserver,
106
+ 322 => :object_lbfarm,
107
+ 323 => :object_lblistener,
108
+ 324 => :object_snapshot,
109
+ 325 => :object_image,
110
+ 326 => :object_lbconfiglistener,
111
+ 327 => :object_datacenter,
112
+ 350 => :object_hosting_account_status,
113
+ 351 => :object_hosting_product,
114
+ 375 => :object_paas,
115
+ 376 => :object_virtualhost,
116
+ 377 => :object_vlan,
117
+ 378 => :object_snapshot_profile,
118
+ 379 => :object_rproxy,
119
+ 401 => :object_certificate,
120
+ 402 => :object_csr,
121
+ 403 => :object_package,
122
+ 404 => :object_cn,
123
+ 405 => :object_wildcard,
124
+ 406 => :object_altname,
125
+ 407 => :object_joi,
126
+ 408 => :object_cert_ida,
127
+ 409 => :object_dcv,
128
+ 600 => :object_site,
129
+ 601 => :object_site_host,
130
+ 602 => :object_gandi_site_host,
131
+ 603 => :object_user,
132
+ 604 => :object_sitemaker_error,
133
+ 605 => :object_site_host_ip,
134
+ 606 => :object_site_offer,
135
+ 607 => :object_site_name,
136
+ 608 => :object_site_count,
137
+ 609 => :object_sitemaker_connection,
138
+ 609 => :object_site_key,
139
+ 700 => :object_tva,
140
+ 701 => :object_currency,
141
+ 702 => :object_catalog_entry,
142
+ 703 => :object_promo_code,
143
+ 704 => :object_coupon_code,
144
+ 705 => :object_pricer_duration,
145
+ 706 => :object_pricer_quantity,
146
+ 707 => :object_refund,
147
+ 708 => :object_fee,
148
+ 709 => :object_bill_item,
149
+ 710 => :object_product,
150
+ 711 => :object_bill,
151
+ 712 => :object_payment,
152
+ 713 => :object_action_type,
153
+ 714 => :object_description,
154
+ 715 => :object_quantity,
155
+ 716 => :object_contact_pref,
156
+ 717 => :object_domain_pref,
157
+ 718 => :object_contract,
158
+ 719 => :object_totp,
159
+ 720 => :object_postit,
160
+ 721 => :object_postit_object_type,
161
+ 722 => :object_business_unit,
162
+ 723 => :object_grid,
163
+ 724 => :object_paymenttype,
164
+ 800 => :object_dns_cname,
165
+ 801 => :object_dns_txt,
166
+ 802 => :object_dns_address,
167
+ 803 => :object_dns_a,
168
+ 804 => :object_dns_aaaa,
169
+ 805 => :object_dns_mx,
170
+ 806 => :object_dns_spf,
171
+ 810 => :object_zone,
172
+ 811 => :object_dns_record,
173
+ }
174
+ CAUSE = {
175
+ 0 => :cause_unknown,
176
+ 1 => :cause_no_kernel,
177
+ 2 => :cause_cmdline_opt,
178
+ 10 => :cause_type,
179
+ 20 => :cause_syntax,
180
+ 23 => :cause_corporate,
181
+ 30 => :cause_value,
182
+ 31 => :cause_size,
183
+ 32 => :cause_expected,
184
+ 33 => :cause_unexpected,
185
+ 34 => :cause_identical,
186
+ 35 => :cause_quota_reached,
187
+ 36 => :cause_name,
188
+ 37 => :cause_badparameter,
189
+ 38 => :cause_hostname,
190
+ 39 => :cause_attached,
191
+ 40 => :cause_dontexist,
192
+ 41 => :cause_exist,
193
+ 42 => :cause_notfound,
194
+ 43 => :cause_no_result,
195
+ 44 => :cause_nothing_to_update,
196
+ 45 => :cause_position,
197
+ 46 => :cause_no_disk,
198
+ 47 => :cause_invalid_phase,
199
+ 48 => :cause_conf,
200
+ 49 => :cause_expired,
201
+ 50 => :cause_noright,
202
+ 51 => :cause_datacenter,
203
+ 52 => :cause_multiple_results,
204
+ 53 => :cause_query,
205
+ 54 => :cause_disabled,
206
+ 55 => :cause_price,
207
+ 56 => :cause_authinfo,
208
+ 60 => :cause_state,
209
+ 61 => :cause_order_not_done,
210
+ 62 => :cause_billed,
211
+ 63 => :cause_not_enough_money,
212
+ 64 => :cause_currency_mismatch,
213
+ 65 => :cause_quantity_or_period_null,
214
+ 66 => :cause_failure,
215
+ 67 => :cause_pending,
216
+ 68 => :cause_running,
217
+ 69 => :cause_attached_running,
218
+ 70 => :cause_incompatibility,
219
+ 71 => :cause_vm_meta_incompatibility,
220
+ 72 => :cause_os_meta_incompatibility,
221
+ 73 => :cause_metas_incompatibility,
222
+ 74 => :cause_vmshares_meta_incompatibility,
223
+ 75 => :cause_meta_dependencies,
224
+ 81 => :cause_not_configured,
225
+ 90 => :cause_invalid_step,
226
+ 91 => :cause_invalid,
227
+ 92 => :cause_invalid_resource,
228
+ 93 => :cause_currency,
229
+ 94 => :cause_epperror,
230
+ 95 => :cause_cannot_shrink,
231
+ 96 => :cause_ip_version_mismatch,
232
+ 97 => :cause_version,
233
+ 98 => :cause_not_attached,
234
+ 99 => :cause_toomany,
235
+ }
236
+ end
237
+ end
238
+ end
@@ -0,0 +1,27 @@
1
+ module Gandi
2
+ class FaultCode
3
+ class Server < FaultCode
4
+ QUALIF = 1
5
+ ERROR = Gandi::ServerError
6
+
7
+ OBJECT = {
8
+ 0 => :object_unknown,
9
+ 100 => :object_database,
10
+ 200 => :object_registries,
11
+ 300 => :object_network,
12
+ 400 => :object_system,
13
+ 500 => :object_application,
14
+ 600 => :object_service,
15
+ 601 => :object_comodo_api,
16
+ }
17
+ CAUSE = {
18
+ 0 => :cause_unknown,
19
+ 4 => :cause_toomany,
20
+ 5 => :cause_unavailable,
21
+ 10 => :cause_connection,
22
+ 20 => :cause_query,
23
+ 30 => :cause_conf,
24
+ }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ module Gandi
2
+ class FaultCode
3
+ class Unknown < FaultCode
4
+ ERROR = Gandi::UnknownError
5
+
6
+ OBJECT = {}
7
+ CAUSE = {}
8
+ end
9
+ end
10
+ end
@@ -181,7 +181,12 @@ module Gandi
181
181
  self.chained << method
182
182
  method_name = chained.join(".")
183
183
  if Gandi::VALID_METHODS.include?(method_name)
184
- res = self.server.call(method_name, api_key, *args)
184
+ begin
185
+ res = self.server.call(method_name, api_key, *args)
186
+ rescue XMLRPC::FaultException => e
187
+ raise Gandi::FaultCode.parse(e.faultCode, e.faultString).exception
188
+ end
189
+
185
190
  if res.is_a?(Array)
186
191
  res.collect! { |x| x.is_a?(Hash) ? Hashie::Mash.new(x) : x }
187
192
  elsif res.is_a?(Hash)
@@ -222,8 +227,6 @@ module Gandi
222
227
 
223
228
  def method_missing(method, *args)
224
229
  ProxyCall.new(@server, self.api_key).send(method, *args)
225
- rescue XMLRPC::FaultException => exception
226
- raise(exception.faultCode < 500_000 ? Gandi::ServerError : Gandi::DataError, exception.faultString)
227
230
  end
228
231
  end
229
232
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gandi
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olivier Ruffin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-26 00:00:00.000000000 Z
11
+ date: 2015-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -33,6 +33,10 @@ files:
33
33
  - README.md
34
34
  - lib/gandi.rb
35
35
  - lib/gandi/errors.rb
36
+ - lib/gandi/fault_code.rb
37
+ - lib/gandi/fault_code/data.rb
38
+ - lib/gandi/fault_code/server.rb
39
+ - lib/gandi/fault_code/unknown.rb
36
40
  - lib/gandi/session.rb
37
41
  homepage: https://github.com/veilleperso/gandi
38
42
  licenses:
@@ -54,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
58
  version: '0'
55
59
  requirements: []
56
60
  rubyforge_project:
57
- rubygems_version: 2.2.2
61
+ rubygems_version: 2.2.3
58
62
  signing_key:
59
63
  specification_version: 4
60
64
  summary: Gandi XML RPC API v3