Class: Nextcloud::Ocs::Group

Inherits:
Nextcloud::OcsApi show all
Includes:
Helpers
Defined in:
lib/nextcloud/ocs/group.rb

Overview

Class with Nextcloud group operation features

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#add_meta, #doc_to_hash, #get_meta, #has_dav_errors, #parse_dav_response, #parse_with_meta, #path_from_href

Methods inherited from Nextcloud::OcsApi

#app, #file_sharing, #group, #user

Methods inherited from Api

#request

Constructor Details

#initialize(args, groupid = nil) ⇒ Group

Initializes a class

Parameters:

  • api (Object)

    Api instance

  • groupid (String, nil) (defaults to: nil)

    Group identifier



18
19
20
21
22
23
24
25
26
27
# File 'lib/nextcloud/ocs/group.rb', line 18

def initialize(args, groupid = nil)
  @groupid = groupid if groupid

  if args.class == Nextcloud::OcsApi
    @api = args
  else
    super(args)
    @api = self
  end
end

Instance Attribute Details

#groupidString?

Returns Group identifier.

Returns:

  • (String, nil)

    Group identifier



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/nextcloud/ocs/group.rb', line 9

class Group < OcsApi
  include Helpers

  attr_accessor :meta, :groupid

  # Initializes a class
  #
  # @param api [Object] Api instance
  # @param groupid [String,nil] Group identifier
  def initialize(args, groupid = nil)
    @groupid = groupid if groupid

    if args.class == Nextcloud::OcsApi
      @api = args
    else
      super(args)
      @api = self
    end
  end

  # Sets group (useful if class is initiated without OcsApi.group)
  #
  # @param userid [String] User identifier
  # @return [Obeject] self
  def set(groupid)
    @groupid = groupid
    self
  end

  # Search for a group
  #
  # @param str [String] Search query
  # @return [Array] Found groups list
  def search(str)
    response = @api.request(:get, "groups?search=#{str}")
    parse_with_meta(response, "//data/groups/element")
  end

  # List all groups
  #
  # @return [Array] All groups
  def all
    search("")
  end

  # Create a group
  #
  # @param groupid [String] Group identifier
  # @return [Object] Instance with meta information
  def create(groupid)
    response = @api.request(:post, "groups", groupid: groupid)
    (@meta = get_meta(response)) && self
  end

  # Get members of a group
  #
  # @return [Array] List of group members
  def members
    response = @api.request(:get, "groups/#{@groupid}")
    parse_with_meta(response, "//data/users/element")
  end

  # Get sub-admins of a group
  #
  # @return [Array] List of group sub-admins
  def subadmins
    response = @api.request(:get, "groups/#{@groupid}/subadmins")
    parse_with_meta(response, "//data/element")
  end

  # Remove a group
  #
  # @param groupid [String] Group identifier
  # @return [Object] Instance with meta information
  def destroy(groupid)
    response = @api.request(:delete, "groups/#{groupid}")
    (@meta = get_meta(response)) && self
  end
end

#metaHash

Returns Information about API response.

Returns:

  • (Hash)

    Information about API response



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/nextcloud/ocs/group.rb', line 9

class Group < OcsApi
  include Helpers

  attr_accessor :meta, :groupid

  # Initializes a class
  #
  # @param api [Object] Api instance
  # @param groupid [String,nil] Group identifier
  def initialize(args, groupid = nil)
    @groupid = groupid if groupid

    if args.class == Nextcloud::OcsApi
      @api = args
    else
      super(args)
      @api = self
    end
  end

  # Sets group (useful if class is initiated without OcsApi.group)
  #
  # @param userid [String] User identifier
  # @return [Obeject] self
  def set(groupid)
    @groupid = groupid
    self
  end

  # Search for a group
  #
  # @param str [String] Search query
  # @return [Array] Found groups list
  def search(str)
    response = @api.request(:get, "groups?search=#{str}")
    parse_with_meta(response, "//data/groups/element")
  end

  # List all groups
  #
  # @return [Array] All groups
  def all
    search("")
  end

  # Create a group
  #
  # @param groupid [String] Group identifier
  # @return [Object] Instance with meta information
  def create(groupid)
    response = @api.request(:post, "groups", groupid: groupid)
    (@meta = get_meta(response)) && self
  end

  # Get members of a group
  #
  # @return [Array] List of group members
  def members
    response = @api.request(:get, "groups/#{@groupid}")
    parse_with_meta(response, "//data/users/element")
  end

  # Get sub-admins of a group
  #
  # @return [Array] List of group sub-admins
  def subadmins
    response = @api.request(:get, "groups/#{@groupid}/subadmins")
    parse_with_meta(response, "//data/element")
  end

  # Remove a group
  #
  # @param groupid [String] Group identifier
  # @return [Object] Instance with meta information
  def destroy(groupid)
    response = @api.request(:delete, "groups/#{groupid}")
    (@meta = get_meta(response)) && self
  end
end

Instance Method Details

#allArray

List all groups

Returns:

  • (Array)

    All groups



50
51
52
# File 'lib/nextcloud/ocs/group.rb', line 50

def all
  search("")
end

#create(groupid) ⇒ Object

Create a group

Parameters:

  • groupid (String)

    Group identifier

Returns:

  • (Object)

    Instance with meta information



58
59
60
61
# File 'lib/nextcloud/ocs/group.rb', line 58

def create(groupid)
  response = @api.request(:post, "groups", groupid: groupid)
  (@meta = get_meta(response)) && self
end

#destroy(groupid) ⇒ Object

Remove a group

Parameters:

  • groupid (String)

    Group identifier

Returns:

  • (Object)

    Instance with meta information



83
84
85
86
# File 'lib/nextcloud/ocs/group.rb', line 83

def destroy(groupid)
  response = @api.request(:delete, "groups/#{groupid}")
  (@meta = get_meta(response)) && self
end

#membersArray

Get members of a group

Returns:

  • (Array)

    List of group members



66
67
68
69
# File 'lib/nextcloud/ocs/group.rb', line 66

def members
  response = @api.request(:get, "groups/#{@groupid}")
  parse_with_meta(response, "//data/users/element")
end

#search(str) ⇒ Array

Search for a group

Parameters:

  • str (String)

    Search query

Returns:

  • (Array)

    Found groups list



42
43
44
45
# File 'lib/nextcloud/ocs/group.rb', line 42

def search(str)
  response = @api.request(:get, "groups?search=#{str}")
  parse_with_meta(response, "//data/groups/element")
end

#set(groupid) ⇒ Obeject

Sets group (useful if class is initiated without OcsApi.group)

Parameters:

  • userid (String)

    User identifier

Returns:

  • (Obeject)

    self



33
34
35
36
# File 'lib/nextcloud/ocs/group.rb', line 33

def set(groupid)
  @groupid = groupid
  self
end

#subadminsArray

Get sub-admins of a group

Returns:

  • (Array)

    List of group sub-admins



74
75
76
77
# File 'lib/nextcloud/ocs/group.rb', line 74

def subadmins
  response = @api.request(:get, "groups/#{@groupid}/subadmins")
  parse_with_meta(response, "//data/element")
end