Class: Ketchup::Note

Inherits:
Object
  • Object
show all
Defined in:
lib/ketchup/note.rb

Overview

Represents a note for list/agenda item in a meeting. Only the content is editable.

If you want to change the order of notes, you can do that using Ketchup::NoteArray (the item’s note array).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, item, params = {}) ⇒ Note

Create a new note for a given item, using an existing api connection. You generally won’t want to call this yourself - the better interface to create new notes is via a item’s note array.

However, if you are doing some internal hacking, it’s worth noting that all keys for parameters in the hash should be strings, not symbols.

Examples:

Ketchup::Note.new api, item, 'content' => "Motion passed."

Parameters:

  • api (Ketchup::API)

    The API connection

  • item (Ketchup::Item)

    The item the note will belong to

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

    Any other details for the note.

See Also:



28
29
30
31
32
33
# File 'lib/ketchup/note.rb', line 28

def initialize(api, item, params = {})
  @api  = api
  @item = item
  
  overwrite params
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



8
9
10
# File 'lib/ketchup/note.rb', line 8

def api
  @api
end

#contentObject

Returns the value of attribute content.



10
11
12
# File 'lib/ketchup/note.rb', line 10

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



8
9
10
# File 'lib/ketchup/note.rb', line 8

def created_at
  @created_at
end

#itemObject (readonly)

Returns the value of attribute item.



8
9
10
# File 'lib/ketchup/note.rb', line 8

def item
  @item
end

#item_idObject (readonly)

Returns the value of attribute item_id.



8
9
10
# File 'lib/ketchup/note.rb', line 8

def item_id
  @item_id
end

#positionObject (readonly)

Returns the value of attribute position.



8
9
10
# File 'lib/ketchup/note.rb', line 8

def position
  @position
end

#shortcode_urlObject (readonly)

Returns the value of attribute shortcode_url.



8
9
10
# File 'lib/ketchup/note.rb', line 8

def shortcode_url
  @shortcode_url
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



8
9
10
# File 'lib/ketchup/note.rb', line 8

def updated_at
  @updated_at
end

Instance Method Details

#destroyObject

Deletes the note from the server. If the note has never been saved, this method will do nothing at all.



57
58
59
60
61
# File 'lib/ketchup/note.rb', line 57

def destroy
  return if new_record?
  
  @api.delete "/notes/#{shortcode_url}.json"
end

#new_record?Boolean

Indicates whether the note exists on the server yet.

Returns:

  • (Boolean)

    True if the note does not exist on the server.



39
40
41
# File 'lib/ketchup/note.rb', line 39

def new_record?
  shortcode_url.nil?
end

#saveObject

Saves the note to the server, whether it’s a new note or an existing one.



45
46
47
48
49
50
51
52
# File 'lib/ketchup/note.rb', line 45

def save
  if new_record?
    overwrite @api.post("/items/#{item.shortcode_url}/notes.json",
      'content' => content)
  else
    overwrite @api.put("/notes/#{shortcode_url}.json", 'content' => content)
  end
end