Sha256: faf56c5d4d7d8de1580c1fdf2b6a36ed14d5e9cacb277be8a8e42369813fabb7

Contents?: true

Size: 833 Bytes

Versions: 1

Compression:

Stored size: 833 Bytes

Contents

module Rapidash
  module Clientable

    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods

      def method(method)
        if method == :http
          include HTTPClient
        elsif method == :oauth
          include OAuthClient
        else
          raise ConfigurationError.new "Invalid API Authentication Method"
        end
      end

      def resource(name)
        mod = self.to_s.split("::")[0...-1]
        if mod.empty?
          mod = Kernel
        else
          mod = Kernel.const_get(mod.join("::"))
        end
        klass = mod.const_get(name.capitalize)
        define_method(name) do |*args|
          klass.new(self, *args)
        end
        define_method("#{name}!".to_sym) do |*args|
          klass.new(self, *args).call!
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rapidash-0.0.1 lib/rapidash/clientable.rb