# File lib/fog/dnsimple/dns.rb, line 26 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :domains => [], :records => {} } end end
# File lib/fog/dnsimple/dns.rb, line 39 def initialize(options={}) @dnsimple_email = options[:dnsimple_email] @dnsimple_password = options[:dnsimple_password] @dnsimple_token = options[:dnsimple_token] @dnsimple_domain = options[:dnsimple_domain] end
# File lib/fog/dnsimple/dns.rb, line 35 def self.reset @data = nil end
# File lib/fog/dnsimple/requests/dns/create_domain.rb, line 31 def create_domain(name) body = { "domain" => { "id" => Fog::Mock.random_numbers(1).to_i, "user_id" => 1, "registrant_id" => nil, "name" => name, "unicode_name" => name, "token" => "4fIFYWYiJayvL2tkf_mkBkqC4L+4RtYqDA", "state" => "registered", "language" => nil, "lockable" => true, "auto_renew" => nil, "whois_protected" => false, "record_count" => 0, "service_count" => 0, "expires_on" => Date.today + 365, "created_at" => Time.now.iso8601, "updated_at" => Time.now.iso8601, } } self.data[:domains] << body response = Excon::Response.new response.status = 201 response.body = body response end
# File lib/fog/dnsimple/requests/dns/create_record.rb, line 41 def create_record(domain, name, type, content, options = {}) body = { "record" => { "id" => Fog::Mock.random_numbers(1).to_i, "domain_id" => domain, "name" => name, "content" => content, "ttl" => 3600, "prio" => nil, "record_type" => type, "system_record" => nil, "created_at" => Time.now.iso8601, "updated_at" => Time.now.iso8601, }.merge(options) } self.data[:records][domain] ||= [] self.data[:records][domain] << body response = Excon::Response.new response.status = 201 response.body = body response end
# File lib/fog/dnsimple/dns.rb, line 46 def data self.class.data[@dnsimple_email] end
# File lib/fog/dnsimple/requests/dns/delete_domain.rb, line 24 def delete_domain(name) self.data[:records].delete name self.data[:domains].reject! { |domain| domain["domain"]["name"] == name } response = Excon::Response.new response.status = 200 response end
# File lib/fog/dnsimple/requests/dns/delete_record.rb, line 20 def delete_record(domain, record_id) self.data[:records][domain].reject! { |record| record["record"]["id"] == record_id } response = Excon::Response.new response.status = 200 response end
# File lib/fog/dnsimple/requests/dns/get_domain.rb, line 26 def get_domain(id) domain = self.data[:domains].find do |domain| domain["domain"]["id"] == id || domain["domain"]["name"] == id end response = Excon::Response.new response.status = 200 response.body = domain response end
# File lib/fog/dnsimple/requests/dns/get_record.rb, line 25 def get_record(domain, record_id) response = Excon::Response.new if self.data[:records].key?(domain) response.status = 200 response.body = self.data[:records][domain].find { |record| record["record"]["id"] == record_id } if response.body.nil? response.status = 404 response.body = { "error" => "Couldn't find Record with id = #{record_id}" } end else response.status = 404 response.body = { "error" => "Couldn't find Domain with name = #{domain}" } end response end
# File lib/fog/dnsimple/requests/dns/list_domains.rb, line 25 def list_domains response = Excon::Response.new response.status = 200 response.body = self.data[:domains] response end
# File lib/fog/dnsimple/requests/dns/list_records.rb, line 25 def list_records(domain) response = Excon::Response.new response.status = 200 response.body = self.data[:records][domain] || [] response end
# File lib/fog/dnsimple/dns.rb, line 50 def reset_data self.class.data.delete(@dnsimple_email) end
# File lib/fog/dnsimple/requests/dns/update_record.rb, line 35 def update_record(domain, record_id, options) record = self.data[:records][domain].find { |record| record["record"]["id"] == record_id } response = Excon::Response.new if record.nil? response.status = 400 else response.status = 200 record["record"].merge!(options) record["record"]["updated_at"] = Time.now.iso8601 response.body = record end response end