Sha256: 58a434e6e9d0304b9c3404fdbf7e30938f49718f3d2d033b1859954cfcfe4e81
Contents?: true
Size: 1.21 KB
Versions: 6
Compression:
Stored size: 1.21 KB
Contents
module Helium # TODO make Metadata inherit from Resource and implement method_missing # for all resources to automatically generate methods for attributes # rather than whitelisting them with hardcoding class Metadata def initialize(opts = {}) @client = opts.fetch(:client) @klass = opts.fetch(:klass) @params = fetch_params end def id @klass.id end def properties @params["attributes"] end def inspect "<Helium::Metadata properties=#{properties}>" end def method_missing(method_name, *arguments, &block) properties[method_name.to_s] || super end def respond_to_missing?(method_name, include_private = false) properties[method_name.to_s] || super end def update(attributes = {}) body = { data: { attributes: attributes, id: id, type: "metadata" } } response = @client.patch(path, body: body) @params = JSON.parse(response.body)["data"] return self end protected def path "#{@klass.resource_path}/metadata" end def fetch_params response = @client.get(path) JSON.parse(response.body)["data"] end end end
Version data entries
6 entries across 6 versions & 1 rubygems