gandi 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README +30 -27
  2. data/lib/gandi.rb +2 -13
  3. data/lib/gandi/session.rb +152 -39
  4. metadata +32 -43
data/README CHANGED
@@ -1,31 +1,34 @@
1
+ DOCUMENTATION
2
+ =============
3
+
4
+ See https://rpc.ote.gandi.net/doc/2.0/
5
+
6
+ API endpoint:
7
+
8
+ * Test: https://rpc.ote.gandi.net/xmlrpc/
9
+ * Production: https://rpc.gandi.net/xmlrpc/
10
+
11
+ Feel free to fork it and fix it you need to.
12
+
1
13
  USAGE
2
14
  =====
3
15
 
4
16
  require 'gandi'
5
- session = Gandi::Session.connect(:login => "FO1234-GANDI", :password => "foobar")
6
-
7
- session.password("new_password")
8
- session.domain_list
9
- session.account_balance
10
-
11
- domain = "example.org"
12
- period = 1
13
- owner_handle = "AA1234-GANDI"
14
- admin_handle = "BB2345-GANDI"
15
- tech_handle = "CC3456-GANDI"
16
- billing_handle = "DD4567-GANDI"
17
- ns_list = ["ns1.example.net", "ns2.example.net", "ns1.example.com"]
18
-
19
- operation = session.domain_create( domain, period,
20
- owner_handle, admin_handle,
21
- tech_handle, billing_handle,
22
- ns_list)
23
-
24
- session.operation_list :state => "PENDING"
25
-
26
- TODO
27
- ====
28
- Tests
29
- Gem release
30
- Argument checking for all Gandi methods
31
- Documentation
17
+
18
+ # test env
19
+ api = Gandi::Session.new("24-character API key", "https://rpc.ote.gandi.net/xmlrpc/")
20
+
21
+ api.domain.list
22
+ api.domain.info('mydomain.com')
23
+ api.hosting.list
24
+ api.catalog.list(product: {type: 'domains'})
25
+ ...
26
+
27
+
28
+ # production env
29
+ api = Gandi::Session.new("24-character API key")
30
+ api.domain.list
31
+ api.domain.info('mydomain.com')
32
+ api.hosting.list
33
+ api.catalog.list(product: {type: 'domains'})
34
+ ...
data/lib/gandi.rb CHANGED
@@ -3,22 +3,11 @@
3
3
  $:.unshift(File.dirname(__FILE__)) unless
4
4
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
5
5
 
6
+ require 'hashie'
6
7
  require 'xmlrpc/client'
7
8
  require 'gandi/session'
8
9
  require 'gandi/errors'
9
10
 
10
- # Gandi/Ruby Library
11
- #
12
- # Author:: Jérôme Lipowicz (mailto:jerome@yayel.com)
13
- # License:: MIT License
14
-
15
- class Array
16
- # from ActiveSupport::CoreExtensions::Array::ExtractOptions
17
- def extract_options!
18
- last.is_a?(::Hash) ? pop : {}
19
- end
20
- end
21
-
22
11
  module Gandi
23
- VERSION = '1.0.0'
12
+ VERSION = '2.0.0'
24
13
  end
data/lib/gandi/session.rb CHANGED
@@ -1,48 +1,161 @@
1
1
  module Gandi
