ost-sdk-ruby-stag 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +1 -12
- data/lib/ost/sdk/ruby/stag.rb +11 -0
- data/lib/ost/sdk/ruby/stag/version.rb +9 -0
- data/ost-sdk-ruby-stag.gemspec +2 -2
- metadata +3 -12
- data/lib/ost-sdk-ruby-stag.rb +0 -8
- data/lib/ost-sdk-ruby-stag/saas.rb +0 -10
- data/lib/ost-sdk-ruby-stag/saas/base.rb +0 -29
- data/lib/ost-sdk-ruby-stag/saas/transaction_kind.rb +0 -52
- data/lib/ost-sdk-ruby-stag/util.rb +0 -13
- data/lib/ost-sdk-ruby-stag/util/api_credentials.rb +0 -32
- data/lib/ost-sdk-ruby-stag/util/common_validator.rb +0 -50
- data/lib/ost-sdk-ruby-stag/util/http_helper.rb +0 -138
- data/lib/ost-sdk-ruby-stag/util/result.rb +0 -225
- data/lib/ost-sdk-ruby-stag/util/services_helper.rb +0 -111
- data/lib/ost-sdk-ruby-stag/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 283ab5ad91903b3173b9c85bf5983a21ce75c11d
|
4
|
+
data.tar.gz: e65d90cccd9abd34eda8633000e2cab7636c47cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd111ab00e189e4f1f138d9bc733a3ae0c5bf90d976803e43b89c1be6522511d7454ebecb5c331ba2ddc2e81bb2dfef139c11885d6686bde3134c48b3e15499e
|
7
|
+
data.tar.gz: 67411e8db18d015e80a38145d645a382b263c9b837938f1f796e4c296dbe411ae5c6c8e8b4e85999be9a00cfb4e2523047f6504ae01a20ab893c2f61b055aca7
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -22,18 +22,7 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
environment = 'sandbox' # possible values sandbox / production
|
28
|
-
|
29
|
-
credentials = OSTSdk::Util::APICredentials.new('api_key', 'api_secret')
|
30
|
-
|
31
|
-
obj = OSTSdk::Saas::TransactionKind.new(environment, credentials)
|
32
|
-
|
33
|
-
obj.list
|
34
|
-
|
35
|
-
obj.create()
|
36
|
-
|
25
|
+
TODO: Write usage instructions here
|
37
26
|
|
38
27
|
## Development
|
39
28
|
|
data/ost-sdk-ruby-stag.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'ost
|
4
|
+
require 'ost/sdk/ruby/stag/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "ost-sdk-ruby-stag"
|
8
|
-
spec.version =
|
8
|
+
spec.version = Ost::Sdk::Ruby::Stag::VERSION
|
9
9
|
spec.authors = ["Puneet Khushwani"]
|
10
10
|
spec.email = ["puneet.khushwani@pepo.com"]
|
11
11
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ost-sdk-ruby-stag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puneet Khushwani
|
@@ -51,17 +51,8 @@ files:
|
|
51
51
|
- Rakefile
|
52
52
|
- bin/console
|
53
53
|
- bin/setup
|
54
|
-
- lib/ost
|
55
|
-
- lib/ost
|
56
|
-
- lib/ost-sdk-ruby-stag/saas/base.rb
|
57
|
-
- lib/ost-sdk-ruby-stag/saas/transaction_kind.rb
|
58
|
-
- lib/ost-sdk-ruby-stag/util.rb
|
59
|
-
- lib/ost-sdk-ruby-stag/util/api_credentials.rb
|
60
|
-
- lib/ost-sdk-ruby-stag/util/common_validator.rb
|
61
|
-
- lib/ost-sdk-ruby-stag/util/http_helper.rb
|
62
|
-
- lib/ost-sdk-ruby-stag/util/result.rb
|
63
|
-
- lib/ost-sdk-ruby-stag/util/services_helper.rb
|
64
|
-
- lib/ost-sdk-ruby-stag/version.rb
|
54
|
+
- lib/ost/sdk/ruby/stag.rb
|
55
|
+
- lib/ost/sdk/ruby/stag/version.rb
|
65
56
|
- ost-sdk-ruby-stag.gemspec
|
66
57
|
homepage: https://sale.stagingsimpletoken.org/
|
67
58
|
licenses: []
|
data/lib/ost-sdk-ruby-stag.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module OSTSdk
|
2
|
-
|
3
|
-
module Saas
|
4
|
-
|
5
|
-
class Base
|
6
|
-
|
7
|
-
include OSTSdk::Util::ServicesHelper
|
8
|
-
|
9
|
-
attr_reader :http_helper
|
10
|
-
|
11
|
-
# Initialize
|
12
|
-
#
|
13
|
-
# @param [Hash] params (mandatory) is a Hash
|
14
|
-
#
|
15
|
-
def initialize(environment, credentials)
|
16
|
-
|
17
|
-
fail 'missing param environment' if environment.nil?
|
18
|
-
fail 'missing/invalid param credentials' if credentials.nil? ||
|
19
|
-
credentials.class != OSTSdk::Util::APICredentials
|
20
|
-
|
21
|
-
@http_helper = OSTSdk::Util::HTTPHelper.new(environment, credentials)
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module OSTSdk
|
2
|
-
|
3
|
-
module Saas
|
4
|
-
|
5
|
-
class TransactionKind < OSTSdk::Saas::Base
|
6
|
-
|
7
|
-
# Initialize
|
8
|
-
#
|
9
|
-
# Arguments:
|
10
|
-
# environment: (String)
|
11
|
-
# credentials: (OSTSdk::Util::APICredentials)
|
12
|
-
#
|
13
|
-
def initialize(environment, credentials)
|
14
|
-
super
|
15
|
-
@url_prefix = 'transaction/kind'
|
16
|
-
end
|
17
|
-
|
18
|
-
# Creates a new transaction type
|
19
|
-
#
|
20
|
-
def list
|
21
|
-
http_helper.send_get_request("#{@url_prefix}/get-all", {})
|
22
|
-
end
|
23
|
-
|
24
|
-
# Creates a new transaction type
|
25
|
-
#
|
26
|
-
# @param [Hash] params (mandatory) is a Hash
|
27
|
-
#
|
28
|
-
def create(params)
|
29
|
-
http_helper.send_post_request("#{@url_prefix}/create", params)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Update a transaction type
|
33
|
-
#
|
34
|
-
# @param [Hash] params (mandatory) is a Hash
|
35
|
-
#
|
36
|
-
def update(params)
|
37
|
-
http_helper.send_post_request("#{@url_prefix}/update", params)
|
38
|
-
end
|
39
|
-
|
40
|
-
# Delete a transaction type
|
41
|
-
#
|
42
|
-
# @param [Hash] params (mandatory) is a Hash
|
43
|
-
#
|
44
|
-
def delete(params)
|
45
|
-
http_helper.send_post_request("#{@url_prefix}/delete", params)
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module OSTSdk
|
2
|
-
|
3
|
-
module Util
|
4
|
-
|
5
|
-
class APICredentials
|
6
|
-
|
7
|
-
# Initialize
|
8
|
-
#
|
9
|
-
# Arguments:
|
10
|
-
# api_key: (String)
|
11
|
-
# api_secret: (String)
|
12
|
-
#
|
13
|
-
def initialize(api_key, api_secret)
|
14
|
-
@api_key = api_key
|
15
|
-
@api_secret = api_secret
|
16
|
-
end
|
17
|
-
|
18
|
-
# Returns:
|
19
|
-
# api_key: (String)
|
20
|
-
#
|
21
|
-
attr_reader :api_key
|
22
|
-
|
23
|
-
# Returns:
|
24
|
-
# api_secret: (String)
|
25
|
-
#
|
26
|
-
attr_reader :api_secret
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module OSTSdk
|
2
|
-
|
3
|
-
module Util
|
4
|
-
|
5
|
-
class CommonValidator
|
6
|
-
|
7
|
-
# Check for numeric-ness of an input
|
8
|
-
#
|
9
|
-
# Arguments:
|
10
|
-
# object: (Float)
|
11
|
-
#
|
12
|
-
# Returns:
|
13
|
-
# Boolean
|
14
|
-
#
|
15
|
-
def self.is_numeric?(object)
|
16
|
-
true if Float(object) rescue false
|
17
|
-
end
|
18
|
-
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# Arguments:
|
22
|
-
# object: (Boolean)
|
23
|
-
#
|
24
|
-
# Returns:
|
25
|
-
# Boolean
|
26
|
-
#
|
27
|
-
def self.is_boolean?(object)
|
28
|
-
[
|
29
|
-
true,
|
30
|
-
false
|
31
|
-
].include?(object)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Is the given object Hash
|
35
|
-
#
|
36
|
-
# Arguments:
|
37
|
-
# object: (Hash)
|
38
|
-
#
|
39
|
-
# Returns:
|
40
|
-
# Boolean
|
41
|
-
#
|
42
|
-
def self.is_a_hash?(obj)
|
43
|
-
obj.is_a?(Hash) || obj.is_a?(ActionController::Parameters)
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
@@ -1,138 +0,0 @@
|
|
1
|
-
module OSTSdk
|
2
|
-
|
3
|
-
module Util
|
4
|
-
|
5
|
-
class HTTPHelper
|
6
|
-
|
7
|
-
require "uri"
|
8
|
-
require "open-uri"
|
9
|
-
require "openssl"
|
10
|
-
require "json"
|
11
|
-
|
12
|
-
# Initialize
|
13
|
-
#
|
14
|
-
# Arguments:
|
15
|
-
# environment: (String)
|
16
|
-
# credentials: (OSTSdk::Util::APICredentials)
|
17
|
-
#
|
18
|
-
def initialize(environment, credentials)
|
19
|
-
set_api_base_url(environment)
|
20
|
-
@api_key = credentials.api_key
|
21
|
-
@api_secret = credentials.api_secret
|
22
|
-
end
|
23
|
-
|
24
|
-
# Send POST requests
|
25
|
-
#
|
26
|
-
# Arguments:
|
27
|
-
# end_point: (String)
|
28
|
-
# request_params: (Hash)
|
29
|
-
#
|
30
|
-
# Returns:
|
31
|
-
# OSTSdk::Util::Result
|
32
|
-
#
|
33
|
-
def send_post_request(endpoint, request_params)
|
34
|
-
perform_and_handle_exceptions('u_hh_1', 'POST request failed') do
|
35
|
-
base_params = get_base_params(endpoint, request_params)
|
36
|
-
uri = post_api_uri(endpoint)
|
37
|
-
http = setup_request(uri)
|
38
|
-
r_params = base_params.merge(request_params)
|
39
|
-
result = http.post(uri.path, hash_to_query_string(r_params))
|
40
|
-
OSTSdk::Util::Result.success({data: JSON.parse(result.body)})
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# Send GET requests
|
45
|
-
#
|
46
|
-
# Arguments:
|
47
|
-
# end_point: (String)
|
48
|
-
# request_params: (Hash)
|
49
|
-
#
|
50
|
-
# Returns:
|
51
|
-
# OSTSdk::Util::Result
|
52
|
-
#
|
53
|
-
def send_get_request(endpoint, request_params)
|
54
|
-
perform_and_handle_exceptions('u_hh_2', 'GET request Failed') do
|
55
|
-
base_params = get_base_params(endpoint, request_params)
|
56
|
-
r_params = base_params.merge(request_params)
|
57
|
-
raw_url = get_api_url(endpoint) + "?#{hash_to_query_string(r_params)}"
|
58
|
-
result = URI.parse(raw_url).read
|
59
|
-
OSTSdk::Util::Result.success({data: JSON.parse(result)})
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def set_api_base_url(env)
|
66
|
-
case env
|
67
|
-
when 'sandbox'
|
68
|
-
@api_base_url = 'http://localhost:3000/'
|
69
|
-
when 'production'
|
70
|
-
@api_base_url = ''
|
71
|
-
else
|
72
|
-
fail "unrecognized ENV #{env}"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def setup_request(uri)
|
77
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
78
|
-
http.read_timeout = 5
|
79
|
-
http.open_timeout = 5
|
80
|
-
if uri.scheme == "https"
|
81
|
-
http.use_ssl = true
|
82
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
83
|
-
end
|
84
|
-
http
|
85
|
-
end
|
86
|
-
|
87
|
-
def get_base_params(endpoint, request_params)
|
88
|
-
request_timestamp = Time.now.to_i.to_s
|
89
|
-
str = endpoint + '::' + request_timestamp + '::' + sort_hash(request_params).to_s
|
90
|
-
signature = generate_signature(@api_secret, str)
|
91
|
-
{"request-timestamp" => request_timestamp, "signature" => signature, "api-key" => @api_key}
|
92
|
-
end
|
93
|
-
|
94
|
-
def generate_signature(api_secret, string_to_sign)
|
95
|
-
digest = OpenSSL::Digest.new('sha256')
|
96
|
-
OpenSSL::HMAC.hexdigest(digest, @api_secret, string_to_sign)
|
97
|
-
end
|
98
|
-
|
99
|
-
def post_api_uri(endpoint)
|
100
|
-
URI(@api_base_url + endpoint)
|
101
|
-
end
|
102
|
-
|
103
|
-
def get_api_url(endpoint)
|
104
|
-
@api_base_url + endpoint
|
105
|
-
end
|
106
|
-
|
107
|
-
# Method which is called in service perform and handle exceptions
|
108
|
-
#
|
109
|
-
def perform_and_handle_exceptions(err_code = 'swt', err_message = 'Something Went Wrong', &block)
|
110
|
-
begin
|
111
|
-
yield if block_given?
|
112
|
-
rescue StandardError => se
|
113
|
-
OSTSdk::Util::Result.exception(se, {error: err_code, error_message: err_message} )
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def sort_hash(request_params)
|
118
|
-
sorted_array = request_params.sort {|a,b| a[0]<=>b[0]}
|
119
|
-
sorted_hash = {}
|
120
|
-
sorted_array.each do |element|
|
121
|
-
sorted_hash[element[0]] = element[1]
|
122
|
-
end
|
123
|
-
sorted_hash
|
124
|
-
end
|
125
|
-
|
126
|
-
def hash_to_query_string(hash)
|
127
|
-
str_array = []
|
128
|
-
hash.each do |k,v|
|
129
|
-
str_array << "#{k}=#{v.to_s}"
|
130
|
-
end
|
131
|
-
str_array.join('&')
|
132
|
-
end
|
133
|
-
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
@@ -1,225 +0,0 @@
|
|
1
|
-
module OSTSdk
|
2
|
-
|
3
|
-
module Util
|
4
|
-
|
5
|
-
class Result
|
6
|
-
|
7
|
-
attr_accessor :error,
|
8
|
-
:error_message,
|
9
|
-
:error_display_text,
|
10
|
-
:error_display_heading,
|
11
|
-
:error_data,
|
12
|
-
:message,
|
13
|
-
:data,
|
14
|
-
:exception
|
15
|
-
|
16
|
-
# Initialize
|
17
|
-
#
|
18
|
-
# Arguments:
|
19
|
-
# params: (Hash)
|
20
|
-
def initialize(params = {})
|
21
|
-
set_error(params)
|
22
|
-
set_message(params[:message])
|
23
|
-
@data = params[:data] || {}
|
24
|
-
end
|
25
|
-
|
26
|
-
# Set Error
|
27
|
-
#
|
28
|
-
# @param [Hash] params is a Hash
|
29
|
-
#
|
30
|
-
def set_error(params)
|
31
|
-
@error = params[:error] if params.key?(:error)
|
32
|
-
@error_message = params[:error_message] if params.key?(:error_message)
|
33
|
-
@error_data = params[:error_data] if params.key?(:error_data)
|
34
|
-
@error_display_text = params[:error_display_text] if params.key?(:error_display_text)
|
35
|
-
@error_display_heading = params[:error_display_heading] if params.key?(:error_display_heading)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Set Message
|
39
|
-
#
|
40
|
-
# @param [String] msg is a String
|
41
|
-
#
|
42
|
-
def set_message(msg)
|
43
|
-
@message = msg
|
44
|
-
end
|
45
|
-
|
46
|
-
# Set Exception
|
47
|
-
#
|
48
|
-
# @param [Exception] e is an Exception
|
49
|
-
#
|
50
|
-
def set_exception(e)
|
51
|
-
@exception = e
|
52
|
-
@error_data = {
|
53
|
-
msg: e.message,
|
54
|
-
trace: e.backtrace
|
55
|
-
}
|
56
|
-
end
|
57
|
-
|
58
|
-
# is valid?
|
59
|
-
#
|
60
|
-
# @return [Boolean] returns True / False
|
61
|
-
#
|
62
|
-
def valid?
|
63
|
-
!invalid?
|
64
|
-
end
|
65
|
-
|
66
|
-
# is invalid?
|
67
|
-
#
|
68
|
-
# @return [Boolean] returns True / False
|
69
|
-
#
|
70
|
-
def invalid?
|
71
|
-
errors_present?
|
72
|
-
end
|
73
|
-
|
74
|
-
# Define error / failed methods
|
75
|
-
#
|
76
|
-
[:error?, :errors?, :failed?].each do |name|
|
77
|
-
define_method(name) { invalid? }
|
78
|
-
end
|
79
|
-
|
80
|
-
# Define success method
|
81
|
-
#
|
82
|
-
[:success?].each do |name|
|
83
|
-
define_method(name) { valid? }
|
84
|
-
end
|
85
|
-
|
86
|
-
# are errors present?
|
87
|
-
#
|
88
|
-
# @return [Boolean] returns True / False
|
89
|
-
#
|
90
|
-
def errors_present?
|
91
|
-
@error.present? ||
|
92
|
-
@error_message.present? ||
|
93
|
-
@error_data.present? ||
|
94
|
-
@error_display_text.present? ||
|
95
|
-
@error_display_heading.present? ||
|
96
|
-
@exception.present?
|
97
|
-
end
|
98
|
-
|
99
|
-
# Exception message
|
100
|
-
#
|
101
|
-
# @return [String]
|
102
|
-
#
|
103
|
-
def exception_message
|
104
|
-
@e_m ||= @exception.present? ? @exception.message : ''
|
105
|
-
end
|
106
|
-
|
107
|
-
# Exception backtrace
|
108
|
-
#
|
109
|
-
# @return [String]
|
110
|
-
#
|
111
|
-
def exception_backtrace
|
112
|
-
@e_b ||= @exception.present? ? @exception.backtrace : ''
|
113
|
-
end
|
114
|
-
|
115
|
-
# Get instance variables Hash style from object
|
116
|
-
#
|
117
|
-
def [](key)
|
118
|
-
instance_variable_get("@#{key}")
|
119
|
-
end
|
120
|
-
|
121
|
-
# Error
|
122
|
-
#
|
123
|
-
# @return [OSTSdk::Util::Result] returns object of OSTSdk::Util::Result class
|
124
|
-
#
|
125
|
-
def self.error(params)
|
126
|
-
new(params)
|
127
|
-
end
|
128
|
-
|
129
|
-
# Success
|
130
|
-
#
|
131
|
-
# @return [OSTSdk::Util::Result] returns object of OSTSdk::Util::Result class
|
132
|
-
#
|
133
|
-
def self.success(params)
|
134
|
-
new(params.merge!(no_error))
|
135
|
-
end
|
136
|
-
|
137
|
-
# Exception
|
138
|
-
#
|
139
|
-
# @return [OSTSdk::Util::Result] returns object of OSTSdk::Util::Result class
|
140
|
-
#
|
141
|
-
def self.exception(e, params = {})
|
142
|
-
obj = new(params)
|
143
|
-
obj.set_exception(e)
|
144
|
-
return obj
|
145
|
-
end
|
146
|
-
|
147
|
-
# No Error
|
148
|
-
#
|
149
|
-
# @return [Hash] returns Hash
|
150
|
-
#
|
151
|
-
def self.no_error
|
152
|
-
@n_err ||= {
|
153
|
-
error: nil,
|
154
|
-
error_message: nil,
|
155
|
-
error_data: nil,
|
156
|
-
error_display_text: nil,
|
157
|
-
error_display_heading: nil
|
158
|
-
}
|
159
|
-
end
|
160
|
-
|
161
|
-
# Fields
|
162
|
-
#
|
163
|
-
# @return [Array] returns Array object
|
164
|
-
#
|
165
|
-
def self.fields
|
166
|
-
error_fields + [:data, :message]
|
167
|
-
end
|
168
|
-
|
169
|
-
# Error Fields
|
170
|
-
#
|
171
|
-
# @return [Array] returns Array object
|
172
|
-
#
|
173
|
-
def self.error_fields
|
174
|
-
[
|
175
|
-
:error,
|
176
|
-
:error_message,
|
177
|
-
:error_data,
|
178
|
-
:error_display_text,
|
179
|
-
:error_display_heading
|
180
|
-
]
|
181
|
-
end
|
182
|
-
|
183
|
-
# Create an Hash out of all instance vars
|
184
|
-
#
|
185
|
-
# @return [Hash] returns Hash object
|
186
|
-
#
|
187
|
-
def to_hash
|
188
|
-
self.class.fields.each_with_object({}) do |key, hash|
|
189
|
-
val = send(key)
|
190
|
-
hash[key] = val if val.present?
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
# To JSON
|
195
|
-
#
|
196
|
-
def to_json
|
197
|
-
|
198
|
-
hash = self.to_hash
|
199
|
-
|
200
|
-
if (hash[:error] == nil)
|
201
|
-
h = {
|
202
|
-
success: true
|
203
|
-
}.merge(hash)
|
204
|
-
h
|
205
|
-
else
|
206
|
-
{
|
207
|
-
success: false,
|
208
|
-
err: {
|
209
|
-
code: hash[:error],
|
210
|
-
msg: hash[:error_message],
|
211
|
-
display_text: hash[:error_display_text].to_s,
|
212
|
-
display_heading: hash[:error_display_heading].to_s,
|
213
|
-
error_data: hash[:error_data] || {}
|
214
|
-
},
|
215
|
-
data: hash[:data]
|
216
|
-
}
|
217
|
-
end
|
218
|
-
|
219
|
-
end
|
220
|
-
|
221
|
-
end
|
222
|
-
|
223
|
-
end
|
224
|
-
|
225
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
module OSTSdk
|
2
|
-
|
3
|
-
module Util
|
4
|
-
|
5
|
-
module ServicesHelper
|
6
|
-
|
7
|
-
# Method which is called in service perform and handle exceptions
|
8
|
-
#
|
9
|
-
def perform_and_handle_exceptions(err_code = 'swt', err_message = 'Something Went Wrong', &block)
|
10
|
-
begin
|
11
|
-
yield if block_given?
|
12
|
-
rescue StandardError => se
|
13
|
-
OSTSdk::Util::Result.exception(se, {error: err_code, error_message: err_message, data: @params} )
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# returns current time
|
18
|
-
#
|
19
|
-
# Returns:
|
20
|
-
# Time
|
21
|
-
#
|
22
|
-
def current_time
|
23
|
-
@c_time ||= Time.now
|
24
|
-
end
|
25
|
-
|
26
|
-
# returns current timestamp
|
27
|
-
#
|
28
|
-
# Returns:
|
29
|
-
# Integer
|
30
|
-
#
|
31
|
-
def current_timestamp
|
32
|
-
@c_tstamp ||= current_time.to_f
|
33
|
-
end
|
34
|
-
|
35
|
-
# Success
|
36
|
-
#
|
37
|
-
# Returns:
|
38
|
-
# OSTSdk::Util::Result
|
39
|
-
#
|
40
|
-
def success
|
41
|
-
success_with_data({})
|
42
|
-
end
|
43
|
-
|
44
|
-
# Success with data
|
45
|
-
#
|
46
|
-
# Arguments:
|
47
|
-
# data: (Hash)
|
48
|
-
#
|
49
|
-
# Returns:
|
50
|
-
# OSTSdk::Util::Result
|
51
|
-
#
|
52
|
-
def success_with_data(data)
|
53
|
-
|
54
|
-
# Allow only Hash data to pass ahead
|
55
|
-
data = {} unless Util::CommonValidator.is_a_hash?(data)
|
56
|
-
|
57
|
-
OSTSdk::Util::Result.success({data: data})
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
# Error with data
|
62
|
-
#
|
63
|
-
# Arguments:
|
64
|
-
# code: (String)
|
65
|
-
# msg: (String)
|
66
|
-
# data: (Hash)
|
67
|
-
#
|
68
|
-
# Returns:
|
69
|
-
# OSTSdk::Util::Result
|
70
|
-
#
|
71
|
-
def error_with_data(code, msg, data = {})
|
72
|
-
|
73
|
-
OSTSdk::Util::Result.error(
|
74
|
-
{
|
75
|
-
error: code,
|
76
|
-
error_message: msg,
|
77
|
-
data: data
|
78
|
-
}
|
79
|
-
)
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
#
|
84
|
-
# Exception with data and wthout action
|
85
|
-
#
|
86
|
-
# Arguments:
|
87
|
-
# e: (Exception)
|
88
|
-
# code: (String)
|
89
|
-
# msg: (String)
|
90
|
-
# data: (Hash optional)
|
91
|
-
#
|
92
|
-
# Returns:
|
93
|
-
# OSTSdk::Util::Result
|
94
|
-
#
|
95
|
-
def exception_with_data(e, code, msg, data = {})
|
96
|
-
|
97
|
-
OSTSdk::Util::Result.exception(
|
98
|
-
e, {
|
99
|
-
error: code,
|
100
|
-
error_message: msg,
|
101
|
-
data: data
|
102
|
-
}
|
103
|
-
)
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|