Sha256: 565249409ded45b57fe36be8ee81ce4d59463fca96d869faa407f522328aee9d

Contents?: true

Size: 650 Bytes

Versions: 4

Compression:

Stored size: 650 Bytes

Contents

module Masheri
  class ApiObjectBase
    def self.create(fields = {})
      # XXX: only send fields that aren't read-only
      new(Masheri.client.call_remote(method('create'), fields))
    end

    def self.fetch(id)
      data = Masheri.client.call_remote(method('fetch'), id)
      data.nil?? nil : new(data)
    end

    def self.delete(id)
      Masheri.client.call_remote(method('delete'), id)
    end

    def self.method(basename)
      "#{name.split(/\:\:/).last.downcase}.#{basename}"
    end

    def initialize(data)
      # XXX: use setter methods
      data.each_pair {|k, v| instance_variable_set("@#{k}".to_sym, v)}
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
masheri-0.3.1 lib/masheri/api_object_base.rb
masheri-0.2.0 lib/masheri/api_object_base.rb
masheri-0.1.1 lib/masheri/api_object_base.rb
masheri-0.1.0 lib/masheri/api_object_base.rb