Sha256: fd24f42f351a364279ebe6c9e60dcee542f7c457b49b571f17e37b33c7b4f287

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

module ZerigoDNS
  class Client
    
    #@!attribute response [r]
    # @return [Faraday::Response] exposes the response.
    ResponseError = Class.new(RuntimeError) do 
      attr_reader :response
      
      # Initialize a new ResponseError with a response.
      def initialize response=nil
        @response=response
      end
      
      # Convert to a string
      # @return [String] The error's message.
      def to_s
        inspect
      end
      
      # @return [String] The error's message
      def message
        inspect
      end
      
      # @return [String] The error's message
      def inspect
        "HTTP Response Error: #{response && response.status}"
      end
    end
    
    # Standard REST Actions
    ACTIONS = %w(get post put patch delete)
    
    ACTIONS.each do |action|
      define_method action do |*args|
        self.class.send(action, *args)
      end
    end
    
    
    class <<self
      # Gets or creates a new faraday connection.
      def connection
        
        # => Note:  Order matters here!
        @connection ||= Faraday.new(
          url: ZerigoDNS.config.site, 
        ) do |faraday|
          faraday.request :zerigo_auth
          faraday.request :multipart
          faraday.request :url_encoded
          
          faraday.adapter Faraday.default_adapter
          
          faraday.response :custom_xml
          faraday.response :custom_error_handler
        end
      end
      
      ACTIONS.each do |action|
        define_method action do |*args|
          connection.send action, *args
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zerigodns-1.1.0 lib/zerigodns/client.rb