Sha256: f9dd0edd50bb739f751dd5fbca1ce6afcc56a8c8cea40b20fa91fe46407a3dfc

Contents?: true

Size: 1.6 KB

Versions: 3

Compression:

Stored size: 1.6 KB

Contents

module Rapidash
  class Client
    include Resourceable

    attr_accessor :extension

    def initialize
      raise ConfigurationError.new "Missing Method, define using `method` on your client"
    end

    class << self
      attr_accessor :patch, :raise_error

      def method(method)
        case method
        when :http then include HTTPClient
        when :oauth then include OAuthClient
        when :test then include TestClient
        else
          raise ConfigurationError.new "Invalid API Authentication Method"
        end
      end

      def use_patch
        @patch = true
      end

      def extension(extension = nil)
        @extension ||= extension
      end

      def site(site = nil)
        @site ||= site
      end

      def raise_errors
        @raise_error = true
      end
    end

    # Instance methods

    def site
      return @site if @site
      self.class.respond_to?(:site) && self.class.site
    end

    def site=(value)
      @site = value
      @connection = nil
    end

    def normalize_url(url)
      if extension
        "#{url}.#{extension}"
      elsif self.class.respond_to?(:extension) && self.class.extension
        "#{url}.#{self.class.extension}"
      else
        url
      end
    end

    def get(url, options = {})
      request(:get, url, options)
    end

    def post(url, options = {})
      request(:post, url, options)
    end

    def put(url, options = {})
      request(:put, url, options)
    end

    def patch(url, options = {})
      request(:patch, url, options)
    end

    def delete(url, options = {})
      request(:delete, url, options)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rapidash-0.2.2 lib/rapidash/client.rb
rapidash-0.2.1 lib/rapidash/client.rb
rapidash-0.2.0 lib/rapidash/client.rb