Sha256: 368bdeb4001bc739fa3359019fd60089b87cab156b34024d839518b4fde22019

Contents?: true

Size: 856 Bytes

Versions: 1

Compression:

Stored size: 856 Bytes

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 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.2 lib/rapidash/base.rb