ms_rest 0.1.1
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/.travis.yml +3 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +48 -0
- data/Rakefile +5 -0
- data/lib/ms_rest.rb +26 -0
- data/lib/ms_rest/credentials/basic_authentication_credentials.rb +62 -0
- data/lib/ms_rest/credentials/service_client_credentials.rb +22 -0
- data/lib/ms_rest/credentials/string_token_provider.rb +41 -0
- data/lib/ms_rest/credentials/token_credentials.rb +61 -0
- data/lib/ms_rest/credentials/token_provider.rb +19 -0
- data/lib/ms_rest/deserialization_error.rb +37 -0
- data/lib/ms_rest/http_operation_error.rb +54 -0
- data/lib/ms_rest/http_operation_response.rb +32 -0
- data/lib/ms_rest/rest_error.rb +11 -0
- data/lib/ms_rest/retry_policy_middleware.rb +44 -0
- data/lib/ms_rest/serialization.rb +22 -0
- data/lib/ms_rest/service_client.rb +26 -0
- data/lib/ms_rest/validation_error.rb +11 -0
- data/lib/ms_rest/version.rb +7 -0
- data/ms_rest.gemspec +35 -0
- metadata +169 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 66e52ea868e63c69e8ad869863f46e007171950a
|
4
|
+
data.tar.gz: b46f282e00f8d3465c4d689d46d3ca630faac570
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6442074cb9bbd55ee4871f75eef3c5df08c8dce58f5633b120c7dcc99cb0a1aebd66e9c4e1f918cb090815d3aa1b4a76cb9121c0ec277221de6c0918723ed98a
|
7
|
+
data.tar.gz: acee51f51cc50f7b269fed59cc520288bcd6d358c180c5f28b2dd3d9f5133d9a00460a5c4de21da479a32898906ce68eca359927b997dcb2388d02cd78cba922
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
source 'https://rubygems.org'
|
6
|
+
|
7
|
+
# Specify your gem's dependencies in ms_rest.gemspec
|
8
|
+
gemspec
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem 'rspec'
|
12
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Microsoft Corporation
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Intro
|
2
|
+
|
3
|
+
MsRest is a library which supports the clients (SDKs) generated with Autorest tool. It contains core logic and helper classes for error handling and authentication. Usually it is not supposed to be used as a standalone gem but only as a dependency for generated client gems.
|
4
|
+
|
5
|
+
# Supported Ruby Versions
|
6
|
+
|
7
|
+
* Ruby 1.9.3
|
8
|
+
* Ruby 2.0
|
9
|
+
* Ruby 2.1
|
10
|
+
* Ruby 2.2
|
11
|
+
|
12
|
+
Note: x64 Ruby for Windows is known to have some compatibility issues.
|
13
|
+
|
14
|
+
# Installation
|
15
|
+
|
16
|
+
install the appropriate gem:
|
17
|
+
|
18
|
+
```
|
19
|
+
gem install ms_rest
|
20
|
+
```
|
21
|
+
|
22
|
+
and reference it in your code:
|
23
|
+
|
24
|
+
```Ruby
|
25
|
+
require 'ms_rest'
|
26
|
+
```
|
27
|
+
|
28
|
+
# Running tests
|
29
|
+
|
30
|
+
MsRest has only unit tests which doesn't require any preparation, just run 'rspec' command from the gem directory.
|
31
|
+
|
32
|
+
# Contribution
|
33
|
+
|
34
|
+
To start working on the gem the only additional dev dependecy is required - rspec. After you've added a new feature and all specs pass - you're good to go with PR. But before starting any bug/feature - please make sure you've thoroughly discussed it with repository maintainers. This gem already powers a few SDKs and backward compatibility should taken in account.
|
35
|
+
|
36
|
+
# Adding gem to you generated SDK
|
37
|
+
|
38
|
+
Reference it in the gemfile and also add this line to your client's gemspec file:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
spec.add_runtime_dependency 'ms_rest', '~> 0.1.0'
|
42
|
+
```
|
43
|
+
|
44
|
+
Don't forget to correct the version.
|
45
|
+
|
46
|
+
# Provide feedback
|
47
|
+
|
48
|
+
Send email to the azsdkteam@microsoft.com or file new issue in this repository.
|
data/Rakefile
ADDED
data/lib/ms_rest.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
require 'base64'
|
6
|
+
require 'openssl'
|
7
|
+
require 'faraday'
|
8
|
+
require 'timeliness'
|
9
|
+
require 'ms_rest/version'
|
10
|
+
|
11
|
+
require 'ms_rest/credentials/token_provider'
|
12
|
+
require 'ms_rest/credentials/string_token_provider'
|
13
|
+
require 'ms_rest/credentials/service_client_credentials'
|
14
|
+
require 'ms_rest/credentials/basic_authentication_credentials'
|
15
|
+
require 'ms_rest/credentials/token_credentials'
|
16
|
+
|
17
|
+
require 'ms_rest/rest_error.rb'
|
18
|
+
require 'ms_rest/deserialization_error.rb'
|
19
|
+
require 'ms_rest/validation_error.rb'
|
20
|
+
require 'ms_rest/serialization.rb'
|
21
|
+
require 'ms_rest/http_operation_response'
|
22
|
+
require 'ms_rest/http_operation_error'
|
23
|
+
require 'ms_rest/retry_policy_middleware'
|
24
|
+
require 'ms_rest/service_client'
|
25
|
+
|
26
|
+
module MsRest; end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRest
|
6
|
+
#
|
7
|
+
# Class which keeps functionality and data for performing HTTP basic authentication.
|
8
|
+
|
9
|
+
#
|
10
|
+
class BasicAuthenticationCredentials < ServiceClientCredentials
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
DEFAULT_SCHEME = 'Basic'
|
15
|
+
|
16
|
+
# @return [String] the scheme for composing credentials.
|
17
|
+
attr_accessor :scheme
|
18
|
+
|
19
|
+
# @return [String] the username for authentication.
|
20
|
+
attr_accessor :user_name
|
21
|
+
|
22
|
+
# @return [String] password for authentication.
|
23
|
+
attr_accessor :password
|
24
|
+
|
25
|
+
public
|
26
|
+
|
27
|
+
#
|
28
|
+
# Creates and initialize new instance of the BasicAuthenticationCredentials class.
|
29
|
+
# @param user_name [String] the username for authentication.
|
30
|
+
# @param password [String] the password for authentication.
|
31
|
+
# @param scheme = DEFAULT_SCHEME [String] the scheme for composing credentials.
|
32
|
+
def initialize(user_name, password, scheme = DEFAULT_SCHEME)
|
33
|
+
fail ArgumentError, 'user_name cannot be nil' if user_name.nil?
|
34
|
+
fail ArgumentError, 'password cannot be nil' if password.nil?
|
35
|
+
fail ArgumentError, 'scheme cannot be nil' if scheme.nil?
|
36
|
+
|
37
|
+
@user_name = user_name
|
38
|
+
@password = password
|
39
|
+
@scheme = scheme
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Attaches basic authentication header to the given HTTP request.
|
44
|
+
# @param request [Net::HTTPRequest] the request authentication header needs to be attached to.
|
45
|
+
#
|
46
|
+
# @return [Net::HTTPRequest] request with attached authentication header.
|
47
|
+
def sign_request(request)
|
48
|
+
super(request)
|
49
|
+
encodeCredentials = Base64.strict_encode64("#{user_name}:#{password}")
|
50
|
+
credentials = "#{scheme} #{encodeCredentials}"
|
51
|
+
|
52
|
+
if (request.respond_to?(:request_headers))
|
53
|
+
request.request_headers[AUTHORIZATION] = credentials
|
54
|
+
elsif request.respond_to?(:headers)
|
55
|
+
request.headers[AUTHORIZATION] = credentials
|
56
|
+
else
|
57
|
+
fail ArgumentError, 'Incorrect request object was provided'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRest
|
6
|
+
#
|
7
|
+
# Class that serves as a base for all authentications classes.
|
8
|
+
#
|
9
|
+
class ServiceClientCredentials
|
10
|
+
|
11
|
+
AUTHORIZATION = 'authorization'
|
12
|
+
|
13
|
+
#
|
14
|
+
# Base method for performing authentication of HTTP requests.
|
15
|
+
# @param request [Net::HTTPRequest] HTTP request to authenticate
|
16
|
+
#
|
17
|
+
# @return [Net::HTTPRequest] authenticated HTTP request
|
18
|
+
def sign_request(request)
|
19
|
+
fail ArgumentError, 'request is nil.' if request.nil?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRest
|
6
|
+
#
|
7
|
+
# Class that provides access to authentication token.
|
8
|
+
#
|
9
|
+
class StringTokenProvider < TokenProvider
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
# @return [String] the access token.
|
14
|
+
attr_accessor :token
|
15
|
+
|
16
|
+
# @return [String] the token type.
|
17
|
+
attr_accessor :token_type
|
18
|
+
|
19
|
+
public
|
20
|
+
|
21
|
+
#
|
22
|
+
# Creates and initalizes a new instance of StringTokenProvider class.
|
23
|
+
|
24
|
+
# @param token [String] the access token.
|
25
|
+
# @param token_type [String] the token type.
|
26
|
+
#
|
27
|
+
def initialize(token, token_type = TokenCredentials::DEFAULT_SCHEME)
|
28
|
+
@token = token
|
29
|
+
@token_type = token_type
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Returns the string value which needs to be attached
|
34
|
+
# to HTTP request header in order to be authorized.
|
35
|
+
#
|
36
|
+
# @return [String] authentication headers.
|
37
|
+
def get_authentication_header
|
38
|
+
"#{token_type} #{token}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRest
|
6
|
+
#
|
7
|
+
# Class which keeps functionality and date for performing OAuth (token based) authentication.
|
8
|
+
#
|
9
|
+
class TokenCredentials < ServiceClientCredentials
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
DEFAULT_SCHEME = 'Bearer'
|
14
|
+
|
15
|
+
# @return [String] the scheme for arranging token in the HTTP header.
|
16
|
+
attr_accessor :token_provider
|
17
|
+
|
18
|
+
public
|
19
|
+
|
20
|
+
#
|
21
|
+
# Creates and initialize new instance of the TokenCredentials class.
|
22
|
+
# @param token_provider [TokenProvider] the token provider.
|
23
|
+
# @param token [String] the token.
|
24
|
+
def initialize(*args)
|
25
|
+
if (args.size == 1)
|
26
|
+
if args[0].respond_to? :get_authentication_header
|
27
|
+
@token_provider = args[0]
|
28
|
+
elsif args[0].is_a? String
|
29
|
+
@token_provider = StringTokenProvider.new args[0], DEFAULT_SCHEME
|
30
|
+
else
|
31
|
+
fail ArgumentError, 'Invalid argument was passed, is can be either TokenProvider or token'
|
32
|
+
end
|
33
|
+
elsif (args.size == 2)
|
34
|
+
token = args[0]
|
35
|
+
token_type = args[1]
|
36
|
+
@token_provider = StringTokenProvider.new token, token_type
|
37
|
+
else
|
38
|
+
fail ArgumentError, 'Invalid number of parameters was passed to TokenCredentials constructor, valid number is 1 or 2'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Attaches OAuth authentication header to the given HTTP request.
|
44
|
+
# @param request [Net::HTTPRequest] the request authentication header needs to be attached to.
|
45
|
+
#
|
46
|
+
# @return [Net::HTTPRequest] request with attached authentication header
|
47
|
+
def sign_request(request)
|
48
|
+
super(request)
|
49
|
+
header = @token_provider.get_authentication_header
|
50
|
+
|
51
|
+
if (request.respond_to?(:request_headers))
|
52
|
+
request.request_headers[AUTHORIZATION] = header
|
53
|
+
elsif request.respond_to?(:headers)
|
54
|
+
request.headers[AUTHORIZATION] = header
|
55
|
+
else
|
56
|
+
fail ArgumentError, 'Incorrect request object was provided'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRest
|
6
|
+
#
|
7
|
+
# Class that provides access to authentication token.
|
8
|
+
#
|
9
|
+
class TokenProvider
|
10
|
+
|
11
|
+
#
|
12
|
+
# Returns the string value which needs to be attached
|
13
|
+
# to HTTP request header in order to be authorized.
|
14
|
+
#
|
15
|
+
# @return [String] authentication headers.
|
16
|
+
def get_authentication_header
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRest
|
6
|
+
#
|
7
|
+
# Class which represents an error happening during deserialization of server response.
|
8
|
+
#
|
9
|
+
class DeserializationError < RestError
|
10
|
+
|
11
|
+
# @return [String] the human readable description of error.
|
12
|
+
attr_accessor :message
|
13
|
+
|
14
|
+
# @return [String] the inner exception message.
|
15
|
+
attr_accessor :exception_message
|
16
|
+
|
17
|
+
# @return [String] the inner exception stacktrace.
|
18
|
+
attr_accessor :exception_stacktrace
|
19
|
+
|
20
|
+
# @return [String] server response which client was unable to parse.
|
21
|
+
attr_accessor :response_body
|
22
|
+
|
23
|
+
#
|
24
|
+
# Creates and initialize new instance of the DeserializationError class.
|
25
|
+
# @param [String] message message the human readable description of error.
|
26
|
+
# @param [String] exception_message the inner exception stacktrace.
|
27
|
+
# @param [String] exception_stacktrace the inner exception stacktrace.
|
28
|
+
# @param [String] response_body server response which client was unable to parse.
|
29
|
+
def initialize(message, exception_message, exception_stacktrace, response_body)
|
30
|
+
@message = message
|
31
|
+
@exception_message = exception_message
|
32
|
+
@exception_stacktrace = exception_stacktrace
|
33
|
+
@response_body = response_body
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRest
|
6
|
+
#
|
7
|
+
# Class which represents an error meaning that either HTTP request or HTTP response was invalid.
|
8
|
+
#
|
9
|
+
class HttpOperationError < RestError
|
10
|
+
|
11
|
+
# @return [Net::HTTPRequest] the HTTP request object.
|
12
|
+
attr_accessor :request
|
13
|
+
|
14
|
+
# @return [Net::HTTPResponse] the HTTP response object.
|
15
|
+
attr_accessor :response
|
16
|
+
|
17
|
+
# @return [String] the HTTP response body.
|
18
|
+
attr_accessor :body
|
19
|
+
|
20
|
+
#
|
21
|
+
# Creates and initialize new instance of the HttpOperationException class.
|
22
|
+
# @param [Net::HTTPRequest] request the HTTP request object.
|
23
|
+
# @param [Net::HTTPResponse] response the HTTP response object.
|
24
|
+
# @param [String] body the HTTP response body.
|
25
|
+
# @param [String] error message.
|
26
|
+
def initialize(*args)
|
27
|
+
if args.size == 1
|
28
|
+
# When only message is provided.
|
29
|
+
super(args[0])
|
30
|
+
elsif args.size == 2
|
31
|
+
# When only request and response provided, body is nil.
|
32
|
+
@request = args[0]
|
33
|
+
@response = args[1]
|
34
|
+
@body = nil
|
35
|
+
super()
|
36
|
+
elsif args.size == 3
|
37
|
+
# When request, response and body were provided.
|
38
|
+
@request = args[0]
|
39
|
+
@response = args[1]
|
40
|
+
@body = args[2]
|
41
|
+
super()
|
42
|
+
elsif args.size == 4
|
43
|
+
# When request, response, body and message were provided.
|
44
|
+
@request = args[0]
|
45
|
+
@response = args[1]
|
46
|
+
@body = args[2]
|
47
|
+
super(args[3])
|
48
|
+
else
|
49
|
+
fail ArgumentError, 'Invalid number of arguments was provided, valid number: 1, 2, 3 or 4'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRest
|
6
|
+
#
|
7
|
+
# Class which represents the data received and deserialized from server.
|
8
|
+
#
|
9
|
+
class HttpOperationResponse
|
10
|
+
|
11
|
+
# @return [Net::HTTPRequest] the HTTP request object.
|
12
|
+
attr_accessor :request
|
13
|
+
|
14
|
+
# @return [Net::HTTPResponse] the HTTP response object.
|
15
|
+
attr_accessor :response
|
16
|
+
|
17
|
+
# @return [String] the HTTP response body.
|
18
|
+
attr_accessor :body
|
19
|
+
|
20
|
+
#
|
21
|
+
# Creates and initialize new instance of the HttpOperationResponse class.
|
22
|
+
# @param [Net::HTTPRequest] request the HTTP request object.
|
23
|
+
# @param [Net::HTTPResponse] response the HTTP response object.
|
24
|
+
# @param [String] body the HTTP response body.
|
25
|
+
def initialize(request, response, body = nil)
|
26
|
+
@request = request
|
27
|
+
@response = response
|
28
|
+
@body = body
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRest
|
6
|
+
#
|
7
|
+
# Class which represents an general exception for REST client.
|
8
|
+
#
|
9
|
+
class RestError < StandardError
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRest
|
6
|
+
#
|
7
|
+
# Class which handles retry policy.
|
8
|
+
#
|
9
|
+
class RetryPolicyMiddleware < Faraday::Response::Middleware
|
10
|
+
#
|
11
|
+
# Initializes a new instance of the RetryPolicyMiddleware class.
|
12
|
+
#
|
13
|
+
def initialize(app, options = {})
|
14
|
+
@times = options[:times] || 5
|
15
|
+
@delay = options[:delay] || 0.01
|
16
|
+
|
17
|
+
super(app)
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# Performs request and response processing.
|
22
|
+
#
|
23
|
+
def call(request_env)
|
24
|
+
request_body = request_env[:body]
|
25
|
+
|
26
|
+
begin
|
27
|
+
request_env[:body] = request_body
|
28
|
+
|
29
|
+
@app.call(request_env).on_complete do |response_env|
|
30
|
+
status_code = response_env.status
|
31
|
+
|
32
|
+
if @times > 0 && (status_code == 408 || (status_code >= 500 && status_code != 501 && status_code != 505))
|
33
|
+
sleep @delay
|
34
|
+
fail 'faraday_retry'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
rescue Exception => e
|
38
|
+
raise e if e.message != 'faraday_retry'
|
39
|
+
@times = @times - 1
|
40
|
+
retry
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRest
|
6
|
+
#
|
7
|
+
# Class which keeps the auxiliary for (de)serializing JSON requests and responses from server.
|
8
|
+
#
|
9
|
+
class Serialization
|
10
|
+
|
11
|
+
#
|
12
|
+
# Deserializes given string value into Ruby Date object.
|
13
|
+
# @param [String] string_value string value to deserialize.
|
14
|
+
#
|
15
|
+
# @return [Date] deserialized Date object.
|
16
|
+
def self.deserialize_date(string_value)
|
17
|
+
result = Timeliness.parse(string_value, :strict => true)
|
18
|
+
fail DeserializationError.new('Error occured in deserializing the response', nil, nil, string_value) if result.nil?
|
19
|
+
return ::Date.parse(result.to_s)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRest
|
6
|
+
#
|
7
|
+
# Class which represents a point of access to the REST API.
|
8
|
+
#
|
9
|
+
class ServiceClient
|
10
|
+
|
11
|
+
# @return [MsRest::ServiceClientCredentials] the credentials object.
|
12
|
+
attr_accessor :credentials
|
13
|
+
|
14
|
+
#
|
15
|
+
# Creates and initialize new instance of the ServiceClient class.
|
16
|
+
#
|
17
|
+
# @param credentials [MsRest::ServiceClientCredentials] credentials to authorize
|
18
|
+
# HTTP requests made by the service client.
|
19
|
+
# @param options additional parameters for the HTTP request (not implemented yet).
|
20
|
+
#
|
21
|
+
def initialize(credentials, options = nil)
|
22
|
+
@credentials = credentials
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRest
|
6
|
+
#
|
7
|
+
# Class which represents an error meaning that invalid Model object was created by user or provided from server.
|
8
|
+
#
|
9
|
+
class ValidationError < RestError
|
10
|
+
end
|
11
|
+
end
|
data/ms_rest.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
2
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
3
|
+
|
4
|
+
# coding: utf-8
|
5
|
+
lib = File.expand_path('../lib', __FILE__)
|
6
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
7
|
+
require 'ms_rest/version'
|
8
|
+
|
9
|
+
Gem::Specification.new do |spec|
|
10
|
+
spec.name = 'ms_rest'
|
11
|
+
spec.version = MsRest::VERSION
|
12
|
+
spec.authors = 'Microsoft Corporation'
|
13
|
+
spec.email = 'azsdkteam@microsoft.com'
|
14
|
+
|
15
|
+
spec.summary = %q{Azure Client Library for Ruby.}
|
16
|
+
spec.description = %q{Azure Client Library for Ruby.}
|
17
|
+
spec.homepage = 'https://rubygems.org/gems/azure'
|
18
|
+
spec.license = 'MIT'
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
spec.bindir = 'bin'
|
22
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.required_ruby_version = '>= 1.9.3'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.3.0'
|
30
|
+
|
31
|
+
spec.add_runtime_dependency 'json', '~> 1.8.3'
|
32
|
+
spec.add_runtime_dependency 'timeliness', '~> 0.3.7'
|
33
|
+
spec.add_runtime_dependency 'concurrent-ruby', ['>= 1.0.0.pre1', '<2']
|
34
|
+
spec.add_runtime_dependency 'faraday', '~> 0.9.1'
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ms_rest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Microsoft Corporation
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-28 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.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.3.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.3.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.8.3
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.8.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: timeliness
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.3.7
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.3.7
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: concurrent-ruby
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.0.0.pre1
|
90
|
+
- - "<"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '2'
|
93
|
+
type: :runtime
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 1.0.0.pre1
|
100
|
+
- - "<"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '2'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: faraday
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.9.1
|
110
|
+
type: :runtime
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 0.9.1
|
117
|
+
description: Azure Client Library for Ruby.
|
118
|
+
email: azsdkteam@microsoft.com
|
119
|
+
executables: []
|
120
|
+
extensions: []
|
121
|
+
extra_rdoc_files: []
|
122
|
+
files:
|
123
|
+
- ".gitignore"
|
124
|
+
- ".travis.yml"
|
125
|
+
- Gemfile
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- lib/ms_rest.rb
|
130
|
+
- lib/ms_rest/credentials/basic_authentication_credentials.rb
|
131
|
+
- lib/ms_rest/credentials/service_client_credentials.rb
|
132
|
+
- lib/ms_rest/credentials/string_token_provider.rb
|
133
|
+
- lib/ms_rest/credentials/token_credentials.rb
|
134
|
+
- lib/ms_rest/credentials/token_provider.rb
|
135
|
+
- lib/ms_rest/deserialization_error.rb
|
136
|
+
- lib/ms_rest/http_operation_error.rb
|
137
|
+
- lib/ms_rest/http_operation_response.rb
|
138
|
+
- lib/ms_rest/rest_error.rb
|
139
|
+
- lib/ms_rest/retry_policy_middleware.rb
|
140
|
+
- lib/ms_rest/serialization.rb
|
141
|
+
- lib/ms_rest/service_client.rb
|
142
|
+
- lib/ms_rest/validation_error.rb
|
143
|
+
- lib/ms_rest/version.rb
|
144
|
+
- ms_rest.gemspec
|
145
|
+
homepage: https://rubygems.org/gems/azure
|
146
|
+
licenses:
|
147
|
+
- MIT
|
148
|
+
metadata: {}
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: 1.9.3
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 2.4.6
|
166
|
+
signing_key:
|
167
|
+
specification_version: 4
|
168
|
+
summary: Azure Client Library for Ruby.
|
169
|
+
test_files: []
|