DistelliClientFramework 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/distelli/clientframework.rb +12 -23
  2. metadata +2 -2
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'set'
4
- require 'logger'
4
+ require 'logging'
5
5
  require 'distelli/servicemarshallers'
6
6
  require 'securerandom'
7
7
  require 'net/http'
@@ -11,15 +11,6 @@ require 'openssl'
11
11
  require 'base64'
12
12
 
13
13
  module Distelli
14
- module Logging
15
- def logger
16
- Logging.logger
17
- end
18
-
19
- def self.logger
20
- @logger ||= Logger.new(STDOUT)
21
- end
22
- end
23
14
 
24
15
  class ClientException < StandardError
25
16
  end
@@ -33,8 +24,8 @@ module Distelli
33
24
  end
34
25
 
35
26
  class RequestSigner
36
- include Distelli::Logging
37
27
  def initialize()
28
+ @logger = Logging::Logger['RequestSigner']
38
29
  end
39
30
 
40
31
  def get_string_to_sign(request_info)
@@ -99,7 +90,7 @@ module Distelli
99
90
 
100
91
  def get_signature(secret_key, request_info)
101
92
  string_to_sign = get_string_to_sign(request_info)
102
- logger.debug("StringToSign:\n"+string_to_sign)
93
+ @logger.debug("StringToSign:\n"+string_to_sign)
103
94
  return hmacsha(secret_key, string_to_sign)
104
95
  end
105
96
 
@@ -111,13 +102,12 @@ module Distelli
111
102
  end
112
103
 
113
104
  class ClientBase
114
- include Distelli::Logging
115
105
  def initialize(credentials, endpoint=nil)
116
106
  @credentials = credentials
117
107
  @endpoint = endpoint
118
108
  @json_marshaller = JsonMarshaller.new
119
109
  @xml_marshaller = XmlMarshaller.new
120
- @logger = nil
110
+ @logger = Logging::Logger['ClientBase']
121
111
  end
122
112
 
123
113
  def set_endpoint(endpoint)
@@ -136,7 +126,7 @@ module Distelli
136
126
  if @endpoint == nil
137
127
  raise ClientException.new("Invalid endpoint: "+@endpoint.to_s)
138
128
  end
139
- logger.debug("Executing request to endpoint: "+@endpoint.to_s)
129
+ @logger.debug("Executing request to endpoint: "+@endpoint.to_s)
140
130
  # uri_str = @endpoint
141
131
  # if request_info.resource_uri != nil
142
132
  # uri_str = uri_str+request_info.resource_uri
@@ -179,15 +169,14 @@ module Distelli
179
169
 
180
170
  http_method = request_info.http_method
181
171
  http_client = Net::HTTP.new(uri.host, uri.port)
182
- http_client.set_debug_output($stdout)
183
172
  if http_method == ServiceConstants::HTTP_METHOD_GET
184
- logger.debug("Executing GET: "+request_info.to_s)
173
+ @logger.debug("Executing GET: "+request_info.to_s)
185
174
  # Create the http request with the URI, Query Params and Headers
186
175
  http_request = Net::HTTP::Get.new(uri.request_uri, request_info.headers)
187
176
  # Execute the request to get the response
188
177
  response = http_client.request(http_request)
189
178
  elsif http_method == ServiceConstants::HTTP_METHOD_POST
190
- logger.debug("Executing POST: "+request_info.to_s)
179
+ @logger.debug("Executing POST: "+request_info.to_s)
191
180
  payload = get_payload(request_info)
192
181
  # Create the http request with the URI, Query Params and Headers
193
182
  http_request = Net::HTTP::Post.new(uri.request_uri, request_info.headers)
@@ -196,7 +185,7 @@ module Distelli
196
185
  # Execute the request to get the response
197
186
  response = http_client.request(http_request)
198
187
  elsif http_method == ServiceConstants::HTTP_METHOD_PUT
199
- logger.debug("Executing PUT: "+request_info.to_s)
188
+ @logger.debug("Executing PUT: "+request_info.to_s)
200
189
  payload = get_payload(request_info)
201
190
  # Create the http request with the URI, Query Params and Headers
202
191
  http_request = Net::HTTP::Put.new(uri.request_uri, request_info.headers)
@@ -205,7 +194,7 @@ module Distelli
205
194
  # Execute the request to get the response
206
195
  response = http_client.request(http_request)
207
196
  elsif http_method == ServiceConstants::HTTP_METHOD_DELETE
208
- logger.debug("Executing DELETE: "+request_info.to_s)
197
+ @logger.debug("Executing DELETE: "+request_info.to_s)
209
198
  # Create the http request with the URI, Query Params and Headers
210
199
  http_request = Net::HTTP::Delete.new(uri.request_uri, request_info.headers)
211
200
  # Execute the request to get the response
@@ -225,11 +214,11 @@ module Distelli
225
214
  if request != nil
226
215
  if request_info.content_type == nil or request_info.content_type == ServiceConstants::CONTENT_TYPE_JSON
227
216
  marshalled_payload = @json_marshaller.marshall(request)
228
- logger.debug("Marshalled Payload: "+marshalled_payload)
217
+ @logger.debug("Marshalled Payload: "+marshalled_payload)
229
218
  return marshalled_payload
230
219
  elsif request_info.content_type == ServiceConstants.CONTENT_TYPE_XML
231
220
  marshalled_payload = @xml_marshaller.marshall(request)
232
- logger.debug("Marshalled Payload: "+marshalled_payload)
221
+ @logger.debug("Marshalled Payload: "+marshalled_payload)
233
222
  return marshalled_payload
234
223
  end
235
224
  end
@@ -238,7 +227,7 @@ module Distelli
238
227
  def handle_response(response)
239
228
  http_status_code = response.code
240
229
  content_type = response[ServiceConstants::CONTENT_TYPE_HEADER]
241
- logger.debug("Received Response "+http_status_code.to_s+", Content-Type: "+content_type.to_s+", Payload: "+response.body.to_s)
230
+ @logger.debug("Received Response "+http_status_code.to_s+", Content-Type: "+content_type.to_s+", Payload: "+response.body.to_s)
242
231
  if http_status_code.to_i/100 != 2
243
232
  error = nil
244
233
  if content_type != nil
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.0'
4
+ version: '1.1'
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-11-19 00:00:00.000000000 Z
12
+ date: 2012-12-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: DistelliServiceMarshallers