zerigodns 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,19 @@
1
1
  # Copyright 2009 Zerigo, Inc. See MIT-LICENSE for license information.
2
2
  # Visit http://www.zerigo.com/docs/managed-dns for updates and documentation.
3
- require 'activeresource-ext'
4
- require 'zerigodns/base'
3
+ require 'faraday'
4
+ require 'multi_xml'
5
+ require 'zerigodns/client'
6
+ require 'zerigodns/client/response_code'
7
+
8
+ require 'zerigodns/middleware'
9
+ require 'zerigodns/middleware/xml'
10
+ require 'zerigodns/middleware/error_handler'
11
+ require 'zerigodns/middleware/zerigo_auth'
12
+
13
+ require 'zerigodns/resource'
14
+ require 'zerigodns/resource/rest'
15
+ require 'zerigodns/resource/naming'
16
+ require 'zerigodns/resource/attributes'
5
17
  require 'zerigodns/config'
6
18
  require 'zerigodns/host'
7
19
  require 'zerigodns/zone'
@@ -0,0 +1,67 @@
1
+ module ZerigoDNS
2
+ class Client
3
+
4
+ #@!attribute response [r]
5
+ # @return [Faraday::Response] exposes the response.
6
+ ResponseError = Class.new(RuntimeError) do
7
+ attr_reader :response
8
+
9
+ # Initialize a new ResponseError with a response.
10
+ def initialize response=nil
11
+ @response=response
12
+ end
13
+
14
+ # Convert to a string
15
+ # @return [String] The error's message.
16
+ def to_s
17
+ inspect
18
+ end
19
+
20
+ # @return [String] The error's message
21
+ def message
22
+ inspect
23
+ end
24
+
25
+ # @return [String] The error's message
26
+ def inspect
27
+ "HTTP Response Error: #{response && response.status}"
28
+ end
29
+ end
30
+
31
+ # Standard REST Actions
32
+ ACTIONS = %w(get post put patch delete)
33
+
34
+ ACTIONS.each do |action|
35
+ define_method action do |*args|
36
+ self.class.send(action, *args)
37
+ end
38
+ end
39
+
40
+
41
+ class <<self
42
+ # Gets or creates a new faraday connection.
43
+ def connection
44
+
45
+ # => Note: Order matters here!
46
+ @connection ||= Faraday.new(
47
+ url: ZerigoDNS.config.site,
48
+ ) do |faraday|
49
+ faraday.request :zerigo_auth
50
+ faraday.request :multipart
51
+ faraday.request :url_encoded
52
+
53
+ faraday.adapter Faraday.default_adapter
54
+
55
+ faraday.response :custom_xml
56
+ faraday.response :custom_error_handler
57
+ end
58
+ end
59
+
60
+ ACTIONS.each do |action|
61
+ define_method action do |*args|
62
+ connection.send action, *args
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,29 @@
1
+ # Represents a response code and allows more expressive querying of response status.
2
+ # e.g. +response.env[:code].ok?+ as opposed to +(200..299).include?(response.status)+
3
+ class ZerigoDNS::Client::ResponseCode
4
+ attr_reader :raw_code
5
+
6
+ def initialize raw_code
7
+ @raw_code = raw_code
8
+ end
9
+
10
+ # @return [Boolean] true if the response was OK
11
+ def ok?
12
+ (200..299).include?(raw_code) || raw_code == 302
13
+ end
14
+
15
+ # @return [Boolean] true if the response was not OK
16
+ def error?
17
+ !ok?
18
+ end
19
+
20
+ # @return [Boolean] true if response is 500 internal server error.
21
+ def server_error?
22
+ raw_code == 500
23
+ end
24
+
25
+ # @return [Boolean] true if response is 404
26
+ def not_found?
27
+ raw_code == 404
28
+ end
29
+ end
@@ -3,16 +3,31 @@ module ZerigoDNS
3
3
  #@attr [String] user Your e-mail address
4
4
  #@attr [Boolean] secure Whether to use HTTPS
5
5
  class Config
6
+ attr_accessor :api_key, :user, :secure, :site
6
7
 
