Class: Hash
- Inherits:
-
Object
- Object
- Hash
- 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.
Direct Known Subclasses
Instance Method Summary collapse
-
#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.
-
#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.
- #to_params(params = {}) ⇒ Object
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.
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.
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 |