Class: Nextcloud::Ocs::App

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

Overview

Application class used for interfering with app specific actions

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, appid = nil) ⇒ App

Application initializer

Parameters:

  • api (Object)

    Api instance

  • appid (Integer, nil) (defaults to: nil)

    Application identifier


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

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

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

Instance Attribute Details

#appidInteger

Returns Application identifier.

Returns:

  • (Integer)

    Application 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
88
# File 'lib/nextcloud/ocs/app.rb', line 9

class App < OcsApi
  include Helpers

  attr_accessor :meta, :appid

  # Application initializer
  #
  # @param api [Object] Api instance
  # @param appid [Integer,nil] Application identifier
  def initialize(args, appid = nil)
    @appid = appid if appid

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

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

  # List enabled applications
  #
  # @return [Array] List of applications that are enabled on an instance
  def enabled
    filter("enabled")
  end

  # List disabled applications
  #
  # @return [Array] List of applications that are disabled on an instance
  def disabled
    filter("disabled")
  end

  # Get information about an applicaiton
  #
  # @param appid [Integer] Application identifier
  # @return [Hash] Application information
  def find(appid)
    response = @api.request(:get, "apps/#{appid}")
    h = doc_to_hash(response, "//data")["data"]
    add_meta(response, h)
  end

  # Enable an application
  #
  # @return [Object] Instance with meta response
  def enable
    response = @api.request(:post, "apps/#{@appid}")
    (@meta = get_meta(response)) && self
  end

  # Disable an application
  #
  # @return [Object] Instance with meta response
  def disable
    response = @api.request(:delete, "apps/#{@appid}")
    (@meta = get_meta(response)) && self
  end

  private

  # Retrieve enabled or disabled applications
  #
  # @param filter [String] Either enabled or disabled
  # @return [Array] List of applications with meta method
  def filter(filter)
    response = @api.request(:get, "apps?filter=#{filter}")
    parse_with_meta(response, "//data/apps/element")
  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
88
# File 'lib/nextcloud/ocs/app.rb', line 9

class App < OcsApi
  include Helpers

  attr_accessor :meta, :appid

  # Application initializer
  #
  # @param api [Object] Api instance
  # @param appid [Integer,nil] Application identifier
  def initialize(args, appid = nil)
    @appid = appid if appid

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

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

  # List enabled applications
  #
  # @return [Array] List of applications that are enabled on an instance
  def enabled
    filter("enabled")
  end

  # List disabled applications
  #
  # @return [Array] List of applications that are disabled on an instance
  def disabled
    filter("disabled")
  end

  # Get information about an applicaiton
  #
  # @param appid [Integer] Application identifier
  # @return [Hash] Application information
  def find(appid)
    response = @api.request(:get, "apps/#{appid}")
    h = doc_to_hash(response, "//data")["data"]
    add_meta(response, h)
  end

  # Enable an application
  #
  # @return [Object] Instance with meta response
  def enable
    response = @api.request(:post, "apps/#{@appid}")
    (@meta = get_meta(response)) && self
  end

  # Disable an application
  #
  # @return [Object] Instance with meta response
  def disable
    response = @api.request(:delete, "apps/#{@appid}")
    (@meta = get_meta(response)) && self
  end

  private

  # Retrieve enabled or disabled applications
  #
  # @param filter [String] Either enabled or disabled
  # @return [Array] List of applications with meta method
  def filter(filter)
    response = @api.request(:get, "apps?filter=#{filter}")
    parse_with_meta(response, "//data/apps/element")
  end
end

Instance Method Details

#disableObject

Disable an application

Returns:

  • (Object)

    Instance with meta response


73
74
75
76
# File 'lib/nextcloud/ocs/app.rb', line 73

def disable
  response = @api.request(:delete, "apps/#{@appid}")
  (@meta = get_meta(response)) && self
end

#disabledArray

List disabled applications

Returns:

  • (Array)

    List of applications that are disabled on an instance


48
49
50
# File 'lib/nextcloud/ocs/app.rb', line 48

def disabled
  filter("disabled")
end

#enableObject

Enable an application

Returns:

  • (Object)

    Instance with meta response


65
66
67
68
# File 'lib/nextcloud/ocs/app.rb', line 65

def enable
  response = @api.request(:post, "apps/#{@appid}")
  (@meta = get_meta(response)) && self
end

#enabledArray

List enabled applications

Returns:

  • (Array)

    List of applications that are enabled on an instance


41
42
43
# File 'lib/nextcloud/ocs/app.rb', line 41

def enabled
  filter("enabled")
end

#find(appid) ⇒ Hash

Get information about an applicaiton

Parameters:

  • appid (Integer)

    Application identifier

Returns:

  • (Hash)

    Application information


56
57
58
59
60
# File 'lib/nextcloud/ocs/app.rb', line 56

def find(appid)
  response = @api.request(:get, "apps/#{appid}")
  h = doc_to_hash(response, "//data")["data"]
  add_meta(response, h)
end

#set(appid) ⇒ Obeject

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

Parameters:

  • userid (String)

    User identifier

Returns:

  • (Obeject)

    self


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

def set(appid)
  @appid = appid
  self
end