Sha256: ea21a71677e4f8ad8b493236e88112c845d30f24a3058a66ff99ecc286a24339

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

module Dimelo::CCP
  class User < Dimelo::CCP::API::Model
    CUSTOM_FIELD_COUNT = 10
    CUSTOM_FIELD_ATTRIBUTES = (1..CUSTOM_FIELD_COUNT).map { |i| "custom_field_#{i}".to_sym }.freeze

    attributes :id, :firstname, :lastname, :screenname, :signature, :email, :private_message, :type, :username, :flow_state, :about, :avatar, :created_at, :updated_at, :blocked, :team, :avatar_url
    attributes *CUSTOM_FIELD_ATTRIBUTES

    submit_attributes :type, :firstname, :lastname, :email, :username, :avatar_url, :about, :password, :created_at, :confirmed_at, *CUSTOM_FIELD_ATTRIBUTES

    has_many :memberships
    has_many :questions
    has_many :answers
    has_many :feedbacks

    def avatar_url(size='normal')
      @avatar_url || avatar.try(:[], size).try(:[], 'url')
    end

    # Blocks the specified user
    def block
      path = "#{compute_path(attributes)}/block"
      response = client.transport(:post, path)
      self.attributes = Dimelo::CCP::API.decode_json(response)
      errors.empty?
    end

    # Unblocks the specified user
    def unblock
      path = "#{compute_path(attributes)}/unblock"
      response = client.transport(:post, path)
      self.attributes = Dimelo::CCP::API.decode_json(response)
      errors.empty?
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dimelo_ccp_api-0.5.0 lib/dimelo/ccp/api/model/user.rb
dimelo_ccp_api-0.4.4 lib/dimelo/ccp/api/model/user.rb
dimelo_ccp_api-0.4.3 lib/dimelo/ccp/api/model/user.rb