class NSOne::Client
Constants
- BASE_URL
Public Class Methods
new(api_key, api_version: "v1", base_url: BASE_URL, logger: nil)
click to toggle source
# File lib/nsone/client.rb, line 12 def initialize(api_key, api_version: "v1", base_url: BASE_URL, logger: nil) @api_key = api_key @base_url = base_url @api_version = api_version @logger = logger end
Private Instance Methods
blank?(object)
click to toggle source
# File lib/nsone/client.rb, line 41 def blank?(object) object.respond_to?(:empty?) ? !!object.empty? : !object end
log(message)
click to toggle source
# File lib/nsone/client.rb, line 30 def log(message) @logger && @logger.debug(message) end
no_dot!(*array)
click to toggle source
Removes trailing dot from all Strings given
# File lib/nsone/client.rb, line 62 def no_dot!(*array) array.map {|a| a.chop! if a[/\.$/] != nil} end
normalize_names!(zone, domain = "")
click to toggle source
Helper to support `domain` name with or without the zone name. e.g. zone: example.com domain: www will generate domain: www.example.com
# File lib/nsone/client.rb, line 55 def normalize_names!(zone, domain = "") domain.replace(zone) if domain.empty? no_dot!(zone, domain) domain << ".#{zone}" unless domain.empty? || domain.include?(zone) end
perform_request(method, path, body = nil)
click to toggle source
# File lib/nsone/client.rb, line 21 def perform_request(method, path, body = nil) body = JSON.dump(body) if body.is_a? Hash log("[NSOne] > #{method} #{path}") log("[NSOne] > #{body}") if body response = transport.request(method, path, body) log("[NSOne] < #{response.inspect}") response end
transport()
click to toggle source
# File lib/nsone/client.rb, line 34 def transport begin @transport ||= NSOne::Transport::NetHttp.new(@base_url, @api_version, @api_key) rescue NSOne::Transport::RateLimitExceeded end end
validate_required!(params, *keys)
click to toggle source
# File lib/nsone/client.rb, line 45 def validate_required!(params, *keys) raise ArgumentError, "Paramenters must be a hash" unless params.is_a? Hash missing = keys.reject { |key| params.has_key?(key) or params.has_key?(key.to_s) } if missing.any? raise MissingParameter, "Missing key(s): #{missing.join(", ")}" end end