lib/hackerone/client.rb in hackerone-client-0.15.0 vs lib/hackerone/client.rb in hackerone-client-0.16.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require "faraday" require "json" require "active_support/time" require_relative "client/version" require_relative "client/report" @@ -22,11 +24,11 @@ DEFAULT_LOW_RANGE = 1...999 DEFAULT_MEDIUM_RANGE = 1000...2499 DEFAULT_HIGH_RANGE = 2500...4999 DEFAULT_CRITICAL_RANGE = 5000...100_000_000 - LENIENT_MODE_ENV_VARIABLE = 'HACKERONE_CLIENT_LENIENT_MODE' + LENIENT_MODE_ENV_VARIABLE = "HACKERONE_CLIENT_LENIENT_MODE" class << self ATTRS = [:low_range, :medium_range, :high_range, :critical_range].freeze attr_accessor :program attr_reader *ATTRS @@ -100,11 +102,11 @@ private def post(endpoint, body) response = with_retry do self.class.hackerone_api_connection.post do |req| - req.headers['Content-Type'] = 'application/json' + req.headers["Content-Type"] = "application/json" req.body = body.to_json req.url endpoint end end @@ -112,11 +114,11 @@ end def get(endpoint, params = nil) response = with_retry do self.class.hackerone_api_connection.get do |req| - req.headers['Content-Type'] = 'application/json' + req.headers["Content-Type"] = "application/json" req.params = params || {} req.url endpoint end end @@ -127,11 +129,11 @@ if response.status.to_s.start_with?("4") raise ArgumentError, "API called failed, probably your fault: #{response.body}" elsif response.status.to_s.start_with?("5") raise RuntimeError, "API called failed, probably their fault: #{response.body}" elsif response.success? - response_body_json = JSON.parse(response.body, :symbolize_names => true) + response_body_json = JSON.parse(response.body, symbolize_names: true) if extract_data && response_body_json.key?(:data) response_body_json[:data] else response_body_json end @@ -143,16 +145,16 @@ def self.hackerone_api_connection unless ENV["HACKERONE_TOKEN_NAME"] && ENV["HACKERONE_TOKEN"] raise NotConfiguredError, "HACKERONE_TOKEN_NAME HACKERONE_TOKEN environment variables must be set" end - @connection ||= Faraday.new(:url => "https://api.hackerone.com/v1") do |faraday| + @connection ||= Faraday.new(url: "https://api.hackerone.com/v1") do |faraday| faraday.basic_auth(ENV["HACKERONE_TOKEN_NAME"], ENV["HACKERONE_TOKEN"]) faraday.adapter Faraday.default_adapter end end - def with_retry(attempts=3, &block) + def with_retry(attempts = 3, &block) attempts_remaining = attempts begin yield rescue StandardError