Sha256: 082f060c1418a3a0c8f1aebcacb370c00be9bd9403a695107d2f52aeefad4c8d

Contents?: true

Size: 864 Bytes

Versions: 2

Compression:

Stored size: 864 Bytes

Contents

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

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

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

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

    private

      def request(method, path, options)
        connection.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.body
      end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
open311-0.3.1 lib/open311/client/request.rb
open311-0.3.0 lib/open311/client/request.rb