dnsimple-ruby 1.2.6 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
 - data/Gemfile +2 -13
 - data/Gemfile.lock +7 -7
 - data/Rakefile +2 -18
 - data/dnsimple-ruby.gemspec +24 -178
 - data/features/support/env.rb +5 -3
 - data/lib/dnsimple-ruby.rb +1 -0
 - data/lib/dnsimple.rb +1 -0
 - data/lib/dnsimple/base.rb +8 -0
 - data/lib/dnsimple/certificate.rb +95 -130
 - data/lib/dnsimple/client.rb +94 -56
 - data/lib/dnsimple/contact.rb +111 -144
 - data/lib/dnsimple/domain.rb +145 -194
 - data/lib/dnsimple/extended_attribute.rb +33 -60
 - data/lib/dnsimple/record.rb +70 -103
 - data/lib/dnsimple/service.rb +24 -47
 - data/lib/dnsimple/template.rb +47 -75
 - data/lib/dnsimple/template_record.rb +53 -84
 - data/lib/dnsimple/transfer_order.rb +17 -34
 - data/lib/dnsimple/user.rb +18 -32
 - data/lib/dnsimple/version.rb +3 -0
 - data/spec/commands/purchase_certificate_spec.rb +16 -4
 - data/spec/dnsimple/client_spec.rb +58 -0
 - data/spec/spec_helper.rb +4 -2
 - metadata +59 -92
 - data/.bundle/config +0 -3
 - data/.rvmrc +0 -1
 - data/VERSION +0 -1
 
    
        data/lib/dnsimple/record.rb
    CHANGED
    
    | 
         @@ -1,128 +1,95 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
               
     | 
| 
       3 
     | 
    
         
            -
                 
     | 
| 
      
 1 
     | 
    
         
            +
            class DNSimple::Record < DNSimple::Base
         
     | 
| 
      
 2 
     | 
    
         
            +
              Aliases = {
         
     | 
| 
      
 3 
     | 
    
         
            +
                'priority'     => 'prio',
         
     | 
| 
      
 4 
     | 
    
         
            +
                'time-to-live' => 'ttl'
         
     | 
| 
      
 5 
     | 
    
         
            +
              }
         
     | 
| 
       4 
6 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
              attr_accessor :id
         
     | 
| 
       6 
8 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 9 
     | 
    
         
            +
              attr_accessor :domain
         
     | 
| 
       8 
10 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
              attr_accessor :name
         
     | 
| 
       10 
12 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 13 
     | 
    
         
            +
              attr_accessor :content
         
     | 
| 
       12 
14 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 15 
     | 
    
         
            +
              attr_accessor :record_type
         
     | 
| 
       14 
16 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 17 
     | 
    
         
            +
              attr_accessor :ttl
         
     | 
| 
       16 
18 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
      
 19 
     | 
    
         
            +
              attr_accessor :prio
         
     | 
| 
       18 
20 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
                 
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
      
 21 
     | 
    
         
            +
              def fqdn
         
     | 
| 
      
 22 
     | 
    
         
            +
                [name, domain.name].delete_if { |v| v !~ DNSimple::BLANK_REGEX }.join(".")
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              def save(options={})
         
     | 
| 
      
 26 
     | 
    
         
            +
                record_hash = {}
         
     | 
| 
      
 27 
     | 
    
         
            +
                %w(name content ttl prio).each do |attribute|
         
     | 
| 
      
 28 
     | 
    
         
            +
                  record_hash[DNSimple::Record.resolve(attribute)] = self.send(attribute)
         
     | 
| 
       25 
29 
     | 
    
         
             
                end
         
     | 
| 
       26 
30 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
                 
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
      
 31 
     | 
    
         
            +
                options.merge!(:body => {:record => record_hash})
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                response = DNSimple::Client.put("domains/#{domain.id}/records/#{id}.json", options)
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                case response.code
         
     | 
| 
      
 36 
     | 
    
         
            +
                when 200
         
     | 
| 
      
 37 
     | 
    
         
            +
                  return self
         
     | 
| 
      
 38 
     | 
    
         
            +
                else
         
     | 
| 
      
 39 
     | 
    
         
            +
                  raise DNSimple::Error, "Failed to update record: #{response.inspect}"
         
     | 
| 
       29 
40 
     | 
    
         
             
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
       30 
42 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
              def delete(options={})
         
     | 
| 
      
 44 
     | 
    
         
            +
                DNSimple::Client.delete "domains/#{domain.id}/records/#{id}", options
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
      
 46 
     | 
    
         
            +
              alias :destroy :delete
         
     | 
