Class: OvirtSDK4::BookmarksService

Inherits:
Service
  • Object
show all
Defined in:
lib/ovirtsdk4/services.rb,
lib/ovirtsdk4/services.rb

Instance Method Summary (collapse)

Instance Method Details

- (Bookmark) add(bookmark, opts = {})

Adds a new bookmark.

Parameters:

Returns:



3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
# File 'lib/ovirtsdk4/services.rb', line 3902

def add(bookmark, opts = {})
  if bookmark.is_a?(Hash)
    bookmark = OvirtSDK4::Bookmark.new(bookmark)
  end
  request = Request.new(:method => :POST, :path => @path)
  begin
    writer = XmlWriter.new(nil, true)
    BookmarkWriter.write_one(bookmark, writer, 'bookmark')
    request.body = writer.string
  ensure
    writer.close
  end
  response = @connection.send(request)
  case response.code
  when 201, 202
    begin
      reader = XmlReader.new(response.body)
      return BookmarkReader.read_one(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end

- (BookmarkService) bookmark_service(id)

Locates the bookmark service.

Parameters:

  • id (String)

    The identifier of the bookmark.

Returns:



3966
3967
3968
# File 'lib/ovirtsdk4/services.rb', line 3966

def bookmark_service(id)
  return BookmarkService.new(@connection, "#{@path}/#{id}")
end

- (Array<Bookmark>) list(opts = {})

Returns the representation of the object managed by this service.

Parameters:

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

    Additional options.

Options Hash (opts):

  • :max (Integer)

    Sets the maximum number of bookmarks to return. If not specified all the bookmarks are returned.

Returns:



3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
# File 'lib/ovirtsdk4/services.rb', line 3937

def list(opts = {})
  query = {}
  value = opts[:max]
  unless value.nil?
    value = Writer.render_integer(value)
    query['max'] = value
  end
  request = Request.new(:method => :GET, :path => @path, :query => query)
  response = @connection.send(request)
  case response.code
  when 200
    begin
      reader = XmlReader.new(response.body)
      return BookmarkReader.read_many(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end

- (Service) service(path)

Locates the service corresponding to the given path.

Parameters:

  • path (String)

    The path of the service.

Returns:

  • (Service)

    A reference to the service.



3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
# File 'lib/ovirtsdk4/services.rb', line 3977

def service(path)
  if path.nil? || path == ''
    return self
  end
  index = path.index('/')
  if index.nil?
    return bookmark_service(path)
  end
  return bookmark_service(path[0..(index - 1)]).service(path[(index +1)..-1])
end

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


3993
3994
3995
# File 'lib/ovirtsdk4/services.rb', line 3993

def to_s
  return "#<#{BookmarksService}:#{@path}>"
end