ms_rest 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 060e261ab92aea964d4856431880cd5ac125fb26
4
- data.tar.gz: 377357c01284a7018d058a680c6ed61d8af5aa6e
3
+ metadata.gz: 79f1ffca11820b2b12a6ba633fb3badc65ee8a83
4
+ data.tar.gz: bae2d6d21cb360239b38a562a36fb68c2adee019
5
5
  SHA512:
6
- metadata.gz: c6fd1d63bf2979d32807251feed857142603b8c82f21d5e9a9ec3867c45a4f8f4773c57fd3dbb6b5d716577e11f5b9a632a21f5e154d2eddc9cc097b2ad71198
7
- data.tar.gz: bdd7d2b73039946ba06a920e0f25b5998f4fe853b763a7a65950a447aba30ffee9b606d31a6f710fc23b9510b72d646ba742bee0d4008755538ef04089c538d0
6
+ metadata.gz: 68352aac8266a90025c1a3fe61bd64318bdbc7a11a5c80b793699611dcbc19bb07ae866271e6acbae14b643c9e2c200f2664eaa0f7b0b51f7778879575f8b6f9
7
+ data.tar.gz: e407d879d4884c9477cb01810f581c20a9e20b7d16b968484a36e14c9ef0871d089323bfe59157f636f7e9dee07654549660f2f5e1186eb6f5c24ea0b618f201
@@ -19,6 +19,7 @@ require 'ms_rest/deserialization_error.rb'
19
19
  require 'ms_rest/validation_error.rb'
20
20
  require 'ms_rest/serialization.rb'
21
21
  require 'ms_rest/http_operation_response'
22
+ require 'ms_rest/http_operation_request'
22
23
  require 'ms_rest/http_operation_error'
23
24
  require 'ms_rest/retry_policy_middleware'
24
25
  require 'ms_rest/service_client'
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  # Licensed under the MIT License. See License.txt in the project root for license information.
4
+ require 'json'
4
5
 
5
6
  module MsRest
6
7
  #
@@ -8,29 +9,34 @@ module MsRest
8
9
  #
9
10
  class DeserializationError < RestError
10
11
 
11
- # @return [String] the human readable description of error.
12
- attr_accessor :message
13
-
14
12
  # @return [String] the inner exception message.
15
13
  attr_accessor :exception_message
16
14
 
17
15
  # @return [String] the inner exception stacktrace.
18
16
  attr_accessor :exception_stacktrace
19
17
 
20
- # @return [String] server response which client was unable to parse.
21
- attr_accessor :response_body
18
+ # @return [MsRest::HttpOperationResponse] server response which client was unable to parse.
19
+ attr_accessor :result
22
20
 
23
21
  #
24
22
  # Creates and initialize new instance of the DeserializationError class.
25
23
  # @param [String] message message the human readable description of error.
26
24
  # @param [String] exception_message the inner exception stacktrace.
27
25
  # @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
26
+ # @param [MsRest::HttpOperationResponse] the request and response
27
+ def initialize(msg, exception_message, exception_stacktrace, result)
28
+ @msg = msg || self.class.name
31
29
  @exception_message = exception_message
32
30
  @exception_stacktrace = exception_stacktrace
33
- @response_body = response_body
31
+ @result = result
32
+ end
33
+
34
+ def to_json(*a)
35
+ {exception_message: exception_message, message: @msg, stacktrace: exception_stacktrace, result: result}.to_json(*a)
36
+ end
37
+
38
+ def to_s
39
+ JSON.pretty_generate(self)
34
40
  end
35
41
 
36
42
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  # Licensed under the MIT License. See License.txt in the project root for license information.
4
+ require 'json'
4
5
 
5
6
  module MsRest
6
7
  #
@@ -8,10 +9,10 @@ module MsRest
8
9
  #
9
10
  class HttpOperationError < RestError
10
11
 
11
- # @return [Net::HTTPRequest] the HTTP request object.
12
+ # @return [Hash] the HTTP request data (uri, body, headers).
12
13
  attr_accessor :request
13
14
 
14
- # @return [Net::HTTPResponse] the HTTP response object.
15
+ # @return [Faraday::Response] the HTTP response object.
15
16
  attr_accessor :response
16
17
 
17
18
  # @return [String] the HTTP response body.
@@ -19,13 +20,15 @@ module MsRest
19
20
 
20
21
  #
21
22
  # 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.
23
+ # @param [Hash] the HTTP request data (uri, body, headers).
24
+ # @param [Faraday::Response] the HTTP response object.
24
25
  # @param [String] body the HTTP response body.
