Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/steam-api/ruby/hash.rb,
lib/steam-api/response.rb

Overview

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.

Returns:

  • (String)

    Escaped parameter string to append to a url.

Direct Known Subclasses

Steam::Response

Instance Method Summary collapse

Instance Method Details

#check_success(success_condition: true) ⇒ Boolean

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

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

Parameters:

  • success_condition (String) (defaults to: true)

    what the success condition should be

Returns:

  • (Boolean)

    Returns true or raises an exception.

Raises:



27
28
29
30
31
32
# 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) ⇒ Object

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

nesting their json a few levels on every request.

Parameters:

  • key (String)

    The key to extract from the hash

Raises:



17
18
19
20
21
# File 'lib/steam-api/response.rb', line 17

def parse_key(key)
  raise Steam::JSONError unless key?(key)

  self[key]
end

#to_params(params = {}) ⇒ Object



8
9
10
11
# File 'lib/steam-api/ruby/hash.rb', line 8

def to_params(params = {})
  params[:format] = :json
  "?#{params.each.map { |x| x.join('=') }.join('&')}"
end