module Unchained::Client::Mixins::Resource

The Resource mixin gives you access to a DSL that lets you define what the class should look like in the JSON response.

Usage:

class Guild
  include Unchained::Client::Mixins::Resource

  attribute :id, String
  attribute :name, String
  attribute :members, Integer, json: 'numberOfMembers'
  attribute :faction, Integer, expand: :faction
end

Public Class Methods

included(base) click to toggle source
# File lib/unchained/client/mixins/resource.rb, line 59
def self.included(base)
  base.extend ClassMethods
end

Public Instance Methods

to_s() click to toggle source

Mostly just a helper method that you can override if you want to.

# File lib/unchained/client/mixins/resource.rb, line 65
def to_s
  attrs = self.class.attributes.map do |attr|
    "#{attr.name}=#{self.send(attr.name)}"
  end.join(', ')

  "[#{self.class.name.split('::').last}] #{attrs}"
end