module Zzlink # User session. class Session attr_accessor :token, :user_id, :client_id, :created_at, :updated_at def initialize(attributes = {}) from_hash(attributes) end def from_hash(attributes) attributes.each_key do |k| setter = case k.to_sym when :userId then :user_id= when :clientId then :client_id= when :createdAt then :created_at= when :updatedAt then :updated_at= else "#{k}=".to_sym end send(setter, attributes[k]) if respond_to?(setter) end end def to_hash hash = {} hash[:userId] = user_id unless user_id.nil? hash[:clientId] = client_id unless client_id.nil? hash[:token] = token unless token.nil? hash[:createdAt] = created_at unless created_at.nil? hash[:updatedAt] = updated_at unless updated_at.nil? hash end end end