Sha256: 6876f78032783ed039b08a8538f3640c4b16a10cc98ae592def39b31fc351914
Contents?: true
Size: 1.58 KB
Versions: 44
Compression:
Stored size: 1.58 KB
Contents
# This class includes methods for calling restful APIs module ApiClient module Resource class Scope < ApiClient::Scope dsl_accessor :path, :return_self => true def format @scopeable.format end def append_format(path) format ? [path, format].join('.') : path end def find(id) path = [@path, id].join('/') path = append_format(path) response = get(path) scoped(self) do raw? ? response : @scopeable.build(response) end end def find_all(params = {}) path = append_format(@path) response = get(path, params) scoped(self) do raw? ? response : @scopeable.build(response) end end def create(params = {}) path = append_format(@path) hash = if @scopeable.namespace { @scopeable.namespace => params } else params end response = post(path, hash) scoped(self) do raw? ? response : @scopeable.build(response) end end def update(id, params = {}) path = [@path, id].join('/') path = append_format(path) hash = if @scopeable.namespace { @scopeable.namespace => params } else params end response = put(path, hash) scoped(self) do raw? ? response : @scopeable.build(response) end end def destroy(id) path = [@path, id].join('/') path = append_format(path) delete(path) true end end end end
Version data entries
44 entries across 44 versions & 1 rubygems