Skip to content

Commit

Permalink
Update EasyCurl to 3.0 and adjust methods (#55)
Browse files Browse the repository at this point in the history
Co-authored-by: eugenekartvelishvili <[email protected]>
Co-authored-by: artememelin <[email protected]>
  • Loading branch information
3 people committed Sep 13, 2024
1 parent 0baaa85 commit 77dc8e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "CryptoExchangeAPIs"
uuid = "5e3d4798-c815-4641-85e1-deed530626d3"
version = "0.29.1"
version = "0.29.2"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand All @@ -19,5 +19,5 @@ NanoDates = "1.0"
Nettle = "1.0.0"
TimeZones = "1.13.0"
Serde = "3.0.0"
EasyCurl = "2.0.0"
EasyCurl = "3.1.0"
julia = "1.8"
24 changes: 7 additions & 17 deletions src/Interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ function log_msg(client::AbstractAPIsClient, query::APIsRequest)
)
end

function http_request(client::AbstractAPIsClient, query::APIsRequest)
function perform_request(client::AbstractAPIsClient, query::APIsRequest)
request_sign!(client, query.query, query.endpoint)

@debug "sending request" log_msg(client, query)...

req = EasyCurl.request(
req = http_request(
query.method,
EasyCurl.joinurl(client.base_url, query.endpoint),
curl_joinurl(client.base_url, query.endpoint);
headers = request_headers(client, query.query),
body = request_body(query.query),
query = request_query(query.query),
Expand All @@ -27,10 +25,8 @@ function http_request(client::AbstractAPIsClient, query::APIsRequest)
connect_timeout = 60,
status_exception = false,
)

@debug "received response" log_msg(client, query)... status_code = req.status headers =
Serde.to_json(req.headers) response = String(view(req.body, 1:length(req.body)))

return req
end

Expand All @@ -41,24 +37,20 @@ end
isretriable(::APIsResult{APIsUndefError}) = true
retry_timeout(e::APIsResult{APIsUndefError}) = e.response.headers.retry_after
retry_maxcount(::APIsResult{APIsUndefError})::Int64 = 1

isretriable(::Exception)::Bool = false
retry_timeout(::Exception)::Float64 = 1
retry_maxcount(::Exception)::Int64 = 10

isretriable(::EasyCurl.EasyCurlError)::Bool = true
retry_timeout(::EasyCurl.EasyCurlError)::Float64 = 10
retry_maxcount(::EasyCurl.EasyCurlError)::Int64 = 2

isretriable(::CurlError)::Bool = true
retry_timeout(::CurlError)::Float64 = 10
retry_maxcount(::CurlError)::Int64 = 2
isretriable(e::APIsResult{<:Exception})::Bool = isretriable(e.result)
retry_timeout(e::APIsResult{<:Exception})::Real = retry_timeout(e.result)
retry_maxcount(e::APIsResult{<:Exception})::Int64 = retry_maxcount(e.result)

function (query::APIsRequest{T})(client::AbstractAPIsClient)::APIsResult where {T}
fetch_data = try
query.num_calls[] += 1
response = http_request(client, query)

response = perform_request(client, query)
payload_data = try
payload_json = Serde.parse_json(response.body)
Serde.deser(T, prepare_json!(T, payload_json))
Expand All @@ -75,7 +67,6 @@ function (query::APIsRequest{T})(client::AbstractAPIsClient)::APIsResult where {
end
throw(APIsResult{typeof(err)}(client, query, APIsResponse(headers, response.status), err))
end

APIsResult{T}(client, query, nothing, payload_data)
catch ex
err = if ex isa APIsResult
Expand All @@ -91,6 +82,5 @@ function (query::APIsRequest{T})(client::AbstractAPIsClient)::APIsResult where {
err
end
end

return iserror(fetch_data) ? throw(fetch_data) : fetch_data
end

0 comments on commit 77dc8e4

Please sign in to comment.