ost-sdk-ruby-stag 0.0.1.pre
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 +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/ost-sdk-ruby-stag.rb +8 -0
- data/lib/ost-sdk-ruby-stag/saas.rb +10 -0
- data/lib/ost-sdk-ruby-stag/saas/base.rb +29 -0
- data/lib/ost-sdk-ruby-stag/saas/transaction_kind.rb +43 -0
- data/lib/ost-sdk-ruby-stag/util.rb +13 -0
- data/lib/ost-sdk-ruby-stag/util/api_credentials.rb +32 -0
- data/lib/ost-sdk-ruby-stag/util/common_validator.rb +50 -0
- data/lib/ost-sdk-ruby-stag/util/http_helper.rb +138 -0
- data/lib/ost-sdk-ruby-stag/util/result.rb +225 -0
- data/lib/ost-sdk-ruby-stag/util/services_helper.rb +120 -0
- data/lib/ost-sdk-ruby-stag/version.rb +5 -0
- data/ost-sdk-ruby-stag.gemspec +23 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 210d873ea1a2bca2ad9bb02d0471e87f156e317d
|
4
|
+
data.tar.gz: 7f76480e6ee7cdea999b58cfa3f40c7222536c72
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4dc0387fcfdf8d506b2d7ca7febe40dee0e3249a57862865951a2bb3a309e5ee217a25143b5572592dfdfb6166d405c3be2adc59a0efbf126d776c4e2300ffaa
|
7
|
+
data.tar.gz: 35aea0fd57e5bf600fb58359b775929db8e30bc38e06cd0d771af7e5fff3c7410462c12c42c48d114219b3395eb8c08647b1b634f4d324da131764ca6486aca4
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Ost::Sdk::Ruby::Stag
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ost/sdk/ruby/stag`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ost-sdk-ruby-stag'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ost-sdk-ruby-stag
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
1. TransactionKind Module
|
26
|
+
|
27
|
+
environment = 'sandbox' # possible values sandbox / production
|
28
|
+
|
29
|
+
credentials = OSTSdk::Util::APICredentials.new('api_key', '2e3ec863fdffcc4425a3d73878e685e702b42bf8')
|
30
|
+
|
31
|
+
obj = OSTSdk::Saas::TransactionKind.new(environment, credentials)
|
32
|
+
|
33
|
+
obj.list(clientId: '1')
|
34
|
+
|
35
|
+
obj.create(client_id: '1', name: 'test_1', kind: '1', value_currency_type: '1')
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
40
|
+
|
41
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ost-sdk-ruby-stag.
|
46
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ost/sdk/ruby/stag"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
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
|
@@ -0,0 +1,43 @@
|
|
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
|
+
# Returns:
|
21
|
+
# response: (OSTSdk::Util::Result)
|
22
|
+
#
|
23
|
+
def list(params = {})
|
24
|
+
http_helper.send_get_request("#{@url_prefix}/get-all", params)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Creates a new transaction type
|
28
|
+
#
|
29
|
+
# Arguments:
|
30
|
+
# params: (Hash)
|
31
|
+
#
|
32
|
+
# Returns:
|
33
|
+
# response: (OSTSdk::Util::Result)
|
34
|
+
#
|
35
|
+
def create(params)
|
36
|
+
http_helper.send_post_request("#{@url_prefix}/new", params)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,32 @@
|
|
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
|
@@ -0,0 +1,50 @@
|
|
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
|
@@ -0,0 +1,138 @@
|
|
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_json
|
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].downcase<=>b[0].downcase}
|
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
|
@@ -0,0 +1,225 @@
|
|
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
|
@@ -0,0 +1,120 @@
|
|
1
|
+
module OSTSdk
|
2
|
+
|
3
|
+
module Util
|
4
|
+
|
5
|
+
module ServicesHelper
|
6
|
+
|
7
|
+
# Wrapper Method which could be used to execute business logic
|
8
|
+
# Error handling code wraps execution of business logic
|
9
|
+
#
|
10
|
+
# Arguments:
|
11
|
+
# err_code: (String)
|
12
|
+
# err_message: (String)
|
13
|
+
# block: (Proc)
|
14
|
+
#
|
15
|
+
# Returns:
|
16
|
+
# OSTSdk::Util::Result
|
17
|
+
#
|
18
|
+
def perform_and_handle_exceptions(err_code = 'swt', err_message = 'Something Went Wrong', &block)
|
19
|
+
begin
|
20
|
+
yield if block_given?
|
21
|
+
rescue StandardError => se
|
22
|
+
OSTSdk::Util::Result.exception(se, {error: err_code, error_message: err_message, data: @params} )
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# returns current time
|
27
|
+
#
|
28
|
+
# Returns:
|
29
|
+
# Time
|
30
|
+
#
|
31
|
+
def current_time
|
32
|
+
@c_time ||= Time.now
|
33
|
+
end
|
34
|
+
|
35
|
+
# returns current timestamp
|
36
|
+
#
|
37
|
+
# Returns:
|
38
|
+
# Integer
|
39
|
+
#
|
40
|
+
def current_timestamp
|
41
|
+
@c_tstamp ||= current_time.to_f
|
42
|
+
end
|
43
|
+
|
44
|
+
# Success
|
45
|
+
#
|
46
|
+
# Returns:
|
47
|
+
# OSTSdk::Util::Result
|
48
|
+
#
|
49
|
+
def success
|
50
|
+
success_with_data({})
|
51
|
+
end
|
52
|
+
|
53
|
+
# Success with data
|
54
|
+
#
|
55
|
+
# Arguments:
|
56
|
+
# data: (Hash)
|
57
|
+
#
|
58
|
+
# Returns:
|
59
|
+
# OSTSdk::Util::Result
|
60
|
+
#
|
61
|
+
def success_with_data(data)
|
62
|
+
|
63
|
+
# Allow only Hash data to pass ahead
|
64
|
+
data = {} unless Util::CommonValidator.is_a_hash?(data)
|
65
|
+
|
66
|
+
OSTSdk::Util::Result.success({data: data})
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
# Error with data
|
71
|
+
#
|
72
|
+
# Arguments:
|
73
|
+
# code: (String)
|
74
|
+
# msg: (String)
|
75
|
+
# data: (Hash)
|
76
|
+
#
|
77
|
+
# Returns:
|
78
|
+
# OSTSdk::Util::Result
|
79
|
+
#
|
80
|
+
def error_with_data(code, msg, data = {})
|
81
|
+
|
82
|
+
OSTSdk::Util::Result.error(
|
83
|
+
{
|
84
|
+
error: code,
|
85
|
+
error_message: msg,
|
86
|
+
data: data
|
87
|
+
}
|
88
|
+
)
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
#
|
93
|
+
# Exception with data and wthout action
|
94
|
+
#
|
95
|
+
# Arguments:
|
96
|
+
# e: (Exception)
|
97
|
+
# code: (String)
|
98
|
+
# msg: (String)
|
99
|
+
# data: (Hash optional)
|
100
|
+
#
|
101
|
+
# Returns:
|
102
|
+
# OSTSdk::Util::Result
|
103
|
+
#
|
104
|
+
def exception_with_data(e, code, msg, data = {})
|
105
|
+
|
106
|
+
OSTSdk::Util::Result.exception(
|
107
|
+
e, {
|
108
|
+
error: code,
|
109
|
+
error_message: msg,
|
110
|
+
data: data
|
111
|
+
}
|
112
|
+
)
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ost-sdk-ruby-stag/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ost-sdk-ruby-stag"
|
8
|
+
spec.version = OSTSdk::VERSION
|
9
|
+
spec.authors = ["Puneet Khushwani"]
|
10
|
+
spec.email = ["puneet.khushwani@pepo.com"]
|
11
|
+
|
12
|
+
spec.summary = "OST Ruby SDK"
|
13
|
+
spec.description = "Init Version"
|
14
|
+
spec.homepage = "https://sale.stagingsimpletoken.org/"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ost-sdk-ruby-stag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.pre
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Puneet Khushwani
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Init Version
|
42
|
+
email:
|
43
|
+
- puneet.khushwani@pepo.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- bin/console
|
53
|
+
- bin/setup
|
54
|
+
- lib/ost-sdk-ruby-stag.rb
|
55
|
+
- lib/ost-sdk-ruby-stag/saas.rb
|
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
|
65
|
+
- ost-sdk-ruby-stag.gemspec
|
66
|
+
homepage: https://sale.stagingsimpletoken.org/
|
67
|
+
licenses: []
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.3.1
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.2.2
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: OST Ruby SDK
|
89
|
+
test_files: []
|