Sha256: 327cadc5844fbaaf7593a5e1d149982e1755263a8fa462752c2f3bbe9dd92f41

Contents?: true

Size: 921 Bytes

Versions: 5

Compression:

Stored size: 921 Bytes

Contents

module Methods
  extend ActiveSupport::Concern

  included do
    attr_accessor :server # server at runtime

    SORT_ORDERS = ['created_at', '-created_at', 'updated_at', '-updated_at'].freeze

    scope :active, -> { where(active: true) }

    validates_uniqueness_of :token, message: 'has already been used'
    validates_presence_of :token
    validates_presence_of :team_id

    def deactivate!
      update_attributes!(active: false)
    end

    def activate!(token)
      update_attributes!(active: true, token: token)
    end

    def to_s
      {
        name: name,
        domain: domain,
        id: team_id
      }.map do |k, v|
        "#{k}=#{v}" if v
      end.compact.join(', ')
    end

    def ping!
      client = Slack::Web::Client.new(token: token)
      auth = client.auth_test
      {
        auth: auth,
        presence: client.users_getPresence(user: auth['user_id'])
      }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
slack-ruby-bot-server-0.12.2 lib/slack-ruby-bot-server/models/team/methods.rb
slack-ruby-bot-server-0.12.1 lib/slack-ruby-bot-server/models/team/methods.rb
slack-ruby-bot-server-0.12.0 lib/slack-ruby-bot-server/models/team/methods.rb
slack-ruby-bot-server-0.11.1 lib/slack-ruby-bot-server/models/team/methods.rb
slack-ruby-bot-server-0.11.0 lib/slack-ruby-bot-server/models/team/methods.rb