Skip to content
This repository has been archived by the owner on Jun 6, 2018. It is now read-only.

Commit

Permalink
First release. Works great on the Gandi testing platform
Browse files Browse the repository at this point in the history
  • Loading branch information
jerome committed Mar 4, 2009
1 parent eedf639 commit 8decfc3
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
USAGE
=====

require 'gandi'
session = Gandi::Session.connect(:login => "FO1234-GANDI", :password => "foobar")

session.password("new_password")
session.domain_list
session.account_balance

domain = "example.org"
period = 1
owner_handle = "AA1234-GANDI"
admin_handle = "BB2345-GANDI"
tech_handle = "CC3456-GANDI"
billing_handle = "DD4567-GANDI"
ns_list = ["ns1.example.net", "ns2.example.net", "ns1.example.com"]

operation = session.domain_create( domain, period,
owner_handle, admin_handle,
tech_handle, billing_handle,
ns_list)

session.operation_list :state => "PENDING"

TODO
====
Tests
Gem release
Argument checking for all Gandi methods
Documentation
24 changes: 24 additions & 0 deletions lib/gandi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Add the directory containing this file to the start of the load path if it
# isn't there already.
$:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))

require 'xmlrpc/client'
require 'gandi/session'
require 'gandi/errors'

# Gandi/Ruby Library
#
# Author:: Jérôme Lipowicz (mailto:[email protected])
# License:: MIT License

class Array
# from ActiveSupport::CoreExtensions::Array::ExtractOptions
def extract_options!
last.is_a?(::Hash) ? pop : {}
end
end

module Gandi
VERSION = '1.0.0'
end
4 changes: 4 additions & 0 deletions lib/gandi/errors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Gandi
class DataError < ArgumentError ; end
class ServerError < RuntimeError ; end
end
44 changes: 44 additions & 0 deletions lib/gandi/session.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module Gandi
class Session
HOST = "https://api.gandi.net/xmlrpc/"

attr_reader :handler, :session_id

def initialize(login, password, host)
@login = login
@password = password
@host = host
end

def connect
@handler = XMLRPC::Client.new2(@host)
@session_id = call("login", @login, @password)
end
alias login connect

def call(*args)
raise LoadError, "no connexion handler is set." unless @handler.is_a?(XMLRPC::Client)
@handler.call(*args)
rescue XMLRPC::FaultException => exception
raise ( exception.faultCode < 500000 ? Gandi::ServerError : Gandi::DataError ), exception.faultString
end

def method_missing(method, *args)
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)
call(method, @session_id, *args)
else
raise NoMethodError, "method #{method} is not available in the GANDI API."
end
end

def self.connect(*args)
config = { :host => HOST }.merge(args.extract_options!)
unless config[:login] && config[:password]
raise ArgumentError, "login and password needed"
end
client = self.new(config[:login], config[:password], config[:host])
client.connect
return client
end
end
end

0 comments on commit 8decfc3

Please sign in to comment.