25
26
  # @param [String] error message.
26
27
  def initialize(*args)
28
+ @msg = self.class.name
27
29
  if args.size == 1
28
30
  # When only message is provided.
31
+ @msg = args[0]
29
32
  super(args[0])
30
33
  elsif args.size == 2
31
34
  # When only request and response provided, body is nil.
@@ -44,11 +47,25 @@ module MsRest
44
47
  @request = args[0]
45
48
  @response = args[1]
46
49
  @body = args[2]
50
+ @msg = args[3]
47
51
  super(args[3])
48
52
  else
49
53
  fail ArgumentError, 'Invalid number of arguments was provided, valid number: 1, 2, 3 or 4'
50
54
  end
51
55
  end
56
+
57
+ def to_json(*a)
58
+ res_dict = response ? { body: response.body, headers: response.headers, status: response.status } : nil
59
+ {message: @msg, request: request, response: res_dict}.to_json(*a)
60
+ end
61
+
62
+ def to_s
63
+ begin
64
+ JSON.pretty_generate(self)
65
+ rescue Exception => ex
66
+ "#{self.class.name} failed in \n\t#{backtrace.join("\n\t")}"
67
+ end
68
+ end
52
69
  end
53
70
 
54
71
  end
@@ -0,0 +1,119 @@
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 HttpOperationRequest
10
+
11
+ # @return [Hash] path parameters to be ERB::Util.url_encode encoded
12
+ attr_accessor :path_params
13
+
14
+ # @return [Hash] path parameters not to be ERB::Util.url_encode encoded
15
+ attr_accessor :skip_encoding_path_params
16
+
17
+ # @return [Hash] query parameters to be ERB::Util.url_encode encoded
18
+ attr_accessor :query_params
19
+
20
+ # @return [Hash] query parameters to be ERB::Util.url_encode encoded
21
+ attr_accessor :skip_encoding_query_params
22
+
23
+ # @return [String] base uri of the request
24
+ attr_accessor :base_uri
25
+
26
+ # @return [String] path template /{replace}/{url_param}
27
+ attr_accessor :path_template
28
+
29
+ # @return [Hash] request headers
30
+ attr_accessor :headers
31
+
32
+ # @return [String] http request method
33
+ attr_accessor :method
34
+
35
+ # @return [String] the HTTP response body.
36
+ attr_accessor :body
37
+
38
+ # @return [Array] the list of middlewares to apply to the Request
39
+ attr_accessor :middlewares
40
+
41
+ # @return [String] full - to log requests, responses and bodies, partial - just requests and responses without body
42
+ attr_accessor :log
43
+
44
+ # Creates and initialize new instance of the HttpOperationResponse class.
45
+ # @param [String|URI] base uri for requests
46
+ # @param [String] path template /{replace}/{url_param}
47
+ # @param [String] http method for the request
48
+ # @param [Hash] body the HTTP response body.
49
+ def initialize(base_uri, path_template, method, options = {})
50
+ fail 'path_template must not be nil' if path_template.nil?
51
+ fail 'method must not be nil' if method.nil?
52
+
53
+ @base_uri = base_uri || ''
54
+ @path_template = path_template
55
+ @method = method
56
+ @headers = {}
57
+
58
+ options.each do |k,v|
59
+ instance_variable_set("@#{k}", v) unless v.nil?
60
+ end
61
+ end
62
+
63
+ # Creates a promise which will execute the request. Block will yield the request for customization.
64
+ # @return [URI] body the HTTP response body.
65
+ def run_promise(&block)
66
+ Concurrent::Promise.new do
67
+ connection = Faraday.new(:url => base_uri) do |faraday|
68
+ middlewares.each{ |args| faraday.use(*args) }
69
+ faraday.adapter Faraday.default_adapter
70
+ logging = ENV['AZURE_HTTP_LOGGING'] || log
71
+ if logging
72
+ faraday.response :logger, nil, { :bodies => logging == 'full' }
73
+ end
74
+ end
75
+
76
+ connection.run_request(:"#{method}", build_path, body, headers) do |req|
77
+ req.params = query_params.reject{|_, v| v.nil?} unless query_params.nil?
78
+ yield(req) if block_given?
79
+ end
80
+ end
81
+ end
82
+
83
+
84
+ # Creates a path from the path template and the path_params and skip_encoding_path_params
85
+ # @return [URI] body the HTTP response body.
86
+ def build_path
87
+ template = path_template.dup
88
+ path_params.each{ |key, value| template["{#{key}}"] = ERB::Util.url_encode(value) } unless path_params.nil?
89
+ skip_encoding_path_params.each{ |key, value| template["{#{key}}"] = value } unless skip_encoding_path_params.nil?
90
+ path = URI.parse(template.gsub(/([^:])\/\//, '\1/'))
91
+ unless skip_encoding_query_params.nil?
92
+ path.query = [(path.query || ""), skip_encoding_query_params.reject{|_, v| v.nil?}.map{|k,v| "#{k}=#{v}"}].join('&')
93
+ end
94
+ path
95
+ end
96
+
97
+ def full_uri
98
+ URI.join(base_uri || '', build_path)
99
+ end
100
+
101
+ def to_json(*a)
102
+ {
103
+ base_uri: base_uri,
104
+ path_template: path_template,
105
+ method: method,
106
+ path_params: path_params,
107
+ skip_encoding_path_params: skip_encoding_path_params,
108
+ query_params: query_params,
109
+ skip_encoding_query_params: skip_encoding_query_params,
110
+ headers: headers,
111
+ body: body,
112
+ middlewares: middlewares,
113
+ log: log
114
+ }.to_json(*a)
115
+ end
116
+
117
+ end
118
+
119
+ end
@@ -8,10 +8,10 @@ module MsRest
8
8
  #
9
9
  class HttpOperationResponse
10
10
 
11
- # @return [Net::HTTPRequest] the HTTP request object.
11
+ # @param [MsRest::HttpOperationRequest] the HTTP request data.
12
12
  attr_accessor :request
13
13
 
14
- # @return [Net::HTTPResponse] the HTTP response object.
14
+ # @return [Faraday::Response] the HTTP response object.
15
15
  attr_accessor :response
16
16
 
17
17
  # @return [String] the HTTP response body.
@@ -19,14 +19,19 @@ module MsRest
19
19
 
20
20
  #
21
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.
22
+ # @param [MsRest::HttpOperationRequest] request the HTTP request object.
23
+ # @param [Faraday::Response] response the HTTP response object.
24
24
  # @param [String] body the HTTP response body.
25
25
  def initialize(request, response, body = nil)
26
26
  @request = request
27
27
  @response = response
28
28
  @body = body
29
29
  end
30
+
31
+ def to_json(*a)
32
+ res_dict = response ? { body: response.body, headers: response.headers, status: response.status } : nil
33
+ {response: res_dict, request: request}.to_json(*a)
34
+ end
30
35
 
31
36
  end
32
37
  end
@@ -3,5 +3,5 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for license information.
4
4
 
5
5
  module MsRest
6
- VERSION = '0.1.2'
6
+ VERSION = '0.2.0'
7
7
  end
@@ -26,10 +26,10 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_development_dependency 'bundler', '~> 1.9'
28
28
  spec.add_development_dependency 'rake', '~> 10.0'
29
- spec.add_development_dependency 'rspec', '~> 3.3.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.3'
30
30
 
31
31
  spec.add_runtime_dependency 'json', '~> 1.7'
32
- spec.add_runtime_dependency 'timeliness', '~> 0.3.7'
32
+ spec.add_runtime_dependency 'timeliness', '~> 0.3'
33
33
  spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
34
- spec.add_runtime_dependency 'faraday', '~> 0.9.1'
34
+ spec.add_runtime_dependency 'faraday', '~> 0.9'
35
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ms_rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Microsoft Corporation
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-23 00:00:00.000000000 Z
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.3.0
47
+ version: '3.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.3.0
54
+ version: '3.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: json
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.3.7
75
+ version: '0.3'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.3.7
82
+ version: '0.3'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: concurrent-ruby
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.9.1
103
+ version: '0.9'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.9.1
110
+ version: '0.9'
111
111
  description: Azure Client Library for Ruby.
112
112
  email: azsdkteam@microsoft.com
113
113
  executables: []
@@ -128,6 +128,7 @@ files:
128
128
  - lib/ms_rest/credentials/token_provider.rb
129
129
  - lib/ms_rest/deserialization_error.rb
130
130
  - lib/ms_rest/http_operation_error.rb
131
+ - lib/ms_rest/http_operation_request.rb
131
132
  - lib/ms_rest/http_operation_response.rb
132
133
  - lib/ms_rest/rest_error.rb
133
134
  - lib/ms_rest/retry_policy_middleware.rb
@@ -161,3 +162,4 @@ signing_key:
161
162
  specification_version: 4
162
163
  summary: Azure Client Library for Ruby.
163
164
  test_files: []
165
+ has_rdoc: