Class: GandiNet::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/gandinet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key = nil, dryrun: true) ⇒ Client

Returns a new instance of Client.



16
17
18
19
20
# File 'lib/gandinet.rb', line 16

def initialize(key=nil, dryrun:true)
  puts "Please provide an API Key." unless key
  @key = key
  @dryrun = dryrun
end

Instance Attribute Details

#dryunObject

Returns the value of attribute dryun.



15
16
17
# File 'lib/gandinet.rb', line 15

def dryun
  @dryun
end

#keyObject

Returns the value of attribute key.



14
15
16
# File 'lib/gandinet.rb', line 14

def key
  @key
end

Instance Method Details

#create(fqdn, given, family, country, streetaddr, orgname, email, phone, zip, city) ⇒ Object

client.create(“…”,“…”,…)



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gandinet.rb', line 31

def create(fqdn,given,family,country,streetaddr,orgname,email,phone,zip,city)
  url = URI("https://api.gandi.net/v5/domain/domains")
  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true
  request = Net::HTTP::Post.new(url)
  request["authorization"] = "Apikey #{key}"
  request["dry-run"] = "1" if @dryrun
  request["content-type"] = 'application/json'
  #puts { fqdn: fqdn, owner: { given: given, family: family, country: country, streetaddr: streetaddr, type: "1", orgname: orgname, email: email, phone: phone, zip: zip, city: city}}.to_json
  request.body = "{\"fqdn\":\"#{fqdn}\",\"owner\":{\"given\":\"#{given}\",\"family\":\"#{family}\",\"country\":\"#{country}\",\"streetaddr\":\"#{streetaddr}\",\"type\":1,\"orgname\":\"#{orgname}\",\"email\":\"#{email}\",\"phone\":\"#{phone}\",\"zip\":\"#{zip}\",\"city\":\"#{city}\"}}"
  response = http.request(request)
  JSON.parse(response.read_body)
end

#domainsObject



21
22
23
24
25
26
27
28
29
# File 'lib/gandinet.rb', line 21

def domains
  url = URI("https://api.gandi.net/v5/domain/domains")
  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true
  request = Net::HTTP::Get.new(url)
  request["authorization"] = "Apikey #{key}"
  response = http.request(request)
  JSON.parse(response.read_body)
end

#info(fqdn) ⇒ Object

client.info(“fqdn”)



45
46
47
48
49
50
51
52
53
# File 'lib/gandinet.rb', line 45

def info(fqdn)
  url = URI("https://api.gandi.net/v5/domain/domains/#{fqdn}")
  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true
  request = Net::HTTP::Get.new(url)
  request["authorization"] = "Apikey #{key}"
  response = http.request(request)
  JSON.parse(response.read_body)
end