Class: Validate::NewsApiQueryValidator

Inherits:
BaseValidator show all
Defined in:
lib/metonym/lib/validators/news_api_query_validator.rb

Constant Summary collapse

COUNTRIES =
%w[ar au at be br bg ca cn co cu cz eg fr de gr hk hu in id ie il it jp lv lt my mx ma nl nz ng no ph pl pt ro ru sa rs sg sk si za kr se ch tw th tr ae ua gb us ve].freeze
CATEGORIES =
%w[business entertainment general health science sports technology].freeze

Instance Method Summary collapse

Constructor Details

#initialize(api_key, args:, format:, endpoint: nil) ⇒ NewsApiQueryValidator

Returns a new instance of NewsApiQueryValidator.



8
9
10
11
12
13
14
15
16
# File 'lib/metonym/lib/validators/news_api_query_validator.rb', line 8

def initialize(api_key, args:, format:, endpoint: nil)
  raise 'API Key is required'        unless key_present?(api_key)
  raise 'Invalid parameter sequence' unless query_valid?(args, endpoint)
  raise 'Invalid country sent'       unless country_valid?(args)
  raise 'Invalid language sent'      unless language_valid?(args)
  raise 'Invalid date or dates sent' unless date_valid?(args)

  true
end