Class: Azure::Core::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/azure/core/service.rb

Overview

A base class for Service implementations

Direct Known Subclasses

FilteredService

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = '') ⇒ Service

Create a new instance of the Service

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



25
26
27
# File 'lib/azure/core/service.rb', line 25

def initialize(host='')
  @host = host
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



29
30
31
# File 'lib/azure/core/service.rb', line 29

def host
  @host
end

Instance Method Details

#call(method, uri, body = nil, headers = nil) {|request| ... } ⇒ Object

Yields:

  • (request)


31
32
33
34
35
36
37
38
39
40
# File 'lib/azure/core/service.rb', line 31

def call(method, uri, body=nil, headers=nil)
  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?

  request.call
end

#generate_uri(path = '', query = {}) ⇒ Object



42
43
44
45
46
# File 'lib/azure/core/service.rb', line 42

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