Skip to content

Commit

Permalink
endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
wookay committed Nov 9, 2019
1 parent cc09105 commit f307588
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ const RFC3339 = DateFormat("yyyy-mm-dd\\THH:MM:SSZ")

function get_clip(client_id::String,
clip_id::String ;
server::HTTP.URI=TWITCH_API_SERVER,
endpoint::HTTP.URI=TWITCH_API_SERVER,
action::Function=http_action)::Vector{UInt8}
headers = ["Client-ID"=>client_id]
query = Dict{String,String}("id" => clip_id)
resp = action(server, "/helix/clips", headers, query)
resp = action(endpoint, "/helix/clips", headers, query)
resp.body
end

function get_clips_by_broadcaster(client_id::String,
broadcaster_id::Int,
started_at::Union{Nothing, Date, DateTime},
ended_at::Union{Nothing, Date, DateTime} ; # started_at + 1 week
server::HTTP.URI=TWITCH_API_SERVER,
endpoint::HTTP.URI=TWITCH_API_SERVER,
action::Function=http_action)::Vector{UInt8}
headers = ["Client-ID"=>client_id]
query = Dict{String,String}("broadcaster_id" => string(broadcaster_id))
Expand All @@ -29,7 +29,7 @@ function get_clips_by_broadcaster(client_id::String,
if !isnothing(ended_at)
query["ended_at"] = Dates.format(ended_at, RFC3339)
end
resp = action(server, "/helix/clips", headers, query)
resp = action(endpoint, "/helix/clips", headers, query)
resp.body
end

Expand Down
4 changes: 2 additions & 2 deletions src/APIv5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ using ..TwitchTools: HTTP, TWITCH_API_SERVER, http_action

function get_clip(client_id::String,
clip_id::String ;
server::HTTP.URI=TWITCH_API_SERVER,
endpoint::HTTP.URI=TWITCH_API_SERVER,
action::Function=http_action)::Vector{UInt8}
headers = ["Client-ID"=>client_id, "Accept"=>"application/vnd.twitchtv.v5+json"]
resp = action(server, "/kraken/clips/$clip_id", headers)
resp = action(endpoint, "/kraken/clips/$clip_id", headers)
resp.body
end

Expand Down
4 changes: 2 additions & 2 deletions src/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ using HTTP: HTTP

const TWITCH_API_SERVER = HTTP.URI("https://api.twitch.tv/")

function http_action(server::HTTP.URI, path::String, headers::Vector{Pair{String,String}}=[], query::Union{Nothing,Dict{String,String}}=nothing)
url = string(merge(server, path=path))
function http_action(endpoint::HTTP.URI, path::String, headers::Vector{Pair{String,String}}=[], query::Union{Nothing,Dict{String,String}}=nothing)
url = string(merge(endpoint, path=path))
HTTP.get(url, headers; query=query)
end

Expand Down
8 changes: 4 additions & 4 deletions test/twitchtools/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ routes() do
get("/kraken/clips/:clipid", ClipController, clips)
end

function mock_action(server, path, headers=[], query=nothing)
function mock_action(endpoint, path, headers=[], query=nothing)
if query !== nothing
path = string(merge(HTTP.URI(path), query=query))
end
Expand All @@ -38,9 +38,9 @@ Bukdu.start(8080)

const local_api_server = HTTP.URI("http://localhost:8080/")

API.get_clip("client_id", "clip_id"; server=local_api_server)
API.get_clips_by_broadcaster("client_id", 0, nothing, nothing; server=local_api_server)
APIv5.get_clip("client_id", "clip_id"; server=local_api_server)
API.get_clip("client_id", "clip_id"; endpoint=local_api_server)
API.get_clips_by_broadcaster("client_id", 0, nothing, nothing; endpoint=local_api_server)
APIv5.get_clip("client_id", "clip_id"; endpoint=local_api_server)

Bukdu.stop()

Expand Down

0 comments on commit f307588

Please sign in to comment.