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.
26 27 28 29 30 |
# File 'lib/steam-api/response.rb', line 26 def check_success(success_condition: true) success = self.parse_key('success') fail 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 |
# File 'lib/steam-api/response.rb', line 17 def parse_key(key) fail Steam::JSONError unless self.key?(key) self[key] end |
#to_params(params = {}) ⇒ Object
7 8 9 10 |
# File 'lib/steam-api/ruby/hash.rb', line 7 def to_params(params = {}) params[:format] = :json return "?#{params.each.map{ |x| x.join('=') }.join('&')}" end |