class Routemaster::Resources::RestResource

Public Class Methods

new(url, client: nil) click to toggle source
# File lib/routemaster/resources/rest_resource.rb, line 10
def initialize(url, client: nil)
  @url_template = Addressable::Template.new(url)
  @client = client || Routemaster::APIClient.new
end

Public Instance Methods

create(params) click to toggle source
# File lib/routemaster/resources/rest_resource.rb, line 15
def create(params)
  @client.post(expanded_url, body: params)
end
destroy(id=nil) click to toggle source
# File lib/routemaster/resources/rest_resource.rb, line 36
def destroy(id=nil)
  # no response wrapping as DELETE is supposed to 204.
  @client.delete(expanded_url(id: id))
end
index(params: {}, filters: {}, enable_caching: false) click to toggle source
# File lib/routemaster/resources/rest_resource.rb, line 23
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
show(id=nil, enable_caching: true) click to toggle source
# File lib/routemaster/resources/rest_resource.rb, line 19
def show(id=nil, enable_caching: true)
  @client.get(expanded_url(id: id), options: { enable_caching: enable_caching })
end
update(id=nil, params) click to toggle source
# File lib/routemaster/resources/rest_resource.rb, line 32
def update(id=nil, params)
  @client.patch(expanded_url(id: id), body: params)
end
url() click to toggle source
# File lib/routemaster/resources/rest_resource.rb, line 41
def url
  @url_template.pattern
end

Private Instance Methods

expanded_url(**params) click to toggle source
# File lib/routemaster/resources/rest_resource.rb, line 47
def expanded_url(**params)
  @url_template.expand(params).to_s
end