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.
43 44 45 46 |
# File 'lib/fog/dnsimple/dns.rb', line 43 def initialize(={}) @dnsimple_email = [:dnsimple_email] @dnsimple_password = [:dnsimple_password] end |
Class Method Details
.data ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/fog/dnsimple/dns.rb', line 30 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :domains => [], :records => {} } end end |
.reset ⇒ Object
39 40 41 |
# File 'lib/fog/dnsimple/dns.rb', line 39 def self.reset @data = nil end |
Instance Method Details
#create_domain(name) ⇒ Object
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 59 60 61 |
# File 'lib/fog/dnsimple/requests/dns/create_domain.rb', line 34 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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fog/dnsimple/requests/dns/create_record.rb', line 44 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
48 49 50 |
# File 'lib/fog/dnsimple/dns.rb', line 48 def data self.class.data[@dnsimple_email] end |
#delete_domain(name) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/fog/dnsimple/requests/dns/delete_domain.rb', line 27 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
23 24 25 26 27 28 29 |
# File 'lib/fog/dnsimple/requests/dns/delete_record.rb', line 23 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
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fog/dnsimple/requests/dns/get_domain.rb', line 29 def get_domain(id) domain = self.data[:domains].detect 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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fog/dnsimple/requests/dns/get_record.rb', line 28 def get_record(domain, record_id) response = Excon::Response.new if self.data[:records].has_key?(domain) response.status = 200 response.body = self.data[:records][domain].detect { |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
28 29 30 31 32 33 |
# File 'lib/fog/dnsimple/requests/dns/list_domains.rb', line 28 def list_domains response = Excon::Response.new response.status = 200 response.body = self.data[:domains] response end |
#list_records(domain) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/fog/dnsimple/requests/dns/list_records.rb', line 28 def list_records(domain) response = Excon::Response.new response.status = 200 response.body = self.data[:records][domain] || [] response end |
#reset_data ⇒ Object
52 53 54 |
# File 'lib/fog/dnsimple/dns.rb', line 52 def reset_data self.class.data.delete(@dnsimple_email) end |
#update_record(domain, record_id, options) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fog/dnsimple/requests/dns/update_record.rb', line 38 def update_record(domain, record_id, ) record = self.data[:records][domain].detect { |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 |