Class: Slack::RPC::Connection

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(token) ⇒ 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)
	@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
# File 'lib/slack/rpc/connection.rb', line 36

def call(command, sub_command, params, &block)
	faraday_response = connection.get("#{command}.#{sub_command}", params.clone.merge({:token => @token}))
	response = Response.new(faraday_response)
	if block then
		yield response
	else
		response
	end
end

#connectionObject

### Slack::RPC::Connection.connection retrieve Faraday Connection object



49
50
51
52
53
54
55
# File 'lib/slack/rpc/connection.rb', line 49

def connection
	@connection ||= Faraday.new(:headers => HEADERS, :url => BASE_URL) { |faraday|
		faraday.request  :url_encoded
		faraday.response :json
		faraday.adapter  Faraday.default_adapter
	}
end