Class: M2mKeygen::ParamsEncoder

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/m2m_keygen/params_encoder.rb

Overview

Encoder for params hash

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ ParamsEncoder

Returns a new instance of ParamsEncoder.



9
10
11
# File 'lib/m2m_keygen/params_encoder.rb', line 9

def initialize(params)
  @params = T.let(params, Types::ParamsType)
end

Instance Method Details

#encodeObject



14
15
16
17
18
19
20
21
# File 'lib/m2m_keygen/params_encoder.rb', line 14

def encode
  return '' if @params.nil? || @params.empty?
  @params
    .sort_by { |k, _| k.to_s }
    .reject { |_, v| (v.is_a?(String) && v == '') || v.nil? }
    .map { |k, v| "#{k}=#{jsonify_value(encode_value(T.must(v)))}" }
    .join('&')
end