| 
       36 
47 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
      
 48 
     | 
    
         
            +
              def self.resolve(name)
         
     | 
| 
      
 49 
     | 
    
         
            +
                DNSimple::Record::Aliases[name] || name
         
     | 
| 
      
 50 
     | 
    
         
            +
              end
         
     | 
| 
       39 
51 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
      
 52 
     | 
    
         
            +
              def self.create(domain, name, record_type, content, options={})
         
     | 
| 
      
 53 
     | 
    
         
            +
                record_hash = {:name => name, :record_type => record_type, :content => content}
         
     | 
| 
      
 54 
     | 
    
         
            +
                record_hash[:ttl] = options.delete(:ttl) || 3600
         
     | 
| 
      
 55 
     | 
    
         
            +
                record_hash[:prio] = options.delete(:priority)
         
     | 
| 
      
 56 
     | 
    
         
            +
                record_hash[:prio] = options.delete(:prio) || ''
         
     | 
| 
       41 
57 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
      
 58 
     | 
    
         
            +
                options.merge!({:body => {:record => record_hash}})
         
     | 
| 
       43 
59 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
                  when 200
         
     | 
| 
       46 
     | 
    
         
            -
                    return self
         
     | 
| 
       47 
     | 
    
         
            -
                  when 401
         
     | 
| 
       48 
     | 
    
         
            -
                    raise DNSimple::AuthenticationFailed
         
     | 
| 
       49 
     | 
    
         
            -
                  else
         
     | 
| 
       50 
     | 
    
         
            -
                    raise DNSimple::Error, "Failed to update record: #{response.inspect}" 
         
     | 
| 
       51 
     | 
    
         
            -
                  end
         
     | 
| 
       52 
     | 
    
         
            -
                end
         
     | 
| 
       53 
     | 
    
         
            -
                
         
     | 
| 
       54 
     | 
    
         
            -
                def delete(options={})
         
     | 
| 
       55 
     | 
    
         
            -
                  options.merge!(DNSimple::Client.standard_options_with_credentials)
         
     | 
| 
       56 
     | 
    
         
            -
                  self.class.delete("#{DNSimple::Client.base_uri}/domains/#{domain.id}/records/#{id}", options)
         
     | 
| 
       57 
     | 
    
         
            -
                end
         
     | 
| 
       58 
     | 
    
         
            -
                alias :destroy :delete
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
                def self.resolve(name)
         
     | 
| 
       61 
     | 
    
         
            -
                  aliases = {
         
     | 
| 
       62 
     | 
    
         
            -
                    'priority' => 'prio',
         
     | 
| 
       63 
     | 
    
         
            -
                    'time-to-live' => 'ttl'
         
     | 
| 
       64 
     | 
    
         
            -
                  }
         
     | 
| 
       65 
     | 
    
         
            -
                  aliases[name] || name
         
     | 
| 
       66 
     | 
    
         
            -
                end
         
     | 
| 
      
 60 
     | 
    
         
            +
                response = DNSimple::Client.post "domains/#{domain.name}/records", options
         
     | 
| 
       67 
61 
     | 
    
         | 
| 
       68 
     | 
    
         
            -
                 
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
                   
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
                   
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
                   
     | 
| 
       75 
     | 
    
         
            -
                  options.merge!({:body => {:record => record_hash}})
         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
                  response = self.post("#{DNSimple::Client.base_uri}/domains/#{domain.name}/records", options) 
         
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
                  pp response if DNSimple::Client.debug?
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
                  case response.code
         
     | 
| 
       82 
     | 
    
         
            -
                  when 201
         
     | 
| 
       83 
     | 
    
         
            -
                    return DNSimple::Record.new({:domain => domain}.merge(response["record"]))
         
     | 
| 
       84 
     | 
    
         
            -
                  when 401
         
     | 
| 
       85 
     | 
    
         
            -
                    raise DNSimple::AuthenticationFailed
         
     | 
| 
       86 
     | 
    
         
            -
                  when 406
         
     | 
| 
       87 
     | 
    
         
            -
                    raise DNSimple::RecordExists.new("#{name}.#{domain.name}", response["errors"])
         
     | 
| 
       88 
     | 
    
         
            -
                  else
         
     | 
| 
       89 
     | 
    
         
            -
                    raise DNSimple::Error, "Failed to create #{name}.#{domain.name}: #{response["errors"]}"
         
     | 
| 
       90 
     | 
    
         
            -
                  end
         
     | 
