be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksamodule Hets
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa class HetsOptions
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa attr_reader :options
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa def self.from_hash(hash)
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa new(hash['options'])
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa end
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa def initialize(opts = {})
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa @options = opts.dup
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa prepare
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa end
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa def add(**opts)
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa @options.merge!(opts.dup)
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa prepare
a3ceba97332fbfa26eb378863f19bf80b808f662Eugen Kuksa self
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa end
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa
8963b7210183205addea9207b1fbda4696316675Eugen Kuksa def merge!(hets_options)
8963b7210183205addea9207b1fbda4696316675Eugen Kuksa add(hets_options.options)
8963b7210183205addea9207b1fbda4696316675Eugen Kuksa end
8963b7210183205addea9207b1fbda4696316675Eugen Kuksa
c81d8ff866d49e8fb7debed924ea9e9043243585Eugen Kuksa def ==(other)
c81d8ff866d49e8fb7debed924ea9e9043243585Eugen Kuksa options == other.options
c81d8ff866d49e8fb7debed924ea9e9043243585Eugen Kuksa end
c81d8ff866d49e8fb7debed924ea9e9043243585Eugen Kuksa
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa protected
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa def prepare
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa remove_nil_fields
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa prepare_url_catalog
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa prepare_access_token
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa end
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa def remove_nil_fields
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa nil_valued_keys = @options.keys.select { |key| @options[key].nil? }
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa nil_valued_keys.each { |key| @options.delete(key) }
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa end
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa def prepare_url_catalog
c73a9fba38c3f997632370857d254425fa5183d7Eugen Kuksa if @options[:'url-catalog'].is_a?(Array)
c73a9fba38c3f997632370857d254425fa5183d7Eugen Kuksa @options[:'url-catalog'].try(:compact!)
c73a9fba38c3f997632370857d254425fa5183d7Eugen Kuksa if @options[:'url-catalog'].blank?
c73a9fba38c3f997632370857d254425fa5183d7Eugen Kuksa @options.delete(:'url-catalog')
c73a9fba38c3f997632370857d254425fa5183d7Eugen Kuksa else
c73a9fba38c3f997632370857d254425fa5183d7Eugen Kuksa @options[:'url-catalog'] = @options[:'url-catalog'].join(',')
c73a9fba38c3f997632370857d254425fa5183d7Eugen Kuksa end
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa end
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa end
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa def prepare_access_token
ef0a297222729eb1bd2d5c960966688cab919cb0Eugen Kuksa if @options[:'access-token']
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa @options[:'access-token'] = @options[:'access-token'].to_s
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa end
78c1cf25949b565eefa81e71c241c4aafd17b7f2Eugen Kuksa end
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksa end
be16f35e063c5c6d4fa08018600d206322bc0c19Eugen Kuksaend