Module: AdsCommon::Utils
- Defined in:
- lib/ads_common/utils.rb
Defined Under Namespace
Modules: String
Class Method Summary collapse
-
.hash_keys_to_str(data) ⇒ Object
Converts all hash keys to strings.
-
.hash_keys_to_sym(data) ⇒ Object
Converts all hash keys to symbols.
-
.save_oauth2_token(filename, token) ⇒ Object
Updates file to include token details.
Class Method Details
.hash_keys_to_str(data) ⇒ Object
Converts all hash keys to strings.
36 37 38 39 40 41 42 |
# File 'lib/ads_common/utils.rb', line 36 def self.hash_keys_to_str(data) return nil if data.nil? return data.inject({}) do |result, (k, v)| result[k.to_s] = v result end end |
.hash_keys_to_sym(data) ⇒ Object
Converts all hash keys to symbols.
45 46 47 48 49 50 51 |
# File 'lib/ads_common/utils.rb', line 45 def self.hash_keys_to_sym(data) return nil if data.nil? return data.inject({}) do |result, (k, v)| result[k.to_sym] = v result end end |
.save_oauth2_token(filename, token) ⇒ Object
Updates file to include token details.
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ads_common/utils.rb', line 54 def self.save_oauth2_token(filename, token) config_data = {} if File.exist?(filename) config_data = YAML::load_file(filename) new_file_name = self.find_new_name(filename) File.rename(filename, new_file_name) end config_data[:authentication][:oauth2_token] = token File.open(filename, 'w') {|f| f.write(YAML::dump(config_data))} end |