trakerr_client 1.0.0r
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.
- data/.gitignore +5 -0
- data/README.md +148 -0
- data/generated/.gitignore +50 -0
- data/generated/.rspec +2 -0
- data/generated/.swagger-codegen-ignore +23 -0
- data/generated/LICENSE +201 -0
- data/generated/README.md +97 -0
- data/generated/docs/AppEvent.md +30 -0
- data/generated/docs/CustomData.md +9 -0
- data/generated/docs/CustomDoubleData.md +17 -0
- data/generated/docs/CustomStringData.md +17 -0
- data/generated/docs/Error.md +10 -0
- data/generated/docs/EventsApi.md +55 -0
- data/generated/docs/InnerStackTrace.md +10 -0
- data/generated/docs/StackTraceLine.md +10 -0
- data/generated/docs/StackTraceLines.md +7 -0
- data/generated/docs/Stacktrace.md +7 -0
- data/generated/git_push.sh +67 -0
- data/generated/lib/trakerr_client/api/events_api.rb +90 -0
- data/generated/lib/trakerr_client/api_client.rb +378 -0
- data/generated/lib/trakerr_client/api_error.rb +47 -0
- data/generated/lib/trakerr_client/configuration.rb +207 -0
- data/generated/lib/trakerr_client/models/app_event.rb +454 -0
- data/generated/lib/trakerr_client/models/custom_data.rb +208 -0
- data/generated/lib/trakerr_client/models/custom_double_data.rb +280 -0
- data/generated/lib/trakerr_client/models/custom_string_data.rb +280 -0
- data/generated/lib/trakerr_client/models/error.rb +217 -0
- data/generated/lib/trakerr_client/models/inner_stack_trace.rb +217 -0
- data/generated/lib/trakerr_client/models/stack_trace_line.rb +217 -0
- data/generated/lib/trakerr_client/models/stack_trace_lines.rb +190 -0
- data/generated/lib/trakerr_client/models/stacktrace.rb +190 -0
- data/generated/lib/trakerr_client/version.rb +26 -0
- data/generated/lib/trakerr_client.rb +60 -0
- data/generated/spec/api/events_api_spec.rb +58 -0
- data/generated/spec/api_client_spec.rb +237 -0
- data/generated/spec/configuration_spec.rb +53 -0
- data/generated/spec/models/app_event_spec.rb +167 -0
- data/generated/spec/models/custom_data_spec.rb +59 -0
- data/generated/spec/models/custom_double_data_spec.rb +107 -0
- data/generated/spec/models/custom_string_data_spec.rb +107 -0
- data/generated/spec/models/error_spec.rb +65 -0
- data/generated/spec/models/inner_stack_trace_spec.rb +65 -0
- data/generated/spec/models/stack_trace_line_spec.rb +65 -0
- data/generated/spec/models/stack_trace_lines_spec.rb +47 -0
- data/generated/spec/models/stacktrace_spec.rb +47 -0
- data/generated/spec/spec_helper.rb +122 -0
- data/generated/trakerr_client.gemspec +55 -0
- data/mkgem.sh +6 -0
- data/test_app.rb +40 -0
- data/trakerr/lib/event_trace_builder.rb +163 -0
- data/trakerr/lib/trakerr.rb +235 -0
- data/trakerr_client.gemspec +58 -0
- metadata +313 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
# Trakerr::EventsApi
|
2
|
+
|
3
|
+
All URIs are relative to *https://www.trakerr.io/api/v1*
|
4
|
+
|
5
|
+
Method | HTTP request | Description
|
6
|
+
------------- | ------------- | -------------
|
7
|
+
[**events_post**](EventsApi.md#events_post) | **POST** /events | Submit an application event or error to Trakerr
|
8
|
+
|
9
|
+
|
10
|
+
# **events_post**
|
11
|
+
> events_post(data)
|
12
|
+
|
13
|
+
Submit an application event or error to Trakerr
|
14
|
+
|
15
|
+
The events endpoint submits an application event or an application error / exception with an optional stacktrace field to Trakerr. ##### Sample POST request body: ``` { \"apiKey\": \"a9a2807a2e8fd4602adae9e8f819790a267213234083\", \"classification\": \"Error\", \"eventType\": \"System.Exception\", \"eventMessage\": \"This is a test exception.\", \"eventTime\": 1479477482291, \"eventStacktrace\": [ { \"type\": \"System.Exception\", \"message\": \"This is a test exception.\", \"traceLines\": [ { \"function\": \"Main\", \"line\": 19, \"file\": \"TrakerrSampleApp\\\\Program.cs\" } ] } ], \"contextAppVersion\": \"1.0\", \"contextEnvName\": \"development\", \"contextEnvHostname\": \"trakerr.io\", \"contextAppOS\": \"Win32NT Service Pack 1\", \"contextAppOSVersion\": \"6.1.7601.65536\" } ``` ##### Sample POST response body (200 OK): ``` { } ```
|
16
|
+
|
17
|
+
### Example
|
18
|
+
```ruby
|
19
|
+
# load the gem
|
20
|
+
require 'trakerr_client'
|
21
|
+
|
22
|
+
api_instance = Trakerr::EventsApi.new
|
23
|
+
|
24
|
+
data = Trakerr::AppEvent.new # AppEvent | Event to submit
|
25
|
+
|
26
|
+
|
27
|
+
begin
|
28
|
+
#Submit an application event or error to Trakerr
|
29
|
+
api_instance.events_post(data)
|
30
|
+
rescue Trakerr::ApiError => e
|
31
|
+
puts "Exception when calling EventsApi->events_post: #{e}"
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
### Parameters
|
36
|
+
|
37
|
+
Name | Type | Description | Notes
|
38
|
+
------------- | ------------- | ------------- | -------------
|
39
|
+
**data** | [**AppEvent**](AppEvent.md)| Event to submit |
|
40
|
+
|
41
|
+
### Return type
|
42
|
+
|
43
|
+
nil (empty response body)
|
44
|
+
|
45
|
+
### Authorization
|
46
|
+
|
47
|
+
No authorization required
|
48
|
+
|
49
|
+
### HTTP request headers
|
50
|
+
|
51
|
+
- **Content-Type**: Not defined
|
52
|
+
- **Accept**: application/json
|
53
|
+
|
54
|
+
|
55
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Trakerr::InnerStackTrace
|
2
|
+
|
3
|
+
## Properties
|
4
|
+
Name | Type | Description | Notes
|
5
|
+
------------ | ------------- | ------------- | -------------
|
6
|
+
**type** | **String** | | [optional]
|
7
|
+
**message** | **String** | | [optional]
|
8
|
+
**trace_lines** | [**StackTraceLines**](StackTraceLines.md) | | [optional]
|
9
|
+
|
10
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Trakerr::StackTraceLine
|
2
|
+
|
3
|
+
## Properties
|
4
|
+
Name | Type | Description | Notes
|
5
|
+
------------ | ------------- | ------------- | -------------
|
6
|
+
**function** | **String** | | [optional]
|
7
|
+
**line** | **Integer** | | [optional]
|
8
|
+
**file** | **String** | | [optional]
|
9
|
+
|
10
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
#
|
3
|
+
# Generated by: https://github.com/swagger-api/swagger-codegen.git
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
|
18
|
+
#
|
19
|
+
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
|
20
|
+
|
21
|
+
git_user_id=$1
|
22
|
+
git_repo_id=$2
|
23
|
+
release_note=$3
|
24
|
+
|
25
|
+
if [ "$git_user_id" = "" ]; then
|
26
|
+
git_user_id="GIT_USER_ID"
|
27
|
+
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
|
28
|
+
fi
|
29
|
+
|
30
|
+
if [ "$git_repo_id" = "" ]; then
|
31
|
+
git_repo_id="GIT_REPO_ID"
|
32
|
+
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
|
33
|
+
fi
|
34
|
+
|
35
|
+
if [ "$release_note" = "" ]; then
|
36
|
+
release_note="Minor update"
|
37
|
+
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
|
38
|
+
fi
|
39
|
+
|
40
|
+
# Initialize the local directory as a Git repository
|
41
|
+
git init
|
42
|
+
|
43
|
+
# Adds the files in the local repository and stages them for commit.
|
44
|
+
git add .
|
45
|
+
|
46
|
+
# Commits the tracked changes and prepares them to be pushed to a remote repository.
|
47
|
+
git commit -m "$release_note"
|
48
|
+
|
49
|
+
# Sets the new remote
|
50
|
+
git_remote=`git remote`
|
51
|
+
if [ "$git_remote" = "" ]; then # git remote not defined
|
52
|
+
|
53
|
+
if [ "$GIT_TOKEN" = "" ]; then
|
54
|
+
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment."
|
55
|
+
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
|
56
|
+
else
|
57
|
+
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
|
58
|
+
fi
|
59
|
+
|
60
|
+
fi
|
61
|
+
|
62
|
+
git pull origin master
|
63
|
+
|
64
|
+
# Pushes (Forces) the changes in the local repository up to the remote repository
|
65
|
+
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
|
66
|
+
git push origin master 2>&1 | grep -v 'To https'
|
67
|
+
|
@@ -0,0 +1,90 @@
|
|
1
|
+
=begin
|
2
|
+
#Trakerr API
|
3
|
+
|
4
|
+
#Get your application events and errors to Trakerr via the *Trakerr API*.
|
5
|
+
|
6
|
+
OpenAPI spec version: 1.0.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
|
10
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
+
you may not use this file except in compliance with the License.
|
12
|
+
You may obtain a copy of the License at
|
13
|
+
|
14
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
15
|
+
|
16
|
+
Unless required by applicable law or agreed to in writing, software
|
17
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
+
See the License for the specific language governing permissions and
|
20
|
+
limitations under the License.
|
21
|
+
|
22
|
+
=end
|
23
|
+
|
24
|
+
require "uri"
|
25
|
+
|
26
|
+
module Trakerr
|
27
|
+
class EventsApi
|
28
|
+
attr_accessor :api_client
|
29
|
+
|
30
|
+
def initialize(api_client = ApiClient.default)
|
31
|
+
@api_client = api_client
|
32
|
+
end
|
33
|
+
|
34
|
+
# Submit an application event or error to Trakerr
|
35
|
+
# The events endpoint submits an application event or an application error / exception with an optional stacktrace field to Trakerr. ##### Sample POST request body: ``` { \"apiKey\": \"a9a2807a2e8fd4602adae9e8f819790a267213234083\", \"classification\": \"Error\", \"eventType\": \"System.Exception\", \"eventMessage\": \"This is a test exception.\", \"eventTime\": 1479477482291, \"eventStacktrace\": [ { \"type\": \"System.Exception\", \"message\": \"This is a test exception.\", \"traceLines\": [ { \"function\": \"Main\", \"line\": 19, \"file\": \"TrakerrSampleApp\\\\Program.cs\" } ] } ], \"contextAppVersion\": \"1.0\", \"contextEnvName\": \"development\", \"contextEnvHostname\": \"trakerr.io\", \"contextAppOS\": \"Win32NT Service Pack 1\", \"contextAppOSVersion\": \"6.1.7601.65536\" } ``` ##### Sample POST response body (200 OK): ``` { } ```
|
36
|
+
# @param data Event to submit
|
37
|
+
# @param [Hash] opts the optional parameters
|
38
|
+
# @return [nil]
|
39
|
+
def events_post(data, opts = {})
|
40
|
+
events_post_with_http_info(data, opts)
|
41
|
+
return nil
|
42
|
+
end
|
43
|
+
|
44
|
+
# Submit an application event or error to Trakerr
|
45
|
+
# The events endpoint submits an application event or an application error / exception with an optional stacktrace field to Trakerr. ##### Sample POST request body: ``` { \"apiKey\": \"a9a2807a2e8fd4602adae9e8f819790a267213234083\", \"classification\": \"Error\", \"eventType\": \"System.Exception\", \"eventMessage\": \"This is a test exception.\", \"eventTime\": 1479477482291, \"eventStacktrace\": [ { \"type\": \"System.Exception\", \"message\": \"This is a test exception.\", \"traceLines\": [ { \"function\": \"Main\", \"line\": 19, \"file\": \"TrakerrSampleApp\\\\Program.cs\" } ] } ], \"contextAppVersion\": \"1.0\", \"contextEnvName\": \"development\", \"contextEnvHostname\": \"trakerr.io\", \"contextAppOS\": \"Win32NT Service Pack 1\", \"contextAppOSVersion\": \"6.1.7601.65536\" } ``` ##### Sample POST response body (200 OK): ``` { } ```
|
46
|
+
# @param data Event to submit
|
47
|
+
# @param [Hash] opts the optional parameters
|
48
|
+
# @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers
|
49
|
+
def events_post_with_http_info(data, opts = {})
|
50
|
+
if @api_client.config.debugging
|
51
|
+
@api_client.config.logger.debug "Calling API: EventsApi.events_post ..."
|
52
|
+
end
|
53
|
+
# verify the required parameter 'data' is set
|
54
|
+
fail ArgumentError, "Missing the required parameter 'data' when calling EventsApi.events_post" if data.nil?
|
55
|
+
# resource path
|
56
|
+
local_var_path = "/events".sub('{format}','json')
|
57
|
+
|
58
|
+
# query parameters
|
59
|
+
query_params = {}
|
60
|
+
|
61
|
+
# header parameters
|
62
|
+
header_params = {}
|
63
|
+
|
64
|
+
# HTTP header 'Accept' (if needed)
|
65
|
+
local_header_accept = ['application/json']
|
66
|
+
local_header_accept_result = @api_client.select_header_accept(local_header_accept) and header_params['Accept'] = local_header_accept_result
|
67
|
+
|
68
|
+
# HTTP header 'Content-Type'
|
69
|
+
local_header_content_type = []
|
70
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type)
|
71
|
+
|
72
|
+
# form parameters
|
73
|
+
form_params = {}
|
74
|
+
|
75
|
+
# http body (model)
|
76
|
+
post_body = @api_client.object_to_http_body(data)
|
77
|
+
auth_names = []
|
78
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path,
|
79
|
+
:header_params => header_params,
|
80
|
+
:query_params => query_params,
|
81
|
+
:form_params => form_params,
|
82
|
+
:body => post_body,
|
83
|
+
:auth_names => auth_names)
|
84
|
+
if @api_client.config.debugging
|
85
|
+
@api_client.config.logger.debug "API called: EventsApi#events_post\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
86
|
+
end
|
87
|
+
return data, status_code, headers
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,378 @@
|
|
1
|
+
=begin
|
2
|
+
#Trakerr API
|
3
|
+
|
4
|
+
#Get your application events and errors to Trakerr via the *Trakerr API*.
|
5
|
+
|
6
|
+
OpenAPI spec version: 1.0.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
|
10
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
+
you may not use this file except in compliance with the License.
|
12
|
+
You may obtain a copy of the License at
|
13
|
+
|
14
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
15
|
+
|
16
|
+
Unless required by applicable law or agreed to in writing, software
|
17
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
+
See the License for the specific language governing permissions and
|
20
|
+
limitations under the License.
|
21
|
+
|
22
|
+
=end
|
23
|
+
|
24
|
+
require 'date'
|
25
|
+
require 'json'
|
26
|
+
require 'logger'
|
27
|
+
require 'tempfile'
|
28
|
+
require 'typhoeus'
|
29
|
+
require 'uri'
|
30
|
+
|
31
|
+
module Trakerr
|
32
|
+
class ApiClient
|
33
|
+
# The Configuration object holding settings to be used in the API client.
|
34
|
+
attr_accessor :config
|
35
|
+
|
36
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
37
|
+
#
|
38
|
+
# @return [Hash]
|
39
|
+
attr_accessor :default_headers
|
40
|
+
|
41
|
+
# Initializes the ApiClient
|
42
|
+
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
43
|
+
def initialize(config = Configuration.default)
|
44
|
+
@config = config
|
45
|
+
@user_agent = "Swagger-Codegen/#{VERSION}/ruby"
|
46
|
+
@default_headers = {
|
47
|
+
'Content-Type' => "application/json",
|
48
|
+
'User-Agent' => @user_agent
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.default
|
53
|
+
@@default ||= ApiClient.new
|
54
|
+
end
|
55
|
+
|
56
|
+
# Call an API with given options.
|
57
|
+
#
|
58
|
+
# @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
|
59
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
60
|
+
def call_api(http_method, path, opts = {})
|
61
|
+
request = build_request(http_method, path, opts)
|
62
|
+
response = request.run
|
63
|
+
|
64
|
+
if @config.debugging
|
65
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
66
|
+
end
|
67
|
+
|
68
|
+
unless response.success?
|
69
|
+
fail ApiError.new(:code => response.code,
|
70
|
+
:response_headers => response.headers,
|
71
|
+
:response_body => response.body),
|
72
|
+
response.status_message
|
73
|
+
end
|
74
|
+
|
75
|
+
if opts[:return_type]
|
76
|
+
data = deserialize(response, opts[:return_type])
|
77
|
+
else
|
78
|
+
data = nil
|
79
|
+
end
|
80
|
+
return data, response.code, response.headers
|
81
|
+
end
|
82
|
+
|
83
|
+
# Builds the HTTP request
|
84
|
+
#
|
85
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
86
|
+
# @param [String] path URL path (e.g. /account/new)
|
87
|
+
# @option opts [Hash] :header_params Header parameters
|
88
|
+
# @option opts [Hash] :query_params Query parameters
|
89
|
+
# @option opts [Hash] :form_params Query parameters
|
90
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
91
|
+
# @return [Typhoeus::Request] A Typhoeus Request
|
92
|
+
def build_request(http_method, path, opts = {})
|
93
|
+
url = build_request_url(path)
|
94
|
+
http_method = http_method.to_sym.downcase
|
95
|
+
|
96
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
97
|
+
query_params = opts[:query_params] || {}
|
98
|
+
form_params = opts[:form_params] || {}
|
99
|
+
|
100
|
+
|
101
|
+
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
102
|
+
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
103
|
+
|
104
|
+
req_opts = {
|
105
|
+
:method => http_method,
|
106
|
+
:headers => header_params,
|
107
|
+
:params => query_params,
|
108
|
+
:params_encoding => @config.params_encoding,
|
109
|
+
:timeout => @config.timeout,
|
110
|
+
:ssl_verifypeer => @config.verify_ssl,
|
111
|
+
:ssl_verifyhost => _verify_ssl_host,
|
112
|
+
:sslcert => @config.cert_file,
|
113
|
+
:sslkey => @config.key_file,
|
114
|
+
:verbose => @config.debugging
|
115
|
+
}
|
116
|
+
|
117
|
+
# set custom cert, if provided
|
118
|
+
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
119
|
+
|
120
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
121
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
122
|
+
req_opts.update :body => req_body
|
123
|
+
if @config.debugging
|
124
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
Typhoeus::Request.new(url, req_opts)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Check if the given MIME is a JSON MIME.
|
132
|
+
# JSON MIME examples:
|
133
|
+
# application/json
|
134
|
+
# application/json; charset=UTF8
|
135
|
+
# APPLICATION/JSON
|
136
|
+
# @param [String] mime MIME
|
137
|
+
# @return [Boolean] True if the MIME is applicaton/json
|
138
|
+
def json_mime?(mime)
|
139
|
+
!(mime =~ /\Aapplication\/json(;.*)?\z/i).nil?
|
140
|
+
end
|
141
|
+
|
142
|
+
# Deserialize the response to the given return type.
|
143
|
+
#
|
144
|
+
# @param [Response] response HTTP response
|
145
|
+
# @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
|
146
|
+
def deserialize(response, return_type)
|
147
|
+
body = response.body
|
148
|
+
return nil if body.nil? || body.empty?
|
149
|
+
|
150
|
+
# return response body directly for String return type
|
151
|
+
return body if return_type == 'String'
|
152
|
+
|
153
|
+
# handle file downloading - save response body into a tmp file and return the File instance
|
154
|
+
return download_file(response) if return_type == 'File'
|
155
|
+
|
156
|
+
# ensuring a default content type
|
157
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
158
|
+
|
159
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
160
|
+
|
161
|
+
begin
|
162
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
163
|
+
rescue JSON::ParserError => e
|
164
|
+
if %w(String Date DateTime).include?(return_type)
|
165
|
+
data = body
|
166
|
+
else
|
167
|
+
raise e
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
convert_to_type data, return_type
|
172
|
+
end
|
173
|
+
|
174
|
+
# Convert data to the given return type.
|
175
|
+
# @param [Object] data Data to be converted
|
176
|
+
# @param [String] return_type Return type
|
177
|
+
# @return [Mixed] Data in a particular type
|
178
|
+
def convert_to_type(data, return_type)
|
179
|
+
return nil if data.nil?
|
180
|
+
case return_type
|
181
|
+
when 'String'
|
182
|
+
data.to_s
|
183
|
+
when 'Integer'
|
184
|
+
data.to_i
|
185
|
+
when 'Float'
|
186
|
+
data.to_f
|
187
|
+
when 'BOOLEAN'
|
188
|
+
data == true
|
189
|
+
when 'DateTime'
|
190
|
+
# parse date time (expecting ISO 8601 format)
|
191
|
+
DateTime.parse data
|
192
|
+
when 'Date'
|
193
|
+
# parse date time (expecting ISO 8601 format)
|
194
|
+
Date.parse data
|
195
|
+
when 'Object'
|
196
|
+
# generic object (usually a Hash), return directly
|
197
|
+
data
|
198
|
+
when /\AArray<(.+)>\z/
|
199
|
+
# e.g. Array<Pet>
|
200
|
+
sub_type = $1
|
201
|
+
data.map {|item| convert_to_type(item, sub_type) }
|
202
|
+
when /\AHash\<String, (.+)\>\z/
|
203
|
+
# e.g. Hash<String, Integer>
|
204
|
+
sub_type = $1
|
205
|
+
{}.tap do |hash|
|
206
|
+
data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
|
207
|
+
end
|
208
|
+
else
|
209
|
+
# models, e.g. Pet
|
210
|
+
Trakerr.const_get(return_type).new.tap do |model|
|
211
|
+
model.build_from_hash data
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
217
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
218
|
+
#
|
219
|
+
# @see Configuration#temp_folder_path
|
220
|
+
# @return [Tempfile] the file downloaded
|
221
|
+
def download_file(response)
|
222
|
+
content_disposition = response.headers['Content-Disposition']
|
223
|
+
if content_disposition and content_disposition =~ /filename=/i
|
224
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
225
|
+
prefix = sanitize_filename(filename)
|
226
|
+
else
|
227
|
+
prefix = 'download-'
|
228
|
+
end
|
229
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
230
|
+
|
231
|
+
tempfile = nil
|
232
|
+
encoding = response.body.encoding
|
233
|
+
Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file|
|
234
|
+
file.write(response.body)
|
235
|
+
tempfile = file
|
236
|
+
end
|
237
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
238
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
239
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
240
|
+
"explicitly with `tempfile.delete`"
|
241
|
+
tempfile
|
242
|
+
end
|
243
|
+
|
244
|
+
# Sanitize filename by removing path.
|
245
|
+
# e.g. ../../sun.gif becomes sun.gif
|
246
|
+
#
|
247
|
+
# @param [String] filename the filename to be sanitized
|
248
|
+
# @return [String] the sanitized filename
|
249
|
+
def sanitize_filename(filename)
|
250
|
+
filename.gsub(/.*[\/\\]/, '')
|
251
|
+
end
|
252
|
+
|
253
|
+
def build_request_url(path)
|
254
|
+
# Add leading and trailing slashes to path
|
255
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
256
|
+
URI.encode(@config.base_url + path)
|
257
|
+
end
|
258
|
+
|
259
|
+
# Builds the HTTP request body
|
260
|
+
#
|
261
|
+
# @param [Hash] header_params Header parameters
|
262
|
+
# @param [Hash] form_params Query parameters
|
263
|
+
# @param [Object] body HTTP body (JSON/XML)
|
264
|
+
# @return [String] HTTP body data in the form of string
|
265
|
+
def build_request_body(header_params, form_params, body)
|
266
|
+
# http form
|
267
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
268
|
+
header_params['Content-Type'] == 'multipart/form-data'
|
269
|
+
data = {}
|
270
|
+
form_params.each do |key, value|
|
271
|
+
case value
|
272
|
+
when File, Array, nil
|
273
|
+
# let typhoeus handle File, Array and nil parameters
|
274
|
+
data[key] = value
|
275
|
+
else
|
276
|
+
data[key] = value.to_s
|
277
|
+
end
|
278
|
+
end
|
279
|
+
elsif body
|
280
|
+
data = body.is_a?(String) ? body : body.to_json
|
281
|
+
else
|
282
|
+
data = nil
|
283
|
+
end
|
284
|
+
data
|
285
|
+
end
|
286
|
+
|
287
|
+
# Update hearder and query params based on authentication settings.
|
288
|
+
#
|
289
|
+
# @param [Hash] header_params Header parameters
|
290
|
+
# @param [Hash] form_params Query parameters
|
291
|
+
# @param [String] auth_names Authentication scheme name
|
292
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
293
|
+
Array(auth_names).each do |auth_name|
|
294
|
+
auth_setting = @config.auth_settings[auth_name]
|
295
|
+
next unless auth_setting
|
296
|
+
case auth_setting[:in]
|
297
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
298
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
299
|
+
else fail ArgumentError, 'Authentication token must be in `query` of `header`'
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
# Sets user agent in HTTP header
|
305
|
+
#
|
306
|
+
# @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
|
307
|
+
def user_agent=(user_agent)
|
308
|
+
@user_agent = user_agent
|
309
|
+
@default_headers['User-Agent'] = @user_agent
|
310
|
+
end
|
311
|
+
|
312
|
+
# Return Accept header based on an array of accepts provided.
|
313
|
+
# @param [Array] accepts array for Accept
|
314
|
+
# @return [String] the Accept header (e.g. application/json)
|
315
|
+
def select_header_accept(accepts)
|
316
|
+
return nil if accepts.nil? || accepts.empty?
|
317
|
+
# use JSON when present, otherwise use all of the provided
|
318
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
319
|
+
return json_accept || accepts.join(',')
|
320
|
+
end
|
321
|
+
|
322
|
+
# Return Content-Type header based on an array of content types provided.
|
323
|
+
# @param [Array] content_types array for Content-Type
|
324
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
325
|
+
def select_header_content_type(content_types)
|
326
|
+
# use application/json by default
|
327
|
+
return 'application/json' if content_types.nil? || content_types.empty?
|
328
|
+
# use JSON when present, otherwise use the first one
|
329
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
330
|
+
return json_content_type || content_types.first
|
331
|
+
end
|
332
|
+
|
333
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
334
|
+
# @param [Object] model object to be converted into JSON string
|
335
|
+
# @return [String] JSON string representation of the object
|
336
|
+
def object_to_http_body(model)
|
337
|
+
return model if model.nil? || model.is_a?(String)
|
338
|
+
local_body = nil
|
339
|
+
if model.is_a?(Array)
|
340
|
+
local_body = model.map{|m| object_to_hash(m) }
|
341
|
+
else
|
342
|
+
local_body = object_to_hash(model)
|
343
|
+
end
|
344
|
+
local_body.to_json
|
345
|
+
end
|
346
|
+
|
347
|
+
# Convert object(non-array) to hash.
|
348
|
+
# @param [Object] obj object to be converted into JSON string
|
349
|
+
# @return [String] JSON string representation of the object
|
350
|
+
def object_to_hash(obj)
|
351
|
+
if obj.respond_to?(:to_hash)
|
352
|
+
obj.to_hash
|
353
|
+
else
|
354
|
+
obj
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
# Build parameter value according to the given collection format.
|
359
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
360
|
+
def build_collection_param(param, collection_format)
|
361
|
+
case collection_format
|
362
|
+
when :csv
|
363
|
+
param.join(',')
|
364
|
+
when :ssv
|
365
|
+
param.join(' ')
|
366
|
+
when :tsv
|
367
|
+
param.join("\t")
|
368
|
+
when :pipes
|
369
|
+
param.join('|')
|
370
|
+
when :multi
|
371
|
+
# return the array directly as typhoeus will handle it as expected
|
372
|
+
param
|
373
|
+
else
|
374
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
375
|
+
end
|
376
|
+
end
|
377
|
+
end
|
378
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
=begin
|
2
|
+
#Trakerr API
|
3
|
+
|
4
|
+
#Get your application events and errors to Trakerr via the *Trakerr API*.
|
5
|
+
|
6
|
+
OpenAPI spec version: 1.0.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
|
10
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
+
you may not use this file except in compliance with the License.
|
12
|
+
You may obtain a copy of the License at
|
13
|
+
|
14
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
15
|
+
|
16
|
+
Unless required by applicable law or agreed to in writing, software
|
17
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
+
See the License for the specific language governing permissions and
|
20
|
+
limitations under the License.
|
21
|
+
|
22
|
+
=end
|
23
|
+
|
24
|
+
module Trakerr
|
25
|
+
class ApiError < StandardError
|
26
|
+
attr_reader :code, :response_headers, :response_body
|
27
|
+
|
28
|
+
# Usage examples:
|
29
|
+
# ApiError.new
|
30
|
+
# ApiError.new("message")
|
31
|
+
# ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
|
32
|
+
# ApiError.new(:code => 404, :message => "Not Found")
|
33
|
+
def initialize(arg = nil)
|
34
|
+
if arg.is_a? Hash
|
35
|
+
arg.each do |k, v|
|
36
|
+
if k.to_s == 'message'
|
37
|
+
super v
|
38
|
+
else
|
39
|
+
instance_variable_set "@#{k}", v
|
40
|
+
end
|
41
|
+
end
|
42
|
+
else
|
43
|
+
super arg
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|