Module: Scribd::Security

Defined in:
lib/scribd/security.rb

Overview

Contains methods for working with iPaper Secure. For more information about iPaper Secure, see the online API documentation.

Class Method Summary collapse

Class Method Details

.document_access_list(document) ⇒ Array<String>

Returns a list of user identifiers that are allowed to access a given document. See the iPaper Secure online documentation for more information.

document ID.

Parameters:

Returns:

  • (Array<String>)

    An array of user identifiers.

See Also:



80
81
82
83
84
85
# File 'lib/scribd/security.rb', line 80

def self.document_access_list(document)
  response = API.instance.send_request('security.getDocumentAccessList', :doc_id => (document.kind_of?(Scribd::Document) ? document.id : document))
  acl = Array.new
  response.get_elements('/rsp/resultset/result/user_identifier').each { |tag| acl << tag.text }
  return acl
end

.grant_access(user_identifier, document = nil) ⇒ Object

Grants a user access to a Document. The user is referenced by his identifier (as used in the iPaper Secure embed code). If no document is provided, globally grants this user access to all documents.

code. (See the online iPaper Secure documentation.) this user access to all documents. Otherwise, grants this user access to one document specified by ID or Document instance.

Parameters:

  • user_identifier (String)

    The user identifier as used in your embed

  • document (Scribd::Document, #to_i, nil) (defaults to: nil)

    If @nil@, globally grants

Raises:

  • (ArgumentError)

    If an invalid value for @document@ is provided.

See Also:



20
21
22
# File 'lib/scribd/security.rb', line 20

def self.grant_access(user_identifier, document=nil)
  set_access user_identifier, true, document
end

.revoke_access(user_identifier, document = nil) ⇒ Object

Revokes from a user access to a Document. The user is referenced by his identifier (as used in the iPaper Secure embed code). If no document is provided, globally revokes access to all documents from this user.

code. (See the online iPaper Secure documentation.) access to all documents from this user. Otherwise, revokes access to one document specified by ID or Document instance.

Parameters:

  • user_identifier (String)

    The user identifier as used in your embed

  • document (Scribd::Document, #to_i, nil) (defaults to: nil)

    If @nil@, globally revokes

Raises:

  • (ArgumentError)

    If an invalid value for @document@ is provided.

See Also:



36
37
38
# File 'lib/scribd/security.rb', line 36

def self.revoke_access(user_identifier, document=nil)
  set_access user_identifier, false, document
end

.set_access(user_identifier, access_allowed, document = nil) ⇒ Object

Sets whether a user has access to a Document. The user is referenced by his identifier (as used in the iPaper Secure embed code). If no document is provided, globally sets access to all documents for this user.

code. (See the online iPaper Secure documentation.) revokes access. access to all documents for this user. Otherwise, sets access to one document specified by ID or Document instance.

Parameters:

  • user_identifier (String)

    The user identifier as used in your embed

  • access_allowed (true, false)

    If @true@, grants access; if @false@,

  • document (Scribd::Document, #to_i, nil) (defaults to: nil)

    If @nil@, globally sets

Raises:

  • (ArgumentError)

    If an invalid value for @document@ is provided.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/scribd/security.rb', line 53

def self.set_access(user_identifier, access_allowed, document=nil)
  allow_value = (access_allowed ? 1 : 0)
  
  if document.nil? then
    API.instance.send_request('security.setAccess', :user_identifier => user_identifier, :allowed => allow_value)
    return
  end
  
  API.instance.send_request('security.setAccess', :user_identifier => user_identifier, :allowed => allow_value, :doc_id => (
    if document.kind_of?(Scribd::Document) then
      document.id
    elsif document.respond_to?(:to_i) then
      document.to_i
    else
      raise ArgumentError, "document must be a Scribd::Document, a document ID, or nil"
    end
  ))
end

.user_access_list(user_identifier) ⇒ Array<Scribd::Document>

Returns a list of documents that a user can view. The user is identified by his user identifier. See the iPaper Secure online documentation for more information.

access.

Parameters:

  • user_identifier (String)

    The user identifier.

Returns:



95
96
97
98
99
100
# File 'lib/scribd/security.rb', line 95

def self.user_access_list(user_identifier)
  response = API.instance.send_request('security.getUserAccessList', :user_identifier => user_identifier)
  acl = Array.new
  response.get_elements('/rsp/resultset/result').each { |tag| acl << Scribd::Document.new(:xml => tag) }
  return acl
end