README.md in pwned-2.3.0 vs README.md in pwned-2.4.0

- old
+ new

@@ -108,16 +108,24 @@ #=> 3303003 ``` #### Custom request options -You can set http request options to be used with `Net::HTTP.start` when making the request to the API. These options are documented in the [`Net::HTTP.start` documentation](https://ruby-doc.org/stdlib-3.0.0/libdoc/net/http/rdoc/Net/HTTP.html#method-c-start). For example: +You can set HTTP request options to be used with `Net::HTTP.start` when making the request to the API. These options are documented in the [`Net::HTTP.start` documentation](https://ruby-doc.org/stdlib-3.0.0/libdoc/net/http/rdoc/Net/HTTP.html#method-c-start). +You can pass the options to the constructor: + ```ruby password = Pwned::Password.new("password", read_timeout: 10) ``` +You can also specify global defaults: + +```ruby +Pwned.default_request_options = { read_timeout: 10 } +``` + ##### HTTP Headers The `:headers` option defines defines HTTP headers. These headers must be string keys. ```ruby @@ -218,21 +226,23 @@ end ``` #### Custom Request Options -You can configure network requests made from the validator using `:request_options` (see [Net::HTTP.start](http://ruby-doc.org/stdlib-2.6.3/libdoc/net/http/rdoc/Net/HTTP.html#method-c-start) for the list of available options). +You can configure network requests made from the validator using `:request_options` (see [Net::HTTP.start](http://ruby-doc.org/stdlib-2.6.3/libdoc/net/http/rdoc/Net/HTTP.html#method-c-start) for the list of available options). ```ruby validates :password, not_pwned: { request_options: { read_timeout: 5, open_timeout: 1 } } ``` +These options override the globally defined default options (see above). + In addition to these options, you can also set the following: ##### HTTP Headers HTTP headers can be specified with the `:headers` key (e.g. `"User-Agent"`) @@ -276,18 +286,18 @@ } ``` ### Using Asynchronously -You may have a use case for hashing the password in advance, and then making the call to the Pwned Passwords API later (for example if you want to enqueue a job without storing the plaintext password). To do this, you can hash the password with the `Pwned.hash_password` method and then initialize the `Pwned::HashPassword` class with the hash, like this: +You may have a use case for hashing the password in advance, and then making the call to the Pwned Passwords API later (for example if you want to enqueue a job without storing the plaintext password). To do this, you can hash the password with the `Pwned.hash_password` method and then initialize the `Pwned::HashedPassword` class with the hash, like this: ```ruby hashed_password = Pwned.hash_password(password) # some time later -Pwned::HashPassword.new(hashed_password, request_options).pwned? +Pwned::HashedPassword.new(hashed_password, request_options).pwned? ``` -The `Pwned::HashPassword` constructor takes all the same options as the regular `Pwned::Password` contructor. +The `Pwned::HashedPassword` constructor takes all the same options as the regular `Pwned::Password` contructor. ### Devise If you are using [Devise](https://github.com/heartcombo/devise) I recommend you use the [devise-pwned_password extension](https://github.com/michaelbanfield/devise-pwned_password) which is now powered by this gem.