Class: Talis::Feeds::Annotation

Inherits:
Resource show all
Defined in:
lib/talis/feeds/annotation.rb

Overview

Represents an annotation, for example, a video resource comment.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

handle_response, new_req_id

Constructor Details

#initialize(data, user: nil) ⇒ Annotation

Creates a new annotation object. For internal use only, use create.

Parameters:

  • data (Hash)

    The incoming annotation data to construct a new annotation object with.

  • user (Talis::User) (defaults to: nil)

    (nil) The user that created the annotation. This will be nil for an annotation that has not been hydrated. Hydrated data is provided by feeds.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/talis/feeds/annotation.rb', line 16

def initialize(data, user: nil)
  # Symbolise all keys for consistency between what was provided
  # and what is returned.
  data = JSON.parse(JSON[data], symbolize_names: true)
  @id = data[:_id]
  @body = data[:hasBody]
  @target = data[:hasTarget].map { |target| underscore(target) }
  @annotated_by = data[:annotatedBy]
  @motivated_by = data[:motivatedBy]
  @expires_at = data[:expiresAt]
  @user = user
end

Instance Attribute Details

#annotated_byObject (readonly)

Returns the value of attribute annotated_by.



6
7
8
# File 'lib/talis/feeds/annotation.rb', line 6

def annotated_by
  @annotated_by
end

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/talis/feeds/annotation.rb', line 6

def body
  @body
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



6
7
8
# File 'lib/talis/feeds/annotation.rb', line 6

def expires_at
  @expires_at
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/talis/feeds/annotation.rb', line 6

def id
  @id
end

#motivated_byObject (readonly)

Returns the value of attribute motivated_by.



6
7
8
# File 'lib/talis/feeds/annotation.rb', line 6

def motivated_by
  @motivated_by
end

#targetObject (readonly)

Returns the value of attribute target.



6
7
8
# File 'lib/talis/feeds/annotation.rb', line 6

def target
  @target
end

#userObject (readonly)

Returns the value of attribute user.



6
7
8
# File 'lib/talis/feeds/annotation.rb', line 6

def user
  @user
end

Class Method Details

.create(opts) ⇒ Talis::Feeds::Annotation

Create a new annotation that is persisted.

Parameters:

  • opts (Hash)

    The annotation data used to create the annotation:

    request_id: 'optional unique ID for the remote request'
    body: {
      format: 'e.g: text/plain',
      type: 'e.g: Text',
      chars: 'annotation content',
      details: { # optional hash to provide additional details.
    },
    target: [
      {
        uri: 'location of target being annotated',
        as_referenced_by: 'optional reference location',
        fragment: 'optional fragment within location'
      }
    ]
    annotated_by: 'Talis user GUID performing the annotation',
    motivated_by: 'optional motivation string',
    expires_at: 'optional ISO 8601 date time string'
    

    }

Returns:

Raises:



62
63
64
65
66
67
# File 'lib/talis/feeds/annotation.rb', line 62

def create(opts)
  validate_annotation opts
  new handle_response(post_annotation(opts))
rescue SocketError
  raise Talis::ServerCommunicationError
end