class OneAndOne::PublicIP
Attributes
id[RW]
specs[RW]
Public Class Methods
new(test: false)
click to toggle source
# File lib/1and1/public_ip.rb, line 11 def initialize(test: false) @id = nil @specs = nil # Check if hitting mock api or live api if test @connection = Excon.new($base_url, :mock => true) else @connection = Excon.new($base_url) end end
Public Instance Methods
create(reverse_dns: nil, type: nil, datacenter_id: nil)
click to toggle source
# File lib/1and1/public_ip.rb, line 57 def create(reverse_dns: nil, type: nil, datacenter_id: nil) # Build POST body new_ip = { 'reverse_dns' => reverse_dns, 'type' => type, 'datacenter_id' => datacenter_id } # Clean out null keys in POST body body = OneAndOne.clean_hash(new_ip) # Stringify the POST body string_body = body.to_json # Build URL path = OneAndOne.build_url('/public_ips') # Perform request response = @connection.request(:method => :post, :path => path, :headers => $header, :body => string_body) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string json = JSON.parse(response.body) # Save new IP ID to PublicIP instance @id = json['id'] @specs = json # If all good, return JSON json end
delete(ip_id: @id)
click to toggle source
# File lib/1and1/public_ip.rb, line 159 def delete(ip_id: @id) # If user passed in IP ID, reassign @id = ip_id # Build URL path = OneAndOne.build_url("/public_ips/#{@id}") # Perform request response = @connection.request(:method => :delete, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end
get(ip_id: @id)
click to toggle source
# File lib/1and1/public_ip.rb, line 97 def get(ip_id: @id) # If user passed in IP ID, reassign @id = ip_id # Build URL path = OneAndOne.build_url("/public_ips/#{@id}") # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string json = JSON.parse(response.body) # Reload specs attribute @specs = json # If all good, return JSON json end
list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil)
click to toggle source
# File lib/1and1/public_ip.rb, line 25 def list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil) # Build hash for query parameters keyword_args = { :page => page, :per_page => per_page, :sort => sort, :q => q, :fields => fields } # Clean out null query parameters params = OneAndOne.clean_hash(keyword_args) # Build URL path = OneAndOne.build_url('/public_ips') # Perform request response = @connection.request(:method => :get, :path => path, :headers => $header, :query => params) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end
modify(ip_id: @id, reverse_dns: nil)
click to toggle source
# File lib/1and1/public_ip.rb, line 125 def modify(ip_id: @id, reverse_dns: nil) # If user passed in shared_storage ID, reassign @id = ip_id # Build PUT body new_ip = { 'reverse_dns' => reverse_dns } # Clean out null keys in POST body body = OneAndOne.clean_hash(new_ip) # Stringify the POST body string_body = body.to_json # Build URL path = OneAndOne.build_url("/public_ips/#{@id}") # Perform request response = @connection.request(:method => :put, :path => path, :headers => $header, :body => string_body) # Check response status OneAndOne.check_response(response.body, response.status) #JSON-ify the response string JSON.parse(response.body) end
reload()
click to toggle source
# File lib/1and1/public_ip.rb, line 181 def reload # This reload fx is just a wrapper for the get fx get end