| 
      
 62 
     | 
    
         
            +
                case response.code
         
     | 
| 
      
 63 
     | 
    
         
            +
                when 201
         
     | 
| 
      
 64 
     | 
    
         
            +
                  return new({:domain => domain}.merge(response["record"]))
         
     | 
| 
      
 65 
     | 
    
         
            +
                when 406
         
     | 
| 
      
 66 
     | 
    
         
            +
                  raise DNSimple::RecordExists.new("#{name}.#{domain.name}", response["errors"])
         
     | 
| 
      
 67 
     | 
    
         
            +
                else
         
     | 
| 
      
 68 
     | 
    
         
            +
                  raise DNSimple::Error, "Failed to create #{name}.#{domain.name}: #{response["errors"]}"
         
     | 
| 
       91 
69 
     | 
    
         
             
                end
         
     | 
| 
      
 70 
     | 
    
         
            +
              end
         
     | 
| 
       92 
71 
     | 
    
         | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
                  response = self.get("#{DNSimple::Client.base_uri}/domains/#{domain.name}/records/#{id}", options)
         
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
                  pp response if DNSimple::Client.debug?
         
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
                  case response.code
         
     | 
| 
       100 
     | 
    
         
            -
                  when 200
         
     | 
| 
       101 
     | 
    
         
            -
                    return DNSimple::Record.new({:domain => domain}.merge(response["record"]))
         
     | 
| 
       102 
     | 
    
         
            -
                  when 401
         
     | 
| 
       103 
     | 
    
         
            -
                    raise DNSimple::AuthenticationFailed
         
     | 
| 
       104 
     | 
    
         
            -
                  when 404
         
     | 
| 
       105 
     | 
    
         
            -
                    raise DNSimple::RecordNotFound, "Could not find record #{id} for domain #{domain.name}"
         
     | 
| 
       106 
     | 
    
         
            -
                  else
         
     | 
| 
       107 
     | 
    
         
            -
                    raise DNSimple::Error, "Failed to find domain #{domain.name}/#{id}: #{response["errors"]}"
         
     | 
| 
       108 
     | 
    
         
            -
                  end
         
     | 
| 
       109 
     | 
    
         
            -
                end
         
     | 
| 
      
 72 
     | 
    
         
            +
              def self.find(domain, id, options={})
         
     | 
| 
      
 73 
     | 
    
         
            +
                response = DNSimple::Client.get("domains/#{domain.name}/records/#{id}", options)
         
     | 
| 
       110 
74 
     | 
    
         | 
| 
       111 
     | 
    
         
            -
                 
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
                   
     | 
| 
      
 75 
     | 
    
         
            +
                case response.code
         
     | 
| 
      
 76 
     | 
    
         
            +
                when 200
         
     | 
| 
      
 77 
     | 
    
         
            +
                  return new({:domain => domain}.merge(response["record"]))
         
     | 
| 
      
 78 
     | 
    
         
            +
                when 404
         
     | 
| 
      
 79 
     | 
    
         
            +
                  raise DNSimple::RecordNotFound, "Could not find record #{id} for domain #{domain.name}"
         
     | 
| 
      
 80 
     | 
    
         
            +
                else
         
     | 
| 
      
 81 
     | 
    
         
            +
                  raise DNSimple::Error, "Failed to find domain #{domain.name}/#{id}: #{response["errors"]}"
         
     | 
| 
      
 82 
     | 
    
         
            +
                end
         
     | 
| 
      
 83 
     | 
    
         
            +
              end
         
     | 
| 
       114 
84 
     | 
    
         | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
      
 85 
     | 
    
         
            +
              def self.all(domain, options={})
         
     | 
| 
      
 86 
     | 
    
         
            +
                response = DNSimple::Client.get("domains/#{domain.name}/records", options)
         
     | 
| 
       116 
87 
     | 
    
         | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
                  else
         
     | 
| 
       123 
     | 
    
         
            -
                    raise DNSimple::Error, "Error listing domains: #{response.code}"
         
     | 
| 
       124 
     | 
    
         
            -
                  end
         
     | 
| 
      
 88 
     | 
    
         
            +
                case response.code
         
     | 
| 
      
 89 
     | 
    
         
            +
                when 200
         
     | 
| 
      
 90 
     | 
    
         
            +
                  response.map { |r| new({:domain => domain}.merge(r["record"])) }
         
     | 
| 
      
 91 
     | 
    
         
            +
                else
         
     | 
| 
      
 92 
     | 
    
         
            +
                  raise DNSimple::Error, "Error listing domains: #{response.code}"
         
     | 
