Sha256: dd401fda60833330d5733f9842f946110785ae79ec6a02b76d04f1f50ca1e4c4
Contents?: true
Size: 1.02 KB
Versions: 4
Compression:
Stored size: 1.02 KB
Contents
module Holistics module Model class Resource attr_accessor :name attr_accessor :errors def initialize(client, name) @client = client @name = name end def all(params = {}) status, body = @client.get("/#{@name}.json", { params: params }) handle_http_result(status, body) end def find(id, params = {}) status, body = @client.get("/#{@name}/#{id}.json", { params: params }) handle_http_result(status, body) end def delete(id, params = {}) status, body = @client.delete("/#{@name}/#{id}.json", { params: params }) handle_http_result(status, body) end private def handle_http_result(status, body) self.errors = nil result = JSON.parse(body) if status == 200 result else self.errors = [result['error']].concat(result['errors'] || []).compact STDERR.puts self.errors.join("\n").red exit 1 end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems