lib/rapidash/base.rb in rapidash-0.0.1 vs lib/rapidash/base.rb in rapidash-0.0.2
- old
+ new
@@ -1,20 +1,41 @@
module Rapidash
class Base
include Urlable
+ include Resourceable
attr_accessor :url, :options, :client
- def initialize
- raise ConfigurationError.new "Missing URL attribute on the resource, set it by calling `url` in your resource class"
+ def initialize(*args)
+ @client, @id, options = args
+
+ if @id.is_a?(Hash)
+ options = @id
+ @id = nil
+ end
+
+ @options ||= {}
+ @options.merge!(options || {})
+ @url = "#{base_url}#{self.class.to_s.split("::")[-1].downcase}"
+ @url += "/#{@id}" if @id
end
def call!
self.options ||= {}
+ self.options.delete(:previous_url)
self.options[:header] ||= {}
self.options[:header]["content-type"] = "application/json"
method = self.options.delete(:method) || :get
client.send(method, url, self.options)
+ end
+
+ private
+
+ def base_url
+ if old_url = self.options[:previous_url]
+ return "#{old_url}/"
+ end
+ ""
end
end
end