Sha256: 1d4bb8e27f963bb7a47c4da73af315b0adaf424691bd11aa0a055688c7e70037
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
module Rapidash class Base include Urlable include Resourceable attr_accessor :url, :options, :client 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 create!(params) self.options[:method] = :post self.options[:body] = params.to_json call! end def update!(params) self.options[:method] = client.class.patch ? :patch : :put self.options[:body] = params.to_json call! end def delete! self.options[:method] = :delete call! 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
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rapidash-0.0.4 | lib/rapidash/base.rb |