| 
       125 
93 
     | 
    
         
             
                end
         
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
       127 
94 
     | 
    
         
             
              end
         
     | 
| 
       128 
95 
     | 
    
         
             
            end
         
     | 
    
        data/lib/dnsimple/service.rb
    CHANGED
    
    | 
         @@ -1,58 +1,35 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
               
     | 
| 
       3 
     | 
    
         
            -
              class Service
         
     | 
| 
       4 
     | 
    
         
            -
                include HTTParty
         
     | 
| 
      
 1 
     | 
    
         
            +
            class DNSimple::Service < DNSimple::Base # Class representing a service that can be applied to a domain
         
     | 
| 
      
 2 
     | 
    
         
            +
              attr_accessor :id
         
     | 
| 
       5 
3 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
              attr_accessor :name
         
     | 
| 
       7 
5 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
              attr_accessor :short_name
         
     | 
| 
       9 
7 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 8 
     | 
    
         
            +
              attr_accessor :description
         
     | 
| 
       11 
9 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
              # Find a service by its ID or short name
         
     | 
| 
      
 11 
     | 
    
         
            +
              def self.find(id_or_short_name, options={})
         
     | 
| 
      
 12 
     | 
    
         
            +
                response = DNSimple::Client.get("services/#{id_or_short_name}.json", options)
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                 
     | 
| 
       16 
     | 
    
         
            -
                   
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                # Find a service by its ID or short name
         
     | 
| 
       23 
     | 
    
         
            -
                def self.find(id_or_short_name, options={})
         
     | 
| 
       24 
     | 
    
         
            -
                  options.merge!({:basic_auth => Client.credentials})
         
     | 
| 
       25 
     | 
    
         
            -
                  response = self.get("#{Client.base_uri}/services/#{id_or_short_name}.json", options)
         
     | 
| 
       26 
     | 
    
         
            -
                  
         
     | 
| 
       27 
     | 
    
         
            -
                  pp response if Client.debug?
         
     | 
| 
       28 
     | 
    
         
            -
                  
         
     | 
| 
       29 
     | 
    
         
            -
                  case response.code
         
     | 
| 
       30 
     | 
    
         
            -
                  when 200
         
     | 
| 
       31 
     | 
    
         
            -
                    return Service.new(response["service"])
         
     | 
| 
       32 
     | 
    
         
            -
                  when 401
         
     | 
| 
       33 
     | 
    
         
            -
                    raise RuntimeError, "Authentication failed"
         
     | 
| 
       34 
     | 
    
         
            -
                  when 404
         
     | 
| 
       35 
     | 
    
         
            -
                    raise RuntimeError, "Could not find service #{id_or_short_name}"
         
     | 
| 
       36 
     | 
    
         
            -
                  else
         
     | 
| 
       37 
     | 
    
         
            -
                    raise DNSimple::Error.new(id_or_short_name, response["errors"])
         
     | 
| 
       38 
     | 
    
         
            -
                  end
         
     | 
| 
      
 14 
     | 
    
         
            +
                case response.code
         
     | 
| 
      
 15 
     | 
    
         
            +
                when 200
         
     | 
| 
      
 16 
     | 
    
         
            +
                  return new(response["service"])
         
     | 
| 
      
 17 
     | 
    
         
            +
                when 404
         
     | 
| 
      
 18 
     | 
    
         
            +
                  raise RuntimeError, "Could not find service #{id_or_short_name}"
         
     | 
| 
      
 19 
     | 
    
         
            +
                else
         
     | 
| 
      
 20 
     | 
    
         
            +
                  raise DNSimple::Error.new(id_or_short_name, response["errors"])
         
     | 
| 
       39 
21 
     | 
    
         
             
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
       40 
23 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                  response = self.get("#{Client.base_uri}/services.json", options)
         
     | 
| 
       45 
     | 
    
         
            -
                  
         
     | 
| 
       46 
     | 
    
         
            -
                  pp response if Client.debug?
         
     | 
| 
      
 24 
     | 
    
         
            +
              # Get all of the services that can be applied to a domain
         
     | 
| 
      
 25 
     | 
    
         
            +
              def self.all(options={})
         
     | 
| 
      
 26 
     | 
    
         
            +
                response = DNSimple::Client.get 'services.json', options
         
     | 
| 
       47 
27 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
                  else
         
     | 
| 
       54 
     | 
    
         
            -
                    raise RuntimeError, "Error: #{response.code}"
         
     | 
| 
       55 
     | 
    
         
            -
                  end
         
     | 
