http: split requests into internal and external requests.

Split requests made by Danbooru::Http into either internal or external
requests. Internal requests are API calls to internal services run by
Danbooru. External requests are requests to external websites, for
example fetching sources or downloading files. External requests may use
a HTTP proxy if one is configured. Internal requests don't.

Fixes a few source extractors not using the HTTP proxy for certain API calls.
This commit is contained in:
evazion
2022-10-18 22:38:19 -05:00
parent 4001701d18
commit 412b7f2727
17 changed files with 38 additions and 29 deletions

View File

@@ -21,10 +21,10 @@ class DeviantArtApiClient
class Error < StandardError; end
BASE_URL = "https://www.deviantart.com/api/v1/oauth2/"
attr_reader :client_id, :client_secret
attr_reader :client_id, :client_secret, :http
def initialize(client_id, client_secret)
@client_id, @client_secret = client_id, client_secret
def initialize(client_id, client_secret, http)
@client_id, @client_secret, @http = client_id, client_secret, http
end
# https://www.deviantart.com/developers/http/v1/20160316/deviation_single/bcc296bdf3b5e40636825a942a514816
@@ -54,7 +54,7 @@ class DeviantArtApiClient
params = { access_token: access_token.token, **params }
url = URI.join(BASE_URL, url).to_s
response = Danbooru::Http.cache(1.minute).get(url, params: params)
response = http.cache(1.minute).get(url, params: params)
response.parse.with_indifferent_access
end