moesif_api 1.0.3 → 1.0.4
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/LICENSE +216 -24
- data/README.md +124 -117
- data/lib/moesif_api/api_helper.rb +150 -150
- data/lib/moesif_api/configuration.rb +17 -17
- data/lib/moesif_api/controllers/api_controller.rb +87 -87
- data/lib/moesif_api/controllers/health_controller.rb +52 -52
- data/lib/moesif_api/exceptions/api_exception.rb +16 -16
- data/lib/moesif_api/http/http_call_back.rb +16 -16
- data/lib/moesif_api/http/http_client.rb +112 -112
- data/lib/moesif_api/http/http_context.rb +14 -14
- data/lib/moesif_api/http/http_method_enum.rb +7 -7
- data/lib/moesif_api/http/http_request.rb +28 -28
- data/lib/moesif_api/http/http_response.rb +19 -19
- data/lib/moesif_api/http/unirest_client.rb +35 -35
- data/lib/moesif_api/models/base_model.rb +32 -32
- data/lib/moesif_api/models/event_model.rb +71 -71
- data/lib/moesif_api/models/event_request_model.rb +90 -90
- data/lib/moesif_api/models/event_response_model.rb +72 -72
- data/lib/moesif_api/models/status_model.rb +44 -44
- data/lib/moesif_api/moesif_api_client.rb +22 -22
- data/lib/moesif_api.rb +33 -33
- data/test/controllers/controller_test_base.rb +28 -28
- data/test/http_response_catcher.rb +16 -16
- data/test/test_helper.rb +94 -94
- metadata +4 -4
@@ -1,151 +1,151 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module MoesifApi
|
4
|
-
class APIHelper
|
5
|
-
# Replaces template parameters in the given url
|
6
|
-
# @param [String] The query string builder to replace the template parameters
|
7
|
-
# @param [Array] The parameters to replace in the url
|
8
|
-
def self.append_url_with_template_parameters(query_builder, parameters)
|
9
|
-
# perform parameter validation
|
10
|
-
raise ArgumentError, 'Given value for parameter \"query_builder\" is invalid.' unless query_builder.instance_of? String
|
11
|
-
|
12
|
-
# return if there are no parameters to replace
|
13
|
-
if parameters.nil?
|
14
|
-
query_builder
|
15
|
-
else
|
16
|
-
# iterate and append parameters
|
17
|
-
parameters.each do |key, value|
|
18
|
-
replace_value = ''
|
19
|
-
|
20
|
-
if value.nil?
|
21
|
-
replace_value = ''
|
22
|
-
elsif value.instance_of? Array
|
23
|
-
value.map!{|element| CGI.escape(element.to_s)}
|
24
|
-
replace_value = value.join('/')
|
25
|
-
else
|
26
|
-
replace_value = CGI.escape(value.to_s)
|
27
|
-
end
|
28
|
-
|
29
|
-
# find the template parameter and replace it with its value
|
30
|
-
query_builder = query_builder.gsub('{' + key.to_s + '}', replace_value)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
return query_builder
|
34
|
-
end
|
35
|
-
|
36
|
-
# Appends the given set of parameters to the given query string
|
37
|
-
# @param [String] The query string builder to replace the template parameters
|
38
|
-
# @param [Array] The parameters to append
|
39
|
-
def self.append_url_with_query_parameters(query_builder, parameters)
|
40
|
-
# perform parameter validation
|
41
|
-
raise ArgumentError, 'Given value for parameter \"query_builder\" is invalid.' unless query_builder.instance_of? String
|
42
|
-
|
43
|
-
# return if there are no parameters to replace
|
44
|
-
if parameters.nil?
|
45
|
-
return query_builder
|
46
|
-
else
|
47
|
-
# remove any nil values
|
48
|
-
parameters = parameters.reject { |_key, value| value.nil? }
|
49
|
-
|
50
|
-
# does the query string already has parameters
|
51
|
-
has_params = query_builder.include? '?'
|
52
|
-
separator = has_params ? '&' : '?'
|
53
|
-
|
54
|
-
# append query with separator and parameters and return
|
55
|
-
return query_builder << separator << URI.encode_www_form(parameters)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# Validates and processes the given Url
|
60
|
-
# @param [String] The given Url to process
|
61
|
-
# @return [String] Pre-processed Url as string
|
62
|
-
def self.clean_url(url)
|
63
|
-
# perform parameter validation
|
64
|
-
raise ArgumentError, 'Invalid Url.' unless url.instance_of? String
|
65
|
-
|
66
|
-
# ensure that the urls are absolute
|
67
|
-
matches = url.match(%r{^(https?:\/\/[^\/]+)})
|
68
|
-
raise ArgumentError, 'Invalid Url format.' if matches.nil?
|
69
|
-
|
70
|
-
# get the http protocol match
|
71
|
-
protocol = matches[1]
|
72
|
-
|
73
|
-
# check if parameters exist
|
74
|
-
index = url.index('?')
|
75
|
-
|
76
|
-
# remove redundant forward slashes
|
77
|
-
query = url[protocol.length...(index != nil ? index : url.length)]
|
78
|
-
query.gsub!(%r{\/\/+}, '/')
|
79
|
-
|
80
|
-
# get the parameters
|
81
|
-
parameters = index != nil ? url[url.index('?')...url.length] : ""
|
82
|
-
|
83
|
-
# return processed url
|
84
|
-
return protocol + query + parameters
|
85
|
-
end
|
86
|
-
|
87
|
-
# Parses JSON string.
|
88
|
-
# @param [String] A JSON string.
|
89
|
-
def self.json_deserialize(json)
|
90
|
-
begin
|
91
|
-
return JSON.parse(json)
|
92
|
-
rescue
|
93
|
-
raise TypeError, "Server responded with invalid JSON."
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
# Form encodes a hash of parameters.
|
98
|
-
# @param [Hash] The hash of parameters to encode.
|
99
|
-
# @return [Hash] A hash with the same parameters form encoded.
|
100
|
-
def self.form_encode_parameters(form_parameters)
|
101
|
-
encoded = Hash.new
|
102
|
-
form_parameters.each do |key, value|
|
103
|
-
encoded.merge!(APIHelper.form_encode value, key)
|
104
|
-
end
|
105
|
-
return encoded
|
106
|
-
end
|
107
|
-
|
108
|
-
# Form encodes an object.
|
109
|
-
# @param [Dynamic] An object to form encode.
|
110
|
-
# @param [String] The name of the object.
|
111
|
-
# @return [Hash] A form encoded representation of the object in the form of a hash.
|
112
|
-
def self.form_encode(obj, instance_name)
|
113
|
-
retval = Hash.new
|
114
|
-
|
115
|
-
# If this is a structure, resolve it's field names.
|
116
|
-
if obj.kind_of? BaseModel
|
117
|
-
obj = obj.to_hash
|
118
|
-
end
|
119
|
-
|
120
|
-
# Create a form encoded hash for this object.
|
121
|
-
if obj == nil
|
122
|
-
nil
|
123
|
-
elsif obj.instance_of? Array
|
124
|
-
obj.each_with_index do |value, index|
|
125
|
-
retval.merge!(APIHelper.form_encode(value, instance_name + "[" + index.to_s + "]"))
|
126
|
-
end
|
127
|
-
elsif obj.instance_of? Hash
|
128
|
-
obj.each do |key, value|
|
129
|
-
retval.merge!(APIHelper.form_encode(value, instance_name + "[" + key + "]"))
|
130
|
-
end
|
131
|
-
else
|
132
|
-
retval[instance_name] = obj
|
133
|
-
end
|
134
|
-
return retval
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
# extend types to support to_bool
|
140
|
-
module ToBoolean
|
141
|
-
def to_bool
|
142
|
-
return true if self == true || self.to_s.strip =~ /^(true|yes|y|1)$/i
|
143
|
-
return false
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
class NilClass; include ToBoolean; end
|
148
|
-
class TrueClass; include ToBoolean; end
|
149
|
-
class FalseClass; include ToBoolean; end
|
150
|
-
class Numeric; include ToBoolean; end
|
1
|
+
|
2
|
+
|
3
|
+
module MoesifApi
|
4
|
+
class APIHelper
|
5
|
+
# Replaces template parameters in the given url
|
6
|
+
# @param [String] The query string builder to replace the template parameters
|
7
|
+
# @param [Array] The parameters to replace in the url
|
8
|
+
def self.append_url_with_template_parameters(query_builder, parameters)
|
9
|
+
# perform parameter validation
|
10
|
+
raise ArgumentError, 'Given value for parameter \"query_builder\" is invalid.' unless query_builder.instance_of? String
|
11
|
+
|
12
|
+
# return if there are no parameters to replace
|
13
|
+
if parameters.nil?
|
14
|
+
query_builder
|
15
|
+
else
|
16
|
+
# iterate and append parameters
|
17
|
+
parameters.each do |key, value|
|
18
|
+
replace_value = ''
|
19
|
+
|
20
|
+
if value.nil?
|
21
|
+
replace_value = ''
|
22
|
+
elsif value.instance_of? Array
|
23
|
+
value.map!{|element| CGI.escape(element.to_s)}
|
24
|
+
replace_value = value.join('/')
|
25
|
+
else
|
26
|
+
replace_value = CGI.escape(value.to_s)
|
27
|
+
end
|
28
|
+
|
29
|
+
# find the template parameter and replace it with its value
|
30
|
+
query_builder = query_builder.gsub('{' + key.to_s + '}', replace_value)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
return query_builder
|
34
|
+
end
|
35
|
+
|
36
|
+
# Appends the given set of parameters to the given query string
|
37
|
+
# @param [String] The query string builder to replace the template parameters
|
38
|
+
# @param [Array] The parameters to append
|
39
|
+
def self.append_url_with_query_parameters(query_builder, parameters)
|
40
|
+
# perform parameter validation
|
41
|
+
raise ArgumentError, 'Given value for parameter \"query_builder\" is invalid.' unless query_builder.instance_of? String
|
42
|
+
|
43
|
+
# return if there are no parameters to replace
|
44
|
+
if parameters.nil?
|
45
|
+
return query_builder
|
46
|
+
else
|
47
|
+
# remove any nil values
|
48
|
+
parameters = parameters.reject { |_key, value| value.nil? }
|
49
|
+
|
50
|
+
# does the query string already has parameters
|
51
|
+
has_params = query_builder.include? '?'
|
52
|
+
separator = has_params ? '&' : '?'
|
53
|
+
|
54
|
+
# append query with separator and parameters and return
|
55
|
+
return query_builder << separator << URI.encode_www_form(parameters)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Validates and processes the given Url
|
60
|
+
# @param [String] The given Url to process
|
61
|
+
# @return [String] Pre-processed Url as string
|
62
|
+
def self.clean_url(url)
|
63
|
+
# perform parameter validation
|
64
|
+
raise ArgumentError, 'Invalid Url.' unless url.instance_of? String
|
65
|
+
|
66
|
+
# ensure that the urls are absolute
|
67
|
+
matches = url.match(%r{^(https?:\/\/[^\/]+)})
|
68
|
+
raise ArgumentError, 'Invalid Url format.' if matches.nil?
|
69
|
+
|
70
|
+
# get the http protocol match
|
71
|
+
protocol = matches[1]
|
72
|
+
|
73
|
+
# check if parameters exist
|
74
|
+
index = url.index('?')
|
75
|
+
|
76
|
+
# remove redundant forward slashes
|
77
|
+
query = url[protocol.length...(index != nil ? index : url.length)]
|
78
|
+
query.gsub!(%r{\/\/+}, '/')
|
79
|
+
|
80
|
+
# get the parameters
|
81
|
+
parameters = index != nil ? url[url.index('?')...url.length] : ""
|
82
|
+
|
83
|
+
# return processed url
|
84
|
+
return protocol + query + parameters
|
85
|
+
end
|
86
|
+
|
87
|
+
# Parses JSON string.
|
88
|
+
# @param [String] A JSON string.
|
89
|
+
def self.json_deserialize(json)
|
90
|
+
begin
|
91
|
+
return JSON.parse(json)
|
92
|
+
rescue
|
93
|
+
raise TypeError, "Server responded with invalid JSON."
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Form encodes a hash of parameters.
|
98
|
+
# @param [Hash] The hash of parameters to encode.
|
99
|
+
# @return [Hash] A hash with the same parameters form encoded.
|
100
|
+
def self.form_encode_parameters(form_parameters)
|
101
|
+
encoded = Hash.new
|
102
|
+
form_parameters.each do |key, value|
|
103
|
+
encoded.merge!(APIHelper.form_encode value, key)
|
104
|
+
end
|
105
|
+
return encoded
|
106
|
+
end
|
107
|
+
|
108
|
+
# Form encodes an object.
|
109
|
+
# @param [Dynamic] An object to form encode.
|
110
|
+
# @param [String] The name of the object.
|
111
|
+
# @return [Hash] A form encoded representation of the object in the form of a hash.
|
112
|
+
def self.form_encode(obj, instance_name)
|
113
|
+
retval = Hash.new
|
114
|
+
|
115
|
+
# If this is a structure, resolve it's field names.
|
116
|
+
if obj.kind_of? BaseModel
|
117
|
+
obj = obj.to_hash
|
118
|
+
end
|
119
|
+
|
120
|
+
# Create a form encoded hash for this object.
|
121
|
+
if obj == nil
|
122
|
+
nil
|
123
|
+
elsif obj.instance_of? Array
|
124
|
+
obj.each_with_index do |value, index|
|
125
|
+
retval.merge!(APIHelper.form_encode(value, instance_name + "[" + index.to_s + "]"))
|
126
|
+
end
|
127
|
+
elsif obj.instance_of? Hash
|
128
|
+
obj.each do |key, value|
|
129
|
+
retval.merge!(APIHelper.form_encode(value, instance_name + "[" + key + "]"))
|
130
|
+
end
|
131
|
+
else
|
132
|
+
retval[instance_name] = obj
|
133
|
+
end
|
134
|
+
return retval
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# extend types to support to_bool
|
140
|
+
module ToBoolean
|
141
|
+
def to_bool
|
142
|
+
return true if self == true || self.to_s.strip =~ /^(true|yes|y|1)$/i
|
143
|
+
return false
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
class NilClass; include ToBoolean; end
|
148
|
+
class TrueClass; include ToBoolean; end
|
149
|
+
class FalseClass; include ToBoolean; end
|
150
|
+
class Numeric; include ToBoolean; end
|
151
151
|
class String; include ToBoolean; end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module MoesifApi
|
4
|
-
class Configuration
|
5
|
-
# The base Uri for API calls
|
6
|
-
@base_uri = 'https://api.moesif.net'
|
7
|
-
|
8
|
-
# Your Application Id for authentication/authorization
|
9
|
-
@application_id = 'TODO: Replace'
|
10
|
-
|
11
|
-
# create the getters and setters
|
12
|
-
class << self
|
13
|
-
attr_accessor :base_uri
|
14
|
-
attr_accessor :application_id
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
|
2
|
+
|
3
|
+
module MoesifApi
|
4
|
+
class Configuration
|
5
|
+
# The base Uri for API calls
|
6
|
+
@base_uri = 'https://api.moesif.net'
|
7
|
+
|
8
|
+
# Your Application Id for authentication/authorization
|
9
|
+
@application_id = 'TODO: Replace'
|
10
|
+
|
11
|
+
# create the getters and setters
|
12
|
+
class << self
|
13
|
+
attr_accessor :base_uri
|
14
|
+
attr_accessor :application_id
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,87 +1,87 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module MoesifApi
|
4
|
-
class ApiController < BaseController
|
5
|
-
@@instance = ApiController.new
|
6
|
-
# Singleton instance of the controller class
|
7
|
-
def self.instance
|
8
|
-
@@instance
|
9
|
-
end
|
10
|
-
|
11
|
-
# Add Single API Event Call
|
12
|
-
# @param [EventModel] body Required parameter: Example:
|
13
|
-
# @return void response from the API call
|
14
|
-
def create_event(body)
|
15
|
-
# the base uri for api requests
|
16
|
-
_query_builder = Configuration.base_uri.dup
|
17
|
-
|
18
|
-
# prepare query string for API call
|
19
|
-
_query_builder << '/v1/events'
|
20
|
-
|
21
|
-
# validate and preprocess url
|
22
|
-
_query_url = APIHelper.clean_url _query_builder
|
23
|
-
|
24
|
-
# prepare headers
|
25
|
-
_headers = {
|
26
|
-
'content-type' => 'application/json; charset=utf-8',
|
27
|
-
'X-Moesif-Application-Id' => Configuration.application_id
|
28
|
-
}
|
29
|
-
|
30
|
-
# Create the HttpRequest object for the call
|
31
|
-
_request = @http_client.post _query_url, headers: _headers, parameters: body.to_json
|
32
|
-
|
33
|
-
# Call the on_before_request callback
|
34
|
-
@http_call_back.on_before_request(_request) if @http_call_back
|
35
|
-
|
36
|
-
# Invoke the API call and get the response
|
37
|
-
_response = @http_client.execute_as_string(_request)
|
38
|
-
|
39
|
-
# Wrap the request and response in an HttpContext object
|
40
|
-
_context = HttpContext.new(_request, _response)
|
41
|
-
|
42
|
-
# Call the on_after_response callback
|
43
|
-
@http_call_back.on_after_response(_context) if @http_call_back
|
44
|
-
|
45
|
-
# Global error handling using HTTP status codes.
|
46
|
-
validate_response(_context)
|
47
|
-
end
|
48
|
-
|
49
|
-
# Add multiple API Events in a single batch (batch size must be less than 250kb)
|
50
|
-
# @param [List of EventModel] body Required parameter: Example:
|
51
|
-
# @return void response from the API call
|
52
|
-
def create_events_batch(body)
|
53
|
-
# the base uri for api requests
|
54
|
-
_query_builder = Configuration.base_uri.dup
|
55
|
-
|
56
|
-
# prepare query string for API call
|
57
|
-
_query_builder << '/v1/events/batch'
|
58
|
-
|
59
|
-
# validate and preprocess url
|
60
|
-
_query_url = APIHelper.clean_url _query_builder
|
61
|
-
|
62
|
-
# prepare headers
|
63
|
-
_headers = {
|
64
|
-
'content-type' => 'application/json; charset=utf-8',
|
65
|
-
'X-Moesif-Application-Id' => Configuration.application_id
|
66
|
-
}
|
67
|
-
|
68
|
-
# Create the HttpRequest object for the call
|
69
|
-
_request = @http_client.post _query_url, headers: _headers, parameters: body.to_json
|
70
|
-
|
71
|
-
# Call the on_before_request callback
|
72
|
-
@http_call_back.on_before_request(_request) if @http_call_back
|
73
|
-
|
74
|
-
# Invoke the API call and get the response
|
75
|
-
_response = @http_client.execute_as_string(_request)
|
76
|
-
|
77
|
-
# Wrap the request and response in an HttpContext object
|
78
|
-
_context = HttpContext.new(_request, _response)
|
79
|
-
|
80
|
-
# Call the on_after_response callback
|
81
|
-
@http_call_back.on_after_response(_context) if @http_call_back
|
82
|
-
|
83
|
-
# Global error handling using HTTP status codes.
|
84
|
-
validate_response(_context)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
1
|
+
|
2
|
+
|
3
|
+
module MoesifApi
|
4
|
+
class ApiController < BaseController
|
5
|
+
@@instance = ApiController.new
|
6
|
+
# Singleton instance of the controller class
|
7
|
+
def self.instance
|
8
|
+
@@instance
|
9
|
+
end
|
10
|
+
|
11
|
+
# Add Single API Event Call
|
12
|
+
# @param [EventModel] body Required parameter: Example:
|
13
|
+
# @return void response from the API call
|
14
|
+
def create_event(body)
|
15
|
+
# the base uri for api requests
|
16
|
+
_query_builder = Configuration.base_uri.dup
|
17
|
+
|
18
|
+
# prepare query string for API call
|
19
|
+
_query_builder << '/v1/events'
|
20
|
+
|
21
|
+
# validate and preprocess url
|
22
|
+
_query_url = APIHelper.clean_url _query_builder
|
23
|
+
|
24
|
+
# prepare headers
|
25
|
+
_headers = {
|
26
|
+
'content-type' => 'application/json; charset=utf-8',
|
27
|
+
'X-Moesif-Application-Id' => Configuration.application_id
|
28
|
+
}
|
29
|
+
|
30
|
+
# Create the HttpRequest object for the call
|
31
|
+
_request = @http_client.post _query_url, headers: _headers, parameters: body.to_json
|
32
|
+
|
33
|
+
# Call the on_before_request callback
|
34
|
+
@http_call_back.on_before_request(_request) if @http_call_back
|
35
|
+
|
36
|
+
# Invoke the API call and get the response
|
37
|
+
_response = @http_client.execute_as_string(_request)
|
38
|
+
|
39
|
+
# Wrap the request and response in an HttpContext object
|
40
|
+
_context = HttpContext.new(_request, _response)
|
41
|
+
|
42
|
+
# Call the on_after_response callback
|
43
|
+
@http_call_back.on_after_response(_context) if @http_call_back
|
44
|
+
|
45
|
+
# Global error handling using HTTP status codes.
|
46
|
+
validate_response(_context)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Add multiple API Events in a single batch (batch size must be less than 250kb)
|
50
|
+
# @param [List of EventModel] body Required parameter: Example:
|
51
|
+
# @return void response from the API call
|
52
|
+
def create_events_batch(body)
|
53
|
+
# the base uri for api requests
|
54
|
+
_query_builder = Configuration.base_uri.dup
|
55
|
+
|
56
|
+
# prepare query string for API call
|
57
|
+
_query_builder << '/v1/events/batch'
|
58
|
+
|
59
|
+
# validate and preprocess url
|
60
|
+
_query_url = APIHelper.clean_url _query_builder
|
61
|
+
|
62
|
+
# prepare headers
|
63
|
+
_headers = {
|
64
|
+
'content-type' => 'application/json; charset=utf-8',
|
65
|
+
'X-Moesif-Application-Id' => Configuration.application_id
|
66
|
+
}
|
67
|
+
|
68
|
+
# Create the HttpRequest object for the call
|
69
|
+
_request = @http_client.post _query_url, headers: _headers, parameters: body.to_json
|
70
|
+
|
71
|
+
# Call the on_before_request callback
|
72
|
+
@http_call_back.on_before_request(_request) if @http_call_back
|
73
|
+
|
74
|
+
# Invoke the API call and get the response
|
75
|
+
_response = @http_client.execute_as_string(_request)
|
76
|
+
|
77
|
+
# Wrap the request and response in an HttpContext object
|
78
|
+
_context = HttpContext.new(_request, _response)
|
79
|
+
|
80
|
+
# Call the on_after_response callback
|
81
|
+
@http_call_back.on_after_response(_context) if @http_call_back
|
82
|
+
|
83
|
+
# Global error handling using HTTP status codes.
|
84
|
+
validate_response(_context)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -1,52 +1,52 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module MoesifApi
|
4
|
-
class HealthController < BaseController
|
5
|
-
@@instance = HealthController.new
|
6
|
-
# Singleton instance of the controller class
|
7
|
-
def self.instance
|
8
|
-
@@instance
|
9
|
-
end
|
10
|
-
|
11
|
-
# Health Probe
|
12
|
-
# @return StatusModel response from the API call
|
13
|
-
def get_health_probe
|
14
|
-
# the base uri for api requests
|
15
|
-
_query_builder = Configuration.base_uri.dup
|
16
|
-
|
17
|
-
# prepare query string for API call
|
18
|
-
_query_builder << '/health/probe'
|
19
|
-
|
20
|
-
# validate and preprocess url
|
21
|
-
_query_url = APIHelper.clean_url _query_builder
|
22
|
-
|
23
|
-
# prepare headers
|
24
|
-
_headers = {
|
25
|
-
'accept' => 'application/json',
|
26
|
-
'X-Moesif-Application-Id' => Configuration.application_id
|
27
|
-
}
|
28
|
-
|
29
|
-
# Create the HttpRequest object for the call
|
30
|
-
_request = @http_client.get _query_url, headers: _headers
|
31
|
-
|
32
|
-
# Call the on_before_request callback
|
33
|
-
@http_call_back.on_before_request(_request) if @http_call_back
|
34
|
-
|
35
|
-
# Invoke the API call and get the response
|
36
|
-
_response = @http_client.execute_as_string(_request)
|
37
|
-
|
38
|
-
# Wrap the request and response in an HttpContext object
|
39
|
-
_context = HttpContext.new(_request, _response)
|
40
|
-
|
41
|
-
# Call the on_after_response callback
|
42
|
-
@http_call_back.on_after_response(_context) if @http_call_back
|
43
|
-
|
44
|
-
# Global error handling using HTTP status codes.
|
45
|
-
validate_response(_context)
|
46
|
-
|
47
|
-
# Return appropriate response type
|
48
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
49
|
-
return StatusModel.from_hash(decoded)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
1
|
+
|
2
|
+
|
3
|
+
module MoesifApi
|
4
|
+
class HealthController < BaseController
|
5
|
+
@@instance = HealthController.new
|
6
|
+
# Singleton instance of the controller class
|
7
|
+
def self.instance
|
8
|
+
@@instance
|
9
|
+
end
|
10
|
+
|
11
|
+
# Health Probe
|
12
|
+
# @return StatusModel response from the API call
|
13
|
+
def get_health_probe
|
14
|
+
# the base uri for api requests
|
15
|
+
_query_builder = Configuration.base_uri.dup
|
16
|
+
|
17
|
+
# prepare query string for API call
|
18
|
+
_query_builder << '/health/probe'
|
19
|
+
|
20
|
+
# validate and preprocess url
|
21
|
+
_query_url = APIHelper.clean_url _query_builder
|
22
|
+
|
23
|
+
# prepare headers
|
24
|
+
_headers = {
|
25
|
+
'accept' => 'application/json',
|
26
|
+
'X-Moesif-Application-Id' => Configuration.application_id
|
27
|
+
}
|
28
|
+
|
29
|
+
# Create the HttpRequest object for the call
|
30
|
+
_request = @http_client.get _query_url, headers: _headers
|
31
|
+
|
32
|
+
# Call the on_before_request callback
|
33
|
+
@http_call_back.on_before_request(_request) if @http_call_back
|
34
|
+
|
35
|
+
# Invoke the API call and get the response
|
36
|
+
_response = @http_client.execute_as_string(_request)
|
37
|
+
|
38
|
+
# Wrap the request and response in an HttpContext object
|
39
|
+
_context = HttpContext.new(_request, _response)
|
40
|
+
|
41
|
+
# Call the on_after_response callback
|
42
|
+
@http_call_back.on_after_response(_context) if @http_call_back
|
43
|
+
|
44
|
+
# Global error handling using HTTP status codes.
|
45
|
+
validate_response(_context)
|
46
|
+
|
47
|
+
# Return appropriate response type
|
48
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
49
|
+
return StatusModel.from_hash(decoded)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module MoesifApi
|
4
|
-
class APIException < StandardError
|
5
|
-
attr_reader :context, :response_code
|
6
|
-
|
7
|
-
# The constructor.
|
8
|
-
# @param [String] The reason for raising an exception
|
9
|
-
# @param [HttpContext] The HttpContext of the API call.
|
10
|
-
def initialize(reason, context)
|
11
|
-
super(reason)
|
12
|
-
@context = context
|
13
|
-
@response_code = context.response.status_code
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
1
|
+
|
2
|
+
|
3
|
+
module MoesifApi
|
4
|
+
class APIException < StandardError
|
5
|
+
attr_reader :context, :response_code
|
6
|
+
|
7
|
+
# The constructor.
|
8
|
+
# @param [String] The reason for raising an exception
|
9
|
+
# @param [HttpContext] The HttpContext of the API call.
|
10
|
+
def initialize(reason, context)
|
11
|
+
super(reason)
|
12
|
+
@context = context
|
13
|
+
@response_code = context.response.status_code
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|