| 
      
 28 
     | 
    
         
            +
                case response.code
         
     | 
| 
      
 29 
     | 
    
         
            +
                when 200
         
     | 
| 
      
 30 
     | 
    
         
            +
                  response.map { |r| new(r["service"]) }
         
     | 
| 
      
 31 
     | 
    
         
            +
                else
         
     | 
| 
      
 32 
     | 
    
         
            +
                  raise RuntimeError, "Error: #{response.code}"
         
     | 
| 
       56 
33 
     | 
    
         
             
                end
         
     | 
| 
       57 
34 
     | 
    
         
             
              end
         
     | 
| 
       58 
35 
     | 
    
         
             
            end
         
     | 
    
        data/lib/dnsimple/template.rb
    CHANGED
    
    | 
         @@ -1,91 +1,63 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
               
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            class DNSimple::Template < DNSimple::Base
         
     | 
| 
      
 2 
     | 
    
         
            +
              # The template ID in DNSimple
         
     | 
| 
      
 3 
     | 
    
         
            +
              attr_accessor :id
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                
         
     | 
| 
       8 
     | 
    
         
            -
                # The template name
         
     | 
| 
       9 
     | 
    
         
            -
                attr_accessor :name
         
     | 
| 
      
 5 
     | 
    
         
            +
              # The template name
         
     | 
| 
      
 6 
     | 
    
         
            +
              attr_accessor :name
         
     | 
| 
       10 
7 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
      
 8 
     | 
    
         
            +
              # The template short name
         
     | 
| 
      
 9 
     | 
    
         
            +
              attr_accessor :short_name
         
     | 
| 
       13 
10 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
              # The template description
         
     | 
| 
      
 12 
     | 
    
         
            +
              attr_accessor :description
         
     | 
| 
       16 
13 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                end
         
     | 
| 
       24 
     | 
    
         
            -
                
         
     | 
| 
       25 
     | 
    
         
            -
                # Delete the template from DNSimple. WARNING: this cannot
         
     | 
| 
       26 
     | 
    
         
            -
                # be undone.
         
     | 
| 
       27 
     | 
    
         
            -
                def delete(options={})
         
     | 
| 
       28 
     | 
    
         
            -
                  options.merge!(DNSimple::Client.standard_options_with_credentials)
         
     | 
| 
       29 
     | 
    
         
            -
                  self.class.delete("#{Client.base_uri}/templates/#{id}", options)
         
     | 
| 
       30 
     | 
    
         
            -
                end
         
     | 
| 
       31 
     | 
    
         
            -
                alias :destroy :delete
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                def self.create(name, short_name, description=nil, options={})
         
     | 
| 
       34 
     | 
    
         
            -
                  options.merge!(DNSimple::Client.standard_options_with_credentials)
         
     | 
| 
       35 
     | 
    
         
            -
                  template_hash = {
         
     | 
| 
       36 
     | 
    
         
            -
                    :name => name, 
         
     | 
| 
       37 
     | 
    
         
            -
                    :short_name => short_name,
         
     | 
| 
       38 
     | 
    
         
            -
                    :description => description
         
     | 
| 
       39 
     | 
    
         
            -
                  }
         
     | 
| 
      
 14 
     | 
    
         
            +
              # Delete the template from DNSimple. WARNING: this cannot
         
     | 
| 
      
 15 
     | 
    
         
            +
              # be undone.
         
     | 
| 
      
 16 
     | 
    
         
            +
              def delete(options={})
         
     | 
| 
      
 17 
     | 
    
         
            +
                DNSimple::Client.delete "templates/#{id}", options
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
              alias :destroy :delete
         
     | 
| 
       40 
20 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
      
 21 
     | 
    
         
            +
              def self.create(name, short_name, description=nil, options={})
         
     | 
| 
      
 22 
     | 
    
         
            +
                template_hash = {
         
     | 
| 
      
 23 
     | 
    
         
            +
                  :name        => name,
         
     | 
| 
      
 24 
     | 
    
         
            +
                  :short_name  => short_name,
         
     | 
| 
      
 25 
     | 
    
         
            +
                  :description => description
         
     | 
| 
      
 26 
     | 
    
         
            +
                }
         
     | 
| 
       42 
27 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
                options.merge!(:body => {:dns_template => template_hash})
         
     | 
| 
       44 
29 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
      
 30 
     | 
    
         
            +
                response = DNSimple::Client.post 'templates', options
         
     | 
| 
       46 
31 
     | 
    
         | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
                  else
         
     | 
