Class: DNSimple::Service

Inherits:
Base
  • Object
show all
Defined in:
lib/dnsimple/service.rb

Overview

Represents a service that can be applied to a domain.

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from DNSimple::Base

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



12
13
14
# File 'lib/dnsimple/service.rb', line 12

def description
  @description
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/dnsimple/service.rb', line 6

def id
  @id
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/dnsimple/service.rb', line 8

def name
  @name
end

#short_nameObject

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



30
31
32
33
34
35
36
37
38
39
# File 'lib/dnsimple/service.rb', line 30

def self.all(options={})
  response = DNSimple::Client.get("/v1/services", options)

  case response.code
  when 200
    response.map { |r| new(r["service"]) }
  else
    raise RequestError.new("Error listing services", response)
  end
end

.find(id_or_short_name, options = {}) ⇒ Object

Find a service by its ID or short name



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dnsimple/service.rb', line 15

def self.find(id_or_short_name, options={})
  id = id_or_short_name
  response = DNSimple::Client.get("/v1/services/#{id}", options)

  case response.code
  when 200
    new(response["service"])
  when 404
    raise RecordNotFound, "Could not find service #{id}"
  else
    raise RequestError.new("Error finding service", response)
  end
end