Class: Fog::DNS::DNSimple::Mock
- Inherits:
-
Object
- Object
- Fog::DNS::DNSimple::Mock
- Defined in:
- lib/fog/dnsimple/dns.rb,
lib/fog/dnsimple/requests/dns/get_domain.rb,
lib/fog/dnsimple/requests/dns/get_record.rb,
lib/fog/dnsimple/requests/dns/list_domains.rb,
lib/fog/dnsimple/requests/dns/list_records.rb,
lib/fog/dnsimple/requests/dns/create_domain.rb,
lib/fog/dnsimple/requests/dns/create_record.rb,
lib/fog/dnsimple/requests/dns/delete_domain.rb,
lib/fog/dnsimple/requests/dns/delete_record.rb,
lib/fog/dnsimple/requests/dns/update_record.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_domain(name) ⇒ Object
- #create_record(domain, name, type, content, options = {}) ⇒ Object
- #data ⇒ Object
- #delete_domain(name) ⇒ Object
- #delete_record(domain, record_id) ⇒ Object
- #get_domain(id) ⇒ Object
- #get_record(domain, record_id) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_domains ⇒ Object
- #list_records(domain) ⇒ Object
- #reset_data ⇒ Object
- #update_record(domain, record_id, options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
39 40 41 42 43 44 |
# File 'lib/fog/dnsimple/dns.rb', line 39 def initialize(={}) @dnsimple_email = [:dnsimple_email] @dnsimple_password = [:dnsimple_password] @dnsimple_token = [:dnsimple_token] @dnsimple_domain = [:dnsimple_domain] end |
Class Method Details
.data ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/fog/dnsimple/dns.rb', line 26 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :domains => [], :records => {} } end end |
.reset ⇒ Object
35 36 37 |
# File 'lib/fog/dnsimple/dns.rb', line 35 def self.reset @data = nil end |
Instance Method Details
#create_domain(name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 |
#create_record(domain, name, type, content, options = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fog/dnsimple/requests/dns/create_record.rb', line 41 def create_record(domain, name, type, content, = {}) 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() } self.data[:records][domain] ||= [] self.data[:records][domain] << body response = Excon::Response.new response.status = 201 response.body = body response end |
#data ⇒ Object
46 47 48 |
# File 'lib/fog/dnsimple/dns.rb', line 46 def data self.class.data[@dnsimple_email] end |
#delete_domain(name) ⇒ Object
24 25 26 27 28 29 30 31 |
# 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 |
#delete_record(domain, record_id) ⇒ Object
20 21 22 23 24 25 26 |
# 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 |
#get_domain(id) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# 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 |
#get_record(domain, record_id) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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 |
#list_domains ⇒ Object
25 26 27 28 29 30 |
# 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 |
#list_records(domain) ⇒ Object
25 26 27 28 29 30 |
# 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 |
#reset_data ⇒ Object
50 51 52 |
# File 'lib/fog/dnsimple/dns.rb', line 50 def reset_data self.class.data.delete(@dnsimple_email) end |
#update_record(domain, record_id, options) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fog/dnsimple/requests/dns/update_record.rb', line 35 def update_record(domain, record_id, ) 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!() record["record"]["updated_at"] = Time.now.iso8601 response.body = record end response end |