lib/rapidash/base.rb in rapidash-0.1.2 vs lib/rapidash/base.rb in rapidash-0.2.0
- old
+ new
@@ -1,8 +1,7 @@
module Rapidash
class Base
-
include Urlable
include Resourceable
attr_accessor :url, :options, :client
@@ -22,11 +21,11 @@
@id = nil
end
@options ||= {}
@options.merge!(options || {})
- @url = "#{base_url}#{self.class.to_s.split("::")[-1].downcase}"
+ @url = "#{base_url}#{resource_url}"
@url += "/#{@id}" if @id
end
def create!(params)
options[:method] = :post
@@ -53,23 +52,26 @@
options[:headers]["content-type"] = "application/json"
method = options.delete(:method) || :get
client.send(method, url, options)
end
+
private
def set_body!(params)
if self.class.root_element
- options[:body] = {self.class.root_element => params}.to_json
+ options[:body] = {self.class.root_element => params}
else
- options[:body] = params.to_json
+ options[:body] = params
end
end
def base_url
- if old_url = self.options[:previous_url]
- return "#{old_url}/"
- end
- ""
+ old_url = self.options[:previous_url]
+ old_url ? "#{old_url}/" : ""
+ end
+
+ def resource_url
+ self.options[:url] || self.class.to_s.split("::")[-1].downcase.pluralize
end
end
end