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
28 29 30 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 |
# File 'lib/fog/dnsimple/requests/dns/create_domain.rb', line 28 def create_domain(name) response = Excon::Response.new response.status = 201 body = { "domain" => { "auto_renew" => nil, "created_at" => Time.now.iso8601, "expires_on" => Date.today + 365, "id" => Fog::Mock.random_numbers(1).to_i, "language" => nil, "lockable" => true, "name" => name, "name_server_status" => "unknown", "registrant_id" => nil, "state" => "registered", "token" => "4fIFYWYiJayvL2tkf_mkBkqC4L+4RtYqDA", "unicode_name" => name, "updated_at" => Time.now.iso8601, "user_id" => 1, "record_count" => 0, "service_count" => 0, "private_whois?" => false } } self.data[:domains] << body response.body = body response end |
#create_record(domain, name, type, content, options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fog/dnsimple/requests/dns/create_record.rb', line 49 def create_record(domain, name, type, content, = {}) response = Excon::Response.new response.status = 201 body = { "record" => { "name" => name, "record_type" => type, "content" => content, "created_at" => Time.now.iso8601, "updated_at" => Time.now.iso8601, "id" => Fog::Mock.random_numbers(1).to_i, "domain_id" => domain }.merge() } self.data[:records][domain] ||= [] self.data[:records][domain] << body 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 |
# 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
22 23 24 25 26 27 |
# File 'lib/fog/dnsimple/requests/dns/delete_record.rb', line 22 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
38 39 40 41 42 43 44 |
# File 'lib/fog/dnsimple/requests/dns/get_domain.rb', line 38 def get_domain(id) domain = self.data[:domains].detect { |domain| domain["domain"]["id"] == id } response = Excon::Response.new response.status = 200 response.body = domain response end |
#get_record(domain, record_id) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fog/dnsimple/requests/dns/get_record.rb', line 35 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
36 37 38 39 40 41 |
# File 'lib/fog/dnsimple/requests/dns/list_domains.rb', line 36 def list_domains response = Excon::Response.new response.status = 200 response.body = self.data[:domains] response end |
#list_records(domain) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/fog/dnsimple/requests/dns/list_records.rb', line 33 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
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fog/dnsimple/requests/dns/update_record.rb', line 43 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 |