Module: EVEApi::Util

Defined in:
lib/eveapi/util.rb

Overview

Utility methods

Instance Method Summary collapse

Instance Method Details

#convert_hash_keys(value) ⇒ Array, Hash

Symbolize and underscore all Hash keys

Parameters:

  • value (Array, Hash)

    Object to process

Returns:

  • (Array, Hash)

    processed output



116
117
118
119
120
121
122
123
124
125
# File 'lib/eveapi/util.rb', line 116

def convert_hash_keys(value)
  case value
  when Array
    value.map { |v| convert_hash_keys(v) }
  when Hash
    Hash[value.map { |k, v| [underscore_key(k), convert_hash_keys(v)] }]
  else
    value
  end
end

#json_get(url, args = {}) ⇒ Hash

Make a GET request, parse JSON if present, and process the result

Parameters:

  • url (String)

    URL to Call

  • args (Hash) (defaults to: {})

    {} arguments passed to Excon

Returns:

  • (Hash)

    processed result from the CREST API



99
100
101
102
# File 'lib/eveapi/util.rb', line 99

def json_get(url, args = {})
  http = Excon.get(url, args).body
  convert_hash_keys(Crack::JSON.parse http)
end

#underscore_key(k) ⇒ Symbol

Make a symbolized and underscored version of a Symbol or String

Parameters:

Returns:

  • (Symbol)

    modified version of the key



108
109
110
# File 'lib/eveapi/util.rb', line 108

def underscore_key(k)
  k.to_s.underscore.to_sym
end