Class: Hibp::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/hibp/query.rb

Overview

Hibp::Query

Used to build and execute request to the HIBP API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint:, headers: {}, parser: Parsers::Json.new) ⇒ Query

Returns a new instance of Query.

Parameters:

  • endpoint (String)
    • A specific API endpoint to call appropriate method
  • headers (Hash) (defaults to: {})
    • Specific request headers
  • parser (Hibp::Parser) (defaults to: Parsers::Json.new)
    • A tool to parse and convert data into appropriate models


20
21
22
23
24
25
26
# File 'lib/hibp/query.rb', line 20

def initialize(endpoint:, headers: {}, parser: Parsers::Json.new)
  @endpoint = endpoint
  @headers = headers

  @parser = parser
  @query_params = {}
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



9
10
11
# File 'lib/hibp/query.rb', line 9

def endpoint
  @endpoint
end

#headersObject (readonly)

Returns the value of attribute headers.



9
10
11
# File 'lib/hibp/query.rb', line 9

def headers
  @headers
end

#parserObject (readonly)

Returns the value of attribute parser.



9
10
11
# File 'lib/hibp/query.rb', line 9

def parser
  @parser
end

Instance Method Details

#fetchArray<String>, ...

Perform query execution(data fetching)

]

Returns:



63
64
65
# File 'lib/hibp/query.rb', line 63

def fetch
  confugure_request.get(headers: @headers, params: @query_params)
end

#where(filters = {}) ⇒ Hibp::Query

Apply query filtration

Parameters:

  • filters (Hash) (defaults to: {})
    • (optional, default: {}) Additional filtration params

Options Hash (filters):

  • :domain (String)
    • Filters the result set to only breaches against the domain specified. It is possible that one site (and consequently domain), is compromised on multiple occasions. (breaches and account_breaches queries)
  • :truncate (Boolean)
    • (default: true) Short/Full data switcher(only name or full breach data) (only for account_breaches query)
  • :unverified (Boolean)
    • Returns breaches that have been flagged as "unverified". (only for account_breaches query)

Returns:



48
49
50
51
52
# File 'lib/hibp/query.rb', line 48

def where(filters = {})
  tap do
    @query_params.merge!(convert_filters(filters))
  end
end