Module: OSTSdk::Util::ServicesHelper
- Included in:
- Saas::Base
- Defined in:
- lib/ost-sdk-ruby/util/services_helper.rb
Instance Method Summary collapse
-
#current_time ⇒ Object
returns current time.
-
#current_timestamp ⇒ Object
returns current timestamp.
-
#error_with_data(code, msg, data = {}) ⇒ Object
Error with data.
-
#exception_with_data(e, code, msg, data = {}) ⇒ Object
Exception with data and wthout action.
-
#perform_and_handle_exceptions(err_code = 'swt', err_message = 'Something Went Wrong', &block) ⇒ Object
Wrapper Method which could be used to execute business logic Error handling code wraps execution of business logic.
-
#success ⇒ Object
Success.
-
#success_with_data(data) ⇒ Object
Success with data.
Instance Method Details
#current_time ⇒ Object
returns current time
Returns:
Time
31 32 33 |
# File 'lib/ost-sdk-ruby/util/services_helper.rb', line 31 def current_time @c_time ||= Time.now end |
#current_timestamp ⇒ Object
returns current timestamp
Returns:
Integer
40 41 42 |
# File 'lib/ost-sdk-ruby/util/services_helper.rb', line 40 def @c_tstamp ||= current_time.to_f end |
#error_with_data(code, msg, data = {}) ⇒ Object
Error with data
Arguments:
code: (String)
msg: (String)
data: (Hash)
Returns:
OSTSdk::Util::Result
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ost-sdk-ruby/util/services_helper.rb', line 80 def error_with_data(code, msg, data = {}) OSTSdk::Util::Result.error( { error: code, error_message: msg, data: data } ) end |
#exception_with_data(e, code, msg, data = {}) ⇒ Object
Exception with data and wthout action
Arguments:
e: (Exception)
code: (String)
msg: (String)
data: (Hash optional)
Returns:
OSTSdk::Util::Result
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/ost-sdk-ruby/util/services_helper.rb', line 104 def exception_with_data(e, code, msg, data = {}) OSTSdk::Util::Result.exception( e, { error: code, error_message: msg, data: data } ) end |
#perform_and_handle_exceptions(err_code = 'swt', err_message = 'Something Went Wrong', &block) ⇒ Object
Wrapper Method which could be used to execute business logic Error handling code wraps execution of business logic
Arguments:
err_code: (String)
err_message: (String)
block: (Proc)
Returns:
OSTSdk::Util::Result
18 19 20 21 22 23 24 |
# File 'lib/ost-sdk-ruby/util/services_helper.rb', line 18 def perform_and_handle_exceptions(err_code = 'swt', = 'Something Went Wrong', &block) begin yield if block_given? rescue StandardError => se OSTSdk::Util::Result.exception(se, {error: err_code, error_message: , data: @params} ) end end |
#success ⇒ Object
Success
Returns:
OSTSdk::Util::Result
49 50 51 |
# File 'lib/ost-sdk-ruby/util/services_helper.rb', line 49 def success success_with_data({}) end |
#success_with_data(data) ⇒ Object
Success with data
Arguments:
data: (Hash)
Returns:
OSTSdk::Util::Result
61 62 63 64 65 66 67 68 |
# File 'lib/ost-sdk-ruby/util/services_helper.rb', line 61 def success_with_data(data) # Allow only Hash data to pass ahead data = {} unless Util::CommonValidator.is_a_hash?(data) OSTSdk::Util::Result.success({data: data}) end |