7
- BASE_ATTRIBUTES = %w(api_key site secure user password)
8
- BASE_ATTRIBUTES.each do |attr|
9
- define_method attr do
10
- ZerigoDNS::Base.send(attr)
11
- end
12
-
13
- define_method "#{attr}=" do |val|
14
- ZerigoDNS::Base.send("#{attr}=", val)
15
- end
8
+ def initialize
9
+ @site = 'https://ns.zerigo.com/api/1.1'
10
+ end
11
+
12
+ # @return [Boolean] +true+ if +https+ is used
13
+ def secure?
14
+ !!secure
15
+ end
16
+
17
+
18
+ # Set +https+ or +http+
19
+ # @param [Boolean] value +true+ to use +https+, false for +http+
20
+ # Note: Will change the value of +site+!
21
+ def secure= value
22
+ @secure=value
23
+
24
+ if secure?
25
+ site = 'https://ns.zerigo.com/api/1.1'
26
+ else
27
+ site = 'http://ns.zerigo.com/api/1.1'
16
28
  end
29
+
30
+ secure
31
+ end
17
32
  end
18
33
  end
@@ -1,23 +1,39 @@
1
- class ZerigoDNS::Host < ZerigoDNS::Base
1
+ class ZerigoDNS::Host < ZerigoDNS::Client
2
+ include ZerigoDNS::Resource
3
+
4
+
2
5
  class << self
3
6
 
7
+
4
8
  # Find host record(s) by zone and hostname
5
- # @param [Symbol, #read] which One of :one, :first, :last, or :all. See http://api.rubyonrails.org/v3.2.1/classes/ActiveResource/Base.html#method-c-find
9
+ # @param [Symbol, #read] which One of :one, :first, :last, or :all.
6
10
  # @param [Zone, #read] zone The zone from which to find the host record.
11
+
7
12
  # @param [String, #read] hostname The hostname to find.
8
13
  # @return Host records, or an empty list if no records found.
9
14
  def find_by_zone_and_hostname which, zone, hostname
10
- fqdn = [hostname, zone.domain].select(&:present?).join('.')
11
- find(which, params: {fqdn: fqdn, zone_id: zone.id})
15
+ if which == :all
16
+ find_all_by_hostname(zone, hostname)
17
+ else
18
+ find_all_by_hostname(zone, hostname).send(which)
19
+ end
12
20
  end
13
21
 
22
+
23
+
24
+
25
+ # Find host record(s) by zone and hostname
26
+ # @param [Zone, #read] zone The zone from which to find the host record.
27
+ # @param [String, #read] hostname The hostname to find.
28
+ # @return Host records, or an empty list if no records found.
14
29
  def find_all_by_hostname zone, hostname
15
- find_by_zone_and_hostname(:all, zone, hostname)
30
+ fqdn = [hostname, zone.domain].reject(&:nil?).reject(&:empty?).join('.')
31
+ all(fqdn: fqdn, zone_id: zone.id)
16
32
  end
17
33
 
18
34
  # @return [Host] The record found, or nil.
19
35
  def find_first_by_hostname zone, hostname
20
- find_by_zone_and_hostname(:all, zone, hostname).try(:first)
36
+ find_all_by_hostname(zone, hostname).first
21
37
  end
22
38
 
23
39
  # Update or Create Host for a zone
@@ -31,7 +47,7 @@ class ZerigoDNS::Host < ZerigoDNS::Base
31
47
  def update_or_create(zone, hostname, type, ttl, data)
32
48
  host = find_first_by_hostname(zone, hostname)
33
49
  if host
34
- host.update_record(type,ttl,data)
50
+ host.update(ttl: ttl, host_type: type, data: data)
35
51
  else
