Class: RSlack::APIClient
- Inherits:
-
Object
- Object
- RSlack::APIClient
- Defined in:
- lib/rslack/api.rb
Constant Summary collapse
- BASEURL =
"https://slack.com/api/"
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #call(endpoint, **params) ⇒ Object
- #channel(id) ⇒ Object
-
#initialize(url: BASEURL, token:) ⇒ APIClient
constructor
A new instance of APIClient.
- #me ⇒ Object
- #post(text: '', **params) ⇒ Object
- #user(id) ⇒ Object
- #websocket ⇒ Object
Constructor Details
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
12 13 14 |
# File 'lib/rslack/api.rb', line 12 def token @token end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
11 12 13 |
# File 'lib/rslack/api.rb', line 11 def url @url end |
Instance Method Details
#call(endpoint, **params) ⇒ Object
40 41 42 43 |
# File 'lib/rslack/api.rb', line 40 def call(endpoint, **params) resp = HTTP.post(BASEURL + endpoint, params: { token: @token }.merge(params)) JSON.parse(resp.body) end |
#channel(id) ⇒ Object
36 37 38 |
# File 'lib/rslack/api.rb', line 36 def channel(id) call('channels.info', channel: id) end |
#me ⇒ Object
24 25 26 |
# File 'lib/rslack/api.rb', line 24 def me call('auth.test') end |
#post(text: '', **params) ⇒ Object
28 29 30 |
# File 'lib/rslack/api.rb', line 28 def post(text: '', **params) call('chat.postMessage', params.merge(text: text)) end |
#user(id) ⇒ Object
32 33 34 |
# File 'lib/rslack/api.rb', line 32 def user(id) call('users.info', user: id) end |
#websocket ⇒ Object
19 20 21 22 |
# File 'lib/rslack/api.rb', line 19 def websocket rtm = call('rtm.start') Faye::WebSocket::Client.new(rtm['url'], {}, { ping: 60 }) end |