Module: Cwsrb::Helpers
- Defined in:
- lib/cwsrb/helpers.rb
Overview
This module has a bunch of utility functions for use in other files.
All methods are marked as module_function
so you can do things like Helpers.resolve
.
Class Method Summary collapse
-
.check_for_errors(response) ⇒ void
Verifies if the response has any errors, and if so, raises a
APIError
. -
.resolve(val) ⇒ String, Integer
Determine if val is an ID or username.
Class Method Details
.check_for_errors(response) ⇒ void
This method returns an undefined value.
Verifies if the response has any errors, and if so, raises a APIError
.
21 22 23 |
# File 'lib/cwsrb/helpers.rb', line 21 def check_for_errors(response) raise Cwsrb::APIError, response['err_msg'] if response['err_idx'] > 0 end |
.resolve(val) ⇒ String, Integer
Determine if val is an ID or username. ID is a bunch of numbers that can or cannot be followed by an 'S'. Username... is not an ID.
12 13 14 15 |
# File 'lib/cwsrb/helpers.rb', line 12 def resolve(val) return val if val.is_a?(Integer) (val =~ /\A(S?\d+)\z/) ? val : "@#{val}" end |