| 
       53 
     | 
    
         
            -
                    raise DNSimple::Error.new(name, response["errors"])
         
     | 
| 
       54 
     | 
    
         
            -
                  end
         
     | 
| 
      
 32 
     | 
    
         
            +
                case response.code
         
     | 
| 
      
 33 
     | 
    
         
            +
                when 201
         
     | 
| 
      
 34 
     | 
    
         
            +
                  return new(response["dns_template"])
         
     | 
| 
      
 35 
     | 
    
         
            +
                else
         
     | 
| 
      
 36 
     | 
    
         
            +
                  raise DNSimple::Error.new(name, response["errors"])
         
     | 
| 
       55 
37 
     | 
    
         
             
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
              end
         
     | 
| 
       56 
39 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                  response = self.get("#{Client.base_uri}/templates/#{id_or_short_name}", options)
         
     | 
| 
       60 
     | 
    
         
            -
                  
         
     | 
| 
       61 
     | 
    
         
            -
                  pp response if Client.debug?
         
     | 
| 
       62 
     | 
    
         
            -
                  
         
     | 
| 
       63 
     | 
    
         
            -
                  case response.code
         
     | 
| 
       64 
     | 
    
         
            -
                  when 200
         
     | 
| 
       65 
     | 
    
         
            -
                    return Template.new(response["dns_template"])
         
     | 
| 
       66 
     | 
    
         
            -
                  when 401
         
     | 
| 
       67 
     | 
    
         
            -
                    raise RuntimeError, "Authentication failed"
         
     | 
| 
       68 
     | 
    
         
            -
                  when 404
         
     | 
| 
       69 
     | 
    
         
            -
                    raise RuntimeError, "Could not find template #{id_or_short_name}"
         
     | 
| 
       70 
     | 
    
         
            -
                  else
         
     | 
| 
       71 
     | 
    
         
            -
                    raise DNSimple::Error.new(id_or_short_name, response["errors"])
         
     | 
| 
       72 
     | 
    
         
            -
                  end
         
     | 
| 
       73 
     | 
    
         
            -
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
              def self.find(id_or_short_name, options={})
         
     | 
| 
      
 41 
     | 
    
         
            +
                response = DNSimple::Client.get "templates/#{id_or_short_name}", options
         
     | 
| 
       74 
42 
     | 
    
         | 
| 
       75 
     | 
    
         
            -
                 
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
                   
     | 
| 
      
 43 
     | 
    
         
            +
                case response.code
         
     | 
| 
      
 44 
     | 
    
         
            +
                when 200
         
     | 
| 
      
 45 
     | 
    
         
            +
                  return new(response["dns_template"])
         
     | 
| 
      
 46 
     | 
    
         
            +
                when 404
         
     | 
| 
      
 47 
     | 
    
         
            +
                  raise RuntimeError, "Could not find template #{id_or_short_name}"
         
     | 
| 
      
 48 
     | 
    
         
            +
                else
         
     | 
| 
      
 49 
     | 
    
         
            +
                  raise DNSimple::Error.new(id_or_short_name, response["errors"])
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
              end
         
     | 
| 
       78 
52 
     | 
    
         | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
      
 53 
     | 
    
         
            +
              def self.all(options={})
         
     | 
| 
      
 54 
     | 
    
         
            +
                response = DNSimple::Client.get 'templates', options
         
     | 
| 
       80 
55 
     | 
    
         | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
                  else
         
     | 
| 
       87 
     | 
    
         
            -
                    raise RuntimeError, "Error: #{response.code}"
         
     | 
| 
       88 
     | 
    
         
            -
                  end
         
     | 
| 
      
 56 
     | 
    
         
            +
                case response.code
         
     | 
| 
      
 57 
     | 
    
         
            +
                when 200
         
     | 
| 
      
 58 
     | 
    
         
            +
                  response.map { |r| new(r["dns_template"]) }
         
     | 
| 
      
 59 
     | 
    
         
            +
                else
         
     | 
| 
      
 60 
     | 
    
         
            +
                  raise RuntimeError, "Error: #{response.code}"
         
     | 
| 
       89 
61 
     | 
    
         
             
                end
         
     | 
| 
       90 
62 
     | 
    
         
             
              end
         
     | 
| 
       91 
63 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,103 +1,72 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
              #  
     | 
| 
       3 
     | 
    
         
            -
               
     | 
| 
       4 
     | 
    
         
            -
                include HTTParty
         
     | 
| 
      
 1 
     | 
    
         
            +
            class DNSimple::TemplateRecord < DNSimple::Base # A single record in a template
         
     | 
