Class: GroupDocs::Document::Annotation

Inherits:
Api::Entity show all
Defined in:
lib/groupdocs/document/annotation.rb

Defined Under Namespace

Classes: Reply

Constant Summary collapse

TYPES =
{
  text:  0,
  area:  1,
  point: 2,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Api::Entity

#inspect, #to_hash

Constructor Details

#initialize(options = {}, &blk) ⇒ Annotation

Creates new GroupDocs::Document::Annotation.

Raises:

  • (ArgumentError)

    If document is not passed or is not an instance of GroupDocs::Document



53
54
55
56
57
# File 'lib/groupdocs/document/annotation.rb', line 53

def initialize(options = {}, &blk)
  super(options, &blk)
  document.is_a?(GroupDocs::Document) or raise ArgumentError,
    "You have to pass GroupDocs::Document object: #{document.inspect}."
end

Instance Attribute Details

#accessObject



29
30
31
# File 'lib/groupdocs/document/annotation.rb', line 29

def access
  @access
end

#boxObject



31
32
33
# File 'lib/groupdocs/document/annotation.rb', line 31

def box
  @box
end

#createdOnObject Also known as: created_on



25
26
27
# File 'lib/groupdocs/document/annotation.rb', line 25

def createdOn
  @createdOn
end

#documentObject



13
14
15
# File 'lib/groupdocs/document/annotation.rb', line 13

def document
  @document
end

#documentGuidObject Also known as: document_guid



21
22
23
# File 'lib/groupdocs/document/annotation.rb', line 21

def documentGuid
  @documentGuid
end

#guidObject



17
18
19
# File 'lib/groupdocs/document/annotation.rb', line 17

def guid
  @guid
end

#idObject



15
16
17
# File 'lib/groupdocs/document/annotation.rb', line 15

def id
  @id
end

#repliesObject



33
34
35
# File 'lib/groupdocs/document/annotation.rb', line 33

def replies
  @replies
end

#replyGuidObject Also known as: reply_guid



23
24
25
# File 'lib/groupdocs/document/annotation.rb', line 23

def replyGuid
  @replyGuid
end

#sessionGuidObject Also known as: session_guid



19
20
21
# File 'lib/groupdocs/document/annotation.rb', line 19

def sessionGuid
  @sessionGuid
end

#typeSymbol

Returns field type in human-readable format.

Returns:

  • (Symbol)


27
28
29
# File 'lib/groupdocs/document/annotation.rb', line 27

def type
  @type
end

Instance Method Details

#add_reply(reply) ⇒ Object

Adds reply to annotation.

Parameters:

Raises:

  • (ArgumentError)

    if reply is not GroupDocs::Document::Annotation::Reply object



126
127
128
129
130
131
132
# File 'lib/groupdocs/document/annotation.rb', line 126

def add_reply(reply)
  reply.is_a?(GroupDocs::Document::Annotation::Reply) or raise ArgumentError,
    "Reply should be GroupDocs::Document::Annotation::Reply object, received: #{reply.inspect}"

  @replies ||= Array.new
  @replies << reply
end

#collaborators_set!(emails, access = {}) ⇒ Array<GroupDocs::User> Also known as: collaborators=

Sets annotation collaborators to given emails.

Parameters:

  • emails (Array)

    List of collaborators’ email addresses

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

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:



168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/groupdocs/document/annotation.rb', line 168

def collaborators_set!(emails, access = {})
  json = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :PUT
    request[:path] = "/ant/{{client_id}}/files/#{document.file.guid}/collaborators"
    request[:request_body] = emails
  end.execute!

  json[:collaborators].map do |collaborator|
    User.new(collaborator)
  end
end

#create!(access = {}) ⇒ Object

Creates new annotation.

Examples:

document = GroupDocs::Document.find!(:name, 'CV.doc')
annotation = GroupDocs::Document::Annotation.new(document: document)
annotation.create!

Parameters:

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

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/groupdocs/document/annotation.rb', line 146

def create!(access = {})
  json = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :POST
    request[:path] = "/ant/{{client_id}}/files/#{document.file.guid}/annotations"
    request[:request_body] = to_hash
  end.execute!

  json.each do |field, value|
    send(:"#{field}=", value) if respond_to?(:"#{field}=")
  end
end

#remove!(access = {}) ⇒ Object

Removes annotation.

Parameters:

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

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


190
191
192
193
194
195
196
# File 'lib/groupdocs/document/annotation.rb', line 190

def remove!(access = {})
  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :DELETE
    request[:path] = "/ant/{{client_id}}/annotations/#{guid}"
  end.execute!
end

#replies!(options = {}, access = {}) ⇒ Array<GroupDocs::Document::Annotation::Reply>

Return an array of replies..

Parameters:

  • options (Hash) (defaults to: {})
  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (options):

  • :after (Time)

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:

Raises:

  • (ArgumentError)

    If :after option is passed but it’s not an instance of Time



210
211
212
# File 'lib/groupdocs/document/annotation.rb', line 210

def replies!(options = {}, access = {})
  Document::Annotation::Reply.get!(self, options, access)
end