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 = '', options = {}) ⇒ Service

Create a new instance of the Service

Parameters:

  • host (String) (defaults to: '')

    The hostname. (optional, Default empty)

  • options (Hash) (defaults to: {})

    options including :client (optional, Default {})



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

def initialize(host='', options = {})
  @host = host
  @client = options[:client] || Azure
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



31
32
33
# File 'lib/azure/core/service.rb', line 31

def client
  @client
end

#hostObject

Returns the value of attribute host.



31
32
33
# File 'lib/azure/core/service.rb', line 31

def host
  @host
end

Instance Method Details

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

Yields:

  • (request)


33
34
35
36
37
# File 'lib/azure/core/service.rb', line 33

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?
  request.call
end

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



39
40
41
42
43
# File 'lib/azure/core/service.rb', line 39

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