| 
      
 2 
     | 
    
         
            +
              # The id of the template record
         
     | 
| 
      
 3 
     | 
    
         
            +
              attr_accessor :id
         
     | 
| 
       5 
4 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 5 
     | 
    
         
            +
              # The template the record belongs to
         
     | 
| 
      
 6 
     | 
    
         
            +
              attr_accessor :template
         
     | 
| 
       8 
7 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 8 
     | 
    
         
            +
              # The name the record points to. This may be blank.
         
     | 
| 
      
 9 
     | 
    
         
            +
              attr_accessor :name
         
     | 
| 
       11 
10 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
              # The content for the record.
         
     | 
| 
      
 12 
     | 
    
         
            +
              attr_accessor :content
         
     | 
| 
       14 
13 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
              # The record type
         
     | 
| 
      
 15 
     | 
    
         
            +
              attr_accessor :record_type
         
     | 
| 
       17 
16 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 17 
     | 
    
         
            +
              # The time-to-live
         
     | 
| 
      
 18 
     | 
    
         
            +
              attr_accessor :ttl
         
     | 
| 
       20 
19 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
              # The priority (only for MX records)
         
     | 
| 
      
 21 
     | 
    
         
            +
              attr_accessor :prio
         
     | 
| 
       23 
22 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
                 
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                def initialize(attributes)
         
     | 
| 
       29 
     | 
    
         
            -
                  attributes.each do |key, value|
         
     | 
| 
       30 
     | 
    
         
            -
                    m = "#{key}=".to_sym
         
     | 
| 
       31 
     | 
    
         
            -
                    self.send(m, value) if self.respond_to?(m)
         
     | 
| 
       32 
     | 
    
         
            -
                  end
         
     | 
| 
       33 
     | 
    
         
            -
                end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                def delete(options={})
         
     | 
| 
       36 
     | 
    
         
            -
                  options.merge!(:basic_auth => Client.credentials)
         
     | 
| 
       37 
     | 
    
         
            -
                  self.class.delete("#{Client.base_uri}/templates/#{template.id}/template_records/#{id}.json", options)
         
     | 
| 
       38 
     | 
    
         
            -
                end
         
     | 
| 
       39 
     | 
    
         
            -
                alias :destroy :delete
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                def self.create(short_name, name, record_type, content, options={})
         
     | 
| 
       42 
     | 
    
         
            -
                  template = Template.find(short_name)
         
     | 
| 
      
 23 
     | 
    
         
            +
              def delete(options={})
         
     | 
| 
      
 24 
     | 
    
         
            +
                DNSimple::Client.delete("templates/#{template.id}/template_records/#{id}.json", options)
         
     | 
| 
      
 25 
     | 
    
         
            +
              end
         
     | 
| 
      
 26 
     | 
    
         
            +
              alias :destroy :delete
         
     | 
| 
       43 
27 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
                  record_hash[:prio] = options.delete(:prio) || ''
         
     | 
| 
      
 28 
     | 
    
         
            +
              def self.create(short_name, name, record_type, content, options={})
         
     | 
| 
      
 29 
     | 
    
         
            +
                template = DNSimple::Template.find(short_name)
         
     | 
| 
       47 
30 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
      
 31 
     | 
    
         
            +
                record_hash = {:name => name, :record_type => record_type, :content => content}
         
     | 
| 
      
 32 
     | 
    
         
            +
                record_hash[:ttl] = options.delete(:ttl) || 3600
         
     | 
| 
      
 33 
     | 
    
         
            +
                record_hash[:prio] = options.delete(:prio) || ''
         
     | 
| 
       50 
34 
     | 
    
         | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
      
 35 
     | 
    
         
            +
                options.merge!({:query => {:dns_template_record => record_hash}})
         
     | 
| 
       52 
36 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
      
 37 
     | 
    
         
            +
                response = DNSimple::Client.post("templates/#{template.id}/template_records.json", options)
         
     | 
| 
       54 
38 
     | 
    
         | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
                  else
         
     | 
| 
       61 
     | 
    
         
            -
                    raise DNSimple::Error.new("#{name}", response["errors"])
         
     | 
| 
       62 
     | 
    
         
            -
                  end
         
     | 
| 
      
 39 
     | 
    
         
            +
                case response.code
         
     | 
| 
      
 40 
     | 
    
         
            +
                when 201
         
     | 
| 
      
 41 
     | 
    
         
            +
                  return new({:template => template}.merge(response["dns_template_record"]))
         
     | 
