Module: Utils
- Defined in:
- lib/quidax/utils.rb
Overview
Base Util
Class Method Summary collapse
- .check_missing_keys(required_keys:, keys:, field:) ⇒ Object
- .handle_server_error(event) ⇒ Object
- .validate_value_in_array(array:, value:, field:) ⇒ Object
- .validate_value_in_range(range:, value:, field:) ⇒ Object
Class Method Details
.check_missing_keys(required_keys:, keys:, field:) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/quidax/utils.rb', line 31 def self.check_missing_keys(required_keys:, keys:, field:) keys.map!(&:to_s) missing_keys = required_keys - keys has_missing_keys = missing_keys.empty? = "missing key(s) in :#{field} #{missing_keys.join(", ")}" raise ArgumentError, unless has_missing_keys end |
.handle_server_error(event) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/quidax/utils.rb', line 7 def self.handle_server_error(event) raise event if event.response.nil? error = QuidaxServerError.new(event.response) error_reponse_code = error.response.status case error_reponse_code when 400 raise error, "HTTP Code 400: Bad request. Review the data sent in the request. Usually, this means a required piece of information is missing" when 401 raise error, "HTTP Code 401: Unauthorized. This happens when you provide an invalid or non-existent secret API key" when 404 raise error, "HTTP Code 404: Resource not found. The data requested does not exist." when 403 raise error, "HTTP Code 403: Forbidden. Not enough permission to perform this operation" when 429 raise error, "HTTP Code 429: You're making too many requests!" when 500, 501, 502, 503, 504 raise error, "HTTP Code #{error_reponse_code}: Server Error. Something went wrong." end end |
.validate_value_in_array(array:, value:, field:) ⇒ Object
40 41 42 43 44 |
# File 'lib/quidax/utils.rb', line 40 def self.validate_value_in_array(array:, value:, field:) = ":#{field} must be one of: #{array.join(", ")}" raise ArgumentError, unless array.include?(value) end |
.validate_value_in_range(range:, value:, field:) ⇒ Object
46 47 48 |
# File 'lib/quidax/utils.rb', line 46 def self.validate_value_in_range(range:, value:, field:) raise ArgumentError, "#{field} must be between #{range}" unless range.include?(value.to_i) end |