2
-
3
- class Session
4
- HOST = "https://api.gandi.net/xmlrpc/"
5
-
6
- attr_reader :handler, :session_id
2
+ VALID_METHODS = %w(
3
+ catalog.list
4
+ contact.balance
5
+ contact.can_associate
6
+ contact.can_associate_domain
7
+ contact.create
8
+ contact.info
9
+ contact.list
10
+ contact.update
11
+ datacenter.list
12
+ domain.available
13
+ domain.contacts.set
14
+ domain.count
15
+ domain.create
16
+ domain.forward.count
17
+ domain.forward.create
18
+ domain.forward.delete
19
+ domain.forward.list
20
+ domain.forward.update
21
+ domain.host.count
22
+ domain.host.create
23
+ domain.host.delete
24
+ domain.host.info
25
+ domain.host.list
26
+ domain.host.update
27
+ domain.info
28
+ domain.list
29
+ domain.mailbox.alias.set
30
+ domain.mailbox.count
31
+ domain.mailbox.create
32
+ domain.mailbox.delete
33
+ domain.mailbox.info
34
+ domain.mailbox.list
35
+ domain.mailbox.purge
36
+ domain.mailbox.responder.activate
37
+ domain.mailbox.responder.deactivate
38
+ domain.mailbox.update
39
+ domain.nameservers.set
40
+ domain.packmail.autorenew
41
+ domain.packmail.create
42
+ domain.packmail.delete
43
+ domain.packmail.info
44
+ domain.packmail.renew
45
+ domain.packmail.update
46
+ domain.renew
47
+ domain.status.lock
48
+ domain.status.unlock
49
+ domain.tld.list
50
+ domain.tld.region
51
+ domain.transferin.proceed
52
+ domain.webredir.count
53
+ domain.webredir.create
54
+ domain.webredir.delete
55
+ domain.webredir.list
56
+ domain.webredir.update
57
+ domain.zone.clone
58
+ domain.zone.count
59
+ domain.zone.create
60
+ domain.zone.delete
61
+ domain.zone.info
62
+ domain.zone.list
63
+ domain.zone.record.add
64
+ domain.zone.record.count
65
+ domain.zone.record.delete
66
+ domain.zone.record.list
67
+ domain.zone.record.set
68
+ domain.zone.set
69
+ domain.zone.update
70
+ domain.zone.version.delete
71
+ domain.zone.version.new
72
+ domain.zone.version.set
73
+ hosting.datacenter.list
74
+ hosting.disk.count
75
+ hosting.disk.create
76
+ hosting.disk.create_from
77
+ hosting.disk.delete
78
+ hosting.disk.info
79
+ hosting.disk.list
80
+ hosting.disk.list_kernels
81
+ hosting.disk.list_options
82
+ hosting.disk.rollback_from
83
+ hosting.disk.update
84
+ hosting.iface.count
85
+ hosting.iface.create
86
+ hosting.iface.delete
87
+ hosting.iface.info
88
+ hosting.iface.ip_attach
89
+ hosting.iface.ip_detach
90
+ hosting.iface.list
91
+ hosting.iface.update
92
+ hosting.image.info
93
+ hosting.image.list
94
+ hosting.ip.count
95
+ hosting.ip.create
96
+ hosting.ip.delete
97
+ hosting.ip.info
98
+ hosting.ip.list
99
+ hosting.ip.update
100
+ hosting.vm.count
101
+ hosting.vm.create
102
+ hosting.vm.create_from
103
+ hosting.vm.delete
104
+ hosting.vm.disk_attach
105
+ hosting.vm.disk_detach
106
+ hosting.vm.disk_rollback
107
+ hosting.vm.iface_attach
108
+ hosting.vm.iface_detach
109
+ hosting.vm.info
110
+ hosting.vm.list
111
+ hosting.vm.reboot
112
+ hosting.vm.start
113
+ hosting.vm.stop
114
+ hosting.vm.update
115
+ operation.count
116
+ operation.info
117
+ operation.list
118
+ )
7
119
 
8
- def initialize(login, password, host, safe_mode = true)
9
- @login = login
10
- @password = password
11
- @host = host
12
- @safe_mode = safe_mode
13
- end
14
-
15
- def connect
16
- @handler = XMLRPC::Client.new2(@host)
17
- @session_id = call("login", @login, @password, @safe_mode)
18
- end
19
- alias login connect
20
-
21
- def call(*args)
22
- raise LoadError, "no connexion handler is set." unless @handler.is_a?(XMLRPC::Client)
23
- @handler.call(*args)
24
- rescue XMLRPC::FaultException => exception
25
- raise ( exception.faultCode < 500000 ? Gandi::ServerError : Gandi::DataError ), exception.faultString
120
+ class ProxyCall
121
+ attr_accessor :server, :api_key, :chained
122
+
123
+ def initialize(server, api_key)
124
+ self.server = server
125
+ self.api_key = api_key
126
+ self.chained = []
127
+ self
26
128
  end
27
-
129
+
28
130
  def method_missing(method, *args)
