This repository has been archived by the owner on Jun 6, 2018. It is now read-only.
forked from jerome/gandi
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First release. Works great on the Gandi testing platform
- Loading branch information
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |