Skip to content

Commit 65f2fc0

Browse files
Added inital functionality.
1 parent 1796852 commit 65f2fc0

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
88
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
99

1010
[compat]
11+
HTTP = "0.8.8"
12+
JSON = "0.21.0"
1113
julia = "1"
12-
JSON = "0.21.0"
13-
HTTP = "0.8.8"
1414

1515
[extras]
1616
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/Slack.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
module Slack
22

3-
greet() = print("Hello World!")
3+
using HTTP
4+
using JSON
5+
6+
include("send.jl")
7+
export
8+
sendtoslack
49

510
end # module

src/send.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Slack
2+
3+
"""
4+
sendtoslack(data::String, user_endpoint::String)
5+
Takes in a string of data and the endpoint url and returns the HTTP response.
6+
The response will be "ok" if the request is sent successfully.
7+
"""
8+
function sendtoslack(data::String, user_endpoint::String)
9+
HTTP.setuseragent!("HTTP.jl")
10+
11+
12+
params = Dict("text"=>"$(data)")
13+
base_url = "https://hooks.slack.com"
14+
15+
endpoint = user_endpoint
16+
url = base_url * endpoint
17+
18+
r = HTTP.post(url,
19+
["Content-Type" => "application/json"],
20+
JSON.json(params))
21+
22+
return (String(r.body))
23+
end

test/runtests.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Slack
22
using Test
33

4-
@testset "Slack.jl" begin
5-
# Write your own tests here.
6-
end
4+
endpoint = "/services/TQVJBU534/BR8C1LMPS/42thawJz34SWSgZCpniyLBSE"
5+
data = "Hello World"
6+
7+
response = sendtoslack(data, endpoint)
8+
@test response == "ok"

0 commit comments

Comments
 (0)