Class: Slack::RPC::Connection
- Inherits:
-
Object
- Object
- Slack::RPC::Connection
- Defined in:
- lib/slack/rpc/connection.rb
Overview
## Slack::RPC::Connection A class for invoke Slack RPC-Style command
Constant Summary collapse
- BASE_URL =
### Slack::RPC::Connection.BASE_URL A base url to invoke Slack RPC-Style command
"https://slack.com/api"- HEADERS =
### Slack::RPC::Connection.HEADERS HTTP request headers as Hash object
{ "Accept" => "application/json", "User-Agent" => "Slack Ruby Gem #{Slack::VERSION}" }
Instance Method Summary collapse
-
#call(command, sub_command, params, &block) ⇒ Object
### Slack::RPC::Connection.call(command, sub_commnad, params, &block) Call Slack RPC-Style command.
-
#connection ⇒ Object
### Slack::RPC::Connection.connection retrieve Faraday Connection object.
-
#initialize(token = nil) ⇒ Connection
constructor
### Slack::RPC::Connection.new(token) Creates a new instance of
Slack::RPC::Connectionclass.
Constructor Details
#initialize(token = nil) ⇒ Connection
### Slack::RPC::Connection.new(token) Creates a new instance of Slack::RPC::Connection class
29 30 31 |
# File 'lib/slack/rpc/connection.rb', line 29 def initialize(token = nil) @token = token end |
Instance Method Details
#call(command, sub_command, params, &block) ⇒ Object
### Slack::RPC::Connection.call(command, sub_commnad, params, &block) Call Slack RPC-Style command
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/slack/rpc/connection.rb', line 36 def call(command, sub_command, params, &block) params = params.clone.merge({:token => @token}) if @token faraday_response = connection.get("#{command}.#{sub_command}", params) response = Response.new(faraday_response) if block then yield response else response end end |
#connection ⇒ Object
### Slack::RPC::Connection.connection retrieve Faraday Connection object
50 51 52 53 54 55 56 |
# File 'lib/slack/rpc/connection.rb', line 50 def connection @connection ||= Faraday.new(:headers => HEADERS, :url => BASE_URL) { |faraday| faraday.request :url_encoded faraday.response :json faraday.adapter Faraday.default_adapter } end |