class RoutificApi::Options

This class represents a set of options for the request

Constants

VALID_PARAMS

Public Class Methods

new(params) click to toggle source
# File lib/routific/options.rb, line 8
def initialize(params)
  # Validates the provided parameters
  validate(params)
  
  VALID_PARAMS.each do |param|
    instance_variable_set "@#{param}", params[param]
  end
end

Public Instance Methods

as_json(options = nil) click to toggle source

Returns the JSON representation of this object def to_json(options = nil)

# File lib/routific/options.rb, line 23
def as_json(options = nil)
  jsonData = {}
  
  VALID_PARAMS.each do |param|
    instance_var = instance_variable_get "@#{param}"
    jsonData[param] = instance_var if instance_var
  end
  jsonData
end
to_json(options) click to toggle source
# File lib/routific/options.rb, line 17
def to_json(options)
  as_json(options).to_json
end

Private Instance Methods

validate(params) click to toggle source

Validates the parameters being provided Raises an ArgumentError if any of the provided params is not supported

# File lib/routific/options.rb, line 36
def validate(params)
  invalid = params.keys.reject { |k| VALID_PARAMS.include?(k) }

  if invalid.any?
    invalid = invalid.join(",")
    raise ArgumentError, "#{invalid} parameter is not supported"
  end
end