lib/rapidash/client.rb in rapidash-0.1.2 vs lib/rapidash/client.rb in rapidash-0.2.0
- old
+ new
@@ -1,14 +1,67 @@
module Rapidash
class Client
- include Clientable
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 = {})
@@ -24,8 +77,7 @@
end
def delete(url, options = {})
request(:delete, url, options)
end
-
end
end