class Hash

Takes a hash and converts it into a URL encoded parameter string.

NOTE: this does not do any uri escaping at this point, since all args
      should be numeric.

@param [Hash] params Hash of params you want broken up into a query string,

escaped, and returned to you.

@return [String] Escaped parameter string to append to a url.

Public Instance Methods

check_success(success_condition: true) click to toggle source

Many responses from the apis (but not all) include a success

field, so this allows us to check it wiht minimal fuss.

@param [String] success_condition what the success condition should be @return [Boolean] Returns true or raises an exception.

# File lib/steam-api/response.rb, line 27
def check_success(success_condition: true)
  success = parse_key('success')
  raise Steam::SteamError unless success == success_condition

  true
end
parse_key(key) click to toggle source

Simple method to access a nested field, since Valve seems to like

nesting their json a few levels on every request.

@param [String] key The key to extract from the hash

# File lib/steam-api/response.rb, line 17
def parse_key(key)
  raise Steam::JSONError unless key?(key)

  self[key]
end
to_params(params = {}) click to toggle source
# File lib/steam-api/ruby/hash.rb, line 8
def to_params(params = {})
  params[:format] = :json
  "?#{params.each.map { |x| x.join('=') }.join('&')}"
end