class Azure::Core::Service

A base class for Service implementations

Attributes

host[RW]

Public Class Methods

new(host='') click to toggle source

Create a new instance of the Service

host - String. The hostname. (optional, Default empty)

# File lib/azure/core/service.rb, line 25
def initialize(host='')
  @host = host
end

Public Instance Methods

call(method, uri, body=nil, headers=nil) { |request| ... } click to toggle source
# File lib/azure/core/service.rb, line 31
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

  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
end
generate_uri(path='', query={}) click to toggle source
# File lib/azure/core/service.rb, line 56
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?
  uri
end