Module: DomainAPI

Defined in:
lib/domainapi.rb

Defined Under Namespace

Classes: BadRequestException, InternalServerErrorException, NoDomainException, NotAuthorizedException, NotFoundException, ServiceException, ServiceUnavailableException, UnknownException, WrongParmatersException

Constant Summary collapse

HOST =

Defaut HOST for the request

"api.domainapi.com"
PORT =

Default PORT for the request

"80"
VERSION =

Default VERSION for the request

"v1"
FORMAT =

Default FORMAT for the request

"json"

Class Method Summary collapse

Class Method Details

.as(format) ⇒ Object

change the format of the response (only XML or JSON)



42
43
44
45
# File 'lib/domainapi.rb', line 42

def self.as(format)     
  @format = format
  self
end

.doObject

check first, raise exception if needed, execute the HTTP request



88
89
90
91
92
# File 'lib/domainapi.rb', line 88

def self.do
  self.validate
  self.build_url
  self.do_request
end

.execute(params = {}) ⇒ Object

Alias to make a request with only one hash



70
71
72
73
# File 'lib/domainapi.rb', line 70

def self.execute(params={})
  self.prepare(params)    
  self.on     params[:on] if params[:on]    
end

.get(service) ⇒ Object

Select which service must be called for this request



36
37
38
39
# File 'lib/domainapi.rb', line 36

def self.get(service)    
  @service = service
  self
end

.on(domain, execute = true) ⇒ Object

Param of the request, usually a domain name or sometime the first part of a domain



63
64
65
66
67
# File 'lib/domainapi.rb', line 63

def self.on(domain,execute=true)
  @domain = domain
  return self.do if execute
  self
end

.prepare(params = {}) ⇒ Object

used to set data but don’t start the request



76
77
78
79
80
81
82
83
84
85
# File 'lib/domainapi.rb', line 76

def self.prepare(params={})
  raise DomainAPI::WrongParmatersException unless params.kind_of? Hash
  self.use    params[:auth] if params[:auth] 
  self.get    params[:service] if params[:service]
  self.as     params[:format] if params[:format] 
  self.where  params[:options] if params[:options] 
  self.with   params[:with] if params[:with]
  self.on(params[:on],false) if params[:on]
  self
end

.use(username, password = false) ⇒ Object

Authentication of the user



26
27
28
29
30
31
32
33
# File 'lib/domainapi.rb', line 26

def self.use(username,password=false)
  if username.kind_of? Hash
     @username,@password = username[:username],username[:password]
  else
    @username, @password = username, password
  end
  self
end

.where(options) ⇒ Object

to specify options to the service



48
49
50
51
52
# File 'lib/domainapi.rb', line 48

def self.where(options)    
  @options = options
  @options = self.vars_hash_to_string(@options) if @options.kind_of? Hash
  self
end

.with(settings = {}) ⇒ Object

to overide settings, only for specific cases or for testing



55
56
57
58
59
60
# File 'lib/domainapi.rb', line 55

def self.with(settings={})
  @host     = settings[:host] ? settings[:host] : HOST
  @port     = settings[:port] ? settings[:port] : PORT
  @version  = settings[:version] ? settings[:version] : VERSION
  self
end