Class: ExchangerateHost::Endpoints::Base

Inherits:
Object
  • Object
show all
Extended by:
Validation
Includes:
HTTParty
Defined in:
lib/exchangerate_host/endpoints/base.rb

Constant Summary

Constants included from Validation

Validation::ACCEPTABLE_DATE_FORMAT, Validation::ALL_OPTIONS_WITH_VALIDATE_METHODS, Validation::VALID_FORMAT, Validation::VALID_SYMBOLS

Class Method Summary collapse

Methods included from Validation

is_positive_integer?, non_subset_values, to_upcase_csv, validate, validate_date, validate_option_values, validate_options, validate_required_options, validate_subset, validate_with_type

Class Method Details

.available_optionsObject



14
15
16
# File 'lib/exchangerate_host/endpoints/base.rb', line 14

def available_options
  required_options + optional_options
end

.endpoint_pathObject



18
19
20
# File 'lib/exchangerate_host/endpoints/base.rb', line 18

def endpoint_path
  ''
end

.optional_optionsObject

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/exchangerate_host/endpoints/base.rb', line 22

def optional_options
  raise NotImplementedError
end

.query_options(options) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/exchangerate_host/endpoints/base.rb', line 42

def query_options(options)
  config_options = ExchangerateHost.configurations.to_options_hash.slice(*available_options)
  merged_options = config_options.merge(options)

  validate(merged_options)
  merged_options[:symbols] = to_upcase_csv(merged_options[:symbols]) if merged_options.key?(:symbols)

  merged_options
end

.request(options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/exchangerate_host/endpoints/base.rb', line 30

def request(options)
  @query = query_options(options)
  res = get(
    "/#{endpoint_path}",
    { query: @query }
  )
  .body

  res = JSON.parse(res) unless @query[:format]
  res
end

.required_optionsObject



26
27
28
# File 'lib/exchangerate_host/endpoints/base.rb', line 26

def required_options
  []
end