module HelpDeskAPI::Utilities

Public Class Methods

parse_response(response, key, obj) click to toggle source

Converts response to JSON then creates given object and calls parse to handle parsing the response JSON

# File lib/helpdeskapi/utilities.rb, line 18
def self.parse_response(response, key, obj)
  hash = JSON.parse response
  hash[key].map { |object_hash| obj.new.parse(object_hash) }
end
validateHash(hash, keys) click to toggle source

Makes sure all keys exist in hash

# File lib/helpdeskapi/utilities.rb, line 8
def self.validateHash(hash, keys)
  keys.each do |key|
    unless hash.has_key? key
      fail HelpDeskAPI::Exceptions.MissingKey, "Missing key #{key} in hash:\n#{hash}\n"
    end
  end
end