Sha256: 142afb7f2e37545008953886c69e827533ebf7e583fd7514b331b2ccc6f12013

Contents?: true

Size: 979 Bytes

Versions: 1

Compression:

Stored size: 979 Bytes

Contents

module FccReboot
  class Client
    module Request
      def get(path, options={}, raw=false)
        request(:get, path, options, raw)
      end

      def post(path, options={}, raw=false)
        request(:post, path, options, raw)
      end

      def put(path, options={}, raw=false)
        request(:put, path, options, raw)
      end

      def delete(path, options={}, raw=false)
        request(:delete, path, options, raw)
      end

      private

      def request(method, path, options, raw)
        response = connection(raw).send(method) do |request|
          case method
          when :get, :delete
            request.url(formatted_path(path), options)
          when :post, :put
            request.path = formatted_path(path)
            request.body = options unless options.empty?
          end
        end
        raw ? response : response.body
      end

      def formatted_path(path)
        [path, format].compact.join('.')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fcc_reboot-0.1 lib/fcc_reboot/client/request.rb