Skip to content

Commit

Permalink
Preparing first version release
Browse files Browse the repository at this point in the history
  • Loading branch information
raphasampaio committed Sep 19, 2023
1 parent 5d7abeb commit f53aa48
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- '1.7'
- '1.8'
- '1.9'
- '1'
- 'nightly'
os:
- ubuntu-latest
- windows-latest
arch:
- x64
steps:
Expand All @@ -41,6 +37,7 @@ jobs:
env:
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
SLACK_USER: ${{ secrets.SLACK_USER }}
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "SlackAPI"
uuid = "45996516-d782-4985-8a4d-8a8f0336c9da"
version = "0.1.2"
version = "0.1.0"

[deps]
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
Expand Down
16 changes: 3 additions & 13 deletions src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,15 @@ function channel_message(
channel::AbstractString,
text::AbstractString,
)
header = [
"Content-Type" => "application/json;charset=utf-8",
"Authorization" => "Bearer $(context.token)",
]

body = JSON.json(Dict("text" => text, "channel" => channel))

return HTTP.post("https://slack.com/api/chat.postMessage", header, body)
return HTTP.post("https://slack.com/api/chat.postMessage", header(context), body)
end

function is_active(context::SlackContext, user::AbstractString)
header = [
"Content-Type" => "application/json;charset=utf-8",
"Authorization" => "Bearer $(context.token)",
]

query = ["user" => user]
query = Dict("user" => user)

response = HTTP.get("https://slack.com/api/users.info", header, query)
response = HTTP.get("https://slack.com/api/users.info", header(context), query = query)

@assert response.status == 200

Expand Down
7 changes: 7 additions & 0 deletions src/context.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ struct SlackContext
return new(token)
end
end

function header(context::SlackContext)
return [
"Content-Type" => "application/json;charset=utf-8",
"Authorization" => "Bearer $(context.token)",
]
end
10 changes: 7 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ function testall()

token = ENV["SLACK_TOKEN"]
channel = ENV["SLACK_CHANNEL"]
user = ENV["SLACK_USER"]

@assert !isempty(token)
@assert !isempty(channel)
@assert !isempty(user)

context = SlackContext(token)

response = SlackAPI.channel_message(context, channel, "testing...")
@assert response.status == 200
@test response.status == 200

@assert SlackAPI.mention("XXXX") == "<@XXXX>"
@test SlackAPI.mention("XXXX") == "<@XXXX>"

# @assert SlackAPI.is_active(context, user)
@test SlackAPI.is_active(context, user) == true

@test SlackAPI.is_active(context, "U1234") == false
end

testall()

0 comments on commit f53aa48

Please sign in to comment.