Sha256: 3dbc032968228b342a740d8cb3c05e981858e4a2c73301ac076531b0bcd5de0a

Contents?: true

Size: 712 Bytes

Versions: 2

Compression:

Stored size: 712 Bytes

Contents

require 'routemaster/api_client'

module Routemaster
  module Resources
    class RestResource
      attr_reader :url

      def initialize(url, client: nil)
        @url = url
        @client = client || Routemaster::APIClient.new(response_class: Responses::HateoasResponse)
      end

      def create(params)
        @client.post(@url, body: params)
      end

      def show(id=nil)
        @client.get(@url.gsub('{id}', id.to_s))
      end

      def index
        @client.get(@url)
      end

      def update(id=nil, params)
        @client.patch(@url.gsub('{id}', id.to_s), body: params)
      end

      def destroy(id=nil)
        @client.delete(@url.gsub('{id}', id.to_s))
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
routemaster-drain-2.3.0 lib/routemaster/resources/rest_resource.rb
routemaster-drain-2.2.2 lib/routemaster/resources/rest_resource.rb