Class: Hibp::Client
- Inherits:
-
Object
- Object
- Hibp::Client
- Defined in:
- lib/hibp/client.rb
Overview
Hibp::Client
Used to fetch data from haveibeenpwned API
Public methods return `Hibp::Query` instance,
which can be configured by applying filters
Data will only be returned if the `#fetch` method is called on the `Hibp::Query` instance.
@see https://haveibeenpwned.com/API/v3
Constant Summary collapse
- CORE_API_HOST =
'https://haveibeenpwned.com/api/v3'
- PASSWORD_API_HOST =
'https://api.pwnedpasswords.com/range'
- CORE_API_SERVICES =
{ breach: 'breach', breaches: 'breaches', account_breaches: 'breachedaccount', data_classes: 'dataclasses', pastes: 'pasteaccount' }.freeze
Instance Attribute Summary collapse
-
#authorization_header ⇒ Object
readonly
Returns the value of attribute authorization_header.
Instance Method Summary collapse
-
#account_breaches(account) ⇒ Hibp::Query
Fetch a list of all breaches a particular account has been involved in.
-
#breach(name) ⇒ Hibp::Query
Find a single breached site.
-
#breaches ⇒ Hibp::Query
Fetch all breached sites in the system Available filters(domain).
-
#data_classes ⇒ Hibp::Query
Fetch all data classes in the system.
-
#initialize(api_key = '') ⇒ Client
constructor
A new instance of Client.
-
#passwords(password, add_padding: false) ⇒ Hibp::Query
Search pwned passwords.
-
#pastes(account) ⇒ Hibp::Query
Search an account for pastes.
Constructor Details
#initialize(api_key = '') ⇒ Client
Returns a new instance of Client.
37 38 39 |
# File 'lib/hibp/client.rb', line 37 def initialize(api_key = '') @authorization_header = { 'hibp-api-key' => api_key } end |
Instance Attribute Details
#authorization_header ⇒ Object (readonly)
Returns the value of attribute authorization_header.
27 28 29 |
# File 'lib/hibp/client.rb', line 27 def @authorization_header end |
Instance Method Details
#account_breaches(account) ⇒ Hibp::Query
This method requires authorization. HIBP API key must be used.
By default, only the name of the breach is returned rather than the complete breach data.
By default, both verified and unverified breaches are returned when performing a search.
Fetch a list of all breaches a particular account has been involved in. Available filters(truncate, unverified, domain)
75 76 77 |
# File 'lib/hibp/client.rb', line 75 def account_breaches(account) configure_core_query(:account_breaches, CGI.escape(account)) end |
#breach(name) ⇒ Hibp::Query
This is the stable value which may or may not be the same as the breach “title” (which can change).
Find a single breached site
49 50 51 |
# File 'lib/hibp/client.rb', line 49 def breach(name) configure_core_query(:breach, name) end |
#breaches ⇒ Hibp::Query
Collection is sorted alphabetically by the title of the breach.
Fetch all breached sites in the system Available filters(domain)
60 61 62 |
# File 'lib/hibp/client.rb', line 60 def breaches configure_core_query(:breaches) end |
#data_classes ⇒ Hibp::Query
Fetch all data classes in the system
A “data class” is an attribute of a record compromised in a breach. For example, many breaches expose data classes such as “Email addresses” and “Passwords”. The values returned by this service are ordered alphabetically in a string array and will expand over time as new breaches expose previously unseen classes of data.
88 89 90 |
# File 'lib/hibp/client.rb', line 88 def data_classes configure_core_query(:data_classes) end |
#passwords(password, add_padding: false) ⇒ Hibp::Query
The API will respond with include the suffix of every hash beginning with the specified password prefix(five first chars of the password hash), and with a count of how many times it appears in the data set.
Search pwned passwords
128 129 130 |
# File 'lib/hibp/client.rb', line 128 def passwords(password, add_padding: false) configure_password_query(password, add_padding) end |
#pastes(account) ⇒ Hibp::Query
This is an authenticated API and an HIBP API key must be passed with the request.
The collection is sorted chronologically with the newest paste first.
Search an account for pastes.
HIBP searches through pastes that are broadcast by the @dumpmon Twitter account and reported as having emails that are a potential indicator of a breach.
Finding an email address in a paste does not immediately mean it has been disclosed as the result of a breach. Review the paste and determine if your account has been compromised then take appropriate action such as changing passwords.
108 109 110 |
# File 'lib/hibp/client.rb', line 108 def pastes(account) configure_core_query(:pastes, CGI.escape(account)) end |