Class: DNSimple::Service
- Inherits:
-
Object
- Object
- DNSimple::Service
- Includes:
- HTTParty
- Defined in:
- lib/dnsimple/service.rb
Overview
Class representing a service that can be applied to a domain
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#short_name ⇒ Object
Returns the value of attribute short_name.
Class Method Summary collapse
-
.all(options = {}) ⇒ Object
Get all of the services that can be applied to a domain.
-
.find(id_or_short_name, options = {}) ⇒ Object
Find a service by its ID or short name.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Service
constructor
:nodoc:.
Constructor Details
#initialize(attributes) ⇒ Service
:nodoc:
15 16 17 18 19 20 |
# File 'lib/dnsimple/service.rb', line 15 def initialize(attributes) attributes.each do |key, value| m = "#{key}=".to_sym self.send(m, value) if self.respond_to?(m) end end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
12 13 14 |
# File 'lib/dnsimple/service.rb', line 12 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/dnsimple/service.rb', line 6 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/dnsimple/service.rb', line 8 def name @name end |
#short_name ⇒ Object
Returns the value of attribute short_name.
10 11 12 |
# File 'lib/dnsimple/service.rb', line 10 def short_name @short_name end |
Class Method Details
.all(options = {}) ⇒ Object
Get all of the services that can be applied to a domain
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/dnsimple/service.rb', line 42 def self.all(={}) .merge!({:basic_auth => Client.credentials}) response = self.get("#{Client.base_uri}/services.json", ) pp response if Client.debug? case response.code when 200 response.map { |r| Service.new(r["service"]) } when 401 raise RuntimeError, "Authentication failed" else raise RuntimeError, "Error: #{response.code}" end end |
.find(id_or_short_name, options = {}) ⇒ Object
Find a service by its ID or short name
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dnsimple/service.rb', line 23 def self.find(id_or_short_name, ={}) .merge!({:basic_auth => Client.credentials}) response = self.get("#{Client.base_uri}/services/#{id_or_short_name}.json", ) pp response if Client.debug? case response.code when 200 return Service.new(response["service"]) when 401 raise RuntimeError, "Authentication failed" when 404 raise RuntimeError, "Could not find service #{id_or_short_name}" else raise DNSimple::Error.new(id_or_short_name, response["errors"]) end end |