Module: OSTSdk::Util::ServicesHelper

Included in:
Saas::Base
Defined in:
lib/ost-sdk-ruby-stag/util/services_helper.rb

Instance Method Summary collapse

Instance Method Details

#current_timeObject

returns current time

Returns:

Time


22
23
24
# File 'lib/ost-sdk-ruby-stag/util/services_helper.rb', line 22

def current_time
  @c_time ||= Time.now
end

#current_timestampObject

returns current timestamp

Returns:

Integer


31
32
33
# File 'lib/ost-sdk-ruby-stag/util/services_helper.rb', line 31

def current_timestamp
  @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


71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ost-sdk-ruby-stag/util/services_helper.rb', line 71

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


95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ost-sdk-ruby-stag/util/services_helper.rb', line 95

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

Method which is called in service perform and handle exceptions



9
10
11
12
13
14
15
# File 'lib/ost-sdk-ruby-stag/util/services_helper.rb', line 9

def perform_and_handle_exceptions(err_code = 'swt', err_message = 'Something Went Wrong', &block)
  begin
    yield if block_given?
  rescue StandardError => se
    OSTSdk::Util::Result.exception(se, {error: err_code, error_message: err_message, data: @params} )
  end
end

#successObject

Success

Returns:

OSTSdk::Util::Result


40
41
42
# File 'lib/ost-sdk-ruby-stag/util/services_helper.rb', line 40

def success
  success_with_data({})
end

#success_with_data(data) ⇒ Object

Success with data

Arguments:

data: (Hash)

Returns:

OSTSdk::Util::Result


52
53
54
55
56
57
58
59
# File 'lib/ost-sdk-ruby-stag/util/services_helper.rb', line 52

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