DistelliClientFramework 1.1 → 1.2
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/lib/distelli/clientframework.rb +42 -25
- metadata +3 -3
@@ -62,10 +62,10 @@ module Distelli
|
|
62
62
|
end
|
63
63
|
|
64
64
|
# Canonicalize the resource
|
65
|
-
if request_info.
|
65
|
+
if request_info.resource == nil
|
66
66
|
string_to_sign.push("")
|
67
67
|
else
|
68
|
-
string_to_sign.push(request_info.
|
68
|
+
string_to_sign.push(request_info.resource)
|
69
69
|
end
|
70
70
|
|
71
71
|
sorted_params = Array.new
|
@@ -122,15 +122,30 @@ module Distelli
|
|
122
122
|
|
123
123
|
end
|
124
124
|
|
125
|
+
private
|
126
|
+
def get_netloc(endpoint)
|
127
|
+
uriparse_result = URI.parse(endpoint)
|
128
|
+
netloc = uriparse_result.host
|
129
|
+
scheme = uriparse_result.scheme
|
130
|
+
port = uriparse_result.port
|
131
|
+
if port != nil
|
132
|
+
if scheme == "http" and port != 80
|
133
|
+
netloc = netloc+":"+port.to_s
|
134
|
+
else
|
135
|
+
netloc = netloc+":"+port
|
136
|
+
end
|
137
|
+
end
|
138
|
+
if scheme != nil and scheme.length() > 0
|
139
|
+
return scheme+"://"+netloc
|
140
|
+
end
|
141
|
+
return netloc
|
142
|
+
end
|
143
|
+
|
125
144
|
def execute(request_info)
|
126
145
|
if @endpoint == nil
|
127
146
|
raise ClientException.new("Invalid endpoint: "+@endpoint.to_s)
|
128
147
|
end
|
129
|
-
@logger.debug("Executing request to endpoint: "+@endpoint.to_s)
|
130
|
-
# uri_str = @endpoint
|
131
|
-
# if request_info.resource_uri != nil
|
132
|
-
# uri_str = uri_str+request_info.resource_uri
|
133
|
-
# end
|
148
|
+
# @logger.debug("Executing request to endpoint: "+@endpoint.to_s)
|
134
149
|
|
135
150
|
request_info.add_header(ServiceConstants::OPERATION_HEADER, request_info.operation)
|
136
151
|
request_info.add_header(ServiceConstants::CONTENT_TYPE_HEADER, request_info.content_type)
|
@@ -154,10 +169,21 @@ module Distelli
|
|
154
169
|
request_info.add_header(ServiceConstants::DATE_HEADER, cur_time.strftime("%a, %d %b %Y %H:%M:%S %z"))
|
155
170
|
|
156
171
|
# Create the URI
|
157
|
-
|
172
|
+
endpoint = get_netloc(@endpoint)
|
173
|
+
if request_info.resource == nil
|
174
|
+
request_info.resource = "/"
|
175
|
+
end
|
158
176
|
|
159
|
-
|
177
|
+
query_string = request_info.get_query_string()
|
178
|
+
if query_string == nil
|
179
|
+
uri = URI.join(endpoint.to_s, request_info.resource.to_s)
|
180
|
+
else
|
181
|
+
uri = URI.join(endpoint.to_s, request_info.resource.to_s, query_string.to_s)
|
182
|
+
end
|
160
183
|
|
184
|
+
@logger.debug("Executing request to [#{endpoint}], [#{request_info.resource}] uri: "+uri.to_s)
|
185
|
+
|
186
|
+
# TODO: Set the Content-MD5 header
|
161
187
|
# Set the authentication headers
|
162
188
|
if @credentials != nil
|
163
189
|
signer = RequestSigner.new
|
@@ -278,14 +304,14 @@ module Distelli
|
|
278
304
|
end
|
279
305
|
|
280
306
|
class RequestInfo
|
281
|
-
attr_accessor :query_params, :headers, :
|
307
|
+
attr_accessor :query_params, :headers, :resource, :operation, :request_id, :request, :request_bytes
|
282
308
|
VALID_CONTENT_TYPES = Set.new [ServiceConstants::CONTENT_TYPE_JSON, ServiceConstants::CONTENT_TYPE_XML, ServiceConstants::CONTENT_TYPE_OCTET_STREAM]
|
283
309
|
VALID_HTTP_METHODS = Set.new [ServiceConstants::HTTP_METHOD_GET, ServiceConstants::HTTP_METHOD_PUT, ServiceConstants::HTTP_METHOD_POST, ServiceConstants::HTTP_METHOD_DELETE]
|
284
310
|
VALID_RESPONSE_TYPES = Set.new [ServiceConstants::RESPONSE_TYPE_XML, ServiceConstants::RESPONSE_TYPE_JSON]
|
285
311
|
def initialize()
|
286
312
|
@query_params = Hash.new
|
287
313
|
@headers = Hash.new
|
288
|
-
@
|
314
|
+
@resource = "/"
|
289
315
|
@operation = nil
|
290
316
|
@request_id = nil
|
291
317
|
@content_type = ServiceConstants::CONTENT_TYPE_JSON
|
@@ -295,26 +321,17 @@ module Distelli
|
|
295
321
|
@response_type = ServiceConstants::RESPONSE_TYPE_JSON
|
296
322
|
end
|
297
323
|
|
298
|
-
|
299
|
-
# and the resource_uri and adding the query params
|
300
|
-
def get_uri(endpoint)
|
301
|
-
uriparse_result = URI.parse(endpoint)
|
302
|
-
uri_str = endpoint
|
303
|
-
resource_uri = uriparse_result.path
|
304
|
-
if resource_uri == nil or resource_uri.length() == 0
|
305
|
-
resource_uri = "/"
|
306
|
-
uri_str = endpoint+resource_uri
|
307
|
-
end
|
308
|
-
|
309
|
-
@resource_uri = resource_uri
|
310
|
-
# now build the query string
|
324
|
+
def get_query_string()
|
311
325
|
query_param_list = Array.new
|
312
326
|
@query_params.each_pair do |k,v|
|
313
327
|
v.each do |x|
|
314
328
|
query_param_list.push(k+'='+x)
|
315
329
|
end
|
316
330
|
end
|
317
|
-
|
331
|
+
if query_param_list.length() > 0
|
332
|
+
return '?'+query_param_list.join('&')
|
333
|
+
end
|
334
|
+
return nil
|
318
335
|
end
|
319
336
|
|
320
337
|
#Lets implement the to_s method of the RequestInfo
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: DistelliClientFramework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: DistelliServiceMarshallers
|
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
56
56
|
rubyforge_project:
|
57
|
-
rubygems_version: 1.8.
|
57
|
+
rubygems_version: 1.8.24
|
58
58
|
signing_key:
|
59
59
|
specification_version: 3
|
60
60
|
summary: Distelli Client classes and marshallers for Ruby Clients
|