| 
      
 42 
     | 
    
         
            +
                else
         
     | 
| 
      
 43 
     | 
    
         
            +
                  raise DNSimple::Error.new("#{name}", response["errors"])
         
     | 
| 
       63 
44 
     | 
    
         
             
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
       64 
46 
     | 
    
         | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                  response = self.get("#{Client.base_uri}/templates/#{template.id}/template_records/#{id}.json", options)
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
                  pp response if Client.debug?
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
                  case response.code
         
     | 
| 
       73 
     | 
    
         
            -
                  when 200
         
     | 
| 
       74 
     | 
    
         
            -
                    return TemplateRecord.new({:template => template}.merge(response["dns_template_record"]))
         
     | 
| 
       75 
     | 
    
         
            -
                  when 401
         
     | 
| 
       76 
     | 
    
         
            -
                    raise RuntimeError, "Authentication failed"
         
     | 
| 
       77 
     | 
    
         
            -
                  when 404
         
     | 
| 
       78 
     | 
    
         
            -
                    raise RuntimeError, "Could not find template record #{id} for template #{short_name}"
         
     | 
| 
       79 
     | 
    
         
            -
                  end
         
     | 
| 
       80 
     | 
    
         
            -
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
              def self.find(short_name, id, options={})
         
     | 
| 
      
 48 
     | 
    
         
            +
                template = DNSimple::Template.find(short_name)
         
     | 
| 
      
 49 
     | 
    
         
            +
                response = DNSimple::Client.get("templates/#{template.id}/template_records/#{id}.json", options)
         
     | 
| 
       81 
50 
     | 
    
         | 
| 
       82 
     | 
    
         
            -
                 
     | 
| 
       83 
     | 
    
         
            -
                 
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
                   
     | 
| 
       87 
     | 
    
         
            -
                  response = self.get("#{Client.base_uri}/templates/#{template.id}/template_records.json", options)
         
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
                  pp response if Client.debug?
         
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
                  case response.code
         
     | 
| 
       92 
     | 
    
         
            -
                  when 200
         
     | 
| 
       93 
     | 
    
         
            -
                    response.map { |r| TemplateRecord.new({:template => template}.merge(r["dns_template_record"])) }
         
     | 
| 
       94 
     | 
    
         
            -
                  when 401
         
     | 
| 
       95 
     | 
    
         
            -
                    raise RuntimeError, "Authentication failed"
         
     | 
| 
       96 
     | 
    
         
            -
                  else
         
     | 
| 
       97 
     | 
    
         
            -
                    raise RuntimeError, "Error: #{response.code}"
         
     | 
| 
       98 
     | 
    
         
            -
                  end
         
     | 
| 
      
 51 
     | 
    
         
            +
                case response.code
         
     | 
| 
      
 52 
     | 
    
         
            +
                when 200
         
     | 
| 
      
 53 
     | 
    
         
            +
                  return new({:template => template}.merge(response["dns_template_record"]))
         
     | 
| 
      
 54 
     | 
    
         
            +
                when 404
         
     | 
| 
      
 55 
     | 
    
         
            +
                  raise RuntimeError, "Could not find template record #{id} for template #{short_name}"
         
     | 
| 
       99 
56 
     | 
    
         
             
                end
         
     | 
| 
       100 
57 
     | 
    
         
             
              end
         
     | 
| 
       101 
58 
     | 
    
         | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
      
 59 
     | 
    
         
            +
              # Get all of the template records for the template with the
         
     | 
| 
      
 60 
     | 
    
         
            +
              # given short name.
         
     | 
| 
      
 61 
     | 
    
         
            +
              def self.all(short_name, options={})
         
     | 
| 
      
 62 
     | 
    
         
            +
                template = DNSimple::Template.find(short_name)
         
     | 
| 
      
 63 
     | 
    
         
            +
                response = DNSimple::Client.get("templates/#{template.id}/template_records.json", options)
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                case response.code
         
     | 
| 
      
 66 
     | 
    
         
            +
                when 200
         
     | 
| 
      
 67 
     | 
    
         
            +
                  response.map { |r| new({:template => template}.merge(r["dns_template_record"])) }
         
     | 
| 
      
 68 
     | 
    
         
            +
                else
         
     | 
| 
      
 69 
     | 
    
         
            +
                  raise RuntimeError, "Error: #{response.code}"
         
     | 
| 
      
 70 
     | 
    
         
            +
                end
         
     | 
| 
      
 71 
     | 
    
         
            +
              end
         
     | 
| 
       103 
72 
     | 
    
         
             
            end
         
     |