Sha256: 228ab9d1d598f38f37c0fb3e884bb2dbb0b16f98f1e7f504762dda462c703ac4

Contents?: true

Size: 977 Bytes

Versions: 4

Compression:

Stored size: 977 Bytes

Contents

module Open311
  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

4 entries across 4 versions & 1 rubygems

Version Path
open311-0.2.3 lib/open311/client/request.rb
open311-0.2.2 lib/open311/client/request.rb
open311-0.2.1 lib/open311/client/request.rb
open311-0.2.0 lib/open311/client/request.rb