36
52
  host = create(
37
53
  :zone_id => zone.id,
@@ -44,16 +60,4 @@ class ZerigoDNS::Host < ZerigoDNS::Base
44
60
  host
45
61
  end
46
62
  end
47
-
48
- # Convienence method to update the record.
49
- # @param [String, #read] type
50
- # @param [String, #read] ttl
51
- # @param [String, #read] data
52
- # @return [Boolean, #read] True if saved, false otherwise.
53
- def update_record type, ttl, data
54
- self.host_type = type
55
- self.data = data
56
- self.ttl = ttl
57
- save
58
- end
59
63
  end
@@ -1,4 +1,7 @@
1
- class ZerigoDNS::HostTemplate < ZerigoDNS::Base
1
+ class ZerigoDNS::HostTemplate < ZerigoDNS::Client
2
+
3
+ include ZerigoDNS::Resource
4
+
2
5
 
3
6
  # Fetches the zone template to which the host template belongs.
4
7
  # @return [ZoneTemplate] The zone template to which the host template belongs.
@@ -0,0 +1,3 @@
1
+ module ZerigoDNS::Middleware
2
+
3
+ end
@@ -0,0 +1,22 @@
1
+ # Rasies exceptions on errors
2
+ class ZerigoDNS::Middleware::ErrorHandler < Faraday::Middleware
3
+ # Constructs new middleware instance
4
+ def initialize app=nil, options={}
5
+ @app = app
6
+ @options = options
7
+ end
8
+
9
+ # Rasies an exception on a response code that is not HTTP OK
10
+ def call request_env
11
+ @app.call(request_env).on_complete do |response|
12
+ response[:code] = ZerigoDNS::Client::ResponseCode.new(response.status)
13
+ if response[:code].ok?
14
+ response
15
+ else
16
+ raise ZerigoDNS::Client::ResponseError.new(response)
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ Faraday::Response.register_middleware custom_error_handler: lambda {ZerigoDNS::Middleware::ErrorHandler}
@@ -0,0 +1,29 @@
1
+ # Simple XML parsing middleware for Faraday.
2
+ # uses +multi_xml+.
3
+ class ZerigoDNS::Middleware::Xml < Faraday::Middleware
4
+
5
+ XML_REGEXP = /xml/
6
+
7
+
8
+ # Parse the XML, if XML exists.
9
+ # Note: This +must+ return the response in order for the stack of middleware to continue.
10
+ # @return [Faraday::Response] The response received
11
+ def call request_env
12
+ @app.call(request_env).on_complete do |response|
13
+ if xml?(response)
14
+ response[:raw_body] = response[:body]
15
+ response[:body] = MultiXml.parse(response[:body])
16
+ end
17
+ response
18
+ end
19
+ end
20
+
21
+
22
+ private
23
+
24
+ def xml? env
25
+ !!XML_REGEXP.match(env[:response_headers]['Content-Type'])
26
+ end
27
+ end
28
+
29
+ Faraday::Response.register_middleware custom_xml: ZerigoDNS::Middleware::Xml
@@ -0,0 +1,26 @@
1
+ # Handles authentication using the Zerigo config.
2
+ class ZerigoDNS::Middleware::ZerigoAuth < Faraday::Middleware
3
+ # Constructs new middleware instance
4
+ def initialize app=nil, options={}
5
+ @app = app
6
+ end
7
+
8
+ # Adds username & api key to Basic Auth header.
9
+ # @param [Faraday::Request] env The request
10
+ def call env
11
+ # => Ruby 1.8.7 does not support Base64.strict_encode64
12
+ auth_enc = Base64.encode64(formatted_login).gsub("\n", '')
13
+ env.request_headers['Authorization'] = "Basic #{auth_enc}"
14
+ @app.call(env)
15
+ end
16
+
17
+ private
18
+
19
+ # Gets the user:password format from ZerigoDNS.config
20
+ # @return [String] formatted login details
21
+ def formatted_login
22
+ [ZerigoDNS.config.user, ZerigoDNS.config.api_key].join(':')
23
+ end
24
+ end
25
+
26
+ Faraday::Request.register_middleware zerigo_auth: ZerigoDNS::Middleware::ZerigoAuth
@@ -0,0 +1,38 @@
1
+ # A lightweight resource class that will do much of the work of ActiveResource
2
+ # without the big dependencies.
3
+
4
+ module ZerigoDNS::Resource
5
+ module ClassMethods
6
+ # Removes the root from the response and hands it off to the class to process it
7
+ # Processes an array response by delegating to the includer's self.from_response
8
+ # @param [Faraday::Response] response The response
9
+ # @return [Object] The result of the parsed response.
10
+ def process_response response
11
+ without_root = response.body.values.first
12
+ case
13
+ when without_root.is_a?(Array) then process_array(response, without_root)
14
+ when without_root.is_a?(Hash) then from_response(response, without_root)
15
+ else without_root
16
+ end
17
+ end
18
+
19
+
20
+ # Processes an array response by delegating to the includer's self.from_response
21
+ # @param [Faraday::Response] response The response
22
+ # @param [Array] body The response body, with root removed
23
+ # @return [Array] The resultant array.
24
+ def process_array response, body
25
+ body.map do |element|
26
+ from_response response, element
27
+ end
28
+ end
29
+ end
30
+
31
+
32
+ def self.included includer
33
+ includer.send :include, Attributes
34
+ includer.send :include, Rest
35
+ includer.send :include, Naming
36
+ includer.send :extend, ClassMethods
37
+ end
38
+ end
@@ -0,0 +1,59 @@
1
+ # Simple attribute handling for resources
2
+ # Ties in with ZerigoDNS::Resource by defining a
3
+ # from_response method to initialize the class by its attributes.
4
+ module ZerigoDNS::Resource::Attributes
5
+ module InstanceMethods
6
+ attr_accessor :attributes
7
+
8
+
9
+ # Allows method-style access to the attributes.
10
+ def method_missing mtd, *args
11
+ if mtd.to_s.chars.to_a.last == '='
12
+ raise ArgumentError, "Invalid number of arguments (#{args.length} for 1)" if args.length != 1
13
+ attributes[mtd.to_s.slice(0,mtd.to_s.length-1)] = args.first
14
+ else
15
+ raise ArgumentError, "Invalid number of arguments (#{args.length} for 0)" if args.length != 0
16
+ attributes[mtd.to_s]
17
+ end
18
+ end
19
+
20
+ # Converts the resource to a hash
21
+ # @return [Hash] The attributes
22
+ def to_hash
23
+ attributes
24
+ end
25
+
26
+ # Initialize a new resource
27
+ # @param [Hash] attributes Initial attributes.
28
+ def initialize attributes={}
29
+ @attributes = {}
30
+ merge_attributes attributes
31
+ end
32
+
33
+ private
34
+
35
+ # Merge current attributes with specified ones.
36
+ # Will handle symbols as well as strings as keys
37
+ # @param [Hash] attrs Attributes to merge
38
+ def merge_attributes attrs
39
+ attrs.each do |key, val|
40
+ send("#{key}=", val)
41
+ end
42
+ end
43
+ end
44
+
45
+
46
+ module ClassMethods
47
+ # Constructs a new resource from a response
48
+ # @param [Faraday::Response] response The response
49
+ # @param [Hash] body The response body without root
50
+ def from_response response, body
51
+ new body
52
+ end
53
+ end
54
+
55
+ def self.included includer
56
+ includer.send :include, InstanceMethods
57
+ includer.send :extend, ClassMethods
58
+ end
59
+ end
@@ -0,0 +1,47 @@
1
+ # Simple attribute handling for resources
2
+ # Ties in with ZerigoDNS::Resource by defining a
3
+ # from_response method to initialize the class by its attributes.
4
+ module ZerigoDNS::Resource::Naming
5
+
6
+ module ClassMethods
7
+ # Default Resource Name
8
+ # @return [String] generated resource name from class name "e.g. ZerigoDNS::ZoneTemplate -> zone_template"
9
+ def default_resource_name
10
+ result = self.to_s.split("::").last.gsub(/([A-Z])/, '_\1').downcase
11
+ result.slice 1, result.length
12
+ end
13
+
14
+
15
+ # Default base path.
16
+ # @return [String] Generated base path from class name (default_resource_name + "s")
17
+ def default_base_path
18
+ "#{resource_name}s"
19
+ end
20
+
21
+
22
+ # Sets & gets the "resource name", which is required for the create & update actions.
23
+ # @param [String] name resource name
24
+ # @return [String] the base path
25
+ def resource_name name=nil
26
+ if name
27
+ @resource_name = name
28
+ end
29
+ @resource_name || default_resource_name
30
+ end
31
+
32
+ # Sets or gets the "base path", where the resource is located.
33
+ # @param [String] path base path
34
+ # @return [String] the base path
35
+ def base_path path=nil
36
+ if path
37
+ @base_path = path
38
+ end
39
+ @base_path || default_base_path
40
+ end
41
+ end
42
+
43
+
44
+ def self.included includer
45
+ includer.send :extend, ClassMethods
46
+ end
47
+ end
@@ -0,0 +1,80 @@
1
+ # Puts a basic resource abstraction over basic REST calls.
2
+ module ZerigoDNS::Resource::Rest
3
+ module InstanceMethods
4
+
5
+ # Update this instance's resource with attributes supplied into +params+
6
+ # @param [Hash] params The attributes to set
7
+ # @return [Object] The instance on which +update+ was called
8
+ def update params
9
+ self.class.update id, params
10
+ merge_attributes params
11
+ self
12
+ end
13
+
14
+ # Destroy this instance's resource
15
+ # @param [Hash] params The attributes to set
16
+ # @raise [ZerigoDNS::Client::ResponseError] if delete does not succeed.
17
+ # @return [Faraday::Response] The response returned from the server.
18
+ def destroy params={}
19
+ self.class.destroy id, params
20
+ end
21
+ end
22
+
23
+ module ClassMethods
24
+
25
+ # Lists all resources
26
+ # @return [Array] The resources as an array
27
+ def all params={}
28
+ process_response get("#{base_path}.xml", params)
29
+ end
30
+
31
+ # Find a single resource
32
+ # @param [Object] id_or_name The id or name of the resource to find
33
+ # @raise [ZerigoDNS::Client::ResponseError] if the find does not succeed.
34
+ # @return [Object] The requested resource.
35
+ def find id_or_name, params={}
36
+ process_response get("#{base_path}/#{id_or_name}.xml", params)
37
+ end
38
+
39
+ # Updates a single resource
40
+ # @param [Object] id_or_name Id or name of the resource
41
+ # @raise [ZerigoDNS::Client::ResponseError] if update does not succeed.
42
+ # @return [Faraday::Response] The response returned by the server.
43
+ def update id_or_name, params={}
44
+ put "#{base_path}/#{id_or_name}.xml", convert(params)
45
+ end
46
+
47
+ # Creates a resource
48
+ # @param [Object] params Parameters to pass to create action
49
+ # @raise [ZerigoDNS::Client::ResponseError] if create does not succeed.
50
+ # @return [Object] the created resource
51
+ def create params={}
52
+ process_response(post "#{base_path}.xml", convert(params))
53
+ end
54
+
55
+ # Deletes a resource
56
+ # @param [Object] params Parameters to pass to delete action
57
+ # @raise [ZerigoDNS::Client::ResponseError] if destroy does not succeed.
58
+ def destroy id_or_name, params={}
59
+ delete "#{base_path}/#{id_or_name}.xml", params
60
+ end
61
+
62
+
63
+ private
64
+
65
+ # Converts a resource object to a hash.
66
+ # @param [Object] object to convert to a hash
67
+ # @raise [ArgumentError] if the object given does not respond to to_hash
68
+ def convert object
69
+ return {resource_name => object} if object.is_a? Hash
70
+ {resource_name => object.to_hash}
71
+ end
72
+
73
+ end
74
+
75
+ def self.included includer
76
+ includer.send :include, InstanceMethods
77
+ includer.send :extend, ClassMethods
78
+ end
79
+ end
80
+
@@ -1,22 +1,22 @@
1
- class ZerigoDNS::Tools < ZerigoDNS::Base
1
+ class ZerigoDNS::Tools < ZerigoDNS::Client
2
2
  class <<self
3
3
 
4
4
  # Fetch current public ipv4 address
5
5
  # @return [String] Current public ipv4 address or "unknown"
6
6
  def public_ipv4
7
- get :public_ipv4
7
+ get('tools/public_ipv4.xml').body['ipv4']
8
8
  end
9
9
 
10
10
  # Fetch current public ipv6 address
11
11
  # @return [String] Current public ipv6 address or "unknown"
12
12
  def public_ipv6
13
- get :public_ipv6
13
+ get('tools/public_ipv6.xml').body['ipv6']
14
14
  end
15
15
 
16
16
  # Fetch the current public IP address (either ipv4 or ipv6)
17
17
  # @return [String] Current public ip address (ipv4 or ipv6)
18
18
  def public_ip
19
- get :public_ip
19
+ get('tools/public_ip').body['ipv4'] || get('tools/public_ip').body['ipv6']
20
20
  end
21
21
  end
22
22
 
@@ -1,9 +1,12 @@
1
- class ZerigoDNS::Zone < ZerigoDNS::Base
1
+ class ZerigoDNS::Zone < ZerigoDNS::Client
2
+ include ZerigoDNS::Resource
3
+
2
4
  class <<self
5
+
3
6
  # Get count of all zones
4
7
  # @return [Fixnum] Count of all zones
5
8
  def count
6
- get(:count).to_i
9
+ get('zones/count.xml').body['count'].to_i
7
10
  end
8
11
 
9
12
  # Find zone by domain name
@@ -19,7 +22,8 @@ class ZerigoDNS::Zone < ZerigoDNS::Base
19
22
  # @return [Zone] the zone found or created.
20
23
  def find_or_create(domain)
21
24
  find_by_domain(domain)
22
- rescue ActiveResource::ResourceNotFound
25
+ rescue ZerigoDNS::Client::ResponseError => e
26
+ raise unless e.response.code.not_found?
23
27
  create(:domain=> domain, :ns_type=>'pri_sec')
24
28
  end
25
29
  end
@@ -27,6 +31,6 @@ class ZerigoDNS::Zone < ZerigoDNS::Base
27
31
  # Get count of all hosts belonging to this zone
28
32
  # @return [Fixnum] Count of all hosts belonging to this zone.
29
33
  def count_hosts
30
- get('hosts/count').to_i
34
+ get("zones/#{id}/hosts/count.xml").body['count'].to_i
31
35
  end
32
36
  end
@@ -1,15 +1,17 @@
1
- class ZerigoDNS::ZoneTemplate < ZerigoDNS::Base
1
+ class ZerigoDNS::ZoneTemplate < ZerigoDNS::Client
2
+
3
+ include ZerigoDNS::Resource
2
4
 
3
5
  # Get count of zone templates
4
6
  # @return [Fixnum] the count of zone templates
5
7
  def self.count
6
- get(:count).to_i
8
+ get('zone_templates/count.xml').body['count'].to_i
7
9
  end
8
10
 
9
11
  # Get count of host templates
10
12
  # @return [Fixnum] the count of host templates for this zone template
11
13
  def count_host_templates
12
- get('host_templates/count').to_i
14
+ get("zone_templates/#{id}/host_templates/count.xml").body['count'].to_i
13
15
  end
14
16
 
15
17
  # Create a zone using the zone template
@@ -28,7 +30,7 @@ class ZerigoDNS::ZoneTemplate < ZerigoDNS::Base
28
30
  # List all host templates of this zone template
29
31
  # @return [Array] An array of host templates
30
32
  def host_templates
31
- @host_templates ||= ZerigoDNS::HostTemplate.find(:all, params: {zone_template_id: id})
33
+ @host_templates ||= ZerigoDNS::HostTemplate.all(zone_template_id: id)
32
34
  end
33
35
 
34
36
  # Create a host template for this template
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zerigodns
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,16 +10,32 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-02-03 00:00:00.000000000 Z
13
+ date: 2015-02-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: activeresource
16
+ name: faraday
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: 3.2.0
22
+ version: 0.9.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 0.9.1
31
+ - !ruby/object:Gem::Dependency
32
+ name: multi_xml
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 0.5.5
23
39
  type: :runtime
24
40
  prerelease: false
25
41
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,7 +43,7 @@ dependencies:
27
43
  requirements:
28
44
  - - ~>
29
45
  - !ruby/object:Gem::Version
30
- version: 3.2.0
46
+ version: 0.5.5
31
47
  - !ruby/object:Gem::Dependency
32
48
  name: yard
33
49
  requirement: !ruby/object:Gem::Requirement
@@ -92,6 +108,22 @@ dependencies:
92
108
  - - ~>
93
109
  - !ruby/object:Gem::Version
94
110
  version: 0.9.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: 0.10.1
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ~>
125
+ - !ruby/object:Gem::Version
126
+ version: 0.10.1
95
127
  description: Gem for interacting with the Zerigo DNS REST API.
96
128
  email: support@zerigo.com
97
129
  executables: []
@@ -101,11 +133,19 @@ extra_rdoc_files:
101
133
  files:
102
134
  - LICENSE
103
135
  - Rakefile
104
- - lib/activeresource-ext.rb
105
- - lib/zerigodns/base.rb
136
+ - lib/zerigodns/client/response_code.rb
137
+ - lib/zerigodns/client.rb
106
138
  - lib/zerigodns/config.rb
107
139
  - lib/zerigodns/host.rb
108
140
  - lib/zerigodns/host_template.rb
141
+ - lib/zerigodns/middleware/error_handler.rb
142
+ - lib/zerigodns/middleware/xml.rb
143
+ - lib/zerigodns/middleware/zerigo_auth.rb
144
+ - lib/zerigodns/middleware.rb
145
+ - lib/zerigodns/resource/attributes.rb
146
+ - lib/zerigodns/resource/naming.rb
147
+ - lib/zerigodns/resource/rest.rb
148
+ - lib/zerigodns/resource.rb
109
149
  - lib/zerigodns/tools.rb
110
150
  - lib/zerigodns/zone.rb
111
151
  - lib/zerigodns/zone_template.rb
@@ -1,43 +0,0 @@
1
- require 'active_resource'
2
- require 'active_support/core_ext/module'
3
-
4
- module ActiveResource
5
- module CaptureHeaders
6
- module InstanceMethods
7
- private
8
- def request_with_headers(method, path, *arguments)
9
- request_without_headers(method, path, *arguments).tap do |resp|
10
- @headers = resp.to_hash
11
- end
12
- end
13
-
14
- end
15
-
16
- def self.included(receiver)
17
- receiver.class_eval do
18
- include InstanceMethods
19
- alias_method_chain :request, :headers
20
- attr :headers
21
- end
22
- end
23
- end
24
-
25
- module RetrieveHeaders
26
- module InstanceMethods
27
- def last_count
28
- @last_count ||= (c = connection.headers['x-query-count']) ? c[0].to_i : nil
29
- end
30
-
31
- end
32
-
33
- def self.included(receiver)
34
- receiver.class_eval do
35
- include InstanceMethods
36
- end
37
- end
38
- end
39
-
40
- end
41
-
42
- ActiveResource::Connection.send :include, ActiveResource::CaptureHeaders
43
- ActiveResource::Base.send :include, ActiveResource::RetrieveHeaders
@@ -1,47 +0,0 @@
1
- module ZerigoDNS
2
- class Base < ActiveResource::Base
3
- class << self
4
- attr_reader :secure
5
- alias_method :api_key, :password
6
- alias_method :api_key=, :password=
7
- def secure=(bool)
8
- @secure=bool
9
- self.site = @secure ? 'https://ns.zerigo.com/api/1.1/' : 'http://ns.zerigo.com/api/1.1/'
10
- end
11
- end
12
-
13
- self.site='https://ns.zerigo.com/api/1.1/'
14
- self.timeout = 5 # timeout after 5 seconds
15
- self.format = ActiveResource::Formats::XmlFormat
16
- @secure = true
17
-
18
-
19
-
20
- # fix load() so that it no longer clobbers @prefix_options
21
- # also fix bug exposed by reload() where attributes is effectively parsed twice, causing the first line to raise an exception the 2nd time
22
- def load(attributes, remove_root = false)
23
- raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash)
24
- new_prefix_options, attributes = split_options(attributes)
25
- @prefix_options.merge!(new_prefix_options)
26
- attributes.each do |key, value|
27
- @attributes[key.to_s] =
28
- case value
29
- when Array
30
- if value.all?{|v2| v2.kind_of?(ActiveResource::Base)}
31
- value.dup rescue value
32
- else
33
- resource = find_or_create_resource_for_collection(key)
34
- value.map { |attrs| attrs.is_a?(String) ? attrs.dup : resource.new(attrs) }
35
- end
36
- when Hash
37
- resource = find_or_create_resource_for(key)
38
- resource.new(value)
39
- else
40
- value.dup rescue value
41
- end
42
- end
43
- self
44
- end
45
- end
46
- end
47
-