lib/azure/core/service.rb in azure-0.7.0.pre vs lib/azure/core/service.rb in azure-0.7.0.pre2

- old
+ new

@@ -19,39 +19,22 @@ # A base class for Service implementations class Service # Create a new instance of the Service # - # host - String. The hostname. (optional, Default empty) - def initialize(host='') + # @param host [String] The hostname. (optional, Default empty) + # @param options [Hash] options including {:client} (optional, Default {}) + def initialize(host='', options = {}) @host = host + @client = options[:client] || Azure end - attr_accessor :host + attr_accessor :host, :client - def call(method, uri, body=nil, headers=nil) - if headers && !body.nil? - if headers['Content-Encoding'].nil? - headers['Content-Encoding'] = body.encoding.to_s - else - body.force_encoding(headers['Content-Encoding']) - end - end - - request = Core::Http::HttpRequest.new(method, uri, body) - request.headers.merge!(headers) if headers - - request.headers['connection'] = 'keep-alive' if request.respond_to? :headers - + def call(method, uri, body=nil, headers={}) + request = Core::Http::HttpRequest.new(method, uri, body: body, headers: headers, client: @client) yield request if block_given? - - response = request.call - - if !response.nil? && !response.body.nil? && response.headers['content-encoding'] - response.body.force_encoding(response.headers['content-encoding']) - end - - response + request.call end def generate_uri(path='', query={}) uri = URI.parse(File.join(host, path)) uri.query = URI.encode_www_form(query) unless query == nil or query.empty? \ No newline at end of file