Class: Slack::RtmApi2

Inherits:
Object
  • Object
show all
Defined in:
lib/slack/rtmapi2.rb,
lib/slack/rtmapi2/client.rb,
lib/slack/rtmapi2/version.rb

Overview

class Slack Real Time Messaging API

Defined Under Namespace

Classes: Client

Constant Summary collapse

VERSION =
'2.0.2'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ RtmApi2

Returns a new instance of RtmApi2.



18
19
20
21
# File 'lib/slack/rtmapi2.rb', line 18

def initialize(options)
  @token = options.fetch(:token)
  @api_url = options[:slack_api_url] || 'https://slack.com/api'
end

Instance Attribute Details

#clientObject



29
30
31
# File 'lib/slack/rtmapi2.rb', line 29

def client
  @client ||= Slack::RtmApi2::Client.new websocket_url: @websocket_url
end

#rtm_state_dataObject

Returns the value of attribute rtm_state_data.



12
13
14
# File 'lib/slack/rtmapi2.rb', line 12

def rtm_state_data
  @rtm_state_data
end

Class Method Details

.get_url(options) ⇒ Object



13
14
15
16
# File 'lib/slack/rtmapi2.rb', line 13

def self.get_url(options)
  body = SlackWeb.call(method: 'rtm.start', token: options[:token])
  URI(body['url'])
end

Instance Method Details

#start_rtmObject



23
24
25
26
27
# File 'lib/slack/rtmapi2.rb', line 23

def start_rtm
  @rtm_state_data = SlackWeb.call(method: 'rtm.start', token: @token)
  @websocket_url = URI(@rtm_state_data['url'])
  client
end