29
- if %w(password account_currency account_balance domain_list domain_available domain_lock domain_unlock domain_info domain_renew domain_create domain_restore domain_del domain_transfer_in_available domain_transfer_in domain_transfer_out domain_trade domain_change_owner domain_change_contact domain_ns_list domain_ns_add domain_ns_del domain_ns_set host_list host_info host_create host_delete domain_gandimail_activate domain_gandimail_deactivate domain_forward_list domain_forward_set domain_forward_delete domain_mailbox_list domain_mailbox_info domain_mailbox_add domain_mailbox_update domain_mailbox_delete domain_mailbox_alias_list domain_mailbox_alias_set domain_mailbox_purge domain_web_redir_list domain_web_redir_add domain_web_redir_del contact_create contact_update contact_del contact_info operation_list operation_details operation_relaunch operation_cancel tld_list).include?(method.to_s)
30
- call(method, @session_id, *args)
131
+ self.chained << method
132
+ method_name = chained.join(".")
133
+ if Gandi::VALID_METHODS.include?(method_name)
134
+ # puts "CALL: #{method_name} - #{api_key} - #{args.inspect}"
135
+ res = self.server.call(method_name, api_key, *args)
136
+ if res.is_a?(Array)
137
+ res.collect! { |x| x.is_a?(Hash) ? Hashie::Mash.new(x) : x }
138
+ else
139
+ Hashie::Mash.new(res)
140
+ end
31
141
  else
32
- raise NoMethodError, "method #{method} is not available in the GANDI API."
142
+ self
33
143
  end
34
144
  end
35
-
36
- # Accepted arguments are:
37
- # :host, :login, :password and :safe_mode (defaults to true)
38
- def self.connect(*args)
39
- config = { :host => HOST, :safe_mode => true }.merge(args.extract_options!)
40
- unless config[:login] && config[:password]
41
- raise ArgumentError, "login and password needed"
42
- end
43
- client = self.new(config[:login], config[:password], config[:host], config[:safe_mode])
44
- client.connect
45
- return client
145
+ end
146
+
147
+ class Session
148
+ attr_reader :api_key
149
+
150
+ def initialize(api_key, endpoint = "https://rpc.gandi.net/xmlrpc/")
151
+ @api_key = api_key
152
+ @server = XMLRPC::Client.new2(endpoint)
153
+ end
154
+
155
+ def method_missing(method, *args)
156
+ ProxyCall.new(@server, self.api_key).send(method, *args)
157
+ rescue XMLRPC::FaultException => exception
158
+ raise(exception.faultCode < 500000 ? Gandi::ServerError : Gandi::DataError, exception.faultString)
46
159
  end
47
160
  end
48
- end
161
+ end
metadata CHANGED
@@ -1,70 +1,59 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gandi
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 0
10
- version: 1.0.0
11
6
  platform: ruby
12
- authors: []
13
-
7
+ authors:
8
+ - Olivier Ruffin
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-02-26 00:00:00 +01:00
19
- default_executable:
20
- dependencies: []
21
-
12
+ date: 2012-03-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hashie
16
+ requirement: &70111286048400 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70111286048400
22
25
  description: Wrapper around gandi xml-rpc API
23
26
  email:
24
27
  executables: []
25
-
26
28
  extensions: []
27
-
28
29
  extra_rdoc_files: []
29
-
30
- files:
30
+ files:
31
31
  - README
32
32
  - lib/gandi/errors.rb
33
33
  - lib/gandi/session.rb
34
34
  - lib/gandi.rb
35
- has_rdoc: true
36
35
  homepage: https://github.com/veilleperso/gandi
37
36
  licenses: []
38
-
39
37
  post_install_message:
40
38
  rdoc_options: []
41
-
42
- require_paths:
39
+ require_paths:
43
40
  - lib
44
- required_ruby_version: !ruby/object:Gem::Requirement
41
+ required_ruby_version: !ruby/object:Gem::Requirement
45
42
  none: false
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- hash: 3
50
- segments:
51
- - 0
52
- version: "0"
53
- required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
48
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
62
53
  requirements: []
63
-
64
54
  rubyforge_project:
65
- rubygems_version: 1.5.2
55
+ rubygems_version: 1.8.11
66
56
  signing_key:
67
57
  specification_version: 3
68
- summary: Gandi XML RPC API
58
+ summary: Gandi XML RPC API v2.0
69
59
  test_files: []
70
-