ToolJet/app/services/slack_query_service.rb
Deepti Kakade b10d777f63
Fixes Rubocop issues in tests (#359)
* Updated project set up guide for Mac, added node version and Webpack install steps.

* Worked on PR comment i.e Can we change this line to Install Node.js ( version: v14.9.0 )

* Fixed "Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping."

* Resolved rubocop comments i.e "Style/FrozenStringLiteralComment: Missing frozen string literal comment." in test folder

Co-authored-by: Deepti Kakade <deepti@saeloun.com>
Co-authored-by: Deepti Kakade <“deepti@saeloun.com”>
2021-07-01 12:54:35 +05:30

44 lines
1.1 KiB
Ruby

# frozen_string_literal: true
class SlackQueryService
attr_accessor :query, :ource, :options, :source_options, :current_user
def initialize(data_query, data_source, options, source_options, current_user)
@query = data_query
@source = data_source
@options = options
@source_options = source_options
@current_user = current_user
end
def process
operation = options["operation"]
access_token = source_options["access_token"]
data = []
if operation === "list_users"
result = HTTParty.get("https://slack.com/api/users.list",
headers: { "Authorization": "Bearer #{access_token}" })
data = JSON.parse(result.body)
end
if operation === "send_message"
body = {
channel: options["channel"],
text: options["message"],
as_user: options["sendAsUser"]
}.to_json
result = HTTParty.post("https://slack.com/api/chat.postMessage",
body: body,
headers: { "Content-Type": "application/json", "Authorization": "Bearer #{access_token}" }
)
data = JSON.parse(result.body)
end
{ status: "success", data: data }
end
end