Class: Nextcloud::Ocs::FileSharingApi::FederatedCloudShares

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/nextcloud/ocs/file_sharing_api.rb

Overview

Wrapper to Federated Cloud Sharing API

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

Constructor Details

#initialize(api) ⇒ FederatedCloudShares

Creates Federated Cloud Sharing class instance

Parameters:

  • api (Object)

    Api object



140
141
142
# File 'lib/nextcloud/ocs/file_sharing_api.rb', line 140

def initialize(api)
  @api = api
end

Instance Attribute Details

#metaHash

Returns Information about API response.

Returns:

  • (Hash)

    Information about API response



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/nextcloud/ocs/file_sharing_api.rb', line 132

class FederatedCloudShares
  include Helpers

  attr_accessor :meta

  # Creates Federated Cloud Sharing class instance
  #
  # @param api [Object] Api object
  def initialize(api)
    @api = api
  end

  # List accepted Federated Cloud Shares
  #
  # @return [Array] List of accepted Federated Cloud Shares
  def accepted
    response = @api.request(:get, "/remote_shares")
    h = doc_to_hash(response, "//data").try(:[], "data").try(:[], "element")
    h = [h] if h.class == Hash
    add_meta(response, h)
  end

  # List pending requests of Federated Cloud Shares
  #
  # @return [Array] List of pending Federated Cloud Shares
  def pending
    response = @api.request(:get, "/remote_shares/pending")
    h = doc_to_hash(response, "//data").try(:[], "data").try(:[], "element")
    h = [h] if h.class == Hash
    add_meta(response, h)
  end

  # Accept a request of a Federated Cloud Share
  #
  # @param shareid [Integer] Federated Cloud Share identifier
  # @return [Object] Instance with meta response
  def accept(shareid)
    response = @api.request(:post, "/remote_shares/pending/#{shareid}")
    (@meta = get_meta(response)) && self
  end

  # Decline a request of a Federated Cloud Share
  #
  # @param shareid [Integer] Federated Cloud Share identifier
  # @return [Object] Instance with meta response
  def decline(shareid)
    response = @api.request(:delete, "/remote_shares/pending/#{shareid}")
    (@meta = get_meta(response)) && self
  end

  # Delete an accepted Federated Cloud Share
  #
  # @param shareid [Integer] Federated Cloud Share identifier
  # @return [Object] Instance with meta response
  def destroy(shareid)
    response = @api.request(:delete, "/remote_shares/#{shareid}")
    (@meta = get_meta(response)) && self
  end

  # Information about accepted Federated Cloud Share
  #
  # @param shareid [Integer] Federated Cloud Share identifier
  # @return [Hash] Information about Federated Cloud Share with meta response
  def find(shareid)
    response = @api.request(:get, "/remote_shares/#{shareid}")
    h = doc_to_hash(response, "//data").try(:[], "data")
    add_meta(response, h)
  end
end

Instance Method Details

#accept(shareid) ⇒ Object

Accept a request of a Federated Cloud Share

Parameters:

  • shareid (Integer)

    Federated Cloud Share identifier

Returns:

  • (Object)

    Instance with meta response



168
169
170
171
# File 'lib/nextcloud/ocs/file_sharing_api.rb', line 168

def accept(shareid)
  response = @api.request(:post, "/remote_shares/pending/#{shareid}")
  (@meta = get_meta(response)) && self
end

#acceptedArray

List accepted Federated Cloud Shares

Returns:

  • (Array)

    List of accepted Federated Cloud Shares



147
148
149
150
151
152
# File 'lib/nextcloud/ocs/file_sharing_api.rb', line 147

def accepted
  response = @api.request(:get, "/remote_shares")
  h = doc_to_hash(response, "//data").try(:[], "data").try(:[], "element")
  h = [h] if h.class == Hash
  add_meta(response, h)
end

#decline(shareid) ⇒ Object

Decline a request of a Federated Cloud Share

Parameters:

  • shareid (Integer)

    Federated Cloud Share identifier

Returns:

  • (Object)

    Instance with meta response



177
178
179
180
# File 'lib/nextcloud/ocs/file_sharing_api.rb', line 177

def decline(shareid)
  response = @api.request(:delete, "/remote_shares/pending/#{shareid}")
  (@meta = get_meta(response)) && self
end

#destroy(shareid) ⇒ Object

Delete an accepted Federated Cloud Share

Parameters:

  • shareid (Integer)

    Federated Cloud Share identifier

Returns:

  • (Object)

    Instance with meta response



186
187
188
189
# File 'lib/nextcloud/ocs/file_sharing_api.rb', line 186

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

#find(shareid) ⇒ Hash

Information about accepted Federated Cloud Share

Parameters:

  • shareid (Integer)

    Federated Cloud Share identifier

Returns:

  • (Hash)

    Information about Federated Cloud Share with meta response



195
196
197
198
199
# File 'lib/nextcloud/ocs/file_sharing_api.rb', line 195

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

#pendingArray

List pending requests of Federated Cloud Shares

Returns:

  • (Array)

    List of pending Federated Cloud Shares



157
158
159
160
161
162
# File 'lib/nextcloud/ocs/file_sharing_api.rb', line 157

def pending
  response = @api.request(:get, "/remote_shares/pending")
  h = doc_to_hash(response, "//data").try(:[], "data").try(:[], "element")
  h = [h] if h.class == Hash
  add_meta(response, h)
end