Sha256: 4e3f84b59a5f902055049ee21048682547bf263cce4ebf5ae38c97e18b4d2387
Contents?: true
Size: 1.3 KB
Versions: 21
Compression:
Stored size: 1.3 KB
Contents
require 'addressable/template' require 'routemaster/api_client' require 'routemaster/responses/hateoas_enumerable_response' require 'routemaster/responses/hateoas_response' module Routemaster module Resources class RestResource def initialize(url, client: nil) @url_template = Addressable::Template.new(url) @client = client || Routemaster::APIClient.new end def create(params) @client.post(expanded_url, body: params) end def show(id=nil, enable_caching: true) @client.get(expanded_url(id: id), options: { enable_caching: enable_caching }) end def index(params: {}, filters: {}, enable_caching: false) @client.get( expanded_url, params: params.merge(filters), options: { enable_caching: enable_caching, response_class: Responses::HateoasEnumerableResponse } ) end def update(id=nil, params) @client.patch(expanded_url(id: id), body: params) end def destroy(id=nil) # no response wrapping as DELETE is supposed to 204. @client.delete(expanded_url(id: id)) end def url @url_template.pattern end private def expanded_url(**params) @url_template.expand(params).to_s end end end end
Version data entries
21 entries across 21 versions & 1 rubygems