Set the default User-Agent sent for outgoing http requests.

* Add a `Danbooru.config.http_headers` config option.

* Refactor various places to use this option instead of setting the user
  agent manually.
This commit is contained in:
evazion
2017-07-19 19:37:14 -05:00
parent d48ed95191
commit 8125d8e796
8 changed files with 29 additions and 48 deletions

View File

@@ -123,19 +123,18 @@ class PixivApiClient
end
def works(illust_id)
headers = {
headers = Danbooru.config.http_headers.merge(
"Referer" => "http://www.pixiv.net",
"User-Agent" => "#{Danbooru.config.safe_app_name}/#{Danbooru.config.version}",
"Content-Type" => "application/x-www-form-urlencoded",
"Authorization" => "Bearer #{access_token}"
}
)
params = {
"image_sizes" => "large",
"include_stats" => "true"
}
url = "https://public-api.secure.pixiv.net/v#{API_VERSION}/works/#{illust_id.to_i}.json"
resp = HTTParty.get(url, Danbooru.config.httparty_options.merge(query: params, headers: headers))
resp = HTTParty.get(url, Danbooru.config.httparty_options.deep_merge(query: params, headers: headers))
if resp.success?
json = parse_api_json(resp.body)
@@ -171,7 +170,7 @@ private
}
url = "https://oauth.secure.pixiv.net/auth/token"
resp = HTTParty.post(url, Danbooru.config.httparty_options.merge(body: params, headers: headers))
resp = HTTParty.post(url, Danbooru.config.httparty_options.deep_merge(body: params, headers: headers))
if resp.success?
json = JSON.parse(resp.body)
access_token